Handle Forbidden error from network_api.show_port in os-interface:show

We can get a 403 back from the neutronv2 API when calling
network_api.show_port so handle that in the compute API extension.

This also updates the v3 API code to match the v2 API code to put the
original error message for the 404 into the HTTPNotFound error.

Closes-Bug: #1378389

Change-Id: I7afc832f26481dc44f1c500b6121e2060f36c63a
This commit is contained in:
Matt Riedemann 2014-10-07 09:32:57 -07:00
parent 74ed140d77
commit 8299e80ad4
3 changed files with 20 additions and 3 deletions

View File

@ -70,6 +70,8 @@ class InterfaceAttachmentController(object):
port_info = self.network_api.show_port(context, port_id)
except exception.NotFound as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.Forbidden as e:
raise exc.HTTPForbidden(explanation=e.format_message())
if port_info['port']['device_id'] != server_id:
msg = _("Instance %(instance)s does not have a port with id"

View File

@ -60,7 +60,7 @@ class InterfaceAttachmentController(object):
return self._items(req, server_id,
entity_maker=_translate_interface_attachment_view)
@extensions.expected_errors(404)
@extensions.expected_errors((403, 404))
def show(self, req, server_id, id):
"""Return data about the given interface attachment."""
context = req.environ['nova.context']
@ -74,8 +74,10 @@ class InterfaceAttachmentController(object):
try:
port_info = self.network_api.show_port(context, port_id)
except exception.NotFound:
raise exc.HTTPNotFound()
except exception.NotFound as e:
raise exc.HTTPNotFound(explanation=e.format_message())
except exception.Forbidden as e:
raise exc.HTTPForbidden(explanation=e.format_message())
if port_info['port']['device_id'] != server_id:
raise exc.HTTPNotFound()

View File

@ -198,6 +198,19 @@ class InterfaceAttachTestsV21(test.NoDBTestCase):
self.attachments.show, req, FAKE_UUID2,
FAKE_PORT_ID1)
@mock.patch.object(network_api.API, 'show_port',
side_effect=exception.Forbidden)
def test_show_forbidden(self, show_port_mock):
req = webob.Request.blank(self.url + '/show')
req.method = 'POST'
req.body = jsonutils.dumps({})
req.headers['content-type'] = 'application/json'
req.environ['nova.context'] = self.context
self.assertRaises(exc.HTTPForbidden,
self.attachments.show, req, FAKE_UUID1,
FAKE_PORT_ID1)
def test_delete(self):
self.stubs.Set(compute_api.API, 'detach_interface',
fake_detach_interface)