From 79887a610bef5b9402d059b9f7afd3d204e7342e Mon Sep 17 00:00:00 2001 From: Jonathan Race Date: Tue, 8 Feb 2022 10:36:36 -0500 Subject: [PATCH] object/notification for Adds Pick guest CPU architecture based on host arch in libvirt driver support This is split 1 of 3 for the architecture emulation feature. This adds the 'hw_emulation_architecture' property to the image meta properties, allowing for operator to define whether they will use emulation or not. This adds the capability as a feature to ensure no impact to normal operations or functionality. Account for object versioning has been added to raise exceptions and handle proper Implements: blueprint pick-guest-arch-based-on-host-arch-in-libvirt-driver Signed-off-by: Jonathan Race Change-Id: If4f598c0d3f9e64617beb54450faa04e7d20dd20 --- .../ImageMetaPropsPayload.json | 2 +- nova/notifications/objects/image.py | 3 ++- nova/objects/image_meta.py | 9 ++++++++- .../test_instance.py | 4 ++-- .../objects/test_notification.py | 2 +- nova/tests/unit/objects/test_image_meta.py | 19 +++++++++++++++++++ nova/tests/unit/objects/test_objects.py | 2 +- 7 files changed, 34 insertions(+), 7 deletions(-) diff --git a/doc/notification_samples/common_payloads/ImageMetaPropsPayload.json b/doc/notification_samples/common_payloads/ImageMetaPropsPayload.json index ef9d49647db7..d1adfcc42733 100644 --- a/doc/notification_samples/common_payloads/ImageMetaPropsPayload.json +++ b/doc/notification_samples/common_payloads/ImageMetaPropsPayload.json @@ -4,5 +4,5 @@ "hw_architecture": "x86_64" }, "nova_object.name": "ImageMetaPropsPayload", - "nova_object.version": "1.8" + "nova_object.version": "1.9" } diff --git a/nova/notifications/objects/image.py b/nova/notifications/objects/image.py index 0240d00105ea..b4852fc4e7b4 100644 --- a/nova/notifications/objects/image.py +++ b/nova/notifications/objects/image.py @@ -125,7 +125,8 @@ class ImageMetaPropsPayload(base.NotificationPayloadBase): # Version 1.6: Added 'socket' to hw_pci_numa_affinity_policy # Version 1.7: Added 'hw_input_bus' field # Version 1.8: Added 'bochs' as an option to 'hw_video_model' - VERSION = '1.8' + # Version 1.9: Added 'hw_emulation_architecture' field + VERSION = '1.9' SCHEMA = { k: ('image_meta_props', k) for k in image_meta.ImageMetaProps.fields} diff --git a/nova/objects/image_meta.py b/nova/objects/image_meta.py index 853e1715e701..bd8ec69ab4b5 100644 --- a/nova/objects/image_meta.py +++ b/nova/objects/image_meta.py @@ -187,14 +187,17 @@ class ImageMetaProps(base.NovaObject): # Version 1.28: Added 'socket' to 'hw_pci_numa_affinity_policy' # Version 1.29: Added 'hw_input_bus' field # Version 1.30: Added 'bochs' as an option to 'hw_video_model' + # Version 1.31: Added 'hw_emulation_architecture' field # NOTE(efried): When bumping this version, the version of # ImageMetaPropsPayload must also be bumped. See its docstring for details. - VERSION = '1.30' + VERSION = '1.31' def obj_make_compatible(self, primitive, target_version): super(ImageMetaProps, self).obj_make_compatible(primitive, target_version) target_version = versionutils.convert_version_to_tuple(target_version) + 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: @@ -294,6 +297,10 @@ class ImageMetaProps(base.NovaObject): # name of guest hardware architecture eg i686, x86_64, ppc64 'hw_architecture': fields.ArchitectureField(), + # hw_architecture field is leveraged for checks against physical nodes + # name of desired emulation architecture eg i686, x86_64, ppc64 + 'hw_emulation_architecture': fields.ArchitectureField(), + # used to decide to expand root disk partition and fs to full size of # root disk 'hw_auto_disk_config': fields.StringField(), diff --git a/nova/tests/functional/notification_sample_tests/test_instance.py b/nova/tests/functional/notification_sample_tests/test_instance.py index 710b2a71fb7d..a1b35c9756d8 100644 --- a/nova/tests/functional/notification_sample_tests/test_instance.py +++ b/nova/tests/functional/notification_sample_tests/test_instance.py @@ -1231,7 +1231,7 @@ class TestInstanceNotificationSample( 'nova_object.data': {}, 'nova_object.name': 'ImageMetaPropsPayload', 'nova_object.namespace': 'nova', - 'nova_object.version': '1.8', + 'nova_object.version': '1.9', }, 'image.size': 58145823, 'image.tags': [], @@ -1327,7 +1327,7 @@ class TestInstanceNotificationSample( 'nova_object.data': {}, 'nova_object.name': 'ImageMetaPropsPayload', 'nova_object.namespace': 'nova', - 'nova_object.version': '1.8', + 'nova_object.version': '1.9', }, 'image.size': 58145823, 'image.tags': [], diff --git a/nova/tests/unit/notifications/objects/test_notification.py b/nova/tests/unit/notifications/objects/test_notification.py index 38d82d9ae9aa..3d9eeece8ea1 100644 --- a/nova/tests/unit/notifications/objects/test_notification.py +++ b/nova/tests/unit/notifications/objects/test_notification.py @@ -386,7 +386,7 @@ notification_object_data = { # ImageMetaProps, so when you see a fail here for that reason, you must # *also* bump the version of ImageMetaPropsPayload. See its docstring for # more information. - 'ImageMetaPropsPayload': '1.8-080bdcba9b96122eab57bf39d47348f7', + 'ImageMetaPropsPayload': '1.9-24a851511d98e652aebd3536e7e08330', 'InstanceActionNotification': '1.0-a73147b93b520ff0061865849d3dfa56', 'InstanceActionPayload': '1.8-4fa3da9cbf0761f1f700ae578f36dc2f', 'InstanceActionRebuildNotification': diff --git a/nova/tests/unit/objects/test_image_meta.py b/nova/tests/unit/objects/test_image_meta.py index 1750caba01b4..6e3725de84c7 100644 --- a/nova/tests/unit/objects/test_image_meta.py +++ b/nova/tests/unit/objects/test_image_meta.py @@ -349,6 +349,25 @@ class TestImageMetaProps(test.NoDBTestCase): self.assertRaises(exception.ObjectActionError, obj.obj_to_primitive, '1.0') + def test_obj_make_compatible_hw_emulation(self): + """Check 'hw_emulation_architecture' compatibility.""" + # assert that 'hw_emulation_architecture' is supported + # on a suitably new version + obj = objects.ImageMetaProps( + hw_emulation_architecture=objects.fields.Architecture.AARCH64, + ) + primitive = obj.obj_to_primitive('1.31') + self.assertIn('hw_emulation_architecture', + primitive['nova_object.data']) + self.assertEqual( + objects.fields.Architecture.AARCH64, + primitive['nova_object.data']['hw_emulation_architecture']) + + # and is absent on older versions + primitive = obj.obj_to_primitive('1.29') + self.assertNotIn('hw_emulation_architecture', + primitive['nova_object.data']) + def test_obj_make_compatible_input_bus(self): """Check 'hw_input_bus' compatibility.""" # assert that 'hw_input_bus' is supported on a suitably new version diff --git a/nova/tests/unit/objects/test_objects.py b/nova/tests/unit/objects/test_objects.py index 33be41616716..6f162dc3bb03 100644 --- a/nova/tests/unit/objects/test_objects.py +++ b/nova/tests/unit/objects/test_objects.py @@ -1072,7 +1072,7 @@ object_data = { 'HyperVLiveMigrateData': '1.4-e265780e6acfa631476c8170e8d6fce0', 'IDEDeviceBus': '1.0-29d4c9f27ac44197f01b6ac1b7e16502', 'ImageMeta': '1.8-642d1b2eb3e880a367f37d72dd76162d', - 'ImageMetaProps': '1.30-5bfc3dd01bbfdbb28cb3a096c0b2f383', + 'ImageMetaProps': '1.31-27337af769b0c85b4ba4be8aebc1a65d', 'Instance': '2.7-d187aec68cad2e4d8b8a03a68e4739ce', 'InstanceAction': '1.2-9a5abc87fdd3af46f45731960651efb5', 'InstanceActionEvent': '1.4-5b1f361bd81989f8bb2c20bb7e8a4cb4',