Merge "Refactor obj_make_compatible to reduce complexity"

This commit is contained in:
Zuul
2024-10-29 16:14:00 +00:00
committed by Gerrit Code Review
4 changed files with 37 additions and 54 deletions
+10
View File
@@ -26,6 +26,7 @@ from oslo_utils import versionutils
from oslo_versionedobjects import base as ovoo_base
from oslo_versionedobjects import exception as ovoo_exc
from nova import exception
from nova import objects
from nova.objects import fields as obj_fields
from nova import utils
@@ -58,6 +59,15 @@ def get_attrname(name):
return '_obj_' + name
def raise_on_too_new_values(version, primitive, field, new_values):
value = primitive.get(field, None)
if value in new_values:
raise exception.ObjectActionError(
action='obj_make_compatible',
reason='%s=%s not supported in version %s' %
(field, value, version))
class NovaObjectRegistry(ovoo_base.VersionedObjectRegistry):
notification_classes = []
+19 -32
View File
@@ -16,7 +16,6 @@ import copy
from oslo_utils import versionutils
from nova import exception
from nova import objects
from nova.objects import base
from nova.objects import fields
@@ -224,32 +223,23 @@ class ImageMetaProps(base.NovaObject):
if target_version < (1, 31):
primitive.pop('hw_emulation_architecture', None)
if target_version < (1, 30):
video = primitive.get('hw_video_model', None)
if video == fields.VideoModel.BOCHS:
raise exception.ObjectActionError(
action='obj_make_compatible',
reason='hw_video_model=%s not supported in version %s' %
(video, target_version))
base.raise_on_too_new_values(
target_version, primitive,
'hw_video_model', (fields.VideoModel.BOCHS,))
if target_version < (1, 29):
primitive.pop('hw_input_bus', None)
if target_version < (1, 28):
policy = primitive.get('hw_pci_numa_affinity_policy', None)
if policy == fields.PCINUMAAffinityPolicy.SOCKET:
raise exception.ObjectActionError(
action='obj_make_compatible',
reason='hw_numa_affinity_policy=%s not supported '
'in version %s' %
(policy, target_version))
base.raise_on_too_new_values(
target_version, primitive,
'hw_pci_numa_affinity_policy',
(fields.PCINUMAAffinityPolicy.SOCKET,))
if target_version < (1, 27):
primitive.pop('hw_tpm_model', None)
primitive.pop('hw_tpm_version', None)
if target_version < (1, 26):
policy = primitive.get('hw_cpu_policy', None)
if policy == fields.CPUAllocationPolicy.MIXED:
raise exception.ObjectActionError(
action='obj_make_compatible',
reason='hw_cpu_policy=%s not supported in version %s' %
(policy, target_version))
base.raise_on_too_new_values(
target_version, primitive,
'hw_cpu_policy', (fields.CPUAllocationPolicy.MIXED,))
if target_version < (1, 25):
primitive.pop('hw_pci_numa_affinity_policy', None)
if target_version < (1, 24):
@@ -259,12 +249,12 @@ class ImageMetaProps(base.NovaObject):
# NOTE(sean-k-mooney): unlike other nova object we version this object
# when composed object are updated.
if target_version < (1, 22):
video = primitive.get('hw_video_model', None)
if video in ('gop', 'virtio', 'none'):
raise exception.ObjectActionError(
action='obj_make_compatible',
reason='hw_video_model=%s not supported in version %s' % (
video, target_version))
base.raise_on_too_new_values(
target_version, primitive,
'hw_video_model',
(fields.VideoModel.GOP,
fields.VideoModel.VIRTIO,
fields.VideoModel.NONE))
if target_version < (1, 21):
primitive.pop('hw_time_hpet', None)
if target_version < (1, 20):
@@ -303,12 +293,9 @@ class ImageMetaProps(base.NovaObject):
primitive.pop('os_require_quiesce', None)
if target_version < (1, 6):
bus = primitive.get('hw_disk_bus', None)
if bus in ('lxc', 'uml'):
raise exception.ObjectActionError(
action='obj_make_compatible',
reason='hw_disk_bus=%s not supported in version %s' % (
bus, target_version))
base.raise_on_too_new_values(
target_version, primitive,
'hw_disk_bus', (fields.DiskBus.LXC, fields.DiskBus.UML))
# Maximum number of NUMA nodes permitted for the guest topology
NUMA_NODES_MAX = 128
+3 -10
View File
@@ -20,7 +20,6 @@ from oslo_utils import versionutils
from nova.db.main import api as db
from nova import exception
from nova.i18n import _
from nova.objects import base
from nova.objects import fields as obj_fields
from nova.virt import hardware
@@ -48,15 +47,9 @@ class InstanceNUMACell(base.NovaEphemeralObject,
# Instance with a 'mixed' CPU policy could not provide a backward
# compatibility.
if target_version < (1, 6):
if primitive['cpu_policy'] == obj_fields.CPUAllocationPolicy.MIXED:
raise exception.ObjectActionError(
action='obj_make_compatible',
reason=_(
'{policy} policy is not supported in '
'version {version}'
).format(policy=primitive['cpu_policy'],
version=target_version))
base.raise_on_too_new_values(
target_version, primitive,
'cpu_policy', (obj_fields.CPUAllocationPolicy.MIXED,))
# NOTE(huaqiang): Since version 1.5, 'cpuset' is modified to track the
# unpinned CPUs only, with pinned CPUs tracked via 'pcpuset' instead.
# For a backward compatibility, move the 'dedicated' instance CPU list
+5 -12
View File
@@ -132,21 +132,14 @@ class PciDevice(base.NovaPersistentObject, base.NovaObject):
if target_version < (1, 5) and 'parent_addr' in primitive:
added_statuses = (fields.PciDeviceStatus.UNCLAIMABLE,
fields.PciDeviceStatus.UNAVAILABLE)
status = primitive['status']
if status in added_statuses:
raise exception.ObjectActionError(
action='obj_make_compatible',
reason='status=%s not supported in version %s' % (
status, target_version))
base.raise_on_too_new_values(
target_version, primitive, 'status', added_statuses)
if target_version < (1, 6) and 'uuid' in primitive:
del primitive['uuid']
if target_version < (1, 7) and 'dev_type' in primitive:
dev_type = primitive['dev_type']
if dev_type == fields.PciDeviceType.VDPA:
raise exception.ObjectActionError(
action='obj_make_compatible',
reason='dev_type=%s not supported in version %s' % (
dev_type, target_version))
base.raise_on_too_new_values(
target_version, primitive,
'dev_type', (fields.PciDeviceType.VDPA,))
def __repr__(self):
return (