From cfd4e2a7228c1e7f6ad677f2dd6dbd09e638dfb7 Mon Sep 17 00:00:00 2001 From: Huanxuan Ao Date: Thu, 9 Feb 2017 18:05:32 +0800 Subject: Modify error handling for role and group commands if command failed, we usually raise exception, if command success, sometimes there is not any output (such as set, add commands) So modify the error handling for role and group commands. Change-Id: I1c0f86c04dcedd9c0d725fd73f3436be9da75ee0 --- openstackclient/identity/v3/group.py | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) (limited to 'openstackclient/identity/v3/group.py') diff --git a/openstackclient/identity/v3/group.py b/openstackclient/identity/v3/group.py index a03a86eb..2afdabc1 100644 --- a/openstackclient/identity/v3/group.py +++ b/openstackclient/identity/v3/group.py @@ -62,18 +62,13 @@ class AddUserToGroup(command.Command): try: identity_client.users.add_to_group(user_id, group_id) - except Exception: - msg = _("%(user)s not added to group %(group)s\n") % { - 'user': parsed_args.user, - 'group': parsed_args.group, - } - sys.stderr.write(msg) - else: - msg = _("%(user)s added to group %(group)s\n") % { + except Exception as e: + msg = _("%(user)s not added to group %(group)s: %(e)s") % { 'user': parsed_args.user, 'group': parsed_args.group, + 'e': e, } - sys.stdout.write(msg) + raise exceptions.CommandError(msg) class CheckUserInGroup(command.Command): @@ -306,18 +301,13 @@ class RemoveUserFromGroup(command.Command): try: identity_client.users.remove_from_group(user_id, group_id) - except Exception: - msg = _("%(user)s not removed from group %(group)s\n") % { - 'user': parsed_args.user, - 'group': parsed_args.group, - } - sys.stderr.write(msg) - else: - msg = _("%(user)s removed from group %(group)s\n") % { + except Exception as e: + msg = _("%(user)s not removed from group %(group)s: %(e)s") % { 'user': parsed_args.user, 'group': parsed_args.group, + 'e': e, } - sys.stdout.write(msg) + raise exceptions.CommandError(msg) class SetGroup(command.Command): -- cgit v1.2.1