From e37148484c3db08200ed163d106a717b0effa1f0 Mon Sep 17 00:00:00 2001 From: Alexey Stupnikov Date: Fri, 25 Jul 2025 19:23:35 +0200 Subject: [PATCH] Remap custom named Image attributes when unsetting Some Image attributes defined in openstacksdk are named differently from actual properties managed by Glance. Because openstackclient checked property names to be unset against Image object properties, it was impossible to unset such properties. This patch introduces a IMAGE_ATTRIBUTES_CUSTOM_NAMES dictionary mapping real property names with custom attribute names. Closes-bug: #2115732 Change-Id: I7296fc293dff9208464c9a07f58ce3e9ffabd3e9 Signed-off-by: Alexey Stupnikov --- openstackclient/image/v2/image.py | 18 ++++++++++++++++++ .../tests/unit/image/v2/test_image.py | 10 +++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/openstackclient/image/v2/image.py b/openstackclient/image/v2/image.py index 6c7ca740ed..d2a1a74eae 100644 --- a/openstackclient/image/v2/image.py +++ b/openstackclient/image/v2/image.py @@ -55,6 +55,19 @@ DISK_CHOICES = [ "iso", "ploop", ] +# A list of openstacksdk Image object attributes (values) that named +# differently from actual properties stored by Glance (keys). +IMAGE_ATTRIBUTES_CUSTOM_NAMES = { + 'os_hidden': 'is_hidden', + 'protected': 'is_protected', + 'os_hash_algo': 'hash_algo', + 'os_hash_value': 'hash_value', + 'img_config_drive': 'needs_config_drive', + 'os_secure_boot': 'needs_secure_boot', + 'hw_vif_multiqueue_enabled': 'is_hw_vif_multiqueue_enabled', + 'hw_boot_menu': 'is_hw_boot_menu_enabled', + 'auto_disk_config': 'has_auto_disk_config', +} MEMBER_STATUS_CHOICES = ["accepted", "pending", "rejected", "all"] LOG = logging.getLogger(__name__) @@ -1478,6 +1491,11 @@ class UnsetImage(command.Command): ) new_props.pop(k, None) kwargs['properties'] = new_props + elif ( + k in IMAGE_ATTRIBUTES_CUSTOM_NAMES + and IMAGE_ATTRIBUTES_CUSTOM_NAMES[k] in image + ): + delattr(image, IMAGE_ATTRIBUTES_CUSTOM_NAMES[k]) else: LOG.error( _( diff --git a/openstackclient/tests/unit/image/v2/test_image.py b/openstackclient/tests/unit/image/v2/test_image.py index 95d384c24b..4f5db9f002 100644 --- a/openstackclient/tests/unit/image/v2/test_image.py +++ b/openstackclient/tests/unit/image/v2/test_image.py @@ -1779,6 +1779,7 @@ class TestImageUnset(TestImage): attrs['hw_rng_model'] = 'virtio' attrs['prop'] = 'test' attrs['prop2'] = 'fake' + attrs['os_secure_boot'] = 'required' self.image = image_fakes.create_one_image(attrs) self.image_client.find_image.return_value = self.image @@ -1822,11 +1823,18 @@ class TestImageUnset(TestImage): 'hw_rng_model', '--property', 'prop', + '--property', + 'os_secure_boot', self.image.id, ] + # openstacksdk translates 'os_secure_boot' property to + # 'needs_secure_boot' Image attribute. This is true for + # all IMAGE_ATTRIBUTES_CUSTOM_NAMES keys + self.assertEqual(self.image.needs_secure_boot, 'required') + self.assertFalse(hasattr(self.image, 'os_secure_boot')) verifylist = [ - ('properties', ['hw_rng_model', 'prop']), + ('properties', ['hw_rng_model', 'prop', 'os_secure_boot']), ('image', self.image.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist)