Merge "Avoid duplicate '/v3' in Keystone endpoint URL"

This commit is contained in:
Zuul 2024-11-13 15:53:25 +00:00 committed by Gerrit Code Review
commit 80c89b025d
2 changed files with 25 additions and 8 deletions

View File

@ -600,14 +600,14 @@ class KsClientWrapper(object):
auth_ref = self.context.auth_plugin.get_access(
self.session)
if hasattr(auth_ref, "service_catalog"):
unversioned_sc_auth_uri = (
auth_ref.service_catalog.get_urls(
service_type='identity',
interface=ks_endpoint_type))
if len(unversioned_sc_auth_uri) > 0:
sc_auth_uri = (
unversioned_sc_auth_uri[0] + "/v3")
return sc_auth_uri
keystone_urls = auth_ref.service_catalog.get_urls(
service_type='identity',
interface=ks_endpoint_type)
if keystone_urls:
keystone_url = keystone_urls[0].rstrip('/')
if not keystone_url.endswith('/v3'):
keystone_url += "/v3"
return keystone_url
except ks_exception.Unauthorized:
LOG.error("Keystone client authentication failed")
return fallback_endpoint

View File

@ -1528,6 +1528,23 @@ class KeystoneClientTest(common.HeatTestCase):
'http://server.public.test:5000/v3')
cfg.CONF.clear_override('server_keystone_endpoint_type')
def test_server_keystone_endpoint_url_config_with_version(self):
"""Return non fallback url path."""
cfg.CONF.set_override('server_keystone_endpoint_type', 'public')
ctx = utils.dummy_context()
ctx.trust_id = None
heat_ks_client = heat_keystoneclient.KeystoneClient(ctx)
fallback_url = 'http://server.fallback.test:5000/v3'
auth_ref = heat_ks_client.context.auth_plugin.get_access(
heat_ks_client.session)
auth_ref.service_catalog.get_urls = mock.MagicMock()
auth_ref.service_catalog.get_urls.return_value = [
'http://server.public.test:5000/v3']
self.assertEqual(
heat_ks_client.server_keystone_endpoint_url(fallback_url),
'http://server.public.test:5000/v3')
cfg.CONF.clear_override('server_keystone_endpoint_type')
def test_server_keystone_endpoint_url_no_config(self):
"""Return fallback as no config option specified."""
ctx = utils.dummy_context()