Esempio n. 1
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 = None
    reason = None
    if (report_pcsd_too_old_on_404 and response.was_connected
            and response_code == 404):
        return reports.pcsd_version_too_old(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 = reports.node_communication_command_unsuccessful
            reason = response.data.rstrip()
        elif response_code == 401:
            report = reports.node_communication_error_not_authorized
            reason = "HTTP error: {0}".format(response_code)
        elif response_code == 403:
            report = reports.node_communication_error_permission_denied
            reason = "HTTP error: {0}".format(response_code)
        elif response_code == 404:
            report = reports.node_communication_error_unsupported_command
            reason = "HTTP error: {0}".format(response_code)
        elif response_code >= 400:
            report = reports.node_communication_error_other_error
            reason = "HTTP error: {0}".format(response_code)
    else:
        if response.errno in [
                pycurl.E_OPERATION_TIMEDOUT, pycurl.E_OPERATION_TIMEOUTED
        ]:
            report = reports.node_communication_error_timed_out
            reason = response.error_msg
        else:
            report = reports.node_communication_error_unable_to_connect
            reason = response.error_msg
    if not report:
        return None
    return report(
        response.request.host_label,
        response.request.action,
        reason,
        severity,
        forceable,
    )
Esempio n. 2
0
 def _get_response_report(self, response):
     report = super()._get_response_report(response)
     if response.was_connected and response.response_code == 404:
         report = reports.pcsd_version_too_old(response.request.target.label)
     return report
Esempio n. 3
0
 def _get_response_report(self, response):
     report = super()._get_response_report(response)
     if response.was_connected and response.response_code == 404:
         report = reports.pcsd_version_too_old(
             response.request.target.label)
     return report