Skip to content

Commit 1464c8a

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Make set/unset command in identity and image pass normally when nothing specified"
2 parents 2740291 + 8a12a39 commit 1464c8a

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
@@ -817,11 +817,6 @@ def take_action(self, parsed_args):
817817
parsed_args.project_domain,
818818
).id
819819

820-
# Checks if anything that requires getting the image
821-
if not (kwargs or parsed_args.deactivate or parsed_args.activate):
822-
msg = _("No arguments specified")
823-
raise exceptions.CommandError(msg)
824-
825820
image = utils.find_resource(
826821
image_client.images, parsed_args.image)
827822

@@ -833,10 +828,6 @@ def take_action(self, parsed_args):
833828
image_client.images.reactivate(image.id)
834829
activation_status = "activated"
835830

836-
# Check if need to do the actual update
837-
if not kwargs:
838-
return {}, {}
839-
840831
if parsed_args.tags:
841832
# Tags should be extended, but duplicates removed
842833
kwargs['tags'] = list(set(image.tags).union(set(parsed_args.tags)))
@@ -909,10 +900,6 @@ def take_action(self, parsed_args):
909900
parsed_args.image,
910901
)
911902

912-
if not (parsed_args.tags or parsed_args.properties):
913-
msg = _("No arguments specified")
914-
raise exceptions.CommandError(msg)
915-
916903
kwargs = {}
917904
tagret = 0
918905
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
@@ -842,6 +842,19 @@ def setUp(self):
842842
# Get the command object to test
843843
self.cmd = image.SetImage(self.app, None)
844844

845+
def test_image_set_no_options(self):
846+
arglist = [
847+
image_fakes.image_id,
848+
]
849+
verifylist = [
850+
('image', image_fakes.image_id)
851+
]
852+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
853+
854+
result = self.cmd.take_action(parsed_args)
855+
856+
self.assertIsNone(result)
857+
845858
def test_image_set_options(self):
846859
arglist = [
847860
'--name', 'new-name',
@@ -1242,6 +1255,19 @@ def setUp(self):
12421255
# Get the command object to test
12431256
self.cmd = image.UnsetImage(self.app, None)
12441257

1258+
def test_image_unset_no_options(self):
1259+
arglist = [
1260+
image_fakes.image_id,
1261+
]
1262+
verifylist = [
1263+
('image', image_fakes.image_id)
1264+
]
1265+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1266+
1267+
result = self.cmd.take_action(parsed_args)
1268+
1269+
self.assertIsNone(result)
1270+
12451271
def test_image_unset_tag_option(self):
12461272

12471273
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)