From 2a870323c3d44d2056b326c184c435a484513532 Mon Sep 17 00:00:00 2001 From: Sean Mooney Date: Thu, 12 Sep 2024 21:05:54 +0100 Subject: [PATCH] allow upgrade of pre-victoria InstanceNUMACells This change ensures that if we are upgrading a InstanceNUMACell object created before victoria <1.5 that we properly set pcpuset=set() when loading the object form the db. This is requried to support instances with a numa topology that do not use cpu pinning. Depends-On: https://review.opendev.org/c/openstack/python-openstackclient/+/929236 Closes-Bug: #2080556 Change-Id: Iea55aabe71c250d8c8e93c61421450b909a7fa3d --- nova/objects/instance_numa.py | 26 ++++++++++++------- nova/tests/unit/objects/test_instance_numa.py | 8 +----- ...-numa-object-upgrade-afa5bb96149ca2f5.yaml | 16 ++++++++++++ 3 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 releasenotes/notes/instance-numa-object-upgrade-afa5bb96149ca2f5.yaml diff --git a/nova/objects/instance_numa.py b/nova/objects/instance_numa.py index ae059d65c2cf..15ad54b63ddb 100644 --- a/nova/objects/instance_numa.py +++ b/nova/objects/instance_numa.py @@ -14,6 +14,7 @@ import itertools +from oslo_log import log as logging from oslo_serialization import jsonutils from oslo_utils import versionutils @@ -24,6 +25,8 @@ from nova.objects import base from nova.objects import fields as obj_fields from nova.virt import hardware +LOG = logging.getLogger(__name__) + # TODO(berrange): Remove NovaObjectDictCompat @base.NovaObjectRegistry.register @@ -63,6 +66,11 @@ class InstanceNUMACell(base.NovaEphemeralObject, obj_fields.CPUAllocationPolicy.DEDICATED): primitive['cpuset'] = primitive['pcpuset'] primitive.pop('pcpuset', None) + LOG.warning( + f'Downgrading InstanceNUMACell to version {target_version} ' + f'may cause the loss of pinned CPUs if mixing different ' + f'verisons of nova on different hosts. This should not ' + f'happen on any supported version after Victoria.') if target_version < (1, 4): primitive.pop('cpuset_reserved', None) @@ -193,17 +201,15 @@ class InstanceNUMATopology(base.NovaObject, if len(cell.cpuset) == 0: continue - if cell.cpu_policy != obj_fields.CPUAllocationPolicy.DEDICATED: - # FIXME(sean-k-mooney): we should be setting the pcpuset - # to an empty set here - # if not 'pcpuset' in cell: - # cell.pcpuset = set() - # update_db = True - continue + if cell.cpu_policy == obj_fields.CPUAllocationPolicy.DEDICATED: + cell.pcpuset = cell.cpuset + cell.cpuset = set() + update_db = True + else: + if 'pcpuset' not in cell: + cell.pcpuset = set() + update_db = True - cell.pcpuset = cell.cpuset - cell.cpuset = set() - update_db = True return update_db # TODO(huaqiang): Remove after Yoga once we are sure these objects have diff --git a/nova/tests/unit/objects/test_instance_numa.py b/nova/tests/unit/objects/test_instance_numa.py index 32b5e7f30856..af1286565ba7 100644 --- a/nova/tests/unit/objects/test_instance_numa.py +++ b/nova/tests/unit/objects/test_instance_numa.py @@ -409,13 +409,7 @@ class _TestInstanceNUMATopology(object): numa_topology.cells, fake_topo_obj_w_cell_v1_4['cells']): self.assertEqual(topo_cell.cpuset, obj_cell.cpuset) - # 'pcpuset' should be an empty set however - # obj_from_db_obj() or more specifically - # _migrate_legacy_dedicated_instance_cpuset() does not set - # 'pcpuset' to an empty set when it is not in the json data. - # self.assertEqual(set(), obj_cell.pcpuset) - self.assertRaises( - NotImplementedError, getattr, obj_cell, 'pcpuset') + self.assertEqual(set(), obj_cell.pcpuset) class TestInstanceNUMATopology( diff --git a/releasenotes/notes/instance-numa-object-upgrade-afa5bb96149ca2f5.yaml b/releasenotes/notes/instance-numa-object-upgrade-afa5bb96149ca2f5.yaml new file mode 100644 index 000000000000..13d149b37632 --- /dev/null +++ b/releasenotes/notes/instance-numa-object-upgrade-afa5bb96149ca2f5.yaml @@ -0,0 +1,16 @@ +--- +upgrade: + - | + In the victoria release, the instance_numa_topology object + was extended to enabled mix cpus (pinned and unpinned cpus) + in the same instance. This change added a new field pcpuset + to the instance_numa_topology object. While the change included + object conversion code to handle the upgrade, it did not account + for instances that have a numa_topology but were not pinned. + i.e. a flavor with hw:mem_page_size or hw:numa_nodes set but + without hw:cpu_policy set to dedicated. As a result, instances + created between liberty and victoria releases with such a flavor + cannot be started after upgrade to victoria. This has now + been fixed. instances created post victoria are not affected by + this issue. see: https://bugs.launchpad.net/nova/+bug/2080556 + for more details. \ No newline at end of file