Fix NotImplementedError handling in interfaces API
attach_interfaces used format_message() of NotImplementedError for getting message, but NotImplementedError doesn't contain it then AttributeError happened. This patch fixes this problem. Partially implements blueprint v2-on-v3-api Change-Id: I2153756a88f67820821e66a494b892e3017ad788
This commit is contained in:
parent
9d357dfc66
commit
dc66ef48e3
|
@ -128,8 +128,9 @@ class InterfaceAttachmentController(wsgi.Controller):
|
|||
except (exception.PortNotFound,
|
||||
exception.NetworkNotFound) as e:
|
||||
raise exc.HTTPNotFound(explanation=e.format_message())
|
||||
except NotImplementedError as e:
|
||||
raise webob.exc.HTTPNotImplemented(explanation=e.format_message())
|
||||
except NotImplementedError:
|
||||
msg = _("The requested functionality is not supported.")
|
||||
raise webob.exc.HTTPNotImplemented(explanation=msg)
|
||||
except exception.InterfaceAttachFailed as e:
|
||||
raise webob.exc.HTTPInternalServerError(
|
||||
explanation=e.format_message())
|
||||
|
@ -156,8 +157,9 @@ class InterfaceAttachmentController(wsgi.Controller):
|
|||
raise exc.HTTPNotFound(explanation=e.format_message())
|
||||
except exception.InstanceIsLocked as e:
|
||||
raise exc.HTTPConflict(explanation=e.format_message())
|
||||
except NotImplementedError as e:
|
||||
raise webob.exc.HTTPNotImplemented(explanation=e.format_message())
|
||||
except NotImplementedError:
|
||||
msg = _("The requested functionality is not supported.")
|
||||
raise webob.exc.HTTPNotImplemented(explanation=msg)
|
||||
except exception.InstanceInvalidState as state_error:
|
||||
common.raise_http_conflict_for_instance_invalid_state(state_error,
|
||||
'detach_interface', server_id)
|
||||
|
|
|
@ -307,6 +307,14 @@ class InterfaceAttachTestsV21(test.NoDBTestCase):
|
|||
self.attachments.create, self.req, FAKE_UUID1,
|
||||
body=body)
|
||||
|
||||
@mock.patch.object(compute_api.API, 'attach_interface',
|
||||
side_effect=NotImplementedError())
|
||||
def test_attach_interface_with_not_implemented(self, _mock):
|
||||
body = {'interfaceAttachment': {'net_id': FAKE_NET_ID1}}
|
||||
self.assertRaises(exc.HTTPNotImplemented,
|
||||
self.attachments.create, self.req, FAKE_UUID1,
|
||||
body=body)
|
||||
|
||||
def test_detach_interface_with_invalid_state(self):
|
||||
def fake_detach_interface_invalid_state(*args, **kwargs):
|
||||
raise exception.InstanceInvalidState(
|
||||
|
@ -321,6 +329,13 @@ class InterfaceAttachTestsV21(test.NoDBTestCase):
|
|||
FAKE_UUID1,
|
||||
FAKE_NET_ID1)
|
||||
|
||||
@mock.patch.object(compute_api.API, 'detach_interface',
|
||||
side_effect=NotImplementedError())
|
||||
def test_detach_interface_with_not_implemented(self, _mock):
|
||||
self.assertRaises(exc.HTTPNotImplemented,
|
||||
self.attachments.delete,
|
||||
self.req, FAKE_UUID1, FAKE_NET_ID1)
|
||||
|
||||
def test_attach_interface_invalid_fixed_ip(self):
|
||||
body = {
|
||||
'interfaceAttachment': {
|
||||
|
|
Loading…
Reference in New Issue