Skip to content

Commit e371484

Browse files
committed
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 <aleksey.stupnikov@gmail.com>
1 parent c7d465a commit e371484

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

openstackclient/image/v2/image.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@
5555
"iso",
5656
"ploop",
5757
]
58+
# A list of openstacksdk Image object attributes (values) that named
59+
# differently from actual properties stored by Glance (keys).
60+
IMAGE_ATTRIBUTES_CUSTOM_NAMES = {
61+
'os_hidden': 'is_hidden',
62+
'protected': 'is_protected',
63+
'os_hash_algo': 'hash_algo',
64+
'os_hash_value': 'hash_value',
65+
'img_config_drive': 'needs_config_drive',
66+
'os_secure_boot': 'needs_secure_boot',
67+
'hw_vif_multiqueue_enabled': 'is_hw_vif_multiqueue_enabled',
68+
'hw_boot_menu': 'is_hw_boot_menu_enabled',
69+
'auto_disk_config': 'has_auto_disk_config',
70+
}
5871
MEMBER_STATUS_CHOICES = ["accepted", "pending", "rejected", "all"]
5972

6073
LOG = logging.getLogger(__name__)
@@ -1478,6 +1491,11 @@ def take_action(self, parsed_args):
14781491
)
14791492
new_props.pop(k, None)
14801493
kwargs['properties'] = new_props
1494+
elif (
1495+
k in IMAGE_ATTRIBUTES_CUSTOM_NAMES
1496+
and IMAGE_ATTRIBUTES_CUSTOM_NAMES[k] in image
1497+
):
1498+
delattr(image, IMAGE_ATTRIBUTES_CUSTOM_NAMES[k])
14811499
else:
14821500
LOG.error(
14831501
_(

openstackclient/tests/unit/image/v2/test_image.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1779,6 +1779,7 @@ def setUp(self):
17791779
attrs['hw_rng_model'] = 'virtio'
17801780
attrs['prop'] = 'test'
17811781
attrs['prop2'] = 'fake'
1782+
attrs['os_secure_boot'] = 'required'
17821783
self.image = image_fakes.create_one_image(attrs)
17831784

17841785
self.image_client.find_image.return_value = self.image
@@ -1822,11 +1823,18 @@ def test_image_unset_property_option(self):
18221823
'hw_rng_model',
18231824
'--property',
18241825
'prop',
1826+
'--property',
1827+
'os_secure_boot',
18251828
self.image.id,
18261829
]
18271830

1831+
# openstacksdk translates 'os_secure_boot' property to
1832+
# 'needs_secure_boot' Image attribute. This is true for
1833+
# all IMAGE_ATTRIBUTES_CUSTOM_NAMES keys
1834+
self.assertEqual(self.image.needs_secure_boot, 'required')
1835+
self.assertFalse(hasattr(self.image, 'os_secure_boot'))
18281836
verifylist = [
1829-
('properties', ['hw_rng_model', 'prop']),
1837+
('properties', ['hw_rng_model', 'prop', 'os_secure_boot']),
18301838
('image', self.image.id),
18311839
]
18321840
parsed_args = self.check_parser(self.cmd, arglist, verifylist)

0 commit comments

Comments
 (0)