Beispiel #1
0
 def test_ignores_error_on_API(self):
     middleware = RPCErrorsMiddleware()
     non_api_request = factory.make_fake_request("/api/2.0/ohai")
     exception_class = random.choice(
         (NoConnectionsAvailable, PowerActionAlreadyInProgress))
     exception = exception_class(factory.make_string())
     self.assertIsNone(
         middleware.process_exception(non_api_request, exception))
Beispiel #2
0
 def test_ignores_non_rpc_errors(self):
     middleware = RPCErrorsMiddleware()
     request = factory.make_fake_request(factory.make_string(), 'POST')
     exception = ZeroDivisionError(
         "You may think it's a long walk down the street to the chemist "
         "but that's just peanuts to space!")
     response = middleware.process_exception(request, exception)
     self.assertIsNone(response)
Beispiel #3
0
    def test_no_connections_available_has_usable_cluster_name_in_msg(self):
        # If a NoConnectionsAvailable exception carries a reference to
        # the cluster UUID, RPCErrorsMiddleware will look up the
        # cluster's name and make the error message it displays more
        # useful.
        middleware = RPCErrorsMiddleware()
        request = factory.make_fake_request(factory.make_string(), 'POST')
        rack_controller = factory.make_RackController()
        error = NoConnectionsAvailable(factory.make_name('msg'),
                                       uuid=rack_controller.system_id)
        middleware.process_exception(request, error)

        expected_error_message = (
            "Error: Unable to connect to rack controller '%s' (%s); no "
            "connections available." %
            (rack_controller.hostname, rack_controller.system_id))
        self.assertEqual([(constants.ERROR, expected_error_message, '')],
                         request._messages.messages)
Beispiel #4
0
    def test_handles_TimeoutError(self):
        middleware = RPCErrorsMiddleware()
        request = factory.make_fake_request(factory.make_string(), 'POST')
        error_message = "Here, have a picture of Queen Victoria!"
        error = TimeoutError(error_message)
        response = middleware.process_exception(request, error)

        # The response is a redirect.
        self.assertEqual(request.path, extract_redirect(response))
        # An error message has been published.
        self.assertEqual([(constants.ERROR, "Error: " + error_message, '')],
                         request._messages.messages)
Beispiel #5
0
    def test_handles_NoConnectionsAvailable(self):
        middleware = RPCErrorsMiddleware()
        request = factory.make_fake_request(factory.make_string(), 'POST')
        error_message = ("No connections available for cluster %s" %
                         factory.make_name('cluster'))
        error = NoConnectionsAvailable(error_message)
        response = middleware.process_exception(request, error)

        # The response is a redirect.
        self.assertEqual(request.path, extract_redirect(response))
        # An error message has been published.
        self.assertEqual([(constants.ERROR, "Error: " + error_message, '')],
                         request._messages.messages)
Beispiel #6
0
    def test_handles_PowerActionAlreadyInProgress(self):
        middleware = RPCErrorsMiddleware()
        request = factory.make_fake_request(factory.make_string(), 'POST')
        error_message = ("Unable to execute power action: another action is "
                         "already in progress for node %s" %
                         factory.make_name('node'))
        error = PowerActionAlreadyInProgress(error_message)
        response = middleware.process_exception(request, error)

        # The response is a redirect.
        self.assertEqual(request.path, extract_redirect(response))
        # An error message has been published.
        self.assertEqual([(constants.ERROR, "Error: %s" % error_message, '')],
                         request._messages.messages)