objects: Add PCI NUMA policy fields

Add the requisite policy field to 'InstacePCIRequests' for the
aforementioned feature. We also add a missing 'super' call for the
'obj_make_compatible' function of this object and add the missing unit
tests for same.

bp share-pci-between-numa-nodes

Change-Id: I9360fe299083045a4baf4a703d2b53b3eb30a558
This commit is contained in:
Stephen Finucane 2017-12-12 11:51:24 +00:00
parent 2506afda54
commit 0cd858b4ab
4 changed files with 47 additions and 2 deletions

View File

@ -734,6 +734,15 @@ class PciDeviceType(BaseNovaEnum):
ALL = (STANDARD, SRIOV_PF, SRIOV_VF)
class PCINUMAAffinityPolicy(BaseNovaEnum):
REQUIRED = "required"
LEGACY = "legacy"
PREFERRED = "preferred"
ALL = (REQUIRED, LEGACY, PREFERRED)
class DiskFormat(BaseNovaEnum):
RBD = "rbd"
LVM = "lvm"
@ -1202,6 +1211,10 @@ class PciDeviceTypeField(BaseEnumField):
AUTO_TYPE = PciDeviceType()
class PCINUMAAffinityPolicyField(BaseEnumField):
AUTO_TYPE = PCINUMAAffinityPolicy()
class DiskFormatField(BaseEnumField):
AUTO_TYPE = DiskFormat()

View File

@ -24,7 +24,8 @@ class InstancePCIRequest(base.NovaObject,
base.NovaObjectDictCompat):
# Version 1.0: Initial version
# Version 1.1: Add request_id
VERSION = '1.1'
# Version 1.2: Add PCI NUMA affinity policy
VERSION = '1.2'
fields = {
'count': fields.IntegerField(),
@ -34,13 +35,18 @@ class InstancePCIRequest(base.NovaObject,
# on major version bump
'is_new': fields.BooleanField(default=False),
'request_id': fields.UUIDField(nullable=True),
'numa_policy': fields.PCINUMAAffinityPolicyField(nullable=True),
}
def obj_load_attr(self, attr):
setattr(self, attr, None)
def obj_make_compatible(self, primitive, target_version):
super(InstancePCIRequest, self).obj_make_compatible(primitive,
target_version)
target_version = versionutils.convert_version_to_tuple(target_version)
if target_version < (1, 2) and 'numa_policy' in primitive:
del primitive['numa_policy']
if target_version < (1, 1) and 'request_id' in primitive:
del primitive['request_id']

View File

@ -12,8 +12,10 @@
import mock
from oslo_serialization import jsonutils
from oslo_versionedobjects import base as ovo_base
from nova import objects
from nova.objects import fields
from nova.tests.unit.objects import test_objects
from nova.tests import uuidsentinel as uuids
@ -133,6 +135,30 @@ class _TestInstancePCIRequests(object):
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,
spec=[{'vendor_id': '8086', 'device_id': '1502'}],
request_id=uuids.pci_request_id,
numa_policy=fields.PCINUMAAffinityPolicy.PREFERRED)
versions = ovo_base.obj_tree_get_versions('InstancePCIRequest')
primitive = topo_obj.obj_to_primitive(target_version='1.1',
version_manifest=versions)
self.assertNotIn('numa_policy', primitive['nova_object.data'])
self.assertIn('request_id', primitive['nova_object.data'])
def test_obj_make_compatible_pre_1_1(self):
topo_obj = objects.InstancePCIRequest(
count=1,
spec=[{'vendor_id': '8086', 'device_id': '1502'}],
request_id=uuids.pci_request_id)
versions = ovo_base.obj_tree_get_versions('InstancePCIRequest')
primitive = topo_obj.obj_to_primitive(target_version='1.0',
version_manifest=versions)
self.assertNotIn('request_id', primitive['nova_object.data'])
class TestInstancePCIRequests(test_objects._LocalTest,
_TestInstancePCIRequests):

View File

@ -1115,7 +1115,7 @@ object_data = {
'InstanceMappingList': '1.2-ee638619aa3d8a82a59c0c83bfa64d78',
'InstanceNUMACell': '1.4-7c1eb9a198dee076b4de0840e45f4f55',
'InstanceNUMATopology': '1.3-ec0030cb0402a49c96da7051c037082a',
'InstancePCIRequest': '1.1-b1d75ebc716cb12906d9d513890092bf',
'InstancePCIRequest': '1.2-6344dd8bd1bf873e7325c07afe47f774',
'InstancePCIRequests': '1.1-65e38083177726d806684cb1cc0136d2',
'LibvirtLiveMigrateBDMInfo': '1.0-252aabb723ca79d5469fa56f64b57811',
'LibvirtLiveMigrateData': '1.4-ae5f344e7f78d3b45c259a0f80ea69f5',