|
13 | 13 | import copy
|
14 | 14 | from unittest import mock
|
15 | 15 |
|
| 16 | +from oslo_serialization import jsonutils |
16 | 17 | from oslo_utils.fixture import uuidsentinel as uuids
|
17 | 18 | from oslo_versionedobjects import base as ovo_base
|
18 | 19 | import testtools
|
@@ -411,6 +412,46 @@ def test_obj_from_db_obj_no_pinning(self):
|
411 | 412 | self.assertEqual(topo_cell.cpuset, obj_cell.cpuset)
|
412 | 413 | self.assertEqual(set(), obj_cell.pcpuset)
|
413 | 414 |
|
| 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 | + |
414 | 455 |
|
415 | 456 | class TestInstanceNUMATopology(
|
416 | 457 | test_objects._LocalTest, _TestInstanceNUMATopology,
|
|
0 commit comments