Browse Source

Support bulk deletion for delete commands in identityv3

Support bulk deletion for delete commands in the list below
identity/v3/consumer
identity/v3/credential
identity/v3/domain
identity/v3/ec2creds
identity/v3/endpoint
identity/v3/federation_protocol
identity/v3/identity_provider
identity/v3/mapping
identity/v3/policy
identity/v3/region
identity/v3/service_provider
identity/v3/service

The unit test in identityv3 need to be refactored, so I add
some functional tests instead. I will add all unit tests at
one time after the refactor completed.

Change-Id: I82367570f59817b47c87b6c7bfeae95ccfe5c50e
Closes-Bug: #1592906
changes/81/340681/6
Huanxuan Ao 5 years ago
parent
commit
60639d76a7
36 changed files with 361 additions and 82 deletions
  1. +3
    -3
      doc/source/command-objects/consumer.rst
  2. +3
    -3
      doc/source/command-objects/domain.rst
  3. +3
    -3
      doc/source/command-objects/federation-protocol.rst
  4. +3
    -3
      doc/source/command-objects/identity-provider.rst
  5. +3
    -3
      doc/source/command-objects/mapping.rst
  6. +3
    -3
      doc/source/command-objects/policy.rst
  7. +3
    -3
      doc/source/command-objects/region.rst
  8. +3
    -3
      doc/source/command-objects/service-provider.rst
  9. +12
    -0
      functional/tests/identity/v3/test_domain.py
  10. +7
    -0
      functional/tests/identity/v3/test_endpoint.py
  11. +7
    -0
      functional/tests/identity/v3/test_idp.py
  12. +7
    -0
      functional/tests/identity/v3/test_region.py
  13. +7
    -0
      functional/tests/identity/v3/test_service.py
  14. +7
    -0
      functional/tests/identity/v3/test_service_provider.py
  15. +26
    -5
      openstackclient/identity/v3/consumer.py
  16. +24
    -3
      openstackclient/identity/v3/credential.py
  17. +20
    -5
      openstackclient/identity/v3/domain.py
  18. +23
    -2
      openstackclient/identity/v3/ec2creds.py
  19. +26
    -5
      openstackclient/identity/v3/endpoint.py
  20. +20
    -4
      openstackclient/identity/v3/federation_protocol.py
  21. +19
    -4
      openstackclient/identity/v3/identity_provider.py
  22. +18
    -4
      openstackclient/identity/v3/mapping.py
  23. +24
    -3
      openstackclient/identity/v3/policy.py
  24. +24
    -4
      openstackclient/identity/v3/region.py
  25. +25
    -6
      openstackclient/identity/v3/service.py
  26. +24
    -4
      openstackclient/identity/v3/service_provider.py
  27. +1
    -1
      openstackclient/tests/identity/v3/test_consumer.py
  28. +1
    -1
      openstackclient/tests/identity/v3/test_domain.py
  29. +1
    -1
      openstackclient/tests/identity/v3/test_endpoint.py
  30. +1
    -1
      openstackclient/tests/identity/v3/test_identity_provider.py
  31. +1
    -1
      openstackclient/tests/identity/v3/test_mappings.py
  32. +1
    -1
      openstackclient/tests/identity/v3/test_protocol.py
  33. +1
    -1
      openstackclient/tests/identity/v3/test_region.py
  34. +1
    -1
      openstackclient/tests/identity/v3/test_service.py
  35. +1
    -1
      openstackclient/tests/identity/v3/test_service_provider.py
  36. +8
    -0
      releasenotes/notes/bug-1592906-ad67ce8736f3cd48.yaml

+ 3
- 3
doc/source/command-objects/consumer.rst View File

@ -24,17 +24,17 @@ Create new consumer
consumer delete
---------------
Delete consumer
Delete consumer(s)
.. program:: consumer delete
.. code:: bash
os consumer delete
<consumer>
<consumer> [<consumer> ...]
.. describe:: <consumer>
Consumer to delete
Consumer(s) to delete
consumer list
-------------


+ 3
- 3
doc/source/command-objects/domain.rst View File

