Skip to content

Commit 3abba6e

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Accept 0 for --min-disk and --min-ram"
2 parents 161c79f + 4464109 commit 3abba6e

5 files changed

Lines changed: 63 additions & 4 deletions

File tree

openstackclient/image/v1/image.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,11 +625,11 @@ def take_action(self, parsed_args):
625625
kwargs = {}
626626
copy_attrs = ('name', 'owner', 'min_disk', 'min_ram', 'properties',
627627
'container_format', 'disk_format', 'size', 'store',
628-
'location', 'copy_from', 'volume', 'force', 'checksum')
628+
'location', 'copy_from', 'volume', 'checksum')
629629
for attr in copy_attrs:
630630
if attr in parsed_args:
631631
val = getattr(parsed_args, attr, None)
632-
if val:
632+
if val is not None:
633633
# Only include a value in kwargs for attributes that are
634634
# actually present on the command line
635635
kwargs[attr] = val
@@ -653,6 +653,8 @@ def take_action(self, parsed_args):
653653
kwargs['is_public'] = True
654654
if parsed_args.private:
655655
kwargs['is_public'] = False
656+
if parsed_args.force:
657+
kwargs['force'] = True
656658

657659
# Wrap the call to catch exceptions in order to close files
658660
try:

openstackclient/image/v2/image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ def get_parser(self, prog_name):
749749
"--tag",
750750
dest="tags",
751751
metavar="<tag>",
752-
default=[],
752+
default=None,
753753
action='append',
754754
help=_("Set a tag on this image "
755755
"(repeat option to set multiple tags)"),
@@ -860,7 +860,7 @@ def take_action(self, parsed_args):
860860
for attr in copy_attrs:
861861
if attr in parsed_args:
862862
val = getattr(parsed_args, attr, None)
863-
if val:
863+
if val is not None:
864864
# Only include a value in kwargs for attributes that are
865865
# actually present on the command line
866866
kwargs[attr] = val

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,32 @@ def test_image_update_volume(self):
689689
)
690690
self.assertIsNone(result)
691691

692+
def test_image_set_numeric_options_to_zero(self):
693+
arglist = [
694+
'--min-disk', '0',
695+
'--min-ram', '0',
696+
self._image.name,
697+
]
698+
verifylist = [
699+
('min_disk', 0),
700+
('min_ram', 0),
701+
('image', self._image.name),
702+
]
703+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
704+
705+
result = self.cmd.take_action(parsed_args)
706+
707+
kwargs = {
708+
'min_disk': 0,
709+
'min_ram': 0,
710+
}
711+
# ImageManager.update(image, **kwargs)
712+
self.images_mock.update.assert_called_with(
713+
self._image.id,
714+
**kwargs
715+
)
716+
self.assertIsNone(result)
717+
692718

693719
class TestImageShow(TestImage):
694720

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,32 @@ def test_image_set_dead_options(self):
13131313
exceptions.CommandError,
13141314
self.cmd.take_action, parsed_args)
13151315

1316+
def test_image_set_numeric_options_to_zero(self):
1317+
arglist = [
1318+
'--min-disk', '0',
1319+
'--min-ram', '0',
1320+
image_fakes.image_name,
1321+
]
1322+
verifylist = [
1323+
('min_disk', 0),
1324+
('min_ram', 0),
1325+
('image', image_fakes.image_name),
1326+
]
1327+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1328+
1329+
result = self.cmd.take_action(parsed_args)
1330+
1331+
kwargs = {
1332+
'min_disk': 0,
1333+
'min_ram': 0,
1334+
}
1335+
# ImageManager.update(image, **kwargs)
1336+
self.images_mock.update.assert_called_with(
1337+
image_fakes.image_id,
1338+
**kwargs
1339+
)
1340+
self.assertIsNone(result)
1341+
13161342

13171343
class TestImageShow(TestImage):
13181344

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
Accept ``0`` as a valid value in the ``image set`` ``--min-disk`` and ``--min-ram`` options.
5+
.. _bug 1719499: https://bugs.launchpad.net/python-openstackclient/+bug/1719499

0 commit comments

Comments
 (0)