diff options
| author | sunyajing <yajing.sun@easystack.cn> | 2016-06-24 12:40:29 +0800 |
|---|---|---|
| committer | Huanxuan Ao <huanxuan.ao@easystack.cn> | 2016-07-22 19:40:50 +0800 |
| commit | c45b1d7b230e900d0416a4953607e5d4e1dc9cfd (patch) | |
| tree | 8fd33e08f4da491210710bc53a876673b08fa12f /openstackclient/tests/identity/v3 | |
| parent | 60639d76a742852e18f9e2889c480be95596c268 (diff) | |
| download | python-openstackclient-c45b1d7b230e900d0416a4953607e5d4e1dc9cfd.tar.gz | |
Fix error for find_service() in identity
if there are more than one services be found with one
name, a NoUniqueMatch exception should be raised but
we can see a NotFound Exception raised instead. It is
because in "find_service()", we use "find_resource()"
first, if "find_resource()" return a exception, we just
think it is a NotFound Exception and continue to find
by type but ignore a NoUniqueMatch exception of
"find_resource()". This patch refactor the "find_service()"
method to solve this problem.
Change-Id: Id4619092c57f276ae0698c89df0d5503b7423a4e
Co-Authored-By: Huanxuan Ao <huanxuan.ao@easystack.cn>
Closes-Bug:#1597296
Diffstat (limited to 'openstackclient/tests/identity/v3')
| -rw-r--r-- | openstackclient/tests/identity/v3/test_service.py | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/openstackclient/tests/identity/v3/test_service.py b/openstackclient/tests/identity/v3/test_service.py index a1f85adc..65d8ebd7 100644 --- a/openstackclient/tests/identity/v3/test_service.py +++ b/openstackclient/tests/identity/v3/test_service.py @@ -15,6 +15,9 @@ import copy +from keystoneclient import exceptions as identity_exc +from osc_lib import exceptions + from openstackclient.identity.v3 import service from openstackclient.tests import fakes from openstackclient.tests.identity.v3 import fakes as identity_fakes @@ -185,7 +188,8 @@ class TestServiceDelete(TestService): def setUp(self): super(TestServiceDelete, self).setUp() - self.services_mock.get.return_value = fakes.FakeResource( + self.services_mock.get.side_effect = identity_exc.NotFound(None) + self.services_mock.find.return_value = fakes.FakeResource( None, copy.deepcopy(identity_fakes.SERVICE), loaded=True, @@ -282,7 +286,8 @@ class TestServiceSet(TestService): def setUp(self): super(TestServiceSet, self).setUp() - self.services_mock.get.return_value = fakes.FakeResource( + self.services_mock.get.side_effect = identity_exc.NotFound(None) + self.services_mock.find.return_value = fakes.FakeResource( None, copy.deepcopy(identity_fakes.SERVICE), loaded=True, @@ -460,7 +465,8 @@ class TestServiceShow(TestService): def setUp(self): super(TestServiceShow, self).setUp() - self.services_mock.get.return_value = fakes.FakeResource( + self.services_mock.get.side_effect = identity_exc.NotFound(None) + self.services_mock.find.return_value = fakes.FakeResource( None, copy.deepcopy(identity_fakes.SERVICE), loaded=True, @@ -484,8 +490,8 @@ class TestServiceShow(TestService): columns, data = self.cmd.take_action(parsed_args) # ServiceManager.get(id) - self.services_mock.get.assert_called_with( - identity_fakes.service_name, + self.services_mock.find.assert_called_with( + name=identity_fakes.service_name ) collist = ('description', 'enabled', 'id', 'name', 'type') @@ -498,3 +504,21 @@ class TestServiceShow(TestService): identity_fakes.service_type, ) self.assertEqual(datalist, data) + + def test_service_show_nounique(self): + self.services_mock.find.side_effect = identity_exc.NoUniqueMatch(None) + arglist = [ + 'nounique_service', + ] + verifylist = [ + ('service', 'nounique_service'), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + try: + self.cmd.take_action(parsed_args) + self.fail('CommandError should be raised.') + except exceptions.CommandError as e: + self.assertEqual( + "Multiple service matches found for 'nounique_service'," + " use an ID to be more specific.", str(e)) |
