From 337d013c94378a4b3f0e8f90e4f5bd745448658f Mon Sep 17 00:00:00 2001 From: David Rosales Date: Fri, 29 Apr 2016 12:12:52 -0500 Subject: Use resource id when name given for identity show Currently a user is allowed to specify either a resource ID or name when running openstack identity comands. In some cases, when a name is specified instead of an ID, the command will return as not able to find the resource when it in fact does exist. The changes here are to check the client against the token on such requests and to extract the ID of the resource specified if enough information exists between the two. We then use the ID associated with the resource to complete the user requests. Change-Id: I40713b0ded42063b786dc21247e854224b9d2fe2 Closes-Bug: #1561599 --- openstackclient/tests/identity/v3/fakes.py | 3 ++ openstackclient/tests/identity/v3/test_domain.py | 10 ++++++ openstackclient/tests/identity/v3/test_project.py | 38 +++++++++++++++++++++++ openstackclient/tests/identity/v3/test_user.py | 11 +++++++ 4 files changed, 62 insertions(+) (limited to 'openstackclient/tests') diff --git a/openstackclient/tests/identity/v3/fakes.py b/openstackclient/tests/identity/v3/fakes.py index cd1b4bd7..dd918616 100644 --- a/openstackclient/tests/identity/v3/fakes.py +++ b/openstackclient/tests/identity/v3/fakes.py @@ -502,6 +502,9 @@ class FakeIdentityv3Client(object): self.role_assignments.resource_class = fakes.FakeResource(None, {}) self.auth_token = kwargs['token'] self.management_url = kwargs['endpoint'] + self.auth = FakeAuth() + self.auth.client = mock.Mock() + self.auth.client.resource_class = fakes.FakeResource(None, {}) class FakeFederationManager(object): diff --git a/openstackclient/tests/identity/v3/test_domain.py b/openstackclient/tests/identity/v3/test_domain.py index f3777f12..e06e0681 100644 --- a/openstackclient/tests/identity/v3/test_domain.py +++ b/openstackclient/tests/identity/v3/test_domain.py @@ -389,6 +389,16 @@ class TestDomainShow(TestDomain): ('domain', identity_fakes.domain_id), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) + self.app.client_manager.identity.tokens.get_token_data.return_value = \ + {'token': + {'project': + {'domain': + {'id': 'd1', + 'name': 'd1' + } + } + } + } # In base command class ShowOne in cliff, abstract method take_action() # returns a two-part tuple with a tuple of column names and a tuple of diff --git a/openstackclient/tests/identity/v3/test_project.py b/openstackclient/tests/identity/v3/test_project.py index 8fcada6e..93bf18af 100644 --- a/openstackclient/tests/identity/v3/test_project.py +++ b/openstackclient/tests/identity/v3/test_project.py @@ -749,6 +749,7 @@ class TestProjectShow(TestProject): self.cmd = project.ShowProject(self.app, None) def test_project_show(self): + arglist = [ identity_fakes.project_id, ] @@ -757,6 +758,16 @@ class TestProjectShow(TestProject): ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) + self.app.client_manager.identity.tokens.get_token_data.return_value = \ + {'token': + {'project': + {'domain': {}, + 'name': parsed_args.project, + 'id': parsed_args.project + } + } + } + # In base command class ShowOne in cliff, abstract method take_action() # returns a two-part tuple with a tuple of column names and a tuple of # data to be shown. @@ -797,6 +808,15 @@ class TestProjectShow(TestProject): ('children', False), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) + self.app.client_manager.identity.tokens.get_token_data.return_value = \ + {'token': + {'project': + {'domain': {}, + 'name': parsed_args.project, + 'id': parsed_args.project + } + } + } columns, data = self.cmd.take_action(parsed_args) self.projects_mock.get.assert_called_with( @@ -845,6 +865,15 @@ class TestProjectShow(TestProject): ('children', True), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) + self.app.client_manager.identity.tokens.get_token_data.return_value = \ + {'token': + {'project': + {'domain': {}, + 'name': parsed_args.project, + 'id': parsed_args.project + } + } + } columns, data = self.cmd.take_action(parsed_args) self.projects_mock.get.assert_called_with( @@ -895,6 +924,15 @@ class TestProjectShow(TestProject): ('children', True), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) + self.app.client_manager.identity.tokens.get_token_data.return_value = \ + {'token': + {'project': + {'domain': {}, + 'name': parsed_args.project, + 'id': parsed_args.project + } + } + } columns, data = self.cmd.take_action(parsed_args) self.projects_mock.get.assert_called_with( diff --git a/openstackclient/tests/identity/v3/test_user.py b/openstackclient/tests/identity/v3/test_user.py index 85522e57..c4fb1521 100644 --- a/openstackclient/tests/identity/v3/test_user.py +++ b/openstackclient/tests/identity/v3/test_user.py @@ -1094,6 +1094,17 @@ class TestUserShow(TestUser): # Get the command object to test self.cmd = user.ShowUser(self.app, None) + self.app.client_manager.identity.auth.client.get_user_id.\ + return_value = 'bbbbbbb-aaaa-aaaa-aaaa-bbbbbbbaaaa' + self.app.client_manager.identity.tokens.get_token_data.return_value = \ + {'token': + {'user': + {'domain': {}, + 'id': 'bbbbbbb-aaaa-aaaa-aaaa-bbbbbbbaaaa', + 'name': 'bbbbbbb-aaaa-aaaa-aaaa-bbbbbbbaaaa' + } + } + } def test_user_show(self): arglist = [ -- cgit v1.2.1