Skip to content

Commit b597517

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Reproduce bug/2097359" into unmaintained/2023.1
2 parents df065e9 + d907c1f commit b597517

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

nova/tests/unit/objects/test_instance_numa.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import copy
1414
from unittest import mock
1515

16+
from oslo_serialization import jsonutils
1617
from oslo_utils.fixture import uuidsentinel as uuids
1718
from oslo_versionedobjects import base as ovo_base
1819
import testtools
@@ -411,6 +412,46 @@ def test_obj_from_db_obj_no_pinning(self):
411412
self.assertEqual(topo_cell.cpuset, obj_cell.cpuset)
412413
self.assertEqual(set(), obj_cell.pcpuset)
413414

415+
def test__migrate_legacy_dedicated_instance_cpuset(self):
416+
# Create a topology with a cell on latest version. Would be nice
417+
# to create one the old 1.4 cell version directly but that is only
418+
# possible indirectly as done below.
419+
topo = objects.InstanceNUMATopology(
420+
instance_uuid=fake_instance_uuid,
421+
cells=[
422+
objects.InstanceNUMACell(id=0, cpuset=set(), pcpuset={0, 1}),
423+
])
424+
topo.cells[0].cpu_policy = objects.fields.CPUAllocationPolicy.DEDICATED
425+
426+
# Use the builtin backlevelling logic to pull it back to old cell
427+
# version
428+
topo_with_cell_1_4 = topo.obj_to_primitive(
429+
target_version='1.3', version_manifest={'InstanceNUMACell': '1.4'})
430+
431+
# Just check that the backlevelling works, and we have a cell with
432+
# version and data on 1.4 level
433+
cell_1_4_primitive = topo_with_cell_1_4['nova_object.data']['cells'][0]
434+
self.assertEqual('1.4', cell_1_4_primitive['nova_object.version'])
435+
self.assertEqual(
436+
(0, 1), cell_1_4_primitive['nova_object.data']['cpuset'])
437+
self.assertNotIn('pcpuset', cell_1_4_primitive['nova_object.data'])
438+
439+
# Now simulate that such old data is loaded from the DB and migrated
440+
# from 1.4 to 1.6 by the data migration
441+
topo_loaded = objects.InstanceNUMATopology.obj_from_db_obj(
442+
self.context, fake_instance_uuid,
443+
jsonutils.dumps(topo_with_cell_1_4))
444+
445+
# In place data migration happens during load, cpuset data is moved to
446+
# pcpuset
447+
self.assertEqual(set(), topo_loaded.cells[0].cpuset)
448+
self.assertEqual({0, 1}, topo_loaded.cells[0].pcpuset)
449+
# but the object version isn't bumped. So when the
450+
# data is saved back to the DB it still has the old version 1.4, but
451+
# also it has the new pcpuset field from version 1.6. This is bug
452+
# https://bugs.launchpad.net/nova/+bug/2097359.
453+
self.assertEqual('1.4', topo_loaded.cells[0].VERSION)
454+
414455

415456
class TestInstanceNUMATopology(
416457
test_objects._LocalTest, _TestInstanceNUMATopology,

0 commit comments

Comments
 (0)