Make set/unset command in identity and image pass normally when nothing specified

Also update its unit tests.

Change-Id: I82b90658b0d4247cdc9a650f14aceda640a32059
Partial-bug: #1588588
This commit is contained in:
sunyajing 2016-06-14 15:44:41 +08:00 committed by Steve Martinelli
parent 2c92b60f45
commit 8a12a39ece
7 changed files with 89 additions and 40 deletions

View File

@ -189,13 +189,6 @@ class SetProject(command.Command):
def take_action(self, parsed_args): def take_action(self, parsed_args):
identity_client = self.app.client_manager.identity 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( project = utils.find_resource(
identity_client.tenants, identity_client.tenants,
parsed_args.project, parsed_args.project,
@ -295,7 +288,6 @@ class UnsetProject(command.Command):
metavar='<key>', metavar='<key>',
action='append', action='append',
default=[], default=[],
required=True,
help=_('Unset a project property ' help=_('Unset a project property '
'(repeat option to unset multiple properties)'), '(repeat option to unset multiple properties)'),
) )
@ -307,9 +299,6 @@ class UnsetProject(command.Command):
identity_client.tenants, identity_client.tenants,
parsed_args.project, parsed_args.project,
) )
if not parsed_args.property:
self.app.log.error(_("No changes requested\n"))
else:
kwargs = project._info kwargs = project._info
for key in parsed_args.property: for key in parsed_args.property:
if key in kwargs: if key in kwargs:

View File

@ -287,15 +287,6 @@ class SetUser(command.Command):
if parsed_args.password_prompt: if parsed_args.password_prompt:
parsed_args.password = utils.get_password(self.app.stdin) 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( user = utils.find_resource(
identity_client.users, identity_client.users,
parsed_args.user, parsed_args.user,

View File

@ -803,11 +803,6 @@ class SetImage(command.Command):
parsed_args.project_domain, parsed_args.project_domain,
).id ).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 = utils.find_resource(
image_client.images, parsed_args.image) image_client.images, parsed_args.image)
@ -819,10 +814,6 @@ class SetImage(command.Command):
image_client.images.reactivate(image.id) image_client.images.reactivate(image.id)
activation_status = "activated" activation_status = "activated"
# Check if need to do the actual update
if not kwargs:
return {}, {}
if parsed_args.tags: if parsed_args.tags:
# Tags should be extended, but duplicates removed # Tags should be extended, but duplicates removed
kwargs['tags'] = list(set(image.tags).union(set(parsed_args.tags))) kwargs['tags'] = list(set(image.tags).union(set(parsed_args.tags)))
@ -895,10 +886,6 @@ class UnsetImage(command.Command):
parsed_args.image, parsed_args.image,
) )
if not (parsed_args.tags or parsed_args.properties):
msg = _("No arguments specified")
raise exceptions.CommandError(msg)
kwargs = {} kwargs = {}
tagret = 0 tagret = 0
propret = 0 propret = 0

View File

@ -16,6 +16,7 @@
import copy import copy
from keystoneauth1 import exceptions as ks_exc from keystoneauth1 import exceptions as ks_exc
from osc_lib import exceptions
from openstackclient.identity.v2_0 import project from openstackclient.identity.v2_0 import project
from openstackclient.tests import fakes from openstackclient.tests import fakes
@ -410,6 +411,26 @@ class TestProjectSet(TestProject):
self.assertIsNone(result) 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): def test_project_set_name(self):
arglist = [ arglist = [
'--name', 'qwerty', '--name', 'qwerty',
@ -604,6 +625,19 @@ class TestProjectUnset(TestProject):
# Get the command object to test # Get the command object to test
self.cmd = project.UnsetProject(self.app, None) 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): def test_project_unset_key(self):
arglist = [ arglist = [
'--property', 'fee', '--property', 'fee',

View File

@ -17,6 +17,7 @@ import copy
import mock import mock
from keystoneauth1 import exceptions as ks_exc from keystoneauth1 import exceptions as ks_exc
from osc_lib import exceptions
from openstackclient.identity.v2_0 import user from openstackclient.identity.v2_0 import user
from openstackclient.tests import fakes from openstackclient.tests import fakes
@ -563,6 +564,27 @@ class TestUserSet(TestUser):
self.assertIsNone(result) 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): def test_user_set_name(self):
arglist = [ arglist = [
'--name', 'qwerty', '--name', 'qwerty',

View File

@ -811,6 +811,19 @@ class TestImageSet(TestImage):
# Get the command object to test # Get the command object to test
self.cmd = image.SetImage(self.app, None) 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): def test_image_set_options(self):
arglist = [ arglist = [
'--name', 'new-name', '--name', 'new-name',
@ -1211,6 +1224,19 @@ class TestImageUnset(TestImage):
# Get the command object to test # Get the command object to test
self.cmd = image.UnsetImage(self.app, None) 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): def test_image_unset_tag_option(self):
arglist = [ arglist = [

View File

@ -1,6 +1,6 @@
--- ---
upgrade: upgrade:
- All ``set`` and ``unset`` commands in network and volume now return - All ``set`` and ``unset`` commands in network, identity, image, and volume now
normally when nothing specified to modify. This will become the default return normally when nothing specified to modify. This will become the default
behavior of OSC ``set`` and ``unset`` commands. behavior of OSC ``set`` and ``unset`` commands.
[Bug `1588588 <https://bugs.launchpad.net/python-openstackclient/+bug/1588588>`_] [Bug `1588588 <https://bugs.launchpad.net/python-openstackclient/+bug/1588588>`_]