Skip to content

Commit 8a12a39

Browse files
sunyajingstevemar
authored andcommitted
Make set/unset command in identity and image pass normally when nothing specified
Also update its unit tests. Change-Id: I82b90658b0d4247cdc9a650f14aceda640a32059 Partial-bug: #1588588
1 parent 2c92b60 commit 8a12a39

7 files changed

Lines changed: 89 additions & 40 deletions

File tree

openstackclient/identity/v2_0/project.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,6 @@ def get_parser(self, prog_name):
189189
def take_action(self, parsed_args):
190190
identity_client = self.app.client_manager.identity
191191

192-
if (not parsed_args.name
193-
and not parsed_args.description
194-
and not parsed_args.enable
195-
and not parsed_args.property
196-
and not parsed_args.disable):
197-
return
198-
199192
project = utils.find_resource(
200193
identity_client.tenants,
201194
parsed_args.project,
@@ -295,7 +288,6 @@ def get_parser(self, prog_name):
295288
metavar='<key>',
296289
action='append',
297290
default=[],
298-
required=True,
299291
help=_('Unset a project property '
300292
'(repeat option to unset multiple properties)'),
301293
)
@@ -307,11 +299,8 @@ def take_action(self, parsed_args):
307299
identity_client.tenants,
308300
parsed_args.project,
309301
)
310-
if not parsed_args.property:
311-
self.app.log.error(_("No changes requested\n"))
312-
else:
313-
kwargs = project._info
314-
for key in parsed_args.property:
315-
if key in kwargs:
316-
kwargs[key] = None
317-
identity_client.tenants.update(project.id, **kwargs)
302+
kwargs = project._info
303+
for key in parsed_args.property:
304+
if key in kwargs:
305+
kwargs[key] = None
306+
identity_client.tenants.update(project.id, **kwargs)

openstackclient/identity/v2_0/user.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -287,15 +287,6 @@ def take_action(self, parsed_args):
287287
if parsed_args.password_prompt:
288288
parsed_args.password = utils.get_password(self.app.stdin)
289289

290-
if (not parsed_args.name
291-
and not parsed_args.name
292-
and not parsed_args.password
293-
and not parsed_args.email
294-
and not parsed_args.project
295-
and not parsed_args.enable
296-
and not parsed_args.disable):
297-
return
298-
299290
user = utils.find_resource(
300291
identity_client.users,
301292
parsed_args.user,

openstackclient/image/v2/image.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -803,11 +803,6 @@ def take_action(self, parsed_args):
803803
parsed_args.project_domain,
804804
).id
805805

806-
# Checks if anything that requires getting the image
807-
if not (kwargs or parsed_args.deactivate or parsed_args.activate):
808-
msg = _("No arguments specified")
809-
raise exceptions.CommandError(msg)
810-
811806
image = utils.find_resource(
812807
image_client.images, parsed_args.image)
813808

@@ -819,10 +814,6 @@ def take_action(self, parsed_args):
819814
image_client.images.reactivate(image.id)
820815
activation_status = "activated"
821816

822-
# Check if need to do the actual update
823-
if not kwargs:
824-
return {}, {}
825-
826817
if parsed_args.tags:
827818
# Tags should be extended, but duplicates removed
828819
kwargs['tags'] = list(set(image.tags).union(set(parsed_args.tags)))
@@ -895,10 +886,6 @@ def take_action(self, parsed_args):
895886
parsed_args.image,
896887
)
897888

898-
if not (parsed_args.tags or parsed_args.properties):
899-
msg = _("No arguments specified")
900-
raise exceptions.CommandError(msg)
901-
902889
kwargs = {}
903890
tagret = 0
904891
propret = 0

openstackclient/tests/identity/v2_0/test_project.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import copy
1717

1818
from keystoneauth1 import exceptions as ks_exc
19+
from osc_lib import exceptions
1920

2021
from openstackclient.identity.v2_0 import project
2122
from openstackclient.tests import fakes
@@ -410,6 +411,26 @@ def test_project_set_no_options(self):
410411

411412
self.assertIsNone(result)
412413