@ -43,17 +43,17 @@ Create new domain
domain delete
-------------
Delete domain
Delete domain(s)
.. program:: domain delete
.. code:: bash
os domain delete
<domain>
<domain> [<domain> ...]
.. describe:: <domain>
Domain to delete (name or ID)
Domain(s) to delete (name or ID)
domain list
-----------


+ 3
- 3
doc/source/command-objects/federation-protocol.rst View File

@ -34,14 +34,14 @@ Create new federation protocol
federation protocol delete
--------------------------
Delete federation protocol
Delete federation protocol(s)
.. program:: federation protocol delete
.. code:: bash
os federation protocol delete
--identity-provider <identity-provider>
<federation-protocol>
<federation-protocol> [<federation-protocol> ...]
.. option:: --identity-provider <identity-provider>
@ -49,7 +49,7 @@ Delete federation protocol
.. describe:: <federation-protocol>
Federation protocol to delete (name or ID)
Federation protocol(s) to delete (name or ID)
federation protocol list
------------------------


+ 3
- 3
doc/source/command-objects/identity-provider.rst View File

@ -49,17 +49,17 @@ Create new identity provider
identity provider delete
------------------------
Delete identity provider
Delete identity provider(s)
.. program:: identity provider delete
.. code:: bash
os identity provider delete
<identity-provider>
<identity-provider> [<identity-provider> ...]
.. describe:: <identity-provider>
Identity provider to delete
Identity provider(s) to delete
identity provider list
----------------------


+ 3
- 3
doc/source/command-objects/mapping.rst View File

@ -30,18 +30,18 @@ Create new mapping
mapping delete
--------------
Delete mapping
Delete mapping(s)
.. program:: mapping delete
.. code:: bash
os mapping delete
<mapping>
<mapping> [<mapping> ...]
.. _mapping_delete-mapping:
.. describe:: <mapping>
Mapping to delete
Mapping(s) to delete
mapping list
------------


+ 3
- 3
doc/source/command-objects/policy.rst View File

@ -27,17 +27,17 @@ Create new policy
policy delete
-------------
Delete policy
Delete policy(s)
.. program:: policy delete
.. code:: bash
os policy delete
<policy>
<policy> [<policy> ...]
.. describe:: <policy>
Policy to delete
Policy(s) to delete
policy list
-----------


+ 3
- 3
doc/source/command-objects/region.rst View File

@ -33,18 +33,18 @@ Create new region
region delete
-------------
Delete region
Delete region(s)
.. program:: region delete
.. code:: bash
os region delete
<region-id>
<region-id> [<region-id> ...]
.. _region_delete-region-id:
.. describe:: <region-id>
Region ID to delete
Region ID(s) to delete
region list
-----------


+ 3
- 3
doc/source/command-objects/service-provider.rst View File

@ -48,17 +48,17 @@ Create new service provider
service provider delete
-----------------------
Delete service provider
Delete service provider(s)
.. program:: service provider delete
.. code:: bash
os service provider delete
<service-provider>
<service-provider> [<service-provider> ...]
.. describe:: <service-provider>
Service provider to delete
Service provider(s) to delete
service provider list
---------------------


+ 12
- 0
functional/tests/identity/v3/test_domain.py View File

@ -43,6 +43,18 @@ class DomainTests(common.IdentityTests):
raw_output = self.openstack('domain delete %s' % domain_name)
self.assertEqual(0, len(raw_output))
def test_domain_multi_delete(self):
domain_1 = self._create_dummy_domain(add_clean_up=False)
domain_2 = self._create_dummy_domain(add_clean_up=False)
# cannot delete enabled domain, disable it first
raw_output = self.openstack('domain set --disable %s' % domain_1)
self.assertEqual(0, len(raw_output))
raw_output = self.openstack('domain set --disable %s' % domain_2)
self.assertEqual(0, len(raw_output))
raw_output = self.openstack(
'domain delete %s %s' % (domain_1, domain_2))
self.assertEqual(0, len(raw_output))
def test_domain_delete_failure(self):
domain_name = self._create_dummy_domain()
# cannot delete enabled domain


+ 7
- 0
functional/tests/identity/v3/test_endpoint.py View File

