Handle NotImplementedError in server_diagnostics v3 api
In libvirt driver, it doesn't implement the function of get_instance_diagnostics().it returns http 500 error No. we expect http 501 if the function is not implemented. Change-Id: I59bfaa27b96284bd56917096e0c3fab0d277ba96 Closes-Bug: 1349680
This commit is contained in:
@@ -19,6 +19,7 @@ from nova.api.openstack import common
|
|||||||
from nova.api.openstack import extensions
|
from nova.api.openstack import extensions
|
||||||
from nova import compute
|
from nova import compute
|
||||||
from nova import exception
|
from nova import exception
|
||||||
|
from nova.i18n import _
|
||||||
|
|
||||||
|
|
||||||
ALIAS = "os-server-diagnostics"
|
ALIAS = "os-server-diagnostics"
|
||||||
@@ -26,7 +27,7 @@ authorize = extensions.extension_authorizer('compute', 'v3:' + ALIAS)
|
|||||||
|
|
||||||
|
|
||||||
class ServerDiagnosticsController(object):
|
class ServerDiagnosticsController(object):
|
||||||
@extensions.expected_errors((404, 409))
|
@extensions.expected_errors((404, 409, 501))
|
||||||
def index(self, req, server_id):
|
def index(self, req, server_id):
|
||||||
context = req.environ["nova.context"]
|
context = req.environ["nova.context"]
|
||||||
authorize(context)
|
authorize(context)
|
||||||
@@ -41,6 +42,9 @@ class ServerDiagnosticsController(object):
|
|||||||
except exception.InstanceInvalidState as state_error:
|
except exception.InstanceInvalidState as state_error:
|
||||||
common.raise_http_conflict_for_instance_invalid_state(state_error,
|
common.raise_http_conflict_for_instance_invalid_state(state_error,
|
||||||
'get_diagnostics')
|
'get_diagnostics')
|
||||||
|
except NotImplementedError:
|
||||||
|
msg = _("Unable to get diagnostics, functionality not implemented")
|
||||||
|
raise webob.exc.HTTPNotImplemented(explanation=msg)
|
||||||
|
|
||||||
|
|
||||||
class ServerDiagnostics(extensions.V3APIExtensionBase):
|
class ServerDiagnostics(extensions.V3APIExtensionBase):
|
||||||
|
|||||||
@@ -109,3 +109,13 @@ class ServerDiagnosticsTest(test.NoDBTestCase):
|
|||||||
'/servers/%s/os-server-diagnostics' % UUID)
|
'/servers/%s/os-server-diagnostics' % UUID)
|
||||||
res = req.get_response(self.router)
|
res = req.get_response(self.router)
|
||||||
self.assertEqual(409, res.status_int)
|
self.assertEqual(409, res.status_int)
|
||||||
|
|
||||||
|
@mock.patch.object(compute_api.API, 'get_instance_diagnostics',
|
||||||
|
side_effect=NotImplementedError)
|
||||||
|
@mock.patch.object(compute_api.API, 'get', fake_instance_get)
|
||||||
|
def test_get_diagnostics_raise_no_notimplementederror(self,
|
||||||
|
mock_get_diagnostics):
|
||||||
|
req = fakes.HTTPRequestV3.blank(
|
||||||
|
'/servers/%s/os-server-diagnostics' % UUID)
|
||||||
|
res = req.get_response(self.router)
|
||||||
|
self.assertEqual(501, res.status_int)
|
||||||
|
|||||||
Reference in New Issue
Block a user