summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjiaopengju <jiaopengju@cmss.chinamobile.com>2018-11-09 10:38:43 +0800
committerjiaopengju <jiaopengju@cmss.chinamobile.com>2018-11-09 22:04:28 +0800
commit90030192a4f346f96fd94651d6435d0e6d76b98d (patch)
tree7f373f803ed4235b3392874f5fcbf8e018df443c
parent66b02df4e466bbf01fdd4f9b2c0c9c39e337906a (diff)
Fix getting services from keystone error
Now, karbor's fullstack is broken, it is because the getting services operation in operationengine is broken. Change-Id: Ibbb717f9a5ed78e0f2d56499a41ab312a47a5837
Notes
Notes (review): Code-Review+2: Jiao Pengju <jiaopengju@cmss.chinamobile.com> Workflow+1: Jiao Pengju <jiaopengju@cmss.chinamobile.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Sat, 10 Nov 2018 13:59:59 +0000 Reviewed-on: https://review.openstack.org/616730 Project: openstack/karbor Branch: refs/heads/master
-rw-r--r--karbor/common/karbor_keystone_plugin.py8
-rw-r--r--karbor/tests/unit/common/__init__.py0
-rw-r--r--karbor/tests/unit/common/test_karbor_keystone_plugin.py48
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
13import mock
14
15
16from karbor.common import karbor_keystone_plugin
17from karbor.tests import base
18
19
20class 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 )