@ -28,6 +28,13 @@ class EndpointTests(common.IdentityTests):
'endpoint delete %s' % endpoint_id)
self.assertEqual(0, len(raw_output))
def test_endpoint_multi_delete(self):
endpoint_1 = self._create_dummy_endpoint(add_clean_up=False)
endpoint_2 = self._create_dummy_endpoint(add_clean_up=False)
raw_output = self.openstack(
'endpoint delete %s %s' % (endpoint_1, endpoint_2))
self.assertEqual(0, len(raw_output))
def test_endpoint_list(self):
endpoint_id = self._create_dummy_endpoint()
raw_output = self.openstack('endpoint list')


+ 7
- 0
functional/tests/identity/v3/test_idp.py View File

@ -26,6 +26,13 @@ class IdentityProviderTests(common.IdentityTests):
% identity_provider)
self.assertEqual(0, len(raw_output))
def test_idp_multi_delete(self):
idp_1 = self._create_dummy_idp(add_clean_up=False)
idp_2 = self._create_dummy_idp(add_clean_up=False)
raw_output = self.openstack(
'identity provider delete %s %s' % (idp_1, idp_2))
self.assertEqual(0, len(raw_output))
def test_idp_show(self):
identity_provider = self._create_dummy_idp(add_clean_up=True)
raw_output = self.openstack('identity provider show %s'


+ 7
- 0
functional/tests/identity/v3/test_region.py View File

@ -27,6 +27,13 @@ class RegionTests(common.IdentityTests):
raw_output = self.openstack('region delete %s' % region_id)
self.assertEqual(0, len(raw_output))
def test_region_multi_delete(self):
region_1 = self._create_dummy_region(add_clean_up=False)
region_2 = self._create_dummy_region(add_clean_up=False)
raw_output = self.openstack(
'region delete %s %s' % (region_1, region_2))
self.assertEqual(0, len(raw_output))
def test_region_list(self):
raw_output = self.openstack('region list')
items = self.parse_listing(raw_output)


+ 7
- 0
functional/tests/identity/v3/test_service.py View File

@ -25,6 +25,13 @@ class ServiceTests(common.IdentityTests):
raw_output = self.openstack('service delete %s' % service_name)
self.assertEqual(0, len(raw_output))
def test_service_multi_delete(self):
service_1 = self._create_dummy_service(add_clean_up=False)
service_2 = self._create_dummy_service(add_clean_up=False)
raw_output = self.openstack(
'service delete %s %s' % (service_1, service_2))
self.assertEqual(0, len(raw_output))
def test_service_list(self):
self._create_dummy_service()
raw_output = self.openstack('service list')


+ 7
- 0
functional/tests/identity/v3/test_service_provider.py View File

@ -26,6 +26,13 @@ class ServiceProviderTests(common.IdentityTests):
% service_provider)
self.assertEqual(0, len(raw_output))
def test_sp_multi_delete(self):
sp1 = self._create_dummy_sp(add_clean_up=False)
sp2 = self._create_dummy_sp(add_clean_up=False)
raw_output = self.openstack(
'service provider delete %s %s' % (sp1, sp2))
self.assertEqual(0, len(raw_output))
def test_sp_show(self):
service_provider = self._create_dummy_sp(add_clean_up=True)
raw_output = self.openstack('service provider show %s'


+ 26
- 5
openstackclient/identity/v3/consumer.py View File

@ -15,13 +15,19 @@
"""Identity v3 Consumer action implementations"""
import logging
from osc_lib.command import command
from osc_lib import exceptions
from osc_lib import utils
import six
from openstackclient.i18n import _
LOG = logging.getLogger(__name__)
class CreateConsumer(command.ShowOne):
"""Create new consumer"""
@ -44,22 +50,37 @@ class CreateConsumer(command.ShowOne):
class DeleteConsumer(command.Command):
"""Delete consumer"""
"""Delete consumer(s)"""
def get_parser(self, prog_name):
parser = super(DeleteConsumer, self).get_parser(prog_name)
parser.add_argument(
'consumer',
metavar='<consumer>',
help=_('Consumer to delete'),
nargs='+',
help=_('Consumer(s) to delete'),
)
return parser
def take_action(self, parsed_args):
identity_client = self.app.client_manager.identity
consumer = utils.find_resource(
identity_client.oauth1.consumers, parsed_args.consumer)
identity_client.oauth1.consumers.delete(consumer.id)
result = 0
for i in parsed_args.consumer:
try:
consumer = utils.find_resource(
identity_client.oauth1.consumers, i)
identity_client.oauth1.consumers.delete(consumer.id)
except Exception as e:
result += 1
LOG.error(_("Failed to delete consumer with name or "
"ID '%(consumer)s': %(e)s")
% {'consumer': i, 'e': e})
if result > 0:
total = len(parsed_args.consumer)
msg = (_("%(result)s of %(total)s consumers failed "
"to delete.") % {'result': result, 'total': total})
raise exceptions.CommandError(msg)
class ListConsumer(command.Lister):


+ 24
- 3
openstackclient/identity/v3/credential.py View File

@ -15,13 +15,19 @@
"""Identity v3 Credential action implementations"""
import logging
from osc_lib.command import command
from osc_lib import exceptions
from osc_lib import utils
import six
from openstackclient.i18n import _
LOG = logging.getLogger(__name__)
class CreateCredential(command.ShowOne):
"""Create credential command"""
@ -72,20 +78,35 @@ class CreateCredential(command.ShowOne):
class DeleteCredential(command.Command):
"""Delete credential command"""
"""Delete credential(s)"""
def get_parser(self, prog_name):
parser = super(DeleteCredential, self).get_parser(prog_name)
parser.add_argument(
'credential',
metavar='<credential-id>',
help=_('ID of credential to delete'),
nargs='+',
help=_('ID of credential(s) to delete'),
)
return parser
def take_action(self, parsed_args):
identity_client = self.app.client_manager.identity
identity_client.credentials.delete(parsed_args.credential)
result = 0
for i in parsed_args.credential:
try:
identity_client.credentials.delete(i)
except Exception as e:
result += 1
LOG.error(_("Failed to delete credentials with "
"ID '%(credential)s': %(e)s")
% {'credential': i, 'e': e})
if result > 0:
total = len(parsed_args.credential)
msg = (_("%(result)s of %(total)s credential failed "
"to delete.") % {'result': result, 'total': total})
raise exceptions.CommandError(msg)
class ListCredential(command.Lister):


+ 20
- 5
openstackclient/identity/v3/domain.py View File

@ -19,6 +19,7 @@ import logging
from keystoneauth1 import exceptions as ks_exc
from osc_lib.command import command
from osc_lib import exceptions
from osc_lib import utils
import six
@ -88,22 +89,36 @@ class CreateDomain(command.ShowOne):
class DeleteDomain(command.Command):
"""Delete domain"""
"""Delete domain(s)"""
def get_parser(self, prog_name):
parser = super(DeleteDomain, self).get_parser(prog_name)
parser.add_argument(
'domain',
metavar='<domain>',
help=_('Domain to delete (name or ID)'),
nargs='+',
help=_('Domain(s) to delete (name or ID)'),
)
return parser
def take_action(self, parsed_args):
identity_client = self.app.client_manager.identity
domain = utils.find_resource(identity_client.domains,
parsed_args.domain)
identity_client.domains.delete(domain.id)
result = 0
for i in parsed_args.domain:
try:
domain = utils.find_resource(identity_client.domains, i)
identity_client.domains.delete(domain.id)
except Exception as e:
result += 1
LOG.error(_("Failed to delete domain with name or "
"ID '%(domain)s': %(e)s")
% {'domain': i, 'e': e})
if result > 0:
total = len(parsed_args.domain)
msg = (_("%(result)s of %(total)s domains failed "
"to delete.") % {'result': result, 'total': total})
raise exceptions.CommandError(msg)
class ListDomain(command.Lister):


+ 23
- 2
openstackclient/identity/v3/ec2creds.py View File

@ -12,7 +12,10 @@
"""Identity v3 EC2 Credentials action implementations"""
import logging
from osc_lib.command import command
from osc_lib import exceptions
from osc_lib import utils
import six
@ -20,6 +23,9 @@ from openstackclient.i18n import _
from openstackclient.identity import common
LOG = logging.getLogger(__name__)
def _determine_ec2_user(parsed_args, client_manager):
"""Determine a user several different ways.
@ -113,7 +119,8 @@ class DeleteEC2Creds(command.Command):
parser.add_argument(
'access_key',
metavar='<access-key>',
help=_('Credentials access key'),
nargs='+',
help=_('Credentials access key(s)'),
)
parser.add_argument(
'--user',
@ -126,7 +133,21 @@ class DeleteEC2Creds(command.Command):
def take_action(self, parsed_args):
client_manager = self.app.client_manager
user = _determine_ec2_user(parsed_args, client_manager)
client_manager.identity.ec2.delete(user, parsed_args.access_key)
result = 0
for i in parsed_args.access_key:
try:
client_manager.identity.ec2.delete(user, i)
except Exception as e:
result += 1
LOG.error(_("Failed to delete EC2 credentials with "
"access key '%(access_key)s': %(e)s")
% {'access_key': i, 'e': e})
if result > 0:
total = len(parsed_args.access_key)
msg = (_("%(result)s of %(total)s EC2 keys failed "
"to delete.") % {'result': result, 'total': total})
raise exceptions.CommandError(msg)
class ListEC2Creds(command.Lister):


+ 26
- 5
openstackclient/identity/v3/endpoint.py View File

@ -15,7 +15,10 @@
"""Identity v3 Endpoint action implementations"""
import logging
from osc_lib.command import command
from osc_lib import exceptions
from osc_lib import utils
import six
@ -23,6 +26,9 @@ from openstackclient.i18n import _
from openstackclient.identity import common
LOG = logging.getLogger(__name__)
def get_service_name(service):
if hasattr(service, 'name'):
return service.name
@ -93,22 +99,37 @@ class CreateEndpoint(command.ShowOne):
class DeleteEndpoint(command.Command):
"""Delete endpoint"""
"""Delete endpoint(s)"""
def get_parser(self, prog_name):
parser = super(DeleteEndpoint, self).get_parser(prog_name)
parser.add_argument(
'endpoint',
metavar='<endpoint-id>',
help=_('Endpoint to delete (ID only)'),
nargs='+',
help=_('Endpoint(s) to delete (ID only)'),
)
return parser
def take_action(self, parsed_args):
identity_client = self.app.client_manager.identity
endpoint_id = utils.find_resource(identity_client.endpoints,
parsed_args.endpoint).id
identity_client.endpoints.delete(endpoint_id)
result = 0
for i in parsed_args.endpoint:
try:
endpoint_id = utils.find_resource(
identity_client.endpoints, i).id
identity_client.endpoints.delete(endpoint_id)
except Exception as e:
result += 1
LOG.error(_("Failed to delete endpoint with "
"ID '%(endpoint)s': %(e)s")
% {'endpoint': i, 'e': e})
if result > 0:
total = len(parsed_args.endpoint)
msg = (_("%(result)s of %(total)s endpoints failed "
"to delete.") % {'result': result, 'total': total})
raise exceptions.CommandError(msg)
class ListEndpoint(command.Lister):


+ 20
- 4
openstackclient/identity/v3/federation_protocol.py View File

@ -17,6 +17,7 @@
import logging
from osc_lib.command import command
from osc_lib import exceptions
from osc_lib import utils
import six
@ -71,14 +72,15 @@ class CreateProtocol(command.ShowOne):
class DeleteProtocol(command.Command):
"""Delete federation protocol"""
"""Delete federation protocol(s)"""
def get_parser(self, prog_name):
parser = super(DeleteProtocol, self).get_parser(prog_name)
parser.add_argument(
'federation_protocol',
metavar='<federation-protocol>',
help=_('Federation protocol to delete (name or ID)'),
nargs='+',
help=_('Federation protocol(s) to delete (name or ID)'),
)
parser.add_argument(
'--identity-provider',
@ -92,8 +94,22 @@ class DeleteProtocol(command.Command):
def take_action(self, parsed_args):
identity_client = self.app.client_manager.identity
identity_client.federation.protocols.delete(
parsed_args.identity_provider, parsed_args.federation_protocol)
result = 0
for i in parsed_args.federation_protocol:
try:
identity_client.federation.protocols.delete(
parsed_args.identity_provider, i)
except Exception as e:
result += 1
LOG.error(_("Failed to delete federation protocol "
"with name or ID '%(protocol)s': %(e)s")
% {'protocol': i, 'e': e})
if result > 0:
total = len(parsed_args.federation_protocol)
msg = (_("%(result)s of %(total)s federation protocols failed"
" to delete.") % {'result': result, 'total': total})
raise exceptions.CommandError(msg)
class ListProtocols(command.Lister):


+ 19
- 4
openstackclient/identity/v3/identity_provider.py View File

@ -16,6 +16,7 @@
import logging
from osc_lib.command import command
from osc_lib import exceptions
from osc_lib import utils
import six
@ -93,21 +94,35 @@ class CreateIdentityProvider(command.ShowOne):
class DeleteIdentityProvider(command.Command):
"""Delete identity provider"""
"""Delete identity provider(s)"""
def get_parser(self, prog_name):
parser = super(DeleteIdentityProvider, self).get_parser(prog_name)
parser.add_argument(
'identity_provider',
metavar='<identity-provider>',
help=_('Identity provider to delete'),
nargs='+',
help=_('Identity provider(s) to delete'),
)
return parser
def take_action(self, parsed_args):
identity_client = self.app.client_manager.identity
identity_client.federation.identity_providers.delete(
parsed_args.identity_provider)
result = 0
for i in parsed_args.identity_provider:
try:
identity_client.federation.identity_providers.delete(i)
except Exception as e:
result += 1
LOG.error(_("Failed to delete identity providers with "
"name or ID '%(provider)s': %(e)s")
% {'provider': i, 'e': e})
if result > 0:
total = len(parsed_args.identity_provider)
msg = (_("%(result)s of %(total)s identity providers failed"
" to delete.") % {'result': result, 'total': total})
raise exceptions.CommandError(msg)
class ListIdentityProvider(command.Lister):


+ 18
- 4
openstackclient/identity/v3/mapping.py View File

@ -111,21 +111,35 @@ class CreateMapping(command.ShowOne, _RulesReader):
class DeleteMapping(command.Command):
"""Delete mapping"""
"""Delete mapping(s)"""
def get_parser(self, prog_name):
parser = super(DeleteMapping, self).get_parser(prog_name)
parser.add_argument(
'mapping',
metavar='<mapping>',
help=_('Mapping to delete'),
nargs='+',
help=_('Mapping(s) to delete'),
)
return parser
def take_action(self, parsed_args):
identity_client = self.app.client_manager.identity
identity_client.federation.mappings.delete(parsed_args.mapping)
result = 0
for i in parsed_args.mapping:
try:
identity_client.federation.mappings.delete(i)
except Exception as e:
result += 1
LOG.error(_("Failed to delete mapping with name or "
"ID '%(mapping)s': %(e)s")
% {'mapping': i, 'e': e})
if result > 0:
total = len(parsed_args.mapping)
msg = (_("%(result)s of %(total)s mappings failed "
"to delete.") % {'result': result, 'total': total})
raise exceptions.CommandError(msg)
class ListMapping(command.Lister):


+ 24
- 3
openstackclient/identity/v3/policy.py View File

@ -15,13 +15,19 @@
"""Identity v3 Policy action implementations"""
import logging
from osc_lib.command import command
from osc_lib import exceptions
from osc_lib import utils
import six
from openstackclient.i18n import _
LOG = logging.getLogger(__name__)
class CreatePolicy(command.ShowOne):
"""Create new policy"""
@ -55,20 +61,35 @@ class CreatePolicy(command.ShowOne):
class DeletePolicy(command.Command):
"""Delete policy"""
"""Delete policy(s)"""
def get_parser(self, prog_name):
parser = super(DeletePolicy, self).get_parser(prog_name)
parser.add_argument(
'policy',
metavar='<policy>',
help=_('Policy to delete'),
nargs='+',
help=_('Policy(s) to delete'),
)
return parser
def take_action(self, parsed_args):
identity_client = self.app.client_manager.identity
identity_client.policies.delete(parsed_args.policy)
result = 0
for i in parsed_args.policy:
try:
identity_client.policies.delete(i)
except Exception as e:
result += 1
LOG.error(_("Failed to delete policy with name or "
"ID '%(policy)s': %(e)s")
% {'policy': i, 'e': e})
if result > 0:
total = len(parsed_args.policy)
msg = (_("%(result)s of %(total)s policys failed "
"to delete.") % {'result': result, 'total': total})
raise exceptions.CommandError(msg)
class ListPolicy(command.Lister):


+ 24
- 4
openstackclient/identity/v3/region.py View File

@ -13,13 +13,19 @@
"""Identity v3 Region action implementations"""
import logging
from osc_lib.command import command
from osc_lib import exceptions
from osc_lib import utils
import six
from openstackclient.i18n import _
LOG = logging.getLogger(__name__)
class CreateRegion(command.ShowOne):
"""Create new region"""
@ -60,21 +66,35 @@ class CreateRegion(command.ShowOne):
class DeleteRegion(command.Command):
"""Delete region"""
"""Delete region(s)"""
def get_parser(self, prog_name):
parser = super(DeleteRegion, self).get_parser(prog_name)
parser.add_argument(
'region',
metavar='<region-id>',
help=_('Region ID to delete'),
nargs='+',
help=_('Region ID(s) to delete'),
)
return parser
def take_action(self, parsed_args):
identity_client = self.app.client_manager.identity
identity_client.regions.delete(parsed_args.region)
result = 0
for i in parsed_args.region:
try:
identity_client.regions.delete(i)
except Exception as e:
result += 1
LOG.error(_("Failed to delete region with "
"ID '%(region)s': %(e)s")
% {'region': i, 'e': e})
if result > 0:
total = len(parsed_args.region)
msg = (_("%(result)s of %(total)s regions failed "
"to delete.") % {'result': result, 'total': total})
raise exceptions.CommandError(msg)
class ListRegion(command.Lister):


+ 25
- 6
openstackclient/identity/v3/service.py View File

@ -15,7 +15,10 @@
"""Identity v3 Service action implementations"""
import logging
from osc_lib.command import command
from osc_lib import exceptions
from osc_lib import utils
import six
@ -23,6 +26,9 @@ from openstackclient.i18n import _
from openstackclient.identity import common
LOG = logging.getLogger(__name__)
class CreateService(command.ShowOne):
"""Create new service"""
@ -75,23 +81,36 @@ class CreateService(command.ShowOne):
class DeleteService(command.Command):
"""Delete service"""
"""Delete service(s)"""
def get_parser(self, prog_name):
parser = super(DeleteService, self).get_parser(prog_name)
parser.add_argument(
'service',
metavar='<service>',
help=_('Service to delete (type, name or ID)'),
nargs='+',
help=_('Service(s) to delete (type, name or ID)'),
)
return parser
def take_action(self, parsed_args):
identity_client = self.app.client_manager.identity
service = common.find_service(identity_client, parsed_args.service)
identity_client.services.delete(service.id)
result = 0
for i in parsed_args.service:
try:
service = common.find_service(identity_client, i)
identity_client.services.delete(service.id)
except Exception as e:
result += 1
LOG.error(_("Failed to delete consumer with type, "
"name or ID '%(service)s': %(e)s")
% {'service': i, 'e': e})
if result > 0:
total = len(parsed_args.service)
msg = (_("%(result)s of %(total)s services failed "
"to delete.") % {'result': result, 'total': total})
raise exceptions.CommandError(msg)
class ListService(command.Lister):


+ 24
- 4
openstackclient/identity/v3/service_provider.py View File

@ -13,13 +13,19 @@
"""Service Provider action implementations"""
import logging
from osc_lib.command import command
from osc_lib import exceptions
from osc_lib import utils
import six
from openstackclient.i18n import _
LOG = logging.getLogger(__name__)
class CreateServiceProvider(command.ShowOne):
"""Create new service provider"""
@ -81,21 +87,35 @@ class CreateServiceProvider(command.ShowOne):
class DeleteServiceProvider(command.Command):
"""Delete service provider"""
"""Delete service provider(s)"""
def get_parser(self, prog_name):
parser = super(DeleteServiceProvider, self).get_parser(prog_name)
parser.add_argument(
'service_provider',
metavar='<service-provider>',
help=_('Service provider to delete'),
nargs='+',
help=_('Service provider(s) to delete'),
)
return parser
def take_action(self, parsed_args):
service_client = self.app.client_manager.identity
service_client.federation.service_providers.delete(
parsed_args.service_provider)
result = 0
for i in parsed_args.service_provider:
try:
service_client.federation.service_providers.delete(i)
except Exception as e:
result += 1
LOG.error(_("Failed to delete service provider with "
"name or ID '%(provider)s': %(e)s")
% {'provider': i, 'e': e})
if result > 0:
total = len(parsed_args.service_provider)
msg = (_("%(result)s of %(total)s service providers failed"
" to delete.") % {'result': result, 'total': total})
raise exceptions.CommandError(msg)
class ListServiceProvider(command.Lister):


+ 1
- 1
openstackclient/tests/identity/v3/test_consumer.py View File

@ -83,7 +83,7 @@ class TestConsumerDelete(TestOAuth1):
identity_fakes.consumer_id,
]
verifylist = [
('consumer', identity_fakes.consumer_id),
('consumer', [identity_fakes.consumer_id]),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)


+ 1
- 1
openstackclient/tests/identity/v3/test_domain.py View File

@ -182,7 +182,7 @@ class TestDomainDelete(TestDomain):
self.domain.id,
]
verifylist = [
('domain', self.domain.id),
('domain', [self.domain.id]),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)


+ 1
- 1
openstackclient/tests/identity/v3/test_endpoint.py View File

@ -273,7 +273,7 @@ class TestEndpointDelete(TestEndpoint):
identity_fakes.endpoint_id,
]
verifylist = [
('endpoint', identity_fakes.endpoint_id),
('endpoint', [identity_fakes.endpoint_id]),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)


+ 1
- 1
openstackclient/tests/identity/v3/test_identity_provider.py View File

@ -255,7 +255,7 @@ class TestIdentityProviderDelete(TestIdentityProvider):
identity_fakes.idp_id,
]
verifylist = [
('identity_provider', identity_fakes.idp_id),
('identity_provider', [identity_fakes.idp_id]),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)


+ 1
- 1
openstackclient/tests/identity/v3/test_mappings.py View File

@ -91,7 +91,7 @@ class TestMappingDelete(TestMapping):
identity_fakes.mapping_id
]
verifylist = [
('mapping', identity_fakes.mapping_id)
('mapping', [identity_fakes.mapping_id])
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)


+ 1
- 1
openstackclient/tests/identity/v3/test_protocol.py View File

@ -88,7 +88,7 @@ class TestProtocolDelete(TestProtocol):
identity_fakes.protocol_id
]
verifylist = [
('federation_protocol', identity_fakes.protocol_id),
('federation_protocol', [identity_fakes.protocol_id]),
('identity_provider', identity_fakes.idp_id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)


+ 1
- 1
openstackclient/tests/identity/v3/test_region.py View File

@ -153,7 +153,7 @@ class TestRegionDelete(TestRegion):
identity_fakes.region_id,
]
verifylist = [
('region', identity_fakes.region_id),
('region', [identity_fakes.region_id]),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)


+ 1
- 1
openstackclient/tests/identity/v3/test_service.py View File

@ -200,7 +200,7 @@ class TestServiceDelete(TestService):
identity_fakes.service_name,
]
verifylist = [
('service', identity_fakes.service_name),
('service', [identity_fakes.service_name]),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)


+ 1
- 1
openstackclient/tests/identity/v3/test_service_provider.py View File

@ -185,7 +185,7 @@ class TestServiceProviderDelete(TestServiceProvider):
service_fakes.sp_id,
]
verifylist = [
('service_provider', service_fakes.sp_id),
('service_provider', [service_fakes.sp_id]),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)


+ 8
- 0
releasenotes/notes/bug-1592906-ad67ce8736f3cd48.yaml View File

@ -0,0 +1,8 @@
---
features:
- |
Support bulk deletion for identity v3 commands: ``consumer``,
``credential``, ``domain``, ``ec2creds``, ``endpoint``,
``federation_protocol``, ``identity_provider``, ``mapping``,
``policy``, ``region``, ``service_provider`` and ``service``.
[Bug `1592906 <https://bugs.launchpad.net/bugs/1592906>`_]

Loading…
Cancel
Save