From 8eede5e9814f3305e0bb66eeb93623ba25b16e9a Mon Sep 17 00:00:00 2001 From: Chris Yeoh Date: Wed, 22 May 2013 21:52:25 +0930 Subject: Catch InstanceNotFound in instance_actions GET Catch the InstanceNotFound exception in the instance_actions index function and handle the error gracefully so a stacktrace is not generated in the log files. This patch does not change the API Fixes bug 1182867 Change-Id: I0764f8abda7176deefe0d103bd86acd0af78780d --- nova/api/openstack/compute/contrib/instance_actions.py | 6 +++++- nova/tests/api/openstack/compute/contrib/test_instance_actions.py | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'nova') diff --git a/nova/api/openstack/compute/contrib/instance_actions.py b/nova/api/openstack/compute/contrib/instance_actions.py index 4eaa9a1ee..3b15de2ba 100644 --- a/nova/api/openstack/compute/contrib/instance_actions.py +++ b/nova/api/openstack/compute/contrib/instance_actions.py @@ -19,6 +19,7 @@ from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova import compute +from nova import exception authorize_actions = extensions.extension_authorizer('compute', 'instance_actions') @@ -84,7 +85,10 @@ class InstanceActionsController(wsgi.Controller): def index(self, req, server_id): """Returns the list of actions recorded for a given instance.""" context = req.environ["nova.context"] - instance = self.compute_api.get(context, server_id) + try: + instance = self.compute_api.get(context, server_id) + except exception.InstanceNotFound as err: + raise exc.HTTPNotFound(explanation=err.format_message()) authorize_actions(context, target=instance) actions_raw = self.action_api.actions_get(context, instance) actions = [self._format_action(action) for action in actions_raw] diff --git a/nova/tests/api/openstack/compute/contrib/test_instance_actions.py b/nova/tests/api/openstack/compute/contrib/test_instance_actions.py index 573385a52..871b831ac 100644 --- a/nova/tests/api/openstack/compute/contrib/test_instance_actions.py +++ b/nova/tests/api/openstack/compute/contrib/test_instance_actions.py @@ -178,6 +178,14 @@ class InstanceActionsTest(test.TestCase): self.assertRaises(exc.HTTPNotFound, self.controller.show, req, FAKE_UUID, FAKE_REQUEST_ID) + def test_instance_not_found(self): + def fake_get(self, context, instance_uuid): + raise exception.InstanceNotFound(instance_id=instance_uuid) + self.stubs.Set(compute_api.API, 'get', fake_get) + req = fakes.HTTPRequest.blank('/v2/123/servers/12/os-instance-actions') + self.assertRaises(exc.HTTPNotFound, self.controller.index, req, + FAKE_UUID) + class InstanceActionsSerializerTest(test.TestCase): def setUp(self): -- cgit