diff options
author | Stephen Finucane <stephenfin@redhat.com> | 2020-03-11 16:01:34 +0000 |
---|---|---|
committer | Stephen Finucane <stephenfin@redhat.com> | 2020-06-19 14:43:12 +0100 |
commit | 690ce37e72f3a189100ab9839c2233e1e4951ba0 (patch) | |
tree | 9ddbc46e4dff1420bcd73c874f955d193b8b831c /nova/tests/unit/objects/test_instance_numa.py | |
parent | dff70b3bce0d3eb2fc493026f0acb3557d85a976 (diff) | |
download | nova-690ce37e72f3a189100ab9839c2233e1e4951ba0.tar.gz |
objects: Replace 'cpu_pinning_requested' helper
This helper avoided a slightly long-winded check for what was
essentially a binary condition before. With the future introduction of a
'mixed' policy, this isn't always going to be suitable going forward.
Replace it with explicit checks for types.
Part of blueprint use-pcpu-and-vcpu-in-one-instance
Change-Id: If7512c998bca770889d81012a17a1a2978cae68e
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Diffstat (limited to 'nova/tests/unit/objects/test_instance_numa.py')
-rw-r--r-- | nova/tests/unit/objects/test_instance_numa.py | 56 |
1 files changed, 41 insertions, 15 deletions
diff --git a/nova/tests/unit/objects/test_instance_numa.py b/nova/tests/unit/objects/test_instance_numa.py index 8278815a75..59c7289b81 100644 --- a/nova/tests/unit/objects/test_instance_numa.py +++ b/nova/tests/unit/objects/test_instance_numa.py @@ -10,11 +10,10 @@ # License for the specific language governing permissions and limitations # under the License. -import copy - import mock from oslo_utils.fixture import uuidsentinel as uuids from oslo_versionedobjects import base as ovo_base +import testtools from nova import exception from nova import objects @@ -94,13 +93,6 @@ class _TestInstanceNUMACell(object): inst_cell.pin_vcpus((0, 14), (1, 15), (2, 16), (3, 17)) self.assertEqual({0: 14, 1: 15, 2: 16, 3: 17}, inst_cell.cpu_pinning) - def test_cpu_pinning_requested(self): - inst_cell = objects.InstanceNUMACell(cpuset=set([0, 1, 2, 3]), - cpu_pinning=None) - self.assertFalse(inst_cell.cpu_pinning_requested) - inst_cell.cpu_policy = fields.CPUAllocationPolicy.DEDICATED - self.assertTrue(inst_cell.cpu_pinning_requested) - def test_cpu_pinning(self): topo_obj = get_fake_obj_numa_topology(self.context) self.assertEqual(set(), topo_obj.cpu_pinning) @@ -192,12 +184,46 @@ class _TestInstanceNUMATopology(object): objects.InstanceNUMATopology.get_by_instance_uuid, self.context, 'fake_uuid') - def test_cpu_pinning_requested(self): - fake_topo_obj = copy.deepcopy(fake_obj_numa_topology) - self.assertFalse(fake_topo_obj.cpu_pinning_requested) - for cell in fake_topo_obj.cells: - cell.cpu_policy = fields.CPUAllocationPolicy.DEDICATED - self.assertTrue(fake_topo_obj.cpu_pinning_requested) + def test_cpu_policy(self): + cpu_policy = fields.CPUAllocationPolicy.SHARED + topology = objects.InstanceNUMATopology( + instance_uuid=fake_instance_uuid, + cells=[ + objects.InstanceNUMACell( + cpuset=set([0, 1, 2, 3]), + cpu_pinning=None, + cpu_policy=cpu_policy, + ), + objects.InstanceNUMACell( + cpuset=set([4, 5, 6, 7]), + cpu_pinning=None, + cpu_policy=cpu_policy, + ), + ], + ) + + self.assertEqual(cpu_policy, topology.cpu_policy) + + def test_cpu_policy__error(self): + """Ensure we raise an error if cells have different values.""" + topology = objects.InstanceNUMATopology( + instance_uuid=fake_instance_uuid, + cells=[ + objects.InstanceNUMACell( + cpuset=set([0, 1, 2, 3]), + cpu_pinning=None, + cpu_policy=None, + ), + objects.InstanceNUMACell( + cpuset=set([4, 5, 6, 7]), + cpu_pinning=None, + cpu_policy=fields.CPUAllocationPolicy.SHARED + ), + ], + ) + + with testtools.ExpectedException(exception.InternalError): + topology.cpu_policy def test_cpuset_reserved(self): topology = objects.InstanceNUMATopology( |