Browse Source

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
jiaopengju 5 months ago
parent
commit
90030192a4

+ 6
- 2
karbor/common/karbor_keystone_plugin.py View File

@@ -89,17 +89,21 @@ class KarborKeystonePlugin(object):
89 89
 
90 90
     def get_service_endpoint(self, service_name, service_type,
91 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 96
         try:
93 97
             service = self.client.services.list(
94 98
                 name=service_name,
95 99
                 service_type=service_type,
96
-                base_url=self.auth_uri)
100
+                base_url=base_url)
97 101
 
98 102
             endpoint = self.client.endpoints.list(
99 103
                 service=service[0],
100 104
                 interface=interface,
101 105
                 region_id=region_id,
102
-                base_url=self.auth_uri)
106
+                base_url=base_url)
103 107
 
104 108
             return endpoint[0].url if endpoint else None
105 109
 

+ 0
- 0
karbor/tests/unit/common/__init__.py View File


+ 48
- 0
karbor/tests/unit/common/test_karbor_keystone_plugin.py View File

@@ -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
+        )

Loading…
Cancel
Save