Skip to content

Commit 23afc0a

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "image: Unset properties rather than setting to None"
2 parents 6f616a2 + 29a7c9a commit 23afc0a

3 files changed

Lines changed: 16 additions & 17 deletions

File tree

openstackclient/image/v2/image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ def take_action(self, parsed_args):
11931193
if parsed_args.properties:
11941194
for k in parsed_args.properties:
11951195
if k in image:
1196-
kwargs[k] = None
1196+
delattr(image, k)
11971197
elif k in image.properties:
11981198
# Since image is an "evil" object from SDK POV we need to
11991199
# pass modified properties object, so that SDK can figure

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def test_image_attributes(self):
119119
'image set ' +
120120
'--property a=b ' +
121121
'--property c=d ' +
122+
'--property hw_rng_model=virtio ' +
122123
'--public ' +
123124
self.name
124125
)
@@ -133,6 +134,7 @@ def test_image_attributes(self):
133134
'image unset ' +
134135
'--property a ' +
135136
'--property c ' +
137+
'--property hw_rng_model ' +
136138
self.name
137139
)
138140
json_output = json.loads(self.openstack(

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

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,15 +1516,16 @@ def test_image_show_human_readable(self):
15161516

15171517
class TestImageUnset(TestImage):
15181518

1519-
attrs = {}
1520-
attrs['tags'] = ['test']
1521-
attrs['prop'] = 'test'
1522-
attrs['prop2'] = 'fake'
1523-
image = image_fakes.FakeImage.create_one_image(attrs)
1524-
15251519
def setUp(self):
15261520
super(TestImageUnset, self).setUp()
15271521

1522+
attrs = {}
1523+
attrs['tags'] = ['test']
1524+
attrs['hw_rng_model'] = 'virtio'
1525+
attrs['prop'] = 'test'
1526+
attrs['prop2'] = 'fake'
1527+
self.image = image_fakes.FakeImage.create_one_image(attrs)
1528+
15281529
self.client.find_image.return_value = self.image
15291530
self.client.remove_tag.return_value = self.image
15301531
self.client.update_image.return_value = self.image
@@ -1567,46 +1568,42 @@ def test_image_unset_tag_option(self):
15671568
def test_image_unset_property_option(self):
15681569

15691570
arglist = [
1571+
'--property', 'hw_rng_model',
15701572
'--property', 'prop',
15711573
self.image.id,
15721574
]
15731575

15741576
verifylist = [
1575-
('properties', ['prop']),
1577+
('properties', ['hw_rng_model', 'prop']),
15761578
('image', self.image.id)
15771579
]
15781580
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
15791581
result = self.cmd.take_action(parsed_args)
15801582

1581-
kwargs = {}
15821583
self.client.update_image.assert_called_with(
1583-
self.image,
1584-
properties={'prop2': 'fake'},
1585-
**kwargs)
1584+
self.image, properties={'prop2': 'fake'})
15861585

15871586
self.assertIsNone(result)
15881587

15891588
def test_image_unset_mixed_option(self):
15901589

15911590
arglist = [
15921591
'--tag', 'test',
1592+
'--property', 'hw_rng_model',
15931593
'--property', 'prop',
15941594
self.image.id,
15951595
]
15961596

15971597
verifylist = [
15981598
('tags', ['test']),
1599-
('properties', ['prop']),
1599+
('properties', ['hw_rng_model', 'prop']),
16001600
('image', self.image.id)
16011601
]
16021602
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
16031603
result = self.cmd.take_action(parsed_args)
16041604

1605-
kwargs = {}
16061605
self.client.update_image.assert_called_with(
1607-
self.image,
1608-
properties={'prop2': 'fake'},
1609-
**kwargs)
1606+
self.image, properties={'prop2': 'fake'})
16101607

16111608
self.client.remove_tag.assert_called_with(
16121609
self.image.id, 'test'

0 commit comments

Comments
 (0)