summaryrefslogtreecommitdiff
path: root/nova/objects/instance_numa.py
diff options
context:
space:
mode:
authorStephen Finucane <stephenfin@redhat.com>2020-04-29 18:00:30 +0100
committerStephen Finucane <stephenfin@redhat.com>2020-05-06 15:40:06 +0100
commit0f61d926b1da0304acf094fd0d189f28bef6b686 (patch)
tree8295c0e94ab7335a17c8650b012a619f5006c678 /nova/objects/instance_numa.py
parent7d25b578da4295d30e113c5dbb05b93ec58e61ee (diff)
downloadnova-0f61d926b1da0304acf094fd0d189f28bef6b686.tar.gz
objects: Add migrate-on-load behavior for legacy NUMA objects
We started storing NUMA information as objects in the database in Kilo (commit bb3202f8594). Prior to this, we had stored this NUMA information as a plain old dict. To facilitate the transition, we provided some handlers based on these '_from_dict' functions. There were used to ensure we could load old-style entries, converting them to objects which we could later save back to the database. It's been over four years (three since Kilo went EOL) and nine (nearly ten) releases, meaning its time to look at dropping this code. At this point, the only thing that could hurt us is attempting to do something with a NUMA-based instance that hasn't been touched since they were first booted on a Kilo or earlier host. Convert the '_to_dict' functionality and overrides of the 'obj_from_primitive' method with a similar check in the DB loading functions. Crucially, inside these DB loading functions, save back when legacy objects are detected. This is acceptable because the 'update_available_resource' in the resource tracker pulls out both compute nodes and instances, with their embedded fields like 'numa_topology', ensuring this will be run as part of the periodic task. NOTE: We don't need to worry about migrations of 'numa_topology' fields in other objects: the 'RequestSpec' and 'MigrationContext' objects were added in Liberty [1][2] and used the 'InstanceNUMATopology' o.vo from the start, while the 'NUMATopology' object has only ever been used in the 'ComputeNode' object. Change-Id: I6cd206542fdd28f3ef551dcc727f4cb35a53f6a3 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Diffstat (limited to 'nova/objects/instance_numa.py')
-rw-r--r--nova/objects/instance_numa.py74
1 files changed, 37 insertions, 37 deletions
diff --git a/nova/objects/instance_numa.py b/nova/objects/instance_numa.py
index 492ccb06d0..62866b328c 100644
--- a/nova/objects/instance_numa.py
+++ b/nova/objects/instance_numa.py
@@ -70,17 +70,6 @@ class InstanceNUMACell(base.NovaEphemeralObject,
def __len__(self):
return len(self.cpuset)
- @classmethod
- def _from_dict(cls, data_dict):
- # NOTE(sahid): Used as legacy, could be renamed in
- # _legacy_from_dict_ to the future to avoid confusing.
- cpuset = hardware.parse_cpu_spec(data_dict.get('cpus', ''))
- memory = data_dict.get('mem', {}).get('total', 0)
- cell_id = data_dict.get('id')
- pagesize = data_dict.get('pagesize')
- return cls(id=cell_id, cpuset=cpuset,
- memory=memory, pagesize=pagesize)
-
@property
def siblings(self):
cpu_list = sorted(list(self.cpuset))
@@ -146,29 +135,47 @@ class InstanceNUMATopology(base.NovaObject,
}
@classmethod
- def obj_from_primitive(cls, primitive, context=None):
+ def obj_from_db_obj(cls, context, instance_uuid, db_obj):
+ primitive = jsonutils.loads(db_obj)
+
if 'nova_object.name' in primitive:
- obj_topology = super(InstanceNUMATopology, cls).obj_from_primitive(
- primitive, context=None)
+ obj = cls.obj_from_primitive(primitive)
else:
- # NOTE(sahid): This compatibility code needs to stay until we can
- # guarantee that there are no cases of the old format stored in
- # the database (or forever, if we can never guarantee that).
- obj_topology = InstanceNUMATopology._from_dict(primitive)
- obj_topology.id = 0
- return obj_topology
+ obj = cls._migrate_legacy_object(context, instance_uuid, primitive)
+
+ return obj
+ # TODO(stephenfin): Remove in X or later, once this has bedded in
@classmethod
- def obj_from_db_obj(cls, instance_uuid, db_obj):
- primitive = jsonutils.loads(db_obj)
- obj_topology = cls.obj_from_primitive(primitive)
+ def _migrate_legacy_object(cls, context, instance_uuid, primitive):
+ """Convert a pre-Liberty object to a real o.vo.
- if 'nova_object.name' not in db_obj:
- obj_topology.instance_uuid = instance_uuid
- # No benefit to store a list of changed fields
- obj_topology.obj_reset_changes()
+ Handle an unversioned object created prior to Liberty, by transforming
+ to a versioned object and saving back the serialized version of this.
- return obj_topology
+ :param context: RequestContext
+ :param instance_uuid: The UUID of the instance this topology is
+ associated with.
+ :param primitive: A serialized representation of the legacy object.
+ :returns: A serialized representation of the updated object.
+ """
+ obj = cls(
+ instance_uuid=instance_uuid,
+ cells=[
+ InstanceNUMACell(
+ id=cell.get('id'),
+ cpuset=hardware.parse_cpu_spec(cell.get('cpus', '')),
+ memory=cell.get('mem', {}).get('total', 0),
+ pagesize=cell.get('pagesize'),
+ ) for cell in primitive.get('cells', [])
+ ],
+ )
+ db_obj = jsonutils.dumps(obj.obj_to_primitive())
+ values = {
+ 'numa_topology': db_obj,
+ }
+ db.instance_extra_update_by_uuid(context, instance_uuid, values)
+ return obj
# TODO(ndipanov) Remove this method on the major version bump to 2.0
@base.remotable
@@ -188,7 +195,8 @@ class InstanceNUMATopology(base.NovaObject,
if db_extra['numa_topology'] is None:
return None
- return cls.obj_from_db_obj(instance_uuid, db_extra['numa_topology'])
+ return cls.obj_from_db_obj(
+ context, instance_uuid, db_extra['numa_topology'])
def _to_json(self):
return jsonutils.dumps(self.obj_to_primitive())
@@ -197,14 +205,6 @@ class InstanceNUMATopology(base.NovaObject,
"""Defined so that boolean testing works the same as for lists."""
return len(self.cells)
- @classmethod
- def _from_dict(cls, data_dict):
- # NOTE(sahid): Used as legacy, could be renamed in _legacy_from_dict_
- # in the future to avoid confusing.
- return cls(cells=[
- InstanceNUMACell._from_dict(cell_dict)
- for cell_dict in data_dict.get('cells', [])])
-
@property
def cpu_pinning(self):
"""Return a set of all host CPUs this NUMATopology is pinned to."""