Raise HTTPNotFound in V2 console extension

In case requested instance is not found, console extension does not catch
InstanceNotFound, which results to internal server error (500).

This patch handle InstanceNotFound exception and raise HTTPNotFound
like V3 console plugin.

Change-Id: Ia982049451f2c529f123da714e994476d4610491
This commit is contained in:
ghanshyam 2014-11-07 08:54:30 +09:00
parent 89cd6a0c49
commit 33b2d7f314
2 changed files with 13 additions and 1 deletions

View File

@ -95,9 +95,12 @@ class Controller(object):
def create(self, req, server_id, body):
"""Creates a new console."""
self.console_api.create_console(
try:
self.console_api.create_console(
req.environ['nova.context'],
server_id)
except exception.InstanceNotFound as e:
raise exc.HTTPNotFound(explanation=e.format_message())
@wsgi.serializers(xml=ConsoleTemplate)
def show(self, req, server_id, id):

View File

@ -144,6 +144,15 @@ class ConsolesControllerTest(test.NoDBTestCase):
req = fakes.HTTPRequest.blank(self.url)
self.controller.create(req, self.uuid, None)
def test_create_console_unknown_instance(self):
def fake_create_console(cons_self, context, instance_id):
raise exception.InstanceNotFound(instance_id=instance_id)
self.stubs.Set(console.api.API, 'create_console', fake_create_console)
req = fakes.HTTPRequest.blank(self.url)
self.assertRaises(webob.exc.HTTPNotFound, self.controller.create,
req, self.uuid, None)
def test_show_console(self):
def fake_get_console(cons_self, context, instance_id, console_id):
self.assertEqual(instance_id, self.uuid)