diff options
author | Zuul <zuul@review.openstack.org> | 2018-11-10 13:59:59 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2018-11-10 13:59:59 +0000 |
commit | cf9b1c491e3fbac4ae64debba735718e9952d80a (patch) | |
tree | 98977d7f0fe5e275745590e3ce2a297db66da6ff | |
parent | e26a0621e5c8947ff315837a87d7d9aedc592953 (diff) | |
parent | 90030192a4f346f96fd94651d6435d0e6d76b98d (diff) |
Merge "Fix getting services from keystone error"
-rw-r--r-- | karbor/common/karbor_keystone_plugin.py | 8 | ||||
-rw-r--r-- | karbor/tests/unit/common/__init__.py | 0 | ||||
-rw-r--r-- | karbor/tests/unit/common/test_karbor_keystone_plugin.py | 48 |
3 files changed, 54 insertions, 2 deletions
diff --git a/karbor/common/karbor_keystone_plugin.py b/karbor/common/karbor_keystone_plugin.py index 0fac665..f579a3b 100644 --- a/karbor/common/karbor_keystone_plugin.py +++ b/karbor/common/karbor_keystone_plugin.py | |||
@@ -89,17 +89,21 @@ class KarborKeystonePlugin(object): | |||
89 | 89 | ||
90 | def get_service_endpoint(self, service_name, service_type, | 90 | def get_service_endpoint(self, service_name, service_type, |
91 | region_id, interface='public'): | 91 | region_id, interface='public'): |
92 | if self._auth_uri and self._auth_uri.endswith('/'): | ||
93 | base_url = self._auth_uri[:-1] | ||
94 | else: | ||
95 | base_url = self._auth_uri | ||
92 | try: | 96 | try: |
93 | service = self.client.services.list( | 97 | service = self.client.services.list( |
94 | name=service_name, | 98 | name=service_name, |
95 | service_type=service_type, | 99 | service_type=service_type, |
96 | base_url=self.auth_uri) | 100 | base_url=base_url) |
97 | 101 | ||
98 | endpoint = self.client.endpoints.list( | 102 | endpoint = self.client.endpoints.list( |
99 | service=service[0], | 103 | service=service[0], |
100 | interface=interface, | 104 | interface=interface, |
101 | region_id=region_id, | 105 | region_id=region_id, |
102 | base_url=self.auth_uri) | 106 | base_url=base_url) |
103 | 107 | ||
104 | return endpoint[0].url if endpoint else None | 108 | return endpoint[0].url if endpoint else None |
105 | 109 | ||
diff --git a/karbor/tests/unit/common/__init__.py b/karbor/tests/unit/common/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/karbor/tests/unit/common/__init__.py | |||
diff --git a/karbor/tests/unit/common/test_karbor_keystone_plugin.py b/karbor/tests/unit/common/test_karbor_keystone_plugin.py new file mode 100644 index 0000000..cdeffbd --- /dev/null +++ b/karbor/tests/unit/common/test_karbor_keystone_plugin.py | |||
@@ -0,0 +1,48 @@ | |||
1 | # Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
2 | # not use this file except in compliance with the License. You may obtain | ||
3 | # a copy of the License at | ||
4 | # | ||
5 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
6 | # | ||
7 | # Unless required by applicable law or agreed to in writing, software | ||
8 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
9 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
10 | # License for the specific language governing permissions and limitations | ||
11 | # under the License. | ||
12 | |||
13 | import mock | ||
14 | |||
15 | |||
16 | from karbor.common import karbor_keystone_plugin | ||
17 | from karbor.tests import base | ||
18 | |||
19 | |||
20 | class KarborKeystonePluginTest(base.TestCase): | ||
21 | |||
22 | def setUp(self): | ||
23 | super(KarborKeystonePluginTest, self).setUp() | ||
24 | self.kc_plugin = karbor_keystone_plugin.KarborKeystonePlugin() | ||
25 | self.kc_plugin.client.services.list = mock.MagicMock() | ||
26 | self.kc_plugin.client.endpoints.list = mock.MagicMock() | ||
27 | self.kc_plugin.client.services.list.return_value = ( | ||
28 | 'http://192.168.1.2:8799') | ||
29 | |||
30 | def test_get_service_endpoint_with_slash_end(self): | ||
31 | self.kc_plugin._auth_uri = 'http://192.168.1.1/identity/v3/' | ||
32 | self.kc_plugin.get_service_endpoint( | ||
33 | 'karbor', 'data-protect', 'fake_region_id', 'public') | ||
34 | self.kc_plugin.client.services.list.assert_called_once_with( | ||
35 | name='karbor', | ||
36 | service_type='data-protect', | ||
37 | base_url='http://192.168.1.1/identity/v3' | ||
38 | ) | ||
39 | |||
40 | def test_get_service_endpoint_with_no_slash_end(self): | ||
41 | self.kc_plugin._auth_uri = 'http://192.168.1.1/identity/v3' | ||
42 | self.kc_plugin.get_service_endpoint( | ||
43 | 'karbor', 'data-protect', 'fake_region_id', 'public') | ||
44 | self.kc_plugin.client.services.list.assert_called_once_with( | ||
45 | name='karbor', | ||
46 | service_type='data-protect', | ||
47 | base_url='http://192.168.1.1/identity/v3' | ||
48 | ) | ||