From 5890c257befe65d3f5cee262061dbaf41cca40b1 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Tue, 20 Aug 2024 09:25:58 +0900 Subject: [PATCH] Add hw_firmware_stateless image property Add the new image property to request stateless firmware. The property will be used by the libvirt driver once the actual logic to enable the feature is implemented. Partially-Implements: blueprint libvirt-stateless-firmware Change-Id: I05d4ff89d2b713b217b6c690e40fd4a16a397b63 --- .../common_payloads/ImageMetaPropsPayload.json | 2 +- nova/notifications/objects/image.py | 3 ++- nova/objects/image_meta.py | 8 +++++++- .../notification_sample_tests/test_instance.py | 4 ++-- .../notifications/objects/test_notification.py | 2 +- nova/tests/unit/objects/test_image_meta.py | 17 +++++++++++++++++ nova/tests/unit/objects/test_objects.py | 2 +- 7 files changed, 31 insertions(+), 7 deletions(-) diff --git a/doc/notification_samples/common_payloads/ImageMetaPropsPayload.json b/doc/notification_samples/common_payloads/ImageMetaPropsPayload.json index 913c75c02744..eb100b7c978c 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.13" + "nova_object.version": "1.14" } diff --git a/nova/notifications/objects/image.py b/nova/notifications/objects/image.py index 575081f4b9df..f714632cd6a6 100644 --- a/nova/notifications/objects/image.py +++ b/nova/notifications/objects/image.py @@ -131,7 +131,8 @@ class ImageMetaPropsPayload(base.NotificationPayloadBase): # Version 1.11: Added 'hw_locked_memory' field # Version 1.12: Added 'hw_viommu_model' field # Version 1.13: Added 'hw_virtio_packed_ring' field - VERSION = '1.13' + # Version 1.14: Added 'hw_firmware_stateless' field + VERSION = '1.14' # NOTE(efried): This logic currently relies on all of the fields of # ImageMetaProps being initialized with no arguments. See the docstring. diff --git a/nova/objects/image_meta.py b/nova/objects/image_meta.py index ab486b30705d..4c3589aaa487 100644 --- a/nova/objects/image_meta.py +++ b/nova/objects/image_meta.py @@ -196,14 +196,17 @@ class ImageMetaProps(base.NovaObject): # Version 1.36: Added 'hw_maxphysaddr_mode' and # 'hw_maxphysaddr_bits' field # Version 1.37: Added 'hw_ephemeral_encryption_secret_uuid' field + # Version 1.38: Added 'hw_firmware_stateless' field # NOTE(efried): When bumping this version, the version of # ImageMetaPropsPayload must also be bumped. See its docstring for details. - VERSION = '1.37' + VERSION = '1.38' 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, 38): + primitive.pop('hw_firmware_stateless', None) if target_version < (1, 37): primitive.pop('hw_ephemeral_encryption_secret_uuid', None) if target_version < (1, 36): @@ -378,6 +381,9 @@ class ImageMetaProps(base.NovaObject): # This indicates the guest needs UEFI firmware 'hw_firmware_type': fields.FirmwareTypeField(), + # This indicates the guest needs stateless firmware + 'hw_firmware_stateless': fields.FlexibleBooleanField(), + # name of the input bus type to use, e.g. usb, virtio 'hw_input_bus': fields.InputBusField(), diff --git a/nova/tests/functional/notification_sample_tests/test_instance.py b/nova/tests/functional/notification_sample_tests/test_instance.py index 1f6d8d2efeff..a3ba04e470b2 100644 --- a/nova/tests/functional/notification_sample_tests/test_instance.py +++ b/nova/tests/functional/notification_sample_tests/test_instance.py @@ -1238,7 +1238,7 @@ class TestInstanceNotificationSample( 'nova_object.data': {}, 'nova_object.name': 'ImageMetaPropsPayload', 'nova_object.namespace': 'nova', - 'nova_object.version': '1.13', + 'nova_object.version': '1.14', }, 'image.size': 58145823, 'image.tags': [], @@ -1334,7 +1334,7 @@ class TestInstanceNotificationSample( 'nova_object.data': {}, 'nova_object.name': 'ImageMetaPropsPayload', 'nova_object.namespace': 'nova', - 'nova_object.version': '1.13', + 'nova_object.version': '1.14', }, '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 d09c7f47b647..8204d2bd3567 100644 --- a/nova/tests/unit/notifications/objects/test_notification.py +++ b/nova/tests/unit/notifications/objects/test_notification.py @@ -385,7 +385,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.13-682cfe847d16301734e1fba924063e6d', + 'ImageMetaPropsPayload': '1.14-af9efd17cd034596be792fa25f24e83d', 'InstanceActionNotification': '1.0-a73147b93b520ff0061865849d3dfa56', 'InstanceActionPayload': '1.8-b948818df6ec562e4eb4b23e515e451b', 'InstanceActionRebuildNotification': diff --git a/nova/tests/unit/objects/test_image_meta.py b/nova/tests/unit/objects/test_image_meta.py index 0225d45f44b5..2b86c196af2b 100644 --- a/nova/tests/unit/objects/test_image_meta.py +++ b/nova/tests/unit/objects/test_image_meta.py @@ -591,3 +591,20 @@ class TestImageMetaProps(test.NoDBTestCase): self.assertNotIn( 'hw_ephemeral_encryption_secret_uuid', primitive['nova_object.data']) + + def test_obj_make_compatible_stateless_firmware(self): + """Check 'hw_firmware_stateless' compatibility.""" + obj = objects.ImageMetaProps( + hw_firmware_stateless=True) + + primitive = obj.obj_to_primitive('1.38') + self.assertIn( + 'hw_firmware_stateless', + primitive['nova_object.data']) + self.assertTrue( + primitive['nova_object.data']['hw_firmware_stateless']) + + primitive = obj.obj_to_primitive('1.37') + self.assertNotIn( + 'hw_firmware_stateless', + primitive['nova_object.data']) diff --git a/nova/tests/unit/objects/test_objects.py b/nova/tests/unit/objects/test_objects.py index e1d1a0330e3b..94bbb7b9d5fc 100644 --- a/nova/tests/unit/objects/test_objects.py +++ b/nova/tests/unit/objects/test_objects.py @@ -1105,7 +1105,7 @@ object_data = { 'HyperVLiveMigrateData': '1.4-e265780e6acfa631476c8170e8d6fce0', 'IDEDeviceBus': '1.0-29d4c9f27ac44197f01b6ac1b7e16502', 'ImageMeta': '1.8-642d1b2eb3e880a367f37d72dd76162d', - 'ImageMetaProps': '1.37-1e0d70fb51041c0446b00695c5ef0e21', + 'ImageMetaProps': '1.38-1f4f4f1b60413aa543e446d716cfbc20', 'Instance': '2.8-2727dba5e4a078e6cc848c1f94f7eb24', 'InstanceAction': '1.2-9a5abc87fdd3af46f45731960651efb5', 'InstanceActionEvent': '1.4-5b1f361bd81989f8bb2c20bb7e8a4cb4',