From 9c62af8a42ebfeb60d88f5ad0af7c1c2fd562853 Mon Sep 17 00:00:00 2001 From: Tang Chen Date: Tue, 21 Jun 2016 15:15:18 +0800 Subject: [PATCH] Make set/unset commands in compute/image/common return normally when nothing specified After this patch, all set/unset commands will return normally when nothing specified. Change-Id: Id94d0329faa1a674006a9aae901f834b41917317 Close-bug: #1588588 --- openstackclient/common/quota.py | 5 ----- openstackclient/compute/v2/flavor.py | 6 ------ openstackclient/image/v1/image.py | 4 ---- openstackclient/tests/compute/v2/test_flavor.py | 15 +++++++++++---- openstackclient/tests/image/v1/test_image.py | 4 ++-- .../notes/bug-1588588-39927ef06ca35730.yaml | 6 +++--- 6 files changed, 16 insertions(+), 24 deletions(-) diff --git a/openstackclient/common/quota.py b/openstackclient/common/quota.py index 087d8ea3fd..69415f0dc0 100644 --- a/openstackclient/common/quota.py +++ b/openstackclient/common/quota.py @@ -142,11 +142,6 @@ class SetQuota(command.Command): if value is not None: compute_kwargs[k] = value - if (compute_kwargs == {} and volume_kwargs == {} - and network_kwargs == {}): - sys.stderr.write("No quotas updated\n") - return - if parsed_args.project: project = utils.find_resource( identity_client.projects, diff --git a/openstackclient/compute/v2/flavor.py b/openstackclient/compute/v2/flavor.py index 0a0d25c2de..bcf97c6955 100644 --- a/openstackclient/compute/v2/flavor.py +++ b/openstackclient/compute/v2/flavor.py @@ -279,9 +279,6 @@ class SetFlavor(command.Command): flavor = _find_flavor(compute_client, parsed_args.flavor) - if not parsed_args.property and not parsed_args.project: - raise exceptions.CommandError(_("Nothing specified to be set.")) - result = 0 if parsed_args.property: try: @@ -368,9 +365,6 @@ class UnsetFlavor(command.Command): flavor = _find_flavor(compute_client, parsed_args.flavor) - if not parsed_args.property and not parsed_args.project: - raise exceptions.CommandError(_("Nothing specified to be unset.")) - result = 0 if parsed_args.property: try: diff --git a/openstackclient/image/v1/image.py b/openstackclient/image/v1/image.py index 27467b0c28..e7b60e5ad5 100644 --- a/openstackclient/image/v1/image.py +++ b/openstackclient/image/v1/image.py @@ -691,10 +691,6 @@ class SetImage(command.Command): image.properties.update(kwargs['properties']) kwargs['properties'] = image.properties - if not kwargs: - LOG.warning(_('no arguments specified')) - return - image = image_client.images.update(image.id, **kwargs) finally: # Clean up open files - make sure data isn't a string diff --git a/openstackclient/tests/compute/v2/test_flavor.py b/openstackclient/tests/compute/v2/test_flavor.py index 4365a540bc..864a43271b 100644 --- a/openstackclient/tests/compute/v2/test_flavor.py +++ b/openstackclient/tests/compute/v2/test_flavor.py @@ -542,8 +542,12 @@ class TestFlavorSet(TestFlavor): ('flavor', self.flavor.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.assertRaises(exceptions.CommandError, self.cmd.take_action, - parsed_args) + result = self.cmd.take_action(parsed_args) + + self.flavors_mock.find.assert_called_with(name=parsed_args.flavor, + is_public=None) + self.flavor_access_mock.add_tenant_access.assert_not_called() + self.assertIsNone(result) class TestFlavorShow(TestFlavor): @@ -717,5 +721,8 @@ class TestFlavorUnset(TestFlavor): ('flavor', self.flavor.id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.assertRaises(exceptions.CommandError, self.cmd.take_action, - parsed_args) + + result = self.cmd.take_action(parsed_args) + self.assertIsNone(result) + + self.flavor_access_mock.remove_tenant_access.assert_not_called() diff --git a/openstackclient/tests/image/v1/test_image.py b/openstackclient/tests/image/v1/test_image.py index 99c0b0eee7..14aa331fbc 100644 --- a/openstackclient/tests/image/v1/test_image.py +++ b/openstackclient/tests/image/v1/test_image.py @@ -475,8 +475,8 @@ class TestImageSet(TestImage): result = self.cmd.take_action(parsed_args) - # Verify update() was not called, if it was show the args - self.assertEqual(self.images_mock.update.call_args_list, []) + self.images_mock.update.assert_called_with(image_fakes.image_id, + **{}) self.assertIsNone(result) def test_image_set_options(self): diff --git a/releasenotes/notes/bug-1588588-39927ef06ca35730.yaml b/releasenotes/notes/bug-1588588-39927ef06ca35730.yaml index c745b6bef2..8621a81cb2 100644 --- a/releasenotes/notes/bug-1588588-39927ef06ca35730.yaml +++ b/releasenotes/notes/bug-1588588-39927ef06ca35730.yaml @@ -1,6 +1,6 @@ --- upgrade: - - All ``set`` and ``unset`` commands in network, identity, image, and volume now - return normally when nothing specified to modify. This will become the default - behavior of OSC ``set`` and ``unset`` commands. + - All ``set`` and ``unset`` commands now return normally when nothing + specified to modify. This will become the default behavior of OSC + ``set`` and ``unset`` commands. [Bug `1588588 `_]