diff --git a/openstackclient/image/v2/image.py b/openstackclient/image/v2/image.py index 7177929339..ad38c01ec2 100644 --- a/openstackclient/image/v2/image.py +++ b/openstackclient/image/v2/image.py @@ -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 diff --git a/openstackclient/tests/functional/image/v2/test_image.py b/openstackclient/tests/functional/image/v2/test_image.py index 264ba5199c..0a3a73602c 100644 --- a/openstackclient/tests/functional/image/v2/test_image.py +++ b/openstackclient/tests/functional/image/v2/test_image.py @@ -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( diff --git a/openstackclient/tests/unit/image/v2/test_image.py b/openstackclient/tests/unit/image/v2/test_image.py index ebeb8353a5..87dfdbeab9 100644 --- a/openstackclient/tests/unit/image/v2/test_image.py +++ b/openstackclient/tests/unit/image/v2/test_image.py @@ -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'