Skip to content

Commit 21ac923

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Support multi-delete for commands in identity V2"
2 parents aa06634 + 6df09fd commit 21ac923

12 files changed

Lines changed: 108 additions & 22 deletions

File tree

doc/source/command-objects/ec2-credentials.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Delete EC2 credentials
5555
os ec2 credentials delete
5656
[--user <user>]
5757
[--user-domain <user-domain>]
58-
<access-key>
58+
<access-key> [<access-key> ...]
5959
6060
.. option:: --user <user>
6161

@@ -71,7 +71,7 @@ Delete EC2 credentials
7171
.. _ec2_credentials_delete-access-key:
7272
.. describe:: access-key
7373

74-
Credentials access key
74+
Credentials access key(s)
7575

7676
The :option:`--user` option is typically only useful for admin users, but
7777
may be allowed for other users depending on the policy of the cloud and

doc/source/command-objects/endpoint.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,18 @@ Create new endpoint
8181
endpoint delete
8282
---------------
8383

84-
Delete endpoint
84+
Delete endpoint(s)
8585

8686
.. program:: endpoint delete
8787
.. code:: bash
8888
8989
os endpoint delete
90-
<endpoint-id>
90+
<endpoint-id> [<endpoint-id> ...]
9191
9292
.. _endpoint_delete-endpoint:
9393
.. describe:: <endpoint-id>
9494

95-
Endpoint to delete (ID only)
95+
Endpoint(s) to delete (ID only)
9696

9797
endpoint list
9898
-------------

doc/source/command-objects/service.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,18 @@ Create new service
4646
service delete
4747
--------------
4848

49-
Delete service
49+
Delete service(s)
5050

5151
.. program:: service delete
5252
.. code-block:: bash
5353
5454
os service delete
55-
<service>
55+
<service> [<service> ...]
5656
5757
.. _service_delete-type:
5858
.. describe:: <service>
5959

60-
Service to delete (type, name or ID)
60+
Service(s) to delete (type, name or ID)
6161

6262
service list
6363
------------

functional/tests/identity/v2/test_ec2_credentials.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ def test_ec2_credentials_delete(self):
2525
)
2626
self.assertEqual(0, len(raw_output))
2727

28+
def test_ec2_credentials_multi_delete(self):
29+
access_key_1 = self._create_dummy_ec2_credentials(add_clean_up=False)
30+
access_key_2 = self._create_dummy_ec2_credentials(add_clean_up=False)
31+
raw_output = self.openstack(
32+
'ec2 credentials delete ' + access_key_1 + ' ' + access_key_2
33+
)
34+
self.assertEqual(0, len(raw_output))
35+
2836
def test_ec2_credentials_list(self):
2937
self._create_dummy_ec2_credentials()
3038
raw_output = self.openstack('ec2 credentials list')

functional/tests/identity/v2/test_endpoint.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ def test_endpoint_delete(self):
2424
'endpoint delete %s' % endpoint_id)
2525
self.assertEqual(0, len(raw_output))
2626

27+
def test_endpoint_multi_delete(self):
28+
endpoint_id_1 = self._create_dummy_endpoint(add_clean_up=False)
29+
endpoint_id_2 = self._create_dummy_endpoint(add_clean_up=False)
30+
raw_output = self.openstack(
31+
'endpoint delete ' + endpoint_id_1 + ' ' + endpoint_id_2)
32+
self.assertEqual(0, len(raw_output))
33+
2734
def test_endpoint_list(self):
2835
endpoint_id = self._create_dummy_endpoint()
2936
raw_output = self.openstack('endpoint list')

functional/tests/identity/v2/test_service.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ def test_service_delete(self):
2323
raw_output = self.openstack('service delete %s' % service_name)
2424
self.assertEqual(0, len(raw_output))
2525

26+
def test_service_multi_delete(self):
27+
service_name_1 = self._create_dummy_service(add_clean_up=False)
28+
service_name_2 = self._create_dummy_service(add_clean_up=False)
29+
raw_output = self.openstack(
30+
'service delete ' + service_name_1 + ' ' + service_name_2)
31+
self.assertEqual(0, len(raw_output))
32+
2633
def test_service_list(self):
2734
self._create_dummy_service()
2835
raw_output = self.openstack('service list')

openstackclient/identity/v2_0/ec2creds.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@
1616

1717
"""Identity v2 EC2 Credentials action implementations"""
1818

19+
import logging
20+
1921
from osc_lib.command import command
22+
from osc_lib import exceptions
2023
from osc_lib import utils
2124
import six
2225

2326
from openstackclient.i18n import _
2427

2528

29+
LOG = logging.getLogger(__name__)
30+
31+
2632
class CreateEC2Creds(command.ShowOne):
2733
"""Create EC2 credentials"""
2834

