From a7885385fb34f7040684343deed040d302dbbfea Mon Sep 17 00:00:00 2001 From: jichen Date: Fri, 6 Dec 2013 10:29:51 -0500 Subject: [PATCH] Quota violations should not cause a stacktrace in the logs Don't show exception logs in api log for resize operations if the resize operations lead to quota violations Change-Id: Ia101c599908c7652cc07fa4c7e7f1b057943e031 Closes-Bug: #1235389 --- nova/api/openstack/compute/contrib/admin_actions.py | 4 ++++ nova/api/openstack/compute/plugins/v3/admin_actions.py | 4 ++++ nova/api/openstack/compute/plugins/v3/servers.py | 4 ++++ nova/api/openstack/compute/servers.py | 4 ++++ .../api/openstack/compute/plugins/v3/test_server_actions.py | 2 +- nova/tests/api/openstack/compute/test_server_actions.py | 2 +- 6 files changed, 18 insertions(+), 2 deletions(-) diff --git a/nova/api/openstack/compute/contrib/admin_actions.py b/nova/api/openstack/compute/contrib/admin_actions.py index 63b782176714..632e4f226d7e 100644 --- a/nova/api/openstack/compute/contrib/admin_actions.py +++ b/nova/api/openstack/compute/contrib/admin_actions.py @@ -137,6 +137,10 @@ class AdminActionsController(wsgi.Controller): try: instance = self.compute_api.get(context, id, want_objects=True) self.compute_api.resize(req.environ['nova.context'], instance) + except exception.QuotaError as error: + raise exc.HTTPRequestEntityTooLarge( + explanation=error.format_message(), + headers={'Retry-After': 0}) except exception.InstanceIsLocked as e: raise exc.HTTPConflict(explanation=e.format_message()) except exception.InstanceInvalidState as state_error: diff --git a/nova/api/openstack/compute/plugins/v3/admin_actions.py b/nova/api/openstack/compute/plugins/v3/admin_actions.py index 724a0db0567d..63777f95bceb 100644 --- a/nova/api/openstack/compute/plugins/v3/admin_actions.py +++ b/nova/api/openstack/compute/plugins/v3/admin_actions.py @@ -124,6 +124,10 @@ class AdminActionsController(wsgi.Controller): try: instance = self.compute_api.get(context, id, want_objects=True) self.compute_api.resize(req.environ['nova.context'], instance) + except exception.QuotaError as error: + raise exc.HTTPRequestEntityTooLarge( + explanation=error.format_message(), + headers={'Retry-After': 0}) except exception.InstanceIsLocked as e: raise exc.HTTPConflict(explanation=e.format_message()) except exception.InstanceInvalidState as state_error: diff --git a/nova/api/openstack/compute/plugins/v3/servers.py b/nova/api/openstack/compute/plugins/v3/servers.py index 66ebb28f957c..444fe6b52703 100644 --- a/nova/api/openstack/compute/plugins/v3/servers.py +++ b/nova/api/openstack/compute/plugins/v3/servers.py @@ -999,6 +999,10 @@ class ServersController(wsgi.Controller): try: self.compute_api.resize(context, instance, flavor_id, **kwargs) + except exception.QuotaError as error: + raise exc.HTTPRequestEntityTooLarge( + explanation=error.format_message(), + headers={'Retry-After': 0}) except exception.FlavorNotFound: msg = _("Unable to locate requested flavor.") raise exc.HTTPBadRequest(explanation=msg) diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index fdf71252ee54..d3c67b73f137 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -1130,6 +1130,10 @@ class Controller(wsgi.Controller): try: self.compute_api.resize(context, instance, flavor_id, **kwargs) + except exception.QuotaError as error: + raise exc.HTTPRequestEntityTooLarge( + explanation=error.format_message(), + headers={'Retry-After': 0}) except exception.FlavorNotFound: msg = _("Unable to locate requested flavor.") raise exc.HTTPBadRequest(explanation=msg) diff --git a/nova/tests/api/openstack/compute/plugins/v3/test_server_actions.py b/nova/tests/api/openstack/compute/plugins/v3/test_server_actions.py index ae5bbd17e7d4..b5833c6b99a8 100644 --- a/nova/tests/api/openstack/compute/plugins/v3/test_server_actions.py +++ b/nova/tests/api/openstack/compute/plugins/v3/test_server_actions.py @@ -577,7 +577,7 @@ class ServerActionsControllerTest(test.TestCase): self.stubs.Set(compute_api.API, 'resize', fake_resize) req = fakes.HTTPRequestV3.blank(self.url) - self.assertRaises(exception.TooManyInstances, + self.assertRaises(webob.exc.HTTPRequestEntityTooLarge, self.controller._action_resize, req, FAKE_UUID, body) diff --git a/nova/tests/api/openstack/compute/test_server_actions.py b/nova/tests/api/openstack/compute/test_server_actions.py index b7a732014787..97a1f0e3d095 100644 --- a/nova/tests/api/openstack/compute/test_server_actions.py +++ b/nova/tests/api/openstack/compute/test_server_actions.py @@ -678,7 +678,7 @@ class ServerActionsControllerTest(test.TestCase): self.stubs.Set(compute_api.API, 'resize', fake_resize) req = fakes.HTTPRequest.blank(self.url) - self.assertRaises(exception.TooManyInstances, + self.assertRaises(webob.exc.HTTPRequestEntityTooLarge, self.controller._action_resize, req, FAKE_UUID, body)