Merge "A service can have no endpoints"
This commit is contained in:
commit
840d3900c1
@ -52,11 +52,7 @@ class Services(object):
|
||||
|
||||
for entry in auth_data[self.service_catalog]:
|
||||
name = entry['type']
|
||||
ep = self.get_endpoints(entry)
|
||||
|
||||
url = ep[self.public_url]
|
||||
if 'identity' in url:
|
||||
url = self.edit_identity_url(ep[self.public_url])
|
||||
url = self.parse_endpoints(self.get_endpoints(entry), name)
|
||||
|
||||
service_class = self.get_service_class(name)
|
||||
service = service_class(name, url, token, self._ssl_validation,
|
||||
@ -93,6 +89,26 @@ class Services(object):
|
||||
self.service_catalog = 'serviceCatalog'
|
||||
self.public_url = 'publicURL'
|
||||
|
||||
def parse_endpoints(self, ep, name):
|
||||
"""Parse an endpoint(s).
|
||||
|
||||
:param ep: endpoint(s)
|
||||
:type ep: dict or list in case of no endpoints
|
||||
:param name: name of a service
|
||||
:type name: string
|
||||
:return: url
|
||||
:rtype: string
|
||||
"""
|
||||
# endpoint list can be empty
|
||||
if len(ep) == 0:
|
||||
url = ""
|
||||
C.LOG.info("Service %s has no endpoints", name)
|
||||
else:
|
||||
url = ep[self.public_url]
|
||||
if 'identity' in url:
|
||||
url = self.edit_identity_url(ep[self.public_url])
|
||||
return url
|
||||
|
||||
def edit_identity_url(self, url):
|
||||
"""A port and identity version are added to url if contains 'identity'
|
||||
|
||||
|
@ -83,6 +83,29 @@ class TestServices(BaseConfigTempestTest):
|
||||
self.assertEqual(services.service_catalog, 'catalog')
|
||||
self.assertEqual(services.public_url, 'url')
|
||||
|
||||
def test_parse_endpoints_empty(self):
|
||||
services = self._create_services_instance()
|
||||
services.public_url = "url"
|
||||
ep = []
|
||||
url = services.parse_endpoints(ep, "ServiceName")
|
||||
self.assertEqual("", url)
|
||||
|
||||
def test_parse_endpoints(self):
|
||||
services = self._create_services_instance()
|
||||
services.public_url = "url"
|
||||
ep = {
|
||||
'url': 'http://10.0.0.107:8386/v1.1/96409a589d',
|
||||
'interface': 'public',
|
||||
'region': 'regioneOne',
|
||||
}
|
||||
url = services.parse_endpoints(ep, "ServiceName")
|
||||
self.assertEqual('http://10.0.0.107:8386/v1.1/96409a589d', url)
|
||||
ep['url'] = 'https://10.0.0.101/identity'
|
||||
auth_url = 'https://10.0.0.101:13000/v2.0'
|
||||
services._clients.auth_provider.auth_url = auth_url
|
||||
url = services.parse_endpoints(ep, 'ServiceName')
|
||||
self.assertEqual('https://10.0.0.101:13000/identity/v2', url)
|
||||
|
||||
def test_edit_identity_url(self):
|
||||
services = self._create_services_instance()
|
||||
url_port = 'https://10.0.0.101:13000/v2.0'
|
||||
|
Loading…
Reference in New Issue
Block a user