Example #1
0
 def test_log_response_not_connected(self, mock_proxy):
     mock_proxy.return_value = False
     expected_debug_data = "* text\n>> data out\n"
     error_msg = "error"
     response = Response.connection_failure(
         MockCurlSimple(
             debug_output=expected_debug_data.encode("utf-8"),
             request=fixture_request(),
         ),
         pycurl.E_HTTP_POST_ERROR,
         error_msg,
     )
     self.com_logger.log_response(response)
     self.reporter.assert_reports(
         fixture_report_item_list_not_connected(
             response.request.host_label, error_msg
         )
         +
         fixture_report_item_list_debug(
             response.request.url, expected_debug_data
         )
     )
     logger_calls = [
         fixture_logger_call_not_connected(
             response.request.host_label, error_msg
         ),
         fixture_logger_call_debug_data(
             response.request.url, expected_debug_data
         )
     ]
     self.assertEqual(logger_calls, self.logger.mock_calls)
Example #2
0
 def test_log_response_connected(self):
     expected_code = 200
     expected_data = "data"
     expected_debug_data = "* text\n>> data out\n"
     response = Response.connection_successful(
         MockCurlSimple(
             info={pycurl.RESPONSE_CODE: expected_code},
             output=expected_data.encode("utf-8"),
             debug_output=expected_debug_data.encode("utf-8"),
             request=fixture_request(),
         )
     )
     self.com_logger.log_response(response)
     self.reporter.assert_reports(
         fixture_report_item_list_on_success(
             response.request.url,
             expected_code,
             expected_data,
             expected_debug_data
         )
     )
     logger_calls = fixture_logger_calls_on_success(
         response.request.url,
         expected_code,
         expected_data,
         expected_debug_data
     )
     self.assertEqual(logger_calls, self.logger.mock_calls)
Example #3
0
 def test_log_retry(self):
     prev_addr = "addr"
     prev_port = 2225
     prev_host = Destination(prev_addr, prev_port)
     response = Response.connection_failure(
         MockCurlSimple(request=fixture_request()),
         pycurl.E_HTTP_POST_ERROR,
         "e",
     )
     self.com_logger.log_retry(response, prev_host)
     self.reporter.assert_reports([(
         severity.WARNING,
         report_codes.NODE_COMMUNICATION_RETRYING,
         {
             "node": response.request.host_label,
             "failed_address": prev_addr,
             "failed_port": prev_port,
             "next_address": response.request.dest.addr,
             "next_port": settings.pcsd_default_port,
             "request": response.request.url,
         },
         None,
     )])
     logger_call = mock.call.warning(
         ("Unable to connect to '{label}' via address '{old_addr}' and "
          "port '{old_port}'. Retrying request '{req}' via address "
          "'{new_addr}' and port '{new_port}'").format(
              label=response.request.host_label,
              old_addr=prev_addr,
              old_port=prev_port,
              new_addr=response.request.dest.addr,
              new_port=settings.pcsd_default_port,
              req=response.request.url,
          ))
     self.assertEqual([logger_call], self.logger.mock_calls)
Example #4
0
def _communication_to_response(
    label,
    dest_list,
    action,
    param_list,
    response_code,
    output,
    debug_output,
    was_connected,
    errno,
    error_msg,
    raw_data,
):
    return Response(
        MockCurlSimple(
            info={pycurl.RESPONSE_CODE: response_code},
            output=output,
            debug_output=debug_output,
            request=Request(
                # We do not need to check if token is the right one in tests:
                # 1) Library commands tests do not care about tokens. That
                #    should be covered once in a specialized test, not in every
                #    single library command test.
                # 2) If we need to test teh case when a token is not accepted
                #    by pcsd, we will do so by setting an appropriate response.
                #    The actual token value doesn't matter.
                RequestTarget(label, dest_list=dest_list, token=None),
                RequestData(action, param_list, raw_data),
            ),
        ),
        was_connected=was_connected,
        errno=errno,
        error_msg=error_msg,
    )
Example #5
0
 def test_log_no_more_addresses(self):
     response = Response.connection_failure(
         MockCurlSimple(request=fixture_request()),
         pycurl.E_HTTP_POST_ERROR,
         "e",
     )
     self.com_logger.log_no_more_addresses(response)
     self.reporter.assert_reports([(
         severity.WARNING,
         report_codes.NODE_COMMUNICATION_NO_MORE_ADDRESSES,
         {
             "node": response.request.host_label,
             "request": response.request.url,
         },
         None,
     )])
     logger_call = mock.call.warning(
         "No more addresses for node {label} to run '{req}'".format(
             label=response.request.host_label,
             req=response.request.url,
         ))
     self.assertEqual([logger_call], self.logger.mock_calls)