Catch NotImplementedError in get_spice_console in v2/v3 API
Currently get_spice_console doesn't catch NotImpelementedError and it will lead to inaccurate information returned back to API caller. This patch adds the catch exception routine and returns a HTTPNotImplemented excpetion. Closes-Bug: #1279195 Change-Id: I16cb0a83c0e1aa9a041dd21af324a39388ca3bb8
This commit is contained in:
parent
eab90a9277
commit
f52a7f181a
|
@ -72,6 +72,10 @@ class ConsolesController(wsgi.Controller):
|
|||
raise webob.exc.HTTPNotFound(explanation=e.format_message())
|
||||
except exception.InstanceNotReady as e:
|
||||
raise webob.exc.HTTPConflict(explanation=e.format_message())
|
||||
except NotImplementedError:
|
||||
msg = _("Unable to get spice console, "
|
||||
"functionality not implemented")
|
||||
raise webob.exc.HTTPNotImplemented(explanation=msg)
|
||||
|
||||
return {'console': {'type': console_type, 'url': output['url']}}
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ class RemoteConsolesController(wsgi.Controller):
|
|||
|
||||
return {'console': {'type': console_type, 'url': output['url']}}
|
||||
|
||||
@extensions.expected_errors((400, 404, 409))
|
||||
@extensions.expected_errors((400, 404, 409, 501))
|
||||
@wsgi.action('get_spice_console')
|
||||
def get_spice_console(self, req, id, body):
|
||||
"""Get text console output."""
|
||||
|
@ -85,6 +85,10 @@ class RemoteConsolesController(wsgi.Controller):
|
|||
raise webob.exc.HTTPNotFound(explanation=e.format_message())
|
||||
except exception.InstanceNotReady as e:
|
||||
raise webob.exc.HTTPConflict(explanation=e.format_message())
|
||||
except NotImplementedError:
|
||||
msg = _("Unable to get spice console, "
|
||||
"functionality not implemented")
|
||||
raise webob.exc.HTTPNotImplemented(explanation=msg)
|
||||
|
||||
return {'console': {'type': console_type, 'url': output['url']}}
|
||||
|
||||
|
|
|
@ -257,6 +257,18 @@ class ConsolesExtensionTest(test.NoDBTestCase):
|
|||
res = req.get_response(self.app)
|
||||
self.assertEqual(res.status_int, 400)
|
||||
|
||||
def test_get_spice_console_not_implemented(self):
|
||||
body = {'os-getSPICEConsole': {'type': 'spice-html5'}}
|
||||
self.stubs.Set(compute_api.API, 'get_spice_console',
|
||||
fakes.fake_not_implemented)
|
||||
req = webob.Request.blank('/v2/fake/servers/1/action')
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
res = req.get_response(self.app)
|
||||
self.assertEqual(res.status_int, 501)
|
||||
|
||||
def test_get_rdp_console(self):
|
||||
body = {'os-getRDPConsole': {'type': 'rdp-html5'}}
|
||||
req = webob.Request.blank('/v2/fake/servers/1/action')
|
||||
|
|
|
@ -222,6 +222,19 @@ class ConsolesExtensionTest(test.NoDBTestCase):
|
|||
self.assertEqual(output,
|
||||
{u'console': {u'url': u'http://fake', u'type': u'spice-html5'}})
|
||||
|
||||
def test_get_spice_console_not_implemented(self):
|
||||
self.stubs.Set(compute_api.API, 'get_spice_console',
|
||||
fakes.fake_not_implemented)
|
||||
|
||||
body = {'get_spice_console': {'type': 'spice-html5'}}
|
||||
req = webob.Request.blank('/v3/servers/1/action')
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dumps(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
res = req.get_response(self.app)
|
||||
self.assertEqual(res.status_int, 501)
|
||||
|
||||
def test_get_spice_console_not_ready(self):
|
||||
self.stubs.Set(compute_api.API, 'get_spice_console',
|
||||
fake_get_spice_console_not_ready)
|
||||
|
|
Loading…
Reference in New Issue