diff options
| author | Huanxuan Ao <huanxuan.ao@easystack.cn> | 2016-12-30 13:22:07 +0800 |
|---|---|---|
| committer | Huanxuan Ao <huanxuan.ao@easystack.cn> | 2017-01-03 23:30:49 +0800 |
| commit | 96578cb8ab9a4b95144c33d0af38863fce8d8892 (patch) | |
| tree | 8fd9c537b48aae84b9b3eaac8aa17079adf251b0 /openstackclient/identity/v2_0/user.py | |
| parent | f020a9ffd6d5602d18c899e7707baaa620ffdd54 (diff) | |
| download | python-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/v2_0/user.py')
| -rw-r--r-- | openstackclient/identity/v2_0/user.py | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/openstackclient/identity/v2_0/user.py b/openstackclient/identity/v2_0/user.py index ddd5b981..2a3dde6b 100644 --- a/openstackclient/identity/v2_0/user.py +++ b/openstackclient/identity/v2_0/user.py @@ -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 @@ -145,12 +146,25 @@ class DeleteUser(command.Command): def take_action(self, parsed_args): identity_client = self.app.client_manager.identity + errors = 0 for user in parsed_args.users: - user_obj = utils.find_resource( - identity_client.users, - user, - ) - identity_client.users.delete(user_obj.id) + try: + user_obj = utils.find_resource( + identity_client.users, + user, + ) + identity_client.users.delete(user_obj.id) + except Exception as e: + errors += 1 + LOG.error(_("Failed to delete user with " + "name or ID '%(user)s': %(e)s"), + {'user': user, 'e': e}) + + if errors > 0: + total = len(parsed_args.users) + msg = (_("%(errors)s of %(total)s users failed " + "to delete.") % {'errors': errors, 'total': total}) + raise exceptions.CommandError(msg) class ListUser(command.Lister): |
