summaryrefslogtreecommitdiff
path: root/openstackclient/identity/v3/role.py
diff options
context:
space:
mode:
authorHuanxuan Ao <huanxuan.ao@easystack.cn>2016-12-30 13:22:07 +0800
committerHuanxuan Ao <huanxuan.ao@easystack.cn>2017-01-03 23:30:49 +0800
commit96578cb8ab9a4b95144c33d0af38863fce8d8892 (patch)
tree8fd9c537b48aae84b9b3eaac8aa17079adf251b0 /openstackclient/identity/v3/role.py
parentf020a9ffd6d5602d18c899e7707baaa620ffdd54 (diff)
downloadpython-openstackclient-96578cb8ab9a4b95144c33d0af38863fce8d8892.tar.gz
Error handling for delete commands in identity
Add missing multi deletion error handling for identity delete commands. All delete commands in identity support error handling now. Change-Id: I05626dcb5e516a423d610906347b02236ba7eeaf
Diffstat (limited to 'openstackclient/identity/v3/role.py')
-rw-r--r--openstackclient/identity/v3/role.py27
1 files changed, 20 insertions, 7 deletions
diff --git a/openstackclient/identity/v3/role.py b/openstackclient/identity/v3/role.py
index c9d0fbf3..994ecc9c 100644
--- a/openstackclient/identity/v3/role.py
+++ b/openstackclient/identity/v3/role.py
@@ -20,6 +20,7 @@ import sys
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
@@ -223,14 +224,26 @@ class DeleteRole(command.Command):
if parsed_args.domain:
domain_id = common.find_domain(identity_client,
parsed_args.domain).id
-
+ errors = 0
for role in parsed_args.roles:
- role_obj = utils.find_resource(
- identity_client.roles,
- role,
- domain_id=domain_id
- )
- identity_client.roles.delete(role_obj.id)
+ try:
+ role_obj = utils.find_resource(
+ identity_client.roles,
+ role,
+ domain_id=domain_id
+ )
+ identity_client.roles.delete(role_obj.id)
+ except Exception as e:
+ errors += 1
+ LOG.error(_("Failed to delete role with "
+ "name or ID '%(role)s': %(e)s"),
+ {'role': role, 'e': e})
+
+ if errors > 0:
+ total = len(parsed_args.roles)
+ msg = (_("%(errors)s of %(total)s roles failed "
+ "to delete.") % {'errors': errors, 'total': total})
+ raise exceptions.CommandError(msg)
class ListRole(command.Lister):