Exemple #1
0
 def __init__(
     self,
     option_name: TypeOptionName,
     deprecation_map: Mapping[str, Optional[str]],
     severity: Optional[ReportItemSeverity] = None,
     option_name_for_report: Optional[str] = None,
 ):
     """
     deprecation_map -- keys are deprecated values and values are new
         values. If values is None, deprecated value has no direct
         replacement
     """
     super().__init__(
         option_name,
         option_name_for_report=option_name_for_report,
     )
     self._severity = (ReportItemSeverity.deprecation()
                       if severity is None else severity)
     self._deprecation_map = deprecation_map
Exemple #2
0
 def __init__(
     self,
     option_name_list: Iterable[TypeOptionName],
     option_type: Optional[str] = None,
     allowed_option_patterns: Optional[Iterable[str]] = None,
     banned_name_list: Optional[Iterable[TypeOptionName]] = None,
     severity: Optional[ReportItemSeverity] = None,
 ):
     """
     allowed_option_patterns -- option patterns to be added to a report
     banned_name_list -- list of options which cannot be forced
     severity -- severity of produced reports, defaults to error
     """
     super().__init__(option_name_list, option_type=option_type)
     self._allowed_option_patterns = allowed_option_patterns or []
     self._banned_name_set = set(banned_name_list or [])
     self._severity = (
         ReportItemSeverity.error() if severity is None else severity
     )
Exemple #3
0
def _validate_devices(
    resources_el: _Element, devices, force_device=False, allow_force=True
) -> ReportItemList:
    report_list: ReportItemList = []
    if not devices:
        report_list.append(
            ReportItem.error(
                reports.messages.RequiredOptionsAreMissing(["stonith devices"])
            )
        )
    invalid_devices = []
    for dev in devices:
        validate_id_report_list: ReportItemList = []
        validate_id(
            dev, description="device id", reporter=validate_id_report_list
        )
        report_list.extend(validate_id_report_list)
        if has_errors(validate_id_report_list):
            continue
        # TODO use the new finding function
        if not is_stonith_resource(resources_el, dev):
            invalid_devices.append(dev)
    if invalid_devices:
        report_list.append(
            ReportItem(
                severity=ReportItemSeverity(
                    level=(
                        ReportItemSeverity.WARNING
                        if force_device and allow_force
                        else ReportItemSeverity.ERROR
                    ),
                    force_code=(
                        None
                        if force_device or not allow_force
                        else report_codes.FORCE
                    ),
                ),
                message=reports.messages.StonithResourcesDoNotExist(
                    invalid_devices
                ),
            )
        )
    return report_list
Exemple #4
0
 def _process_response(self, response):
     report_item = self._get_response_report(response)
     node_label = response.request.target.label
     if report_item is None:
         self._report(
             ReportItem.info(
                 reports.messages.CorosyncConfigAcceptedByNode(node_label)))
     else:
         self._report_list([
             report_item,
             ReportItem(
                 severity=ReportItemSeverity(
                     self._failure_severity,
                     self._failure_forceable,
                 ),
                 # pylint: disable=line-too-long
                 message=reports.messages.
                 CorosyncConfigDistributionNodeError(node_label, ),
             ),
         ])
Exemple #5
0
def _complete_agent_list(
    runner: CommandRunner,
    report_processor: ReportProcessor,
    agent_names: Iterable[ResourceAgentName],
    describe: bool,
    search: Optional[str],
) -> List[Dict[str, Any]]:
    agent_factory = ResourceAgentFacadeFactory(runner, report_processor)
    search_lower = search.lower() if search else None
    agent_list = []
    for name in agent_names:
        if search_lower and search_lower not in name.full_name.lower():
            continue
        try:
            metadata = (agent_factory.facade_from_parsed_name(name).metadata
                        if describe else name_to_void_metadata(name))
            agent_list.append(_agent_metadata_to_dict(metadata, describe))
        except ResourceAgentError as e:
            report_processor.report(
                resource_agent_error_to_report_item(
                    e, ReportItemSeverity.warning()))
    return agent_list
Exemple #6
0
def response_to_report_item(
    response,
    severity=ReportItemSeverity.ERROR,
    forceable=None,
    report_pcsd_too_old_on_404=False,
):
    """
    Returns report item which corresponds to response if was not successful.
    Otherwise returns None.

    Response response -- response from which report item shoculd be created
    ReportItemseverity severity -- severity of report item
    string forceable -- force code
    bool report_pcsd_too_old_on_404 -- if False, report unsupported command
    """
    response_code = response.response_code
    report_item = None
    reason = None
    if (report_pcsd_too_old_on_404 and response.was_connected
            and response_code == 404):
        return ReportItem.error(
            reports.messages.PcsdVersionTooOld(response.request.host_label))
    if response.was_connected:
        if response_code == 400:
            # old pcsd protocol: error messages are commonly passed in plain
            # text in response body with HTTP code 400
            # we need to be backward compatible with that
            report_item = reports.messages.NodeCommunicationCommandUnsuccessful
            reason = response.data.rstrip()
        elif response_code == 401:
            report_item = reports.messages.NodeCommunicationErrorNotAuthorized
            reason = "HTTP error: {0}".format(response_code)
        elif response_code == 403:
            report_item = (
                reports.messages.NodeCommunicationErrorPermissionDenied)
            reason = "HTTP error: {0}".format(response_code)
        elif response_code == 404:
            report_item = (
                reports.messages.NodeCommunicationErrorUnsupportedCommand)
            reason = "HTTP error: {0}".format(response_code)
        elif response_code >= 400:
            report_item = reports.messages.NodeCommunicationError
            reason = "HTTP error: {0}".format(response_code)
    else:
        if response.errno in [
                pycurl.E_OPERATION_TIMEDOUT,
                pycurl.E_OPERATION_TIMEOUTED,
        ]:
            report_item = reports.messages.NodeCommunicationErrorTimedOut
            reason = response.error_msg
        else:
            report_item = reports.messages.NodeCommunicationErrorUnableToConnect
            reason = response.error_msg
    if not report_item:
        return None
    return ReportItem(
        severity=ReportItemSeverity(severity, forceable),
        message=report_item(
            response.request.host_label,
            response.request.action,
            reason,
        ),
    )