From 8a12a39ece3882af56b42898ffee0d537c96edc8 Mon Sep 17 00:00:00 2001 From: sunyajing Date: Tue, 14 Jun 2016 15:44:41 +0800 Subject: [PATCH] Make set/unset command in identity and image pass normally when nothing specified Also update its unit tests. Change-Id: I82b90658b0d4247cdc9a650f14aceda640a32059 Partial-bug: #1588588 --- openstackclient/identity/v2_0/project.py | 21 +++--------- openstackclient/identity/v2_0/user.py | 9 ----- openstackclient/image/v2/image.py | 13 ------- .../tests/identity/v2_0/test_project.py | 34 +++++++++++++++++++ .../tests/identity/v2_0/test_user.py | 22 ++++++++++++ openstackclient/tests/image/v2/test_image.py | 26 ++++++++++++++ .../notes/bug-1588588-39927ef06ca35730.yaml | 4 +-- 7 files changed, 89 insertions(+), 40 deletions(-) diff --git a/openstackclient/identity/v2_0/project.py b/openstackclient/identity/v2_0/project.py index 8be482fe57..c4f730e0a7 100644 --- a/openstackclient/identity/v2_0/project.py +++ b/openstackclient/identity/v2_0/project.py @@ -189,13 +189,6 @@ class SetProject(command.Command): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity - if (not parsed_args.name - and not parsed_args.description - and not parsed_args.enable - and not parsed_args.property - and not parsed_args.disable): - return - project = utils.find_resource( identity_client.tenants, parsed_args.project, @@ -295,7 +288,6 @@ class UnsetProject(command.Command): metavar='', action='append', default=[], - required=True, help=_('Unset a project property ' '(repeat option to unset multiple properties)'), ) @@ -307,11 +299,8 @@ class UnsetProject(command.Command): identity_client.tenants, parsed_args.project, ) - if not parsed_args.property: - self.app.log.error(_("No changes requested\n")) - else: - kwargs = project._info - for key in parsed_args.property: - if key in kwargs: - kwargs[key] = None - identity_client.tenants.update(project.id, **kwargs) + kwargs = project._info + for key in parsed_args.property: + if key in kwargs: + kwargs[key] = None + identity_client.tenants.update(project.id, **kwargs) diff --git a/openstackclient/identity/v2_0/user.py b/openstackclient/identity/v2_0/user.py index 7777bab886..3ee2a65e55 100644 --- a/openstackclient/identity/v2_0/user.py +++ b/openstackclient/identity/v2_0/user.py @@ -287,15 +287,6 @@ class SetUser(command.Command): if parsed_args.password_prompt: parsed_args.password = utils.get_password(self.app.stdin) - if (not parsed_args.name - and not parsed_args.name - and not parsed_args.password - and not parsed_args.email - and not parsed_args.project - and not parsed_args.enable - and not parsed_args.disable): - return - user = utils.find_resource( identity_client.users, parsed_args.user, diff --git a/openstackclient/image/v2/image.py b/openstackclient/image/v2/image.py index 62f7bee88c..47ba649386 100644 --- a/openstackclient/image/v2/image.py +++ b/openstackclient/image/v2/image.py @@ -803,11 +803,6 @@ class SetImage(command.Command): parsed_args.project_domain, ).id - # Checks if anything that requires getting the image - if not (kwargs or parsed_args.deactivate or parsed_args.activate): - msg = _("No arguments specified") - raise exceptions.CommandError(msg) - image = utils.find_resource( image_client.images, parsed_args.image) @@ -819,10 +814,6 @@ class SetImage(command.Command): image_client.images.reactivate(image.id) activation_status = "activated" - # Check if need to do the actual update - if not kwargs: - return {}, {} - if parsed_args.tags: # Tags should be extended, but duplicates removed kwargs['tags'] = list(set(image.tags).union(set(parsed_args.tags))) @@ -895,10 +886,6 @@ class UnsetImage(command.Command): parsed_args.image, ) - if not (parsed_args.tags or parsed_args.properties): - msg = _("No arguments specified") - raise exceptions.CommandError(msg) - kwargs = {} tagret = 0 propret = 0 diff --git a/openstackclient/tests/identity/v2_0/test_project.py b/openstackclient/tests/identity/v2_0/test_project.py index 38684aaffe..1eb1260419 100644 --- a/openstackclient/tests/identity/v2_0/test_project.py +++ b/openstackclient/tests/identity/v2_0/test_project.py @@ -16,6 +16,7 @@ import copy from keystoneauth1 import exceptions as ks_exc +from osc_lib import exceptions from openstackclient.identity.v2_0 import project from openstackclient.tests import fakes @@ -410,6 +411,26 @@ class TestProjectSet(TestProject): self.assertIsNone(result) + def test_project_set_unexist_project(self): + arglist = [ + "unexist-project", + ] + verifylist = [ + ('project', "unexist-project"), + ('name', None), + ('description', None), + ('enable', False), + ('disable', False), + ('property', None), + ] + self.projects_mock.get.side_effect = exceptions.NotFound(None) + self.projects_mock.find.side_effect = exceptions.NotFound(None) + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.assertRaises( + exceptions.CommandError, self.cmd.take_action, parsed_args) + def test_project_set_name(self): arglist = [ '--name', 'qwerty', @@ -604,6 +625,19 @@ class TestProjectUnset(TestProject): # Get the command object to test self.cmd = project.UnsetProject(self.app, None) + def test_project_unset_no_options(self): + arglist = [ + identity_fakes.project_name, + ] + verifylist = [ + ('project', identity_fakes.project_name), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + result = self.cmd.take_action(parsed_args) + + self.assertIsNone(result) + def test_project_unset_key(self): arglist = [ '--property', 'fee', diff --git a/openstackclient/tests/identity/v2_0/test_user.py b/openstackclient/tests/identity/v2_0/test_user.py index caf38a6f26..f7a7b08c3f 100644 --- a/openstackclient/tests/identity/v2_0/test_user.py +++ b/openstackclient/tests/identity/v2_0/test_user.py @@ -17,6 +17,7 @@ import copy import mock from keystoneauth1 import exceptions as ks_exc +from osc_lib import exceptions from openstackclient.identity.v2_0 import user from openstackclient.tests import fakes @@ -563,6 +564,27 @@ class TestUserSet(TestUser): self.assertIsNone(result) + def test_user_set_unexist_user(self): + arglist = [ + "unexist-user", + ] + verifylist = [ + ('name', None), + ('password', None), + ('email', None), + ('project', None), + ('enable', False), + ('disable', False), + ('user', "unexist-user"), + ] + self.users_mock.get.side_effect = exceptions.NotFound(None) + self.users_mock.find.side_effect = exceptions.NotFound(None) + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.assertRaises( + exceptions.CommandError, self.cmd.take_action, parsed_args) + def test_user_set_name(self): arglist = [ '--name', 'qwerty', diff --git a/openstackclient/tests/image/v2/test_image.py b/openstackclient/tests/image/v2/test_image.py index 92e0660faf..3dbf504aff 100644 --- a/openstackclient/tests/image/v2/test_image.py +++ b/openstackclient/tests/image/v2/test_image.py @@ -811,6 +811,19 @@ class TestImageSet(TestImage): # Get the command object to test self.cmd = image.SetImage(self.app, None) + def test_image_set_no_options(self): + arglist = [ + image_fakes.image_id, + ] + verifylist = [ + ('image', image_fakes.image_id) + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + result = self.cmd.take_action(parsed_args) + + self.assertIsNone(result) + def test_image_set_options(self): arglist = [ '--name', 'new-name', @@ -1211,6 +1224,19 @@ class TestImageUnset(TestImage): # Get the command object to test self.cmd = image.UnsetImage(self.app, None) + def test_image_unset_no_options(self): + arglist = [ + image_fakes.image_id, + ] + verifylist = [ + ('image', image_fakes.image_id) + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + result = self.cmd.take_action(parsed_args) + + self.assertIsNone(result) + def test_image_unset_tag_option(self): arglist = [ diff --git a/releasenotes/notes/bug-1588588-39927ef06ca35730.yaml b/releasenotes/notes/bug-1588588-39927ef06ca35730.yaml index 440bb7d31c..c745b6bef2 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 and volume now return - normally when nothing specified to modify. This will become the default + - 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. [Bug `1588588 `_]