Merge "Fix getting services from keystone error"

This commit is contained in:
Zuul 2018-11-10 13:59:59 +00:00 committed by Gerrit Code Review
commit cf9b1c491e
3 changed files with 54 additions and 2 deletions

View File

@ -89,17 +89,21 @@ class KarborKeystonePlugin(object):
def get_service_endpoint(self, service_name, service_type,
region_id, interface='public'):
if self._auth_uri and self._auth_uri.endswith('/'):
base_url = self._auth_uri[:-1]
else:
base_url = self._auth_uri
try:
service = self.client.services.list(
name=service_name,
service_type=service_type,
base_url=self.auth_uri)
base_url=base_url)
endpoint = self.client.endpoints.list(
service=service[0],
interface=interface,
region_id=region_id,
base_url=self.auth_uri)
base_url=base_url)
return endpoint[0].url if endpoint else None

View File

View File

@ -0,0 +1,48 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
from karbor.common import karbor_keystone_plugin
from karbor.tests import base
class KarborKeystonePluginTest(base.TestCase):
def setUp(self):
super(KarborKeystonePluginTest, self).setUp()
self.kc_plugin = karbor_keystone_plugin.KarborKeystonePlugin()
self.kc_plugin.client.services.list = mock.MagicMock()
self.kc_plugin.client.endpoints.list = mock.MagicMock()
self.kc_plugin.client.services.list.return_value = (
'http://192.168.1.2:8799')
def test_get_service_endpoint_with_slash_end(self):
self.kc_plugin._auth_uri = 'http://192.168.1.1/identity/v3/'
self.kc_plugin.get_service_endpoint(
'karbor', 'data-protect', 'fake_region_id', 'public')
self.kc_plugin.client.services.list.assert_called_once_with(
name='karbor',
service_type='data-protect',
base_url='http://192.168.1.1/identity/v3'
)
def test_get_service_endpoint_with_no_slash_end(self):
self.kc_plugin._auth_uri = 'http://192.168.1.1/identity/v3'
self.kc_plugin.get_service_endpoint(
'karbor', 'data-protect', 'fake_region_id', 'public')
self.kc_plugin.client.services.list.assert_called_once_with(
name='karbor',
service_type='data-protect',
base_url='http://192.168.1.1/identity/v3'
)