From 4464109c7754a9287f75ec2af84398700d1450e6 Mon Sep 17 00:00:00 2001 From: ShogoAdachi Date: Thu, 7 Sep 2017 19:10:24 +0900 Subject: Accept 0 for --min-disk and --min-ram The current openstackclient implementation cannot accept 0 for --min-disk and --min-ram with the "openstack image set" command. If theses options get set to 0, the option parser in openstackclient wrongly interprets 0 as no option value. The 0 is valid for these options if administrators want to make it the default(no minimum requirements). This patch fix the parser so that it avoids only 'None'. Change-Id: Ie8ee37484c02c26f54adc56263fcd167c0ce7eb3 Closes-bug: #1719499 --- openstackclient/tests/unit/image/v1/test_image.py | 26 +++++++++++++++++++++++ openstackclient/tests/unit/image/v2/test_image.py | 26 +++++++++++++++++++++++ 2 files changed, 52 insertions(+) (limited to 'openstackclient/tests') diff --git a/openstackclient/tests/unit/image/v1/test_image.py b/openstackclient/tests/unit/image/v1/test_image.py index 8a83feb0..ae578d91 100644 --- a/openstackclient/tests/unit/image/v1/test_image.py +++ b/openstackclient/tests/unit/image/v1/test_image.py @@ -689,6 +689,32 @@ class TestImageSet(TestImage): ) self.assertIsNone(result) + def test_image_set_numeric_options_to_zero(self): + arglist = [ + '--min-disk', '0', + '--min-ram', '0', + self._image.name, + ] + verifylist = [ + ('min_disk', 0), + ('min_ram', 0), + ('image', self._image.name), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + result = self.cmd.take_action(parsed_args) + + kwargs = { + 'min_disk': 0, + 'min_ram': 0, + } + # ImageManager.update(image, **kwargs) + self.images_mock.update.assert_called_with( + self._image.id, + **kwargs + ) + self.assertIsNone(result) + class TestImageShow(TestImage): diff --git a/openstackclient/tests/unit/image/v2/test_image.py b/openstackclient/tests/unit/image/v2/test_image.py index 429ddd28..383619ef 100644 --- a/openstackclient/tests/unit/image/v2/test_image.py +++ b/openstackclient/tests/unit/image/v2/test_image.py @@ -1313,6 +1313,32 @@ class TestImageSet(TestImage): exceptions.CommandError, self.cmd.take_action, parsed_args) + def test_image_set_numeric_options_to_zero(self): + arglist = [ + '--min-disk', '0', + '--min-ram', '0', + image_fakes.image_name, + ] + verifylist = [ + ('min_disk', 0), + ('min_ram', 0), + ('image', image_fakes.image_name), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + result = self.cmd.take_action(parsed_args) + + kwargs = { + 'min_disk': 0, + 'min_ram': 0, + } + # ImageManager.update(image, **kwargs) + self.images_mock.update.assert_called_with( + image_fakes.image_id, + **kwargs + ) + self.assertIsNone(result) + class TestImageShow(TestImage): -- cgit v1.2.1