From c757b5e073f1fda548a42caba11e6608e10b5570 Mon Sep 17 00:00:00 2001 From: Martin Kopec Date: Thu, 3 May 2018 05:18:50 -0400 Subject: [PATCH] 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 --- config_tempest/services/services.py | 26 +++++++++++++++---- .../tests/services/test_services.py | 23 ++++++++++++++++ 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/config_tempest/services/services.py b/config_tempest/services/services.py index b0afce9a..ce2bfa81 100644 --- a/config_tempest/services/services.py +++ b/config_tempest/services/services.py @@ -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' diff --git a/config_tempest/tests/services/test_services.py b/config_tempest/tests/services/test_services.py index e441fdd8..f01b4c84 100644 --- a/config_tempest/tests/services/test_services.py +++ b/config_tempest/tests/services/test_services.py @@ -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'