diff --git a/openstackclient/identity/v3/group.py b/openstackclient/identity/v3/group.py index 2afdabc171..b5f5d8ad88 100644 --- a/openstackclient/identity/v3/group.py +++ b/openstackclient/identity/v3/group.py @@ -102,12 +102,15 @@ class CheckUserInGroup(command.Command): try: identity_client.users.check_in_group(user_id, group_id) - except Exception: - msg = _("%(user)s not in group %(group)s\n") % { - 'user': parsed_args.user, - 'group': parsed_args.group, - } - sys.stderr.write(msg) + except ks_exc.http.HTTPClientError as e: + if e.http_status == 403 or e.http_status == 404: + msg = _("%(user)s not in group %(group)s\n") % { + 'user': parsed_args.user, + 'group': parsed_args.group, + } + sys.stderr.write(msg) + else: + raise e else: msg = _("%(user)s in group %(group)s\n") % { 'user': parsed_args.user, diff --git a/openstackclient/tests/unit/identity/v3/test_group.py b/openstackclient/tests/unit/identity/v3/test_group.py index 00bd217dad..5870e1dbc3 100644 --- a/openstackclient/tests/unit/identity/v3/test_group.py +++ b/openstackclient/tests/unit/identity/v3/test_group.py @@ -115,6 +115,23 @@ class TestGroupCheckUser(TestGroup): self.user.id, self.group.id) self.assertIsNone(result) + def test_group_check_user_server_error(self): + def server_error(*args): + raise ks_exc.http.InternalServerError + self.users_mock.check_in_group.side_effect = server_error + arglist = [ + self.group.name, + self.user.name, + ] + verifylist = [ + ('group', self.group.name), + ('user', self.user.name), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.assertRaises(ks_exc.http.InternalServerError, + self.cmd.take_action, parsed_args) + class TestGroupCreate(TestGroup): diff --git a/releasenotes/notes/bug-1672634-ef754cb5109dd0f2.yaml b/releasenotes/notes/bug-1672634-ef754cb5109dd0f2.yaml new file mode 100644 index 0000000000..be874ab616 --- /dev/null +++ b/releasenotes/notes/bug-1672634-ef754cb5109dd0f2.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Narrow acceptable negative response codes for ``group contains user`` + [Bug `1672634 `_]