Merge "image: Unset properties rather than setting to None"

This commit is contained in:
Zuul 2021-01-06 11:16:25 +00:00 committed by Gerrit Code Review
commit 23afc0af92
3 changed files with 16 additions and 17 deletions

View File

@ -1193,7 +1193,7 @@ class UnsetImage(command.Command):
if parsed_args.properties:
for k in parsed_args.properties:
if k in image:
kwargs[k] = None
delattr(image, k)
elif k in image.properties:
# Since image is an "evil" object from SDK POV we need to
# pass modified properties object, so that SDK can figure

View File

@ -119,6 +119,7 @@ class ImageTests(base.BaseImageTests):
'image set ' +
'--property a=b ' +
'--property c=d ' +
'--property hw_rng_model=virtio ' +
'--public ' +
self.name
)
@ -133,6 +134,7 @@ class ImageTests(base.BaseImageTests):
'image unset ' +
'--property a ' +
'--property c ' +
'--property hw_rng_model ' +
self.name
)
json_output = json.loads(self.openstack(

View File

@ -1516,15 +1516,16 @@ class TestImageShow(TestImage):
class TestImageUnset(TestImage):
attrs = {}
attrs['tags'] = ['test']
attrs['prop'] = 'test'
attrs['prop2'] = 'fake'
image = image_fakes.FakeImage.create_one_image(attrs)
def setUp(self):
super(TestImageUnset, self).setUp()
attrs = {}
attrs['tags'] = ['test']
attrs['hw_rng_model'] = 'virtio'
attrs['prop'] = 'test'
attrs['prop2'] = 'fake'
self.image = image_fakes.FakeImage.create_one_image(attrs)
self.client.find_image.return_value = self.image
self.client.remove_tag.return_value = self.image
self.client.update_image.return_value = self.image
@ -1567,22 +1568,20 @@ class TestImageUnset(TestImage):
def test_image_unset_property_option(self):
arglist = [
'--property', 'hw_rng_model',
'--property', 'prop',
self.image.id,
]
verifylist = [
('properties', ['prop']),
('properties', ['hw_rng_model', 'prop']),
('image', self.image.id)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
kwargs = {}
self.client.update_image.assert_called_with(
self.image,
properties={'prop2': 'fake'},
**kwargs)
self.image, properties={'prop2': 'fake'})
self.assertIsNone(result)
@ -1590,23 +1589,21 @@ class TestImageUnset(TestImage):
arglist = [
'--tag', 'test',
'--property', 'hw_rng_model',
'--property', 'prop',
self.image.id,
]
verifylist = [
('tags', ['test']),
('properties', ['prop']),
('properties', ['hw_rng_model', 'prop']),
('image', self.image.id)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
kwargs = {}
self.client.update_image.assert_called_with(
self.image,
properties={'prop2': 'fake'},
**kwargs)
self.image, properties={'prop2': 'fake'})
self.client.remove_tag.assert_called_with(
self.image.id, 'test'