A service can have no endpoints

If a service has no endpoints, python-tempestconf fails,
because it expects a url. This patch fixes this.

Change-Id: Iaadb7959b98ecb895f0f1cbd177cbb2f2f16e776
This commit is contained in:
Martin Kopec 2018-05-03 05:18:50 -04:00
parent 3fcafee74f
commit c757b5e073
2 changed files with 44 additions and 5 deletions

View File

@ -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'

View File

@ -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'