objects: Remove 'NovaObjectDictCompat' from 'InstancePCIRequest'

Addresses a long-standing TODO. We remove the
'InstancePCIRequests.from_request_spec_instance_props' helper since it's
entirely unnecessary: the built-in 'obj_from_primitive' wrapper will do
what we want here (creating an o.vo from a serialized representation of
the object).

Change-Id: I5208b7dff996828137dfddfdd2db8737126884e3
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2020-04-27 14:06:31 +01:00
parent 028b3bca16
commit 86ded7f65d
5 changed files with 24 additions and 45 deletions

View File

@ -18,10 +18,8 @@ from nova.objects import base
from nova.objects import fields
# TODO(berrange): Remove NovaObjectDictCompat
@base.NovaObjectRegistry.register
class InstancePCIRequest(base.NovaObject,
base.NovaObjectDictCompat):
class InstancePCIRequest(base.NovaObject):
# Version 1.0: Initial version
# Version 1.1: Added request_id field
# Version 1.2: Added numa_policy field
@ -70,10 +68,8 @@ class InstancePCIRequest(base.NovaObject,
del primitive['request_id']
# TODO(berrange): Remove NovaObjectDictCompat
@base.NovaObjectRegistry.register
class InstancePCIRequests(base.NovaObject,
base.NovaObjectDictCompat):
class InstancePCIRequests(base.NovaObject):
# Version 1.0: Initial version
# Version 1.1: InstancePCIRequest 1.1
VERSION = '1.1'
@ -155,9 +151,3 @@ class InstancePCIRequests(base.NovaObject,
'request_id': x.request_id,
'requester_id': x.requester_id} for x in self.requests]
return jsonutils.dumps(blob)
@classmethod
def from_request_spec_instance_props(cls, pci_requests):
objs = [InstancePCIRequest(**request)
for request in pci_requests['requests']]
return cls(requests=objs, instance_uuid=pci_requests['instance_uuid'])

View File

@ -248,9 +248,9 @@ class RequestSpec(base.NovaObject):
def _from_instance_pci_requests(self, pci_requests):
if isinstance(pci_requests, dict):
pci_req_cls = objects.InstancePCIRequests
self.pci_requests = pci_req_cls.from_request_spec_instance_props(
pci_requests)
self.pci_requests = objects.InstancePCIRequests.obj_from_primitive(
pci_requests,
)
else:
self.pci_requests = pci_requests

View File

@ -112,23 +112,6 @@ class _TestInstancePCIRequests(object):
self.assertIsNone(req.requests[0].requester_id)
self.assertEqual(uuids.requester_id, req.requests[1].requester_id)
def test_from_request_spec_instance_props(self):
requests = objects.InstancePCIRequests(
requests=[objects.InstancePCIRequest(count=1,
request_id=FAKE_UUID,
spec=[{'vendor_id': '8086',
'device_id': '1502'}])
],
instance_uuid=FAKE_UUID)
result = jsonutils.to_primitive(requests)
result = objects.InstancePCIRequests.from_request_spec_instance_props(
result)
self.assertEqual(1, len(result.requests))
self.assertEqual(1, result.requests[0].count)
self.assertEqual(FAKE_UUID, result.requests[0].request_id)
self.assertEqual([{'vendor_id': '8086', 'device_id': '1502'}],
result.requests[0].spec)
def test_obj_make_compatible_pre_1_2(self):
topo_obj = objects.InstancePCIRequest(
count=1,

View File

@ -116,14 +116,19 @@ class _TestRequestSpecObject(object):
else:
self.assertEqual(instance.get(field), getattr(spec, field))
@mock.patch.object(objects.InstancePCIRequests,
'from_request_spec_instance_props')
def test_from_instance_with_pci_requests(self, pci_from_spec):
fake_pci_requests = objects.InstancePCIRequests()
pci_from_spec.return_value = fake_pci_requests
def test_from_instance_with_pci_requests(self):
fake_pci_requests = objects.InstancePCIRequests(
instance_uuid=uuids.instance,
requests=[
objects.InstancePCIRequest(
count=1,
spec=[{'vendor_id': '8086'}],
),
],
)
instance = dict(
uuid=uuidutils.generate_uuid(),
uuid=uuids.instance,
root_gb=10,
ephemeral_gb=0,
memory_mb=10,
@ -132,14 +137,15 @@ class _TestRequestSpecObject(object):
project_id=fakes.FAKE_PROJECT_ID,
user_id=fakes.FAKE_USER_ID,
availability_zone='nova',
pci_requests={
'instance_uuid': 'fakeid',
'requests': [{'count': 1, 'spec': [{'vendor_id': '8086'}]}]})
pci_requests=fake_pci_requests.obj_to_primitive(),
)
spec = objects.RequestSpec()
spec._from_instance(instance)
pci_from_spec.assert_called_once_with(instance['pci_requests'])
self.assertEqual(fake_pci_requests, spec.pci_requests)
self.assertEqual(
fake_pci_requests.requests[0].spec,
spec.pci_requests.requests[0].spec,
)
def test_from_instance_with_numa_stuff(self):
instance = dict(

View File

@ -255,7 +255,7 @@ class PciRequestTestCase(test.NoDBTestCase):
requests = request._translate_alias_to_requests(
"QuickAssist : 3, IntelNIC: 1")
self.assertEqual(set([p['count'] for p in requests]), set([1, 3]))
self.assertEqual(set([p.count for p in requests]), set([1, 3]))
self._verify_result(expect_request, requests)
def test_translate_alias_to_requests_invalid(self):
@ -292,7 +292,7 @@ class PciRequestTestCase(test.NoDBTestCase):
requests = request._translate_alias_to_requests(
"QuickAssist : 3, IntelNIC: 1", affinity_policy=policy)
self.assertEqual(set([p['count'] for p in requests]), set([1, 3]))
self.assertEqual(set([p.count for p in requests]), set([1, 3]))
self._verify_result(expect_request, requests)
@mock.patch.object(objects.compute_node.ComputeNode,