api: handle NotImplementedError for console output
Some drivers do not implement getting console output. Catch this exception at the API layer and return a 501 from the API in this case. Change-Id: I144850f4431a7588430da298ba348039bed25403
This commit is contained in:
parent
b32d01d44c
commit
8a5dd60e62
|
@ -70,6 +70,9 @@ class ConsoleOutputController(wsgi.Controller):
|
|||
raise webob.exc.HTTPNotFound(_('Unable to get console'))
|
||||
except exception.InstanceNotReady as e:
|
||||
raise webob.exc.HTTPConflict(explanation=e.format_message())
|
||||
except NotImplementedError:
|
||||
msg = _("Unable to get console log, functionality not implemented")
|
||||
raise webob.exc.HTTPNotImplemented(explanation=msg)
|
||||
|
||||
# XML output is not correctly escaped, so remove invalid characters
|
||||
remove_re = re.compile('[\x00-\x08\x0B-\x1F]')
|
||||
|
|
|
@ -34,7 +34,7 @@ class ConsoleOutputController(wsgi.Controller):
|
|||
super(ConsoleOutputController, self).__init__(*args, **kwargs)
|
||||
self.compute_api = compute.API()
|
||||
|
||||
@extensions.expected_errors((400, 404, 409))
|
||||
@extensions.expected_errors((400, 404, 409, 501))
|
||||
@wsgi.action('get_console_output')
|
||||
def get_console_output(self, req, id, body):
|
||||
"""Get text console output."""
|
||||
|
@ -69,6 +69,9 @@ class ConsoleOutputController(wsgi.Controller):
|
|||
length)
|
||||
except exception.InstanceNotReady as e:
|
||||
raise webob.exc.HTTPConflict(explanation=e.format_message())
|
||||
except NotImplementedError:
|
||||
msg = _("Unable to get console log, functionality not implemented")
|
||||
raise webob.exc.HTTPNotImplemented(explanation=msg)
|
||||
|
||||
# XML output is not correctly escaped, so remove invalid characters
|
||||
remove_re = re.compile('[\x00-\x08\x0B-\x1F]')
|
||||
|
|
|
@ -176,3 +176,15 @@ class ConsoleOutputExtensionTest(test.NoDBTestCase):
|
|||
req.headers["content-type"] = "application/json"
|
||||
res = req.get_response(self.app)
|
||||
self.assertEqual(res.status_int, 400)
|
||||
|
||||
def test_not_implemented(self):
|
||||
self.stubs.Set(compute_api.API, 'get_console_output',
|
||||
fakes.fake_not_implemented)
|
||||
body = {'os-getConsoleOutput': {}}
|
||||
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)
|
||||
|
|
|
@ -137,3 +137,10 @@ class ConsoleOutputExtensionTest(test.NoDBTestCase):
|
|||
req = self._create_request(length_dict={'length': 2.5})
|
||||
res = req.get_response(self.app)
|
||||
self.assertEqual(res.status_int, 400)
|
||||
|
||||
def test_get_console_output_not_implemented(self):
|
||||
self.stubs.Set(compute_api.API, 'get_console_output',
|
||||
fakes.fake_not_implemented)
|
||||
req = self._create_request()
|
||||
res = req.get_response(self.app)
|
||||
self.assertEqual(res.status_int, 501)
|
||||
|
|
|
@ -710,3 +710,7 @@ def stub_bdm_get_all_by_instance(context, instance_uuid):
|
|||
def fake_get_available_languages(domain):
|
||||
existing_translations = ['en_GB', 'en_AU', 'de', 'zh_CN', 'en_US']
|
||||
return existing_translations
|
||||
|
||||
|
||||
def fake_not_implemented(*args, **kwargs):
|
||||
raise NotImplementedError()
|
||||
|
|
Loading…
Reference in New Issue