Exemplo n.º 1
0
def node_communicator_exception_to_report_item(
    e, severity=ReportItemSeverity.ERROR, forceable=None
):
    """
    Transform NodeCommunicationException to ReportItem
    """
    if isinstance(e, NodeCommandUnsuccessfulException):
        return reports.node_communication_command_unsuccessful(
            e.node,
            e.command,
            e.reason
        )
    exception_to_report = {
        NodeAuthenticationException:
            reports.node_communication_error_not_authorized,
        NodePermissionDeniedException:
            reports.node_communication_error_permission_denied,
        NodeUnsupportedCommandException:
            reports.node_communication_error_unsupported_command,
        NodeCommunicationException:
            reports.node_communication_error_other_error,
        NodeConnectionException:
            reports.node_communication_error_unable_to_connect,
    }
    if e.__class__ in exception_to_report:
        return exception_to_report[e.__class__](
            e.node,
            e.command,
            e.reason,
            severity,
            forceable
        )
    raise e
Exemplo n.º 2
0
def node_communicator_exception_to_report_item(e,
                                               severity=ReportItemSeverity.
                                               ERROR,
                                               forceable=None):
    """
    Transform NodeCommunicationException to ReportItem
    """
    if isinstance(e, NodeCommandUnsuccessfulException):
        return reports.node_communication_command_unsuccessful(
            e.node, e.command, e.reason)
    exception_to_report = {
        NodeAuthenticationException:
        reports.node_communication_error_not_authorized,
        NodePermissionDeniedException:
        reports.node_communication_error_permission_denied,
        NodeUnsupportedCommandException:
        reports.node_communication_error_unsupported_command,
        NodeCommunicationException:
        reports.node_communication_error_other_error,
        NodeConnectionException:
        reports.node_communication_error_unable_to_connect,
    }
    if e.__class__ in exception_to_report:
        return exception_to_report[e.__class__](e.node, e.command, e.reason,
                                                severity, forceable)
    raise e
Exemplo n.º 3
0
    def _process_response(self, response):
        report = response_to_report_item(response,
                                         severity=ReportItemSeverity.WARNING)
        if report is not None:
            self._report(report)
            return self._get_next_list()

        node = response.request.target.label
        try:
            output = json.loads(response.data)
            if output["status"] == "success":
                self._was_successful = True
                self._cluster_status = output["data"]
                return []
            if output["status_msg"]:
                self._report(
                    reports.node_communication_command_unsuccessful(
                        node, response.request.action, output["status_msg"]))
            # TODO Node name should be added to each received report item and
            # those modified report itemss should be reported. That, however,
            # requires reports overhaul which would add posibility to add a
            # node name to any report item. Also, infos and warnings should not
            # be ignored.
            if output["report_list"]:
                for report_data in output["report_list"]:
                    if (report_data["severity"] == ReportItemSeverity.ERROR
                            and report_data["report_text"]):
                        self._report(
                            reports.node_communication_command_unsuccessful(
                                node, response.request.action,
                                report_data["report_text"]))
        except (ValueError, LookupError, TypeError):
            self._report(
                reports.invalid_response_format(
                    node,
                    severity=ReportItemSeverity.WARNING,
                ))

        return self._get_next_list()