Fix identity URL parsing

The identity URLs have a different rules for parsing,
but the code before looked for word 'identity' in
whole given URL to determine it was an identity URL.
This can conflict with a URL hostname which can contain
'identity' too.
The patch fixes that by looking for 'identity' only in
URL.path (after hostname:port part).
The patch also adds a new unit test for this case.

Change-Id: I265f4d38d81dc74b05f2af9adb6fe33db876329c
Story: 2002965
Task: 22970
This commit is contained in:
Martin Kopec 2018-07-18 13:09:59 +00:00
parent 947946419c
commit 61f9d66fc7
2 changed files with 14 additions and 2 deletions

View File

@ -136,7 +136,7 @@ class Services(object):
C.LOG.info("Service %s has no endpoints", name)
else:
url = ep[self.public_url]
if 'identity' in url:
if 'identity' in urllib.parse.urlparse(url).path:
url = self.edit_identity_url(ep[self.public_url])
return url
@ -147,7 +147,6 @@ class Services(object):
:type url: string
:rtype: string
"""
# self._clients.auth_provider.auth_url stores identity.uri(_v3) value
# from TempestConf
port = urllib.parse.urlparse(self._clients.auth_provider.auth_url).port

View File

@ -106,6 +106,19 @@ class TestServices(BaseConfigTempestTest):
url = services.parse_endpoints(ep, 'ServiceName')
self.assertEqual('https://10.0.0.101:13000/identity/v2', url)
def test_parse_endpoints_not_ip_hostname(self):
services = self._create_services_instance()
services.public_url = "url"
url = "https://identity-my.cloud.com:35456/v2.0"
ep = {
'url': url,
'interface': 'public',
'region': 'regioneOne',
}
services._clients.auth_provider.auth_url = "35456"
url_resp = services.parse_endpoints(ep, "ServiceName")
self.assertEqual(url, url_resp)
def test_edit_identity_url(self):
services = self._create_services_instance()
url_port = 'https://10.0.0.101:13000/v2.0'