414+
def test_project_set_unexist_project(self):
415+
arglist = [
416+
"unexist-project",
417+
]
418+
verifylist = [
419+
('project', "unexist-project"),
420+
('name', None),
421+
('description', None),
422+
('enable', False),
423+
('disable', False),
424+
('property', None),
425+
]
426+
self.projects_mock.get.side_effect = exceptions.NotFound(None)
427+
self.projects_mock.find.side_effect = exceptions.NotFound(None)
428+
429+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
430+
431+
self.assertRaises(
432+
exceptions.CommandError, self.cmd.take_action, parsed_args)
433+
413434
def test_project_set_name(self):
414435
arglist = [
415436
'--name', 'qwerty',
@@ -604,6 +625,19 @@ def setUp(self):
604625
# Get the command object to test
605626
self.cmd = project.UnsetProject(self.app, None)
606627

628+
def test_project_unset_no_options(self):
629+
arglist = [
630+
identity_fakes.project_name,
631+
]
632+
verifylist = [
633+
('project', identity_fakes.project_name),
634+
]
635+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
636+
637+
result = self.cmd.take_action(parsed_args)
638+
639+
self.assertIsNone(result)
640+
607641
def test_project_unset_key(self):
608642
arglist = [
609643
'--property', 'fee',

openstackclient/tests/identity/v2_0/test_user.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import mock
1818

1919
from keystoneauth1 import exceptions as ks_exc
20+
from osc_lib import exceptions
2021

2122
from openstackclient.identity.v2_0 import user
2223
from openstackclient.tests import fakes
@@ -563,6 +564,27 @@ def test_user_set_no_options(self):
563564

564565
self.assertIsNone(result)
565566

567+
def test_user_set_unexist_user(self):
568+
arglist = [
569+
"unexist-user",
570+
]
571+
verifylist = [
572+
('name', None),
573+
('password', None),
574+
('email', None),
575+
('project', None),
576+
('enable', False),
577+
('disable', False),
578+
('user', "unexist-user"),
579+
]
580+
self.users_mock.get.side_effect = exceptions.NotFound(None)
581+
self.users_mock.find.side_effect = exceptions.NotFound(None)
582+
583+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
584+
585+
self.assertRaises(
586+
exceptions.CommandError, self.cmd.take_action, parsed_args)
587+
566588
def test_user_set_name(self):
567589
arglist = [
568590
'--name', 'qwerty',

openstackclient/tests/image/v2/test_image.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,19 @@ def setUp(self):
811811
# Get the command object to test
812812
self.cmd = image.SetImage(self.app, None)
813813

814+
def test_image_set_no_options(self):
815+
arglist = [
816+
image_fakes.image_id,
817+
]
818+
verifylist = [
819+
('image', image_fakes.image_id)
820+
]
821+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
822+
823+
result = self.cmd.take_action(parsed_args)
824+
825+
self.assertIsNone(result)
826+
814827
def test_image_set_options(self):
815828
arglist = [
816829
'--name', 'new-name',
@@ -1211,6 +1224,19 @@ def setUp(self):
12111224
# Get the command object to test
12121225
self.cmd = image.UnsetImage(self.app, None)
12131226

1227+
def test_image_unset_no_options(self):
1228+
arglist = [
1229+
image_fakes.image_id,
1230+
]
1231+
verifylist = [
1232+
('image', image_fakes.image_id)
1233+
]
1234+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1235+
1236+
result = self.cmd.take_action(parsed_args)
1237+
1238+
self.assertIsNone(result)
1239+
12141240
def test_image_unset_tag_option(self):
12151241

12161242
arglist = [
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
upgrade:
3-
- All ``set`` and ``unset`` commands in network and volume now return
4-
normally when nothing specified to modify. This will become the default
3+
- All ``set`` and ``unset`` commands in network, identity, image, and volume now
4+
return normally when nothing specified to modify. This will become the default
55
behavior of OSC ``set`` and ``unset`` commands.
66
[Bug `1588588 <https://bugs.launchpad.net/python-openstackclient/+bug/1588588>`_]

0 commit comments

Comments
 (0)