Catch InstanceNotFound exceptions for V2 API virtual interfaces
Use the common.get_instance method to get the instance object in the V2 API virtual interfaces extension rather than call the compute api directly. The utility function handes InstanceNotFound exceptions and tranlsates them to HTTPNotFound rather than letting them propagate up causing a traceback. Co-Authored-By: Michael Still <mikal@stillhq.com> Change-Id: I8abee22c53195926e3d2af1da9b14cd9d3608e63 Closes-Bug: 1270804
This commit is contained in:
parent
b6429b4c1a
commit
d9b2c0127c
|
@ -59,8 +59,8 @@ class ServerVirtualInterfaceController(object):
|
|||
def _items(self, req, server_id, entity_maker):
|
||||
"""Returns a list of VIFs, transformed through entity_maker."""
|
||||
context = req.environ['nova.context']
|
||||
instance = common.get_instance(self.compute_api, context, server_id)
|
||||
|
||||
instance = self.compute_api.get(context, server_id)
|
||||
vifs = self.network_api.get_vifs_by_instance(context, instance)
|
||||
limited_list = common.limited(vifs, req)
|
||||
res = [entity_maker(context, vif) for vif in limited_list]
|
||||
|
|
|
@ -39,7 +39,8 @@ EXPECTED_NET_UUIDS = ['00000000-0000-0000-0000-00000000000000001',
|
|||
'11111111-1111-1111-1111-11111111111111112']
|
||||
|
||||
|
||||
def compute_api_get(self, context, instance_id):
|
||||
def compute_api_get(self, context, instance_id, expected_attrs=None,
|
||||
want_objects=False):
|
||||
return dict(uuid=FAKE_UUID, id=instance_id, instance_type_id=1, host='bob')
|
||||
|
||||
|
||||
|
|
|
@ -19,6 +19,9 @@ import webob
|
|||
from nova.api.openstack.compute.contrib import virtual_interfaces
|
||||
from nova.api.openstack import wsgi
|
||||
from nova import compute
|
||||
from nova.compute import api as compute_api
|
||||
from nova import context
|
||||
from nova import exception
|
||||
from nova import network
|
||||
from nova.openstack.common import jsonutils
|
||||
from nova import test
|
||||
|
@ -28,7 +31,8 @@ from nova.tests.api.openstack import fakes
|
|||
FAKE_UUID = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
|
||||
|
||||
|
||||
def compute_api_get(self, context, instance_id):
|
||||
def compute_api_get(self, context, instance_id, expected_attrs=None,
|
||||
want_objects=False):
|
||||
return dict(uuid=FAKE_UUID, id=instance_id, instance_type_id=1, host='bob')
|
||||
|
||||
|
||||
|
@ -39,6 +43,11 @@ def get_vifs_by_instance(self, context, instance_id):
|
|||
'address': '11-11-11-11-11-11'}]
|
||||
|
||||
|
||||
class FakeRequest(object):
|
||||
def __init__(self, context):
|
||||
self.environ = {'nova.context': context}
|
||||
|
||||
|
||||
class ServerVirtualInterfaceTest(test.NoDBTestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
@ -66,6 +75,22 @@ class ServerVirtualInterfaceTest(test.NoDBTestCase):
|
|||
'mac_address': '11-11-11-11-11-11'}]}
|
||||
self.assertEqual(res_dict, response)
|
||||
|
||||
def test_vif_instance_not_found(self):
|
||||
self.mox.StubOutWithMock(compute_api.API, 'get')
|
||||
fake_context = context.RequestContext('fake', 'fake')
|
||||
fake_req = FakeRequest(fake_context)
|
||||
|
||||
compute_api.API.get(fake_context, 'fake_uuid',
|
||||
expected_attrs=None,
|
||||
want_objects=False).AndRaise(
|
||||
exception.InstanceNotFound(instance_id='instance-0000'))
|
||||
|
||||
self.mox.ReplayAll()
|
||||
self.assertRaises(
|
||||
webob.exc.HTTPNotFound,
|
||||
virtual_interfaces.ServerVirtualInterfaceController().index,
|
||||
fake_req, 'fake_uuid')
|
||||
|
||||
|
||||
class ServerVirtualInterfaceSerializerTest(test.NoDBTestCase):
|
||||
def setUp(self):
|
||||
|
|
Loading…
Reference in New Issue