@@ -85,9 +91,10 @@ class DeleteEC2Creds(command.Command):
8591
def get_parser(self, prog_name):
8692
parser = super(DeleteEC2Creds, self).get_parser(prog_name)
8793
parser.add_argument(
88-
'access_key',
94+
'access_keys',
8995
metavar='<access-key>',
90-
help=_('Credentials access key'),
96+
nargs='+',
97+
help=_('Credentials access keys'),
9198
)
9299
parser.add_argument(
93100
'--user',
@@ -108,7 +115,21 @@ def take_action(self, parsed_args):
108115
# Get the user from the current auth
109116
user = self.app.client_manager.auth_ref.user_id
110117

111-
identity_client.ec2.delete(user, parsed_args.access_key)
118+
result = 0
119+
for access_key in parsed_args.access_keys:
120+
try:
121+
identity_client.ec2.delete(user, access_key)
122+
except Exception as e:
123+
result += 1
124+
LOG.error(_("Failed to delete EC2 keys with "
125+
"access key '%(access_key)s': %(e)s")
126+
% {'access_key': access_key, 'e': e})
127+
128+
if result > 0:
129+
total = len(parsed_args.access_keys)
130+
msg = (_("%(result)s of %(total)s EC2 keys failed "
131+
"to delete.") % {'result': result, 'total': total})
132+
raise exceptions.CommandError(msg)
112133

113134

114135
class ListEC2Creds(command.Lister):

openstackclient/identity/v2_0/endpoint.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,20 @@
1515

1616
"""Endpoint action implementations"""
1717

18+
import logging
19+
1820
from osc_lib.command import command
21+
from osc_lib import exceptions
1922
from osc_lib import utils
2023
import six
2124

2225
from openstackclient.i18n import _
2326
from openstackclient.identity import common
2427

2528

29+
LOG = logging.getLogger(__name__)
30+
31+
2632
class CreateEndpoint(command.ShowOne):
2733
"""Create new endpoint"""
2834

@@ -74,20 +80,36 @@ def take_action(self, parsed_args):
7480

7581

7682
class DeleteEndpoint(command.Command):
77-
"""Delete endpoint"""
83+
"""Delete endpoint(s)"""
7884

7985
def get_parser(self, prog_name):
8086
parser = super(DeleteEndpoint, self).get_parser(prog_name)
8187
parser.add_argument(
82-
'endpoint',
88+
'endpoints',
8389
metavar='<endpoint-id>',
84-
help=_('Endpoint to delete (ID only)'),
90+
nargs='+',
91+
help=_('Endpoint(s) to delete (ID only)'),
8592
)
8693
return parser
8794

8895
def take_action(self, parsed_args):
8996
identity_client = self.app.client_manager.identity
90-
identity_client.endpoints.delete(parsed_args.endpoint)
97+
98+
result = 0
99+
for endpoint in parsed_args.endpoints:
100+
try:
101+
identity_client.endpoints.delete(endpoint)
102+
except Exception as e:
103+
result += 1
104+
LOG.error(_("Failed to delete endpoint with "
105+
"ID '%(endpoint)s': %(e)s")
106+
% {'endpoint': endpoint, 'e': e})
107+
108+
if result > 0:
109+
total = len(parsed_args.endpoints)
110+
msg = (_("%(result)s of %(total)s endpoints failed "
111+
"to delete.") % {'result': result, 'total': total})
112+
raise exceptions.CommandError(msg)
91113

92114

93115
class ListEndpoint(command.Lister):

openstackclient/identity/v2_0/service.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,37 @@ def take_action(self, parsed_args):
9191

9292

9393
class DeleteService(command.Command):
94-
"""Delete service"""
94+
"""Delete service(s)"""
9595

9696
def get_parser(self, prog_name):
9797
parser = super(DeleteService, self).get_parser(prog_name)
9898
parser.add_argument(
99-
'service',
99+
'services',
100100
metavar='<service>',
101-
help=_('Service to delete (type, name or ID)'),
101+
nargs='+',
102+
help=_('Service(s) to delete (type, name or ID)'),
102103
)
103104
return parser
104105

105106
def take_action(self, parsed_args):
106107
identity_client = self.app.client_manager.identity
107-
service = common.find_service(identity_client, parsed_args.service)
108-
identity_client.services.delete(service.id)
108+
109+
result = 0
110+
for service in parsed_args.services:
111+
try:
112+
service = common.find_service(identity_client, service)
113+
identity_client.services.delete(service.id)
114+
except Exception as e:
115+
result += 1
116+
LOG.error(_("Failed to delete service with "
117+
"name or ID '%(service)s': %(e)s")
118+
% {'service': service, 'e': e})
119+
120+
if result > 0:
121+
total = len(parsed_args.services)
122+
msg = (_("%(result)s of %(total)s services failed "
123+
"to delete.") % {'result': result, 'total': total})
124+
raise exceptions.CommandError(msg)
109125

110126

111127
class ListService(command.Lister):

openstackclient/tests/identity/v2_0/test_endpoint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def test_endpoint_delete_no_options(self):
112112
self.fake_endpoint.id,
113113
]
114114
verifylist = [
115-
('endpoint', self.fake_endpoint.id),
115+
('endpoints', [self.fake_endpoint.id]),
116116
]
117117
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
118118

0 commit comments

Comments
 (0)