cleanup NovaObjectDictCompat from virtual_interface
cleanup subclassing on NovaObjectDictCompat and fix subsequent tests and code associated with nova/objects/virtual_interface.py Due to the exhaustive nature of changes, the cleanup is done one object at a time. This is the second patch of the series. There shall be more patches to follow for other objects. Related to blueprint liberty-objects Change-Id: Ia66bea59828beaeb8d79348331619d0b848c1a3f
This commit is contained in:
parent
a0923fc4e2
commit
2b4e1fe0cc
@ -33,7 +33,7 @@ class ExtendedServerVIFNetController(wsgi.Controller):
|
||||
for vif in resp_obj.obj['virtual_interfaces']:
|
||||
vif1 = self.network_api.get_vif_by_mac_address(context,
|
||||
vif['mac_address'])
|
||||
vif[key] = vif1['net_uuid']
|
||||
vif[key] = vif1.net_uuid
|
||||
|
||||
|
||||
class Extended_virtual_interfaces_net(extensions.ExtensionDescriptor):
|
||||
|
@ -27,8 +27,8 @@ authorize = extensions.extension_authorizer('compute', 'virtual_interfaces')
|
||||
def _translate_vif_summary_view(_context, vif):
|
||||
"""Maps keys for VIF summary view."""
|
||||
d = {}
|
||||
d['id'] = vif['uuid']
|
||||
d['mac_address'] = vif['address']
|
||||
d['id'] = vif.uuid
|
||||
d['mac_address'] = vif.address
|
||||
return d
|
||||
|
||||
|
||||
|
@ -29,8 +29,8 @@ authorize = extensions.os_compute_authorizer(ALIAS)
|
||||
def _translate_vif_summary_view(_context, vif):
|
||||
"""Maps keys for VIF summary view."""
|
||||
d = {}
|
||||
d['id'] = vif['uuid']
|
||||
d['mac_address'] = vif['address']
|
||||
d['id'] = vif.uuid
|
||||
d['mac_address'] = vif.address
|
||||
return d
|
||||
|
||||
|
||||
|
@ -19,10 +19,8 @@ from nova.objects import base
|
||||
from nova.objects import fields
|
||||
|
||||
|
||||
# TODO(berrange): Remove NovaObjectDictCompat
|
||||
@base.NovaObjectRegistry.register
|
||||
class VirtualInterface(base.NovaPersistentObject, base.NovaObject,
|
||||
base.NovaObjectDictCompat):
|
||||
class VirtualInterface(base.NovaPersistentObject, base.NovaObject):
|
||||
# Version 1.0: Initial version
|
||||
VERSION = '1.0'
|
||||
|
||||
@ -37,7 +35,7 @@ class VirtualInterface(base.NovaPersistentObject, base.NovaObject,
|
||||
@staticmethod
|
||||
def _from_db_object(context, vif, db_vif):
|
||||
for field in vif.fields:
|
||||
vif[field] = db_vif[field]
|
||||
setattr(vif, field, db_vif[field])
|
||||
vif._context = context
|
||||
vif.obj_reset_changes()
|
||||
return vif
|
||||
|
@ -19,22 +19,29 @@ import webob
|
||||
from nova.api.openstack.compute.contrib import extended_virtual_interfaces_net
|
||||
from nova import compute
|
||||
from nova import network
|
||||
from nova.objects import virtual_interface as vif_obj
|
||||
from nova import test
|
||||
from nova.tests.unit.api.openstack import fakes
|
||||
|
||||
|
||||
FAKE_UUID = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
|
||||
|
||||
EXPECTED_NET_UUIDS = [123,
|
||||
456]
|
||||
|
||||
FAKE_VIFS = [{'uuid': '00000000-0000-0000-0000-00000000000000000',
|
||||
'address': '00-00-00-00-00-00',
|
||||
'net_uuid': '00000000-0000-0000-0000-00000000000000001'},
|
||||
{'uuid': '11111111-1111-1111-1111-11111111111111111',
|
||||
'address': '11-11-11-11-11-11',
|
||||
'net_uuid': '11111111-1111-1111-1111-11111111111111112'}]
|
||||
|
||||
EXPECTED_NET_UUIDS = ['00000000-0000-0000-0000-00000000000000001',
|
||||
'11111111-1111-1111-1111-11111111111111112']
|
||||
def _generate_fake_vifs(context):
|
||||
vif = vif_obj.VirtualInterface(context=context)
|
||||
vif.address = '00-00-00-00-00-00'
|
||||
vif.net_uuid = 123
|
||||
vif.uuid = '00000000-0000-0000-0000-00000000000000000'
|
||||
fake_vifs = [vif]
|
||||
vif = vif_obj.VirtualInterface(context=context)
|
||||
vif.address = '11-11-11-11-11-11'
|
||||
vif.net_uuid = 456
|
||||
vif.uuid = '11111111-1111-1111-1111-11111111111111111'
|
||||
fake_vifs.append(vif)
|
||||
return fake_vifs
|
||||
|
||||
|
||||
def compute_api_get(self, context, instance_id, expected_attrs=None,
|
||||
@ -43,14 +50,14 @@ def compute_api_get(self, context, instance_id, expected_attrs=None,
|
||||
|
||||
|
||||
def get_vifs_by_instance(self, context, instance_id):
|
||||
return FAKE_VIFS
|
||||
return _generate_fake_vifs(context)
|
||||
|
||||
|
||||
def get_vif_by_mac_address(self, context, mac_address):
|
||||
if mac_address == "00-00-00-00-00-00":
|
||||
return {'net_uuid': '00000000-0000-0000-0000-00000000000000001'}
|
||||
return _generate_fake_vifs(context)[0]
|
||||
else:
|
||||
return {'net_uuid': '11111111-1111-1111-1111-11111111111111112'}
|
||||
return _generate_fake_vifs(context)[1]
|
||||
|
||||
|
||||
class ExtendedServerVIFNetTest(test.NoDBTestCase):
|
||||
|
@ -22,6 +22,7 @@ from nova.compute import api as compute_api
|
||||
from nova import context
|
||||
from nova import exception
|
||||
from nova import network
|
||||
from nova.objects import virtual_interface as vif_obj
|
||||
from nova import test
|
||||
from nova.tests.unit.api.openstack import fakes
|
||||
|
||||
@ -34,11 +35,22 @@ def compute_api_get(self, context, instance_id, expected_attrs=None,
|
||||
return dict(uuid=FAKE_UUID, id=instance_id, instance_type_id=1, host='bob')
|
||||
|
||||
|
||||
def _generate_fake_vifs(context):
|
||||
vif = vif_obj.VirtualInterface(context=context)
|
||||
vif.address = '00-00-00-00-00-00'
|
||||
vif.network_id = 123
|
||||
vif.uuid = '00000000-0000-0000-0000-00000000000000000'
|
||||
fake_vifs = [vif]
|
||||
vif = vif_obj.VirtualInterface(context=context)
|
||||
vif.address = '11-11-11-11-11-11'
|
||||
vif.network_id = 456
|
||||
vif.uuid = '11111111-1111-1111-1111-11111111111111111'
|
||||
fake_vifs.append(vif)
|
||||
return fake_vifs
|
||||
|
||||
|
||||
def get_vifs_by_instance(self, context, instance_id):
|
||||
return [{'uuid': '00000000-0000-0000-0000-00000000000000000',
|
||||
'address': '00-00-00-00-00-00'},
|
||||
{'uuid': '11111111-1111-1111-1111-11111111111111111',
|
||||
'address': '11-11-11-11-11-11'}]
|
||||
return _generate_fake_vifs(context)
|
||||
|
||||
|
||||
class FakeRequest(object):
|
||||
|
@ -36,7 +36,7 @@ class _TestVirtualInterface(object):
|
||||
@staticmethod
|
||||
def _compare(test, db, obj):
|
||||
for field, value in db.items():
|
||||
test.assertEqual(db[field], obj[field])
|
||||
test.assertEqual(db[field], getattr(obj, field))
|
||||
|
||||
def test_get_by_id(self):
|
||||
with mock.patch.object(db, 'virtual_interface_get') as get:
|
||||
|
Loading…
x
Reference in New Issue
Block a user