Beispiel #1
0
 def exception_to_report_list(exception, file_type_code, file_path,
                              force_code, is_forced_or_warning):
     del file_type_code  # this is defined by the report code
     if isinstance(exception, InvalidLines):
         return [
             ReportItem(
                 severity=get_severity(force_code, is_forced_or_warning),
                 message=reports.messages.BoothConfigUnexpectedLines(
                     exception.args[0],
                     file_path,
                 ),
             )
         ]
     raise exception
Beispiel #2
0
def validate_stonith_watchdog_timeout(
    stonith_watchdog_timeout: str, force: bool = False
) -> reports.ReportItemList:
    """
    Check sbd status and config when user is setting stonith-watchdog-timeout
    Returns error message if the value is unacceptable, otherwise return nothing
    to set the property

    stonith_watchdog_timeout -- value to be validated
    """
    severity = reports.get_severity(reports.codes.FORCE, force)
    if _is_device_set_local():
        return (
            [
                reports.ReportItem(
                    severity,
                    reports.messages.StonithWatchdogTimeoutCannotBeSet(
                        reports.const.SBD_SET_UP_WITH_DEVICES
                    ),
                )
            ]
            if stonith_watchdog_timeout not in ["", "0"]
            else []
        )

    if stonith_watchdog_timeout in ["", "0"]:
        return [
            reports.ReportItem(
                severity,
                reports.messages.StonithWatchdogTimeoutCannotBeUnset(
                    reports.const.SBD_SET_UP_WITHOUT_DEVICES
                ),
            )
        ]
    return validate.ValidatorAll(
        [
            _StonithWatchdogTimeoutValidator(
                "stonith-watchdog-timeout",
                _get_local_sbd_watchdog_timeout(),
                severity=severity,
            )
        ]
    ).validate({"stonith-watchdog-timeout": stonith_watchdog_timeout})
Beispiel #3
0
def raw_file_error_report(
    error: RawFileError,
    force_code: Optional[reports.types.ForceCode] = None,
    is_forced_or_warning: bool = False,
) -> reports.ReportItem:
    """
    Translate a RawFileError instance to a report

    error -- an exception to be translated
    force_code -- is it a forcible error? by which code?
    is_forced_or_warning -- translate to a warning if True, error otherwise
    """
    return reports.ReportItem(
        severity=reports.get_severity(force_code, is_forced_or_warning),
        message=reports.messages.FileIoError(
            error.metadata.file_type_code,
            error.action,
            error.reason,
            # do not report real file path if we were working with a ghost file
            file_path=("" if isinstance(error, GhostFileError) else
                       error.metadata.path),
        ),
    )
Beispiel #4
0
    def validate_parameters_update(
        self,
        current_parameters: Mapping[str, str],
        new_parameters: Mapping[str, str],
        force: bool = False,
    ) -> reports.ReportItemList:
        # This is just a basic validation checking that required parameters are
        # set and all set parameters are known to an agent. Missing checks are:
        # 1. values checks - if a param is an integer, then "abc" is not valid
        # 2. warnings should be emitted when a deprecated param is set
        # 3. errors should be emitted when a deprecated parameter and a
        #    parameter obsoleting it are set at the same time
        # 4. possibly some other checks
        # All of these have been missing in pcs since ever (ad 1. agents have
        # never provided enough info for us to do such validations, ad 2. and
        # 3. there were no deprecated parameters before). The checks should be
        # implemented in agents themselves, so I'm not adding them now either.
        report_items = []

        # get resulting set of agent's parameters
        final_parameters = dict(current_parameters)
        for name, value in new_parameters.items():
            if value:
                final_parameters[name] = value
            else:
                if name in final_parameters:
                    del final_parameters[name]

        # report unknown parameters
        report_items.extend(
            validate.NamesIn(
                {param.name for param in self._get_parameters()},
                option_type=self._agent_type_label,
                severity=reports.get_severity(reports.codes.FORCE, force),
            ).validate(
                # Do not report unknown parameters already set in the CIB. They
                # have been reported already when the were added to the CIB.
                {
                    name: value
                    for name, value in new_parameters.items()
                    if name not in current_parameters
                }
            )
        )

        # report missing or removed required parameters
        missing_parameters = self._find_missing_required_parameters(
            final_parameters
        )
        if missing_parameters:
            report_items.append(
                reports.ReportItem(
                    severity=self._validate_report_severity(force),
                    message=reports.messages.RequiredOptionsAreMissing(
                        sorted(missing_parameters),
                        self._agent_type_label,
                    ),
                )
            )

        return report_items
Beispiel #5
0
    def validate_parameters_create(
        self,
        parameters: Mapping[str, str],
        force: bool = False,
        # TODO remove this argument, see pcs.lib.cib.commands.remote_node.create
        # for details
        do_not_report_instance_attribute_server_exists: bool = False,
    ) -> reports.ReportItemList:
        # This is just a basic validation checking that required parameters are
        # set and all set parameters are known to an agent. Missing checks are:
        # 1. values checks - if a param is an integer, then "abc" is not valid
        # 2. warnings should be emitted when a deprecated param is set
        # 3. errors should be emitted when a deprecated parameter and a
        #    parameter obsoleting it are set at the same time
        # 4. possibly some other checks
        # All of these have been missing in pcs since ever (ad 1. agents have
        # never provided enough info for us to do such validations, ad 2. and
        # 3. there were no deprecated parameters before). The checks should be
        # implemented in agents themselves, so I'm not adding them now either.
        report_items = []

        # report unknown parameters
        report_items.extend(
            validate.NamesIn(
                {param.name for param in self._get_parameters()},
                option_type=self._agent_type_label,
                severity=reports.get_severity(reports.codes.FORCE, force),
            ).validate(parameters)
        )
        # TODO remove this "if", see pcs.lib.cib.commands.remote_node.create
        # for details
        if do_not_report_instance_attribute_server_exists:
            for report_item in report_items:
                if isinstance(report_item, reports.ReportItem) and isinstance(
                    report_item.message, reports.messages.InvalidOptions
                ):
                    report_msg = cast(
                        reports.messages.InvalidOptions, report_item.message
                    )
                    report_item.message = reports.messages.InvalidOptions(
                        report_msg.option_names,
                        sorted(
                            [
                                value
                                for value in report_msg.allowed
                                if value != "server"
                            ]
                        ),
                        report_msg.option_type,
                        report_msg.allowed_patterns,
                    )

        # report missing required parameters
        missing_parameters = self._find_missing_required_parameters(parameters)
        if missing_parameters:
            report_items.append(
                reports.ReportItem(
                    severity=self._validate_report_severity(force),
                    message=reports.messages.RequiredOptionsAreMissing(
                        sorted(missing_parameters),
                        self._agent_type_label,
                    ),
                )
            )

        return report_items