From d227f6d237c4309b21a32a115fc5b09b9ba46ef0 Mon Sep 17 00:00:00 2001 From: Jamie Lennox Date: Fri, 7 Aug 2015 19:16:42 +1000 Subject: [PATCH] Replace endpoint_type with interface in catalog We've been trying to move people onto using interface rather than endpoint_type for a while as interface is what is talked about in all the API docs and is what is exposed by the clients. Rename all occurrences of endpoint_type with interface. Change-Id: If18d8e27e499c294cb4dc94521da843341287362 --- keystoneauth1/access/service_catalog.py | 82 +++++++++---------- keystoneauth1/identity/base.py | 2 +- .../tests/unit/v2_0/test_service_catalog.py | 24 +++--- .../tests/unit/v3/test_service_catalog.py | 42 +++++----- 4 files changed, 75 insertions(+), 75 deletions(-) diff --git a/keystoneauth1/access/service_catalog.py b/keystoneauth1/access/service_catalog.py index 93604b43..7d14c4e9 100644 --- a/keystoneauth1/access/service_catalog.py +++ b/keystoneauth1/access/service_catalog.py @@ -35,28 +35,28 @@ class ServiceCatalog(object): return endpoint.get('region_id') or endpoint.get('region') @abc.abstractmethod - def is_endpoint_type_match(self, endpoint, endpoint_type): + def is_interface_match(self, endpoint, interface): """Helper function to normalize endpoint matching across v2 and v3. :returns: True if the provided endpoint matches the required - endpoint_type otherwise False. + interface otherwise False. """ @staticmethod - def normalize_endpoint_type(self, endpoint_type): + def normalize_interface(self, interface): """Handle differences in the way v2 and v3 catalogs specify endpoint. Both v2 and v3 must be able to handle the endpoint style of the other. - For example v2 must be able to handle a 'public' endpoint_type and - v3 must be able to handle a 'publicURL' endpoint_type. + For example v2 must be able to handle a 'public' interface and + v3 must be able to handle a 'publicURL' interface. :returns: the endpoint string in the format appropriate for this service catalog. """ - return endpoint_type + return interface @utils.positional() - def get_endpoints(self, service_type=None, endpoint_type=None, + def get_endpoints(self, service_type=None, interface=None, region_name=None, service_name=None, service_id=None, endpoint_id=None): """Fetch and filter endpoints for the specified service(s). @@ -68,7 +68,7 @@ class ServiceCatalog(object): be skipped. This allows compatibility with services that existed before the name was available in the catalog. """ - endpoint_type = self.normalize_endpoint_type(endpoint_type) + interface = self.normalize_interface(interface) sc = {} @@ -105,8 +105,8 @@ class ServiceCatalog(object): endpoints = sc.setdefault(st, []) for endpoint in service.get('endpoints', []): - if (endpoint_type and not - self.is_endpoint_type_match(endpoint, endpoint_type)): + if (interface and not + self.is_interface_match(endpoint, interface)): continue if (region_name and region_name != self._get_endpoint_region(endpoint)): @@ -132,7 +132,7 @@ class ServiceCatalog(object): @abc.abstractmethod @utils.positional() - def get_urls(self, service_type=None, endpoint_type='public', + def get_urls(self, service_type=None, interface='public', region_name=None, service_name=None, service_id=None, endpoint_id=None): """Fetch endpoint urls from the service catalog. @@ -142,7 +142,7 @@ class ServiceCatalog(object): endpoint of the specified type. :param string service_type: Service type of the endpoint. - :param string endpoint_type: Type of endpoint. + :param string interface: Type of endpoint. Possible values: public or publicURL, internal or internalURL, admin or adminURL @@ -156,7 +156,7 @@ class ServiceCatalog(object): raise NotImplementedError() @utils.positional() - def url_for(self, service_type=None, endpoint_type='public', + def url_for(self, service_type=None, interface='public', region_name=None, service_name=None, service_id=None, endpoint_id=None): """Fetch an endpoint from the service catalog. @@ -170,7 +170,7 @@ class ServiceCatalog(object): `admin` or 'adminURL` :param string service_type: Service type of the endpoint. - :param string endpoint_type: Type of endpoint. + :param string interface: Type of endpoint. :param string region_name: Region of the endpoint. :param string service_name: The assigned name of the service. :param string service_id: The identifier of a service. @@ -180,7 +180,7 @@ class ServiceCatalog(object): raise exceptions.EmptyCatalog('The service catalog is empty.') urls = self.get_urls(service_type=service_type, - endpoint_type=endpoint_type, + interface=interface, region_name=region_name, service_name=service_name, service_id=service_id, @@ -192,27 +192,27 @@ class ServiceCatalog(object): pass if service_name and region_name: - msg = ('%(endpoint_type)s endpoint for %(service_type)s service ' + msg = ('%(interface)s endpoint for %(service_type)s service ' 'named %(service_name)s in %(region_name)s region not ' 'found' % - {'endpoint_type': endpoint_type, + {'interface': interface, 'service_type': service_type, 'service_name': service_name, 'region_name': region_name}) elif service_name: - msg = ('%(endpoint_type)s endpoint for %(service_type)s service ' + msg = ('%(interface)s endpoint for %(service_type)s service ' 'named %(service_name)s not found' % - {'endpoint_type': endpoint_type, + {'interface': interface, 'service_type': service_type, 'service_name': service_name}) elif region_name: - msg = ('%(endpoint_type)s endpoint for %(service_type)s service ' + msg = ('%(interface)s endpoint for %(service_type)s service ' 'in %(region_name)s region not found' % - {'endpoint_type': endpoint_type, + {'interface': interface, 'service_type': service_type, 'region_name': region_name}) else: - msg = ('%(endpoint_type)s endpoint for %(service_type)s service ' + msg = ('%(interface)s endpoint for %(service_type)s service ' 'not found' % - {'endpoint_type': endpoint_type, + {'interface': interface, 'service_type': service_type}) raise exceptions.EndpointNotFound(msg) @@ -231,29 +231,29 @@ class ServiceCatalogV2(ServiceCatalog): return cls(token['access'].get('serviceCatalog', {})) @staticmethod - def normalize_endpoint_type(endpoint_type): - if endpoint_type and 'URL' not in endpoint_type: - endpoint_type = endpoint_type + 'URL' + def normalize_interface(interface): + if interface and 'URL' not in interface: + interface = interface + 'URL' - return endpoint_type + return interface - def is_endpoint_type_match(self, endpoint, endpoint_type): - return endpoint_type in endpoint + def is_interface_match(self, endpoint, interface): + return interface in endpoint @utils.positional() - def get_urls(self, service_type=None, endpoint_type='publicURL', + def get_urls(self, service_type=None, interface='publicURL', region_name=None, service_name=None, service_id=None, endpoint_id=None): - endpoint_type = self.normalize_endpoint_type(endpoint_type) + interface = self.normalize_interface(interface) endpoints = self._get_service_endpoints(service_type=service_type, - endpoint_type=endpoint_type, + interface=interface, region_name=region_name, service_name=service_name, service_id=service_id, endpoint_id=endpoint_id) - return tuple([endpoint[endpoint_type] for endpoint in endpoints]) + return tuple([endpoint[interface] for endpoint in endpoints]) class ServiceCatalogV3(ServiceCatalog): @@ -269,24 +269,24 @@ class ServiceCatalogV3(ServiceCatalog): return cls(token['token'].get('catalog', {})) @staticmethod - def normalize_endpoint_type(endpoint_type): - if endpoint_type: - endpoint_type = endpoint_type.rstrip('URL') + def normalize_interface(interface): + if interface: + interface = interface.rstrip('URL') - return endpoint_type + return interface - def is_endpoint_type_match(self, endpoint, endpoint_type): + def is_interface_match(self, endpoint, interface): try: - return endpoint_type == endpoint['interface'] + return interface == endpoint['interface'] except KeyError: return False @utils.positional() - def get_urls(self, service_type=None, endpoint_type='publicURL', + def get_urls(self, service_type=None, interface='publicURL', region_name=None, service_name=None, service_id=None, endpoint_id=None): endpoints = self._get_service_endpoints(service_type=service_type, - endpoint_type=endpoint_type, + interface=interface, region_name=region_name, service_name=service_name, service_id=service_id, diff --git a/keystoneauth1/identity/base.py b/keystoneauth1/identity/base.py index 8fee3ec6..68ca3416 100644 --- a/keystoneauth1/identity/base.py +++ b/keystoneauth1/identity/base.py @@ -217,7 +217,7 @@ class BaseIdentityPlugin(base.BaseAuthPlugin): service_catalog = self.get_access(session).service_catalog url = service_catalog.url_for(service_type=service_type, - endpoint_type=interface, + interface=interface, region_name=region_name, service_name=service_name) diff --git a/keystoneauth1/tests/unit/v2_0/test_service_catalog.py b/keystoneauth1/tests/unit/v2_0/test_service_catalog.py index 3a7dd18d..f62764a6 100644 --- a/keystoneauth1/tests/unit/v2_0/test_service_catalog.py +++ b/keystoneauth1/tests/unit/v2_0/test_service_catalog.py @@ -96,7 +96,7 @@ class ServiceCatalogTest(utils.TestCase): auth_ref = access.create(body=self.AUTH_RESPONSE_BODY) sc = auth_ref.service_catalog public_ep = sc.get_endpoints(service_type='compute', - endpoint_type='publicURL') + interface='publicURL') self.assertEqual(public_ep['compute'][1]['tenantId'], '2') self.assertEqual(public_ep['compute'][1]['versionId'], '1.1') self.assertEqual(public_ep['compute'][1]['internalURL'], @@ -108,7 +108,7 @@ class ServiceCatalogTest(utils.TestCase): self.assertRaises(exceptions.EmptyCatalog, auth_ref.service_catalog.url_for, service_type='image', - endpoint_type='internalURL') + interface='internalURL') def test_service_catalog_get_endpoints_region_names(self): auth_ref = access.create(body=self.AUTH_RESPONSE_BODY) @@ -170,7 +170,7 @@ class ServiceCatalogTest(utils.TestCase): auth_ref = access.create(body=self.AUTH_RESPONSE_BODY) sc = auth_ref.service_catalog - url = sc.url_for(service_name='Image Servers', endpoint_type='public', + url = sc.url_for(service_name='Image Servers', interface='public', service_type='image', region_name='North') self.assertEqual('https://image.north.host/v1/', url) @@ -178,13 +178,13 @@ class ServiceCatalogTest(utils.TestCase): service_name='Image Servers', service_type='compute') urls = sc.get_urls(service_type='image', service_name='Image Servers', - endpoint_type='public') + interface='public') self.assertIn('https://image.north.host/v1/', urls) self.assertIn('https://image.south.host/v1/', urls) urls = sc.get_urls(service_type='image', service_name='Servers', - endpoint_type='public') + interface='public') self.assertEqual(0, len(urls)) @@ -202,12 +202,12 @@ class ServiceCatalogTest(utils.TestCase): auth_ref = access.create(body=token) urls = auth_ref.service_catalog.get_urls(service_type='compute', - endpoint_type='publicURL') + interface='publicURL') self.assertEqual(set(['public-0', 'public-1', 'public-2']), set(urls)) urls = auth_ref.service_catalog.get_urls(service_type='compute', - endpoint_type='publicURL', + interface='publicURL', region_name='region-1') self.assertEqual(('public-1', ), urls) @@ -225,24 +225,24 @@ class ServiceCatalogTest(utils.TestCase): auth_ref = access.create(body=token) # initially assert that we get back all our urls for a simple filter - urls = auth_ref.service_catalog.get_urls(endpoint_type='public') + urls = auth_ref.service_catalog.get_urls(interface='public') self.assertEqual(2, len(urls)) urls = auth_ref.service_catalog.get_urls(endpoint_id=endpoint_id, - endpoint_type='public') + interface='public') self.assertEqual((public_url, ), urls) # with bad endpoint_id nothing should be found urls = auth_ref.service_catalog.get_urls(endpoint_id=uuid.uuid4().hex, - endpoint_type='public') + interface='public') self.assertEqual(0, len(urls)) # we ignore a service_id because v2 doesn't know what it is urls = auth_ref.service_catalog.get_urls(endpoint_id=endpoint_id, service_id=uuid.uuid4().hex, - endpoint_type='public') + interface='public') self.assertEqual((public_url, ), urls) @@ -261,7 +261,7 @@ class ServiceCatalogTest(utils.TestCase): auth_ref = access.create(body=token) urls = auth_ref.service_catalog.get_urls(service_type=None, - endpoint_type='public') + interface='public') self.assertEqual(3, len(urls)) diff --git a/keystoneauth1/tests/unit/v3/test_service_catalog.py b/keystoneauth1/tests/unit/v3/test_service_catalog.py index 0f6ac288..713586c3 100644 --- a/keystoneauth1/tests/unit/v3/test_service_catalog.py +++ b/keystoneauth1/tests/unit/v3/test_service_catalog.py @@ -78,7 +78,7 @@ class ServiceCatalogTest(utils.TestCase): self.assertEqual(sc.url_for(service_type='compute'), "https://compute.north.host/novapi/public") self.assertEqual(sc.url_for(service_type='compute', - endpoint_type='internal'), + interface='internal'), "https://compute.north.host/novapi/internal") self.assertRaises(exceptions.EndpointNotFound, @@ -92,7 +92,7 @@ class ServiceCatalogTest(utils.TestCase): sc = auth_ref.service_catalog public_ep = sc.get_endpoints(service_type='compute', - endpoint_type='public') + interface='public') self.assertEqual(public_ep['compute'][0]['region'], 'North') self.assertEqual(public_ep['compute'][0]['url'], "https://compute.north.host/novapi/public") @@ -103,7 +103,7 @@ class ServiceCatalogTest(utils.TestCase): body=self.AUTH_RESPONSE_BODY) sc = auth_ref.service_catalog - url = sc.url_for(service_type='image', endpoint_type='public') + url = sc.url_for(service_type='image', interface='public') self.assertEqual(url, "http://glance.north.host/glanceapi/public") self.AUTH_RESPONSE_BODY['token']['region_name'] = "South" @@ -112,7 +112,7 @@ class ServiceCatalogTest(utils.TestCase): sc = auth_ref.service_catalog url = sc.url_for(service_type='image', region_name="South", - endpoint_type='internal') + interface='internal') self.assertEqual(url, "http://glance.south.host/glanceapi/internal") def test_service_catalog_empty(self): @@ -122,7 +122,7 @@ class ServiceCatalogTest(utils.TestCase): self.assertRaises(exceptions.EmptyCatalog, auth_ref.service_catalog.url_for, service_type='image', - endpoint_type='internalURL') + interface='internalURL') def test_service_catalog_get_endpoints_region_names(self): sc = access.create(auth_token=uuid.uuid4().hex, @@ -186,11 +186,11 @@ class ServiceCatalogTest(utils.TestCase): sc = access.create(auth_token=uuid.uuid4().hex, body=self.AUTH_RESPONSE_BODY).service_catalog - url = sc.url_for(service_name='glance', endpoint_type='public', + url = sc.url_for(service_name='glance', interface='public', service_type='image', region_name='North') self.assertEqual('http://glance.north.host/glanceapi/public', url) - url = sc.url_for(service_name='glance', endpoint_type='public', + url = sc.url_for(service_name='glance', interface='public', service_type='image', region_name='South') self.assertEqual('http://glance.south.host/glanceapi/public', url) @@ -198,14 +198,14 @@ class ServiceCatalogTest(utils.TestCase): service_name='glance', service_type='compute') urls = sc.get_urls(service_type='image', service_name='glance', - endpoint_type='public') + interface='public') self.assertIn('http://glance.north.host/glanceapi/public', urls) self.assertIn('http://glance.south.host/glanceapi/public', urls) urls = sc.get_urls(service_type='image', service_name='Servers', - endpoint_type='public') + interface='public') self.assertEqual(0, len(urls)) @@ -260,7 +260,7 @@ class ServiceCatalogTest(utils.TestCase): # this will work because there are no service names on that token url_ref = 'http://public.com:8774/v2/225da22d3ce34b15877ea70b2a575f58' url = pr_sc.url_for(service_type='compute', service_name='NotExist', - endpoint_type='public') + interface='public') self.assertEqual(url_ref, url) ab_auth_ref = access.create(body=self.AUTH_RESPONSE_BODY) @@ -269,7 +269,7 @@ class ServiceCatalogTest(utils.TestCase): # this won't work because there is a name and it's not this one self.assertRaises(exceptions.EndpointNotFound, ab_sc.url_for, service_type='compute', service_name='NotExist', - endpoint_type='public') + interface='public') class ServiceCatalogV3Test(ServiceCatalogTest): @@ -281,7 +281,7 @@ class ServiceCatalogV3Test(ServiceCatalogTest): self.assertEqual(sc.url_for(service_type='compute'), 'https://compute.north.host/novapi/public') self.assertEqual(sc.url_for(service_type='compute', - endpoint_type='internal'), + interface='internal'), 'https://compute.north.host/novapi/internal') self.assertRaises(exceptions.EndpointNotFound, @@ -294,7 +294,7 @@ class ServiceCatalogV3Test(ServiceCatalogTest): body=self.AUTH_RESPONSE_BODY).service_catalog public_ep = sc.get_endpoints(service_type='compute', - endpoint_type='public') + interface='public') self.assertEqual(public_ep['compute'][0]['region_id'], 'North') self.assertEqual(public_ep['compute'][0]['url'], 'https://compute.north.host/novapi/public') @@ -313,12 +313,12 @@ class ServiceCatalogV3Test(ServiceCatalogTest): auth_ref = access.create(resp=None, body=token) urls = auth_ref.service_catalog.get_urls(service_type='compute', - endpoint_type='public') + interface='public') self.assertEqual(set(['public-0', 'public-1', 'public-2']), set(urls)) urls = auth_ref.service_catalog.get_urls(service_type='compute', - endpoint_type='public', + interface='public', region_name='region-1') self.assertEqual(('public-1', ), urls) @@ -339,34 +339,34 @@ class ServiceCatalogV3Test(ServiceCatalogTest): # initially assert that we get back all our urls for a simple filter urls = auth_ref.service_catalog.get_urls(service_type='compute', - endpoint_type='public') + interface='public') self.assertEqual(2, len(urls)) # with bad endpoint_id nothing should be found urls = auth_ref.service_catalog.get_urls(service_type='compute', endpoint_id=uuid.uuid4().hex, - endpoint_type='public') + interface='public') self.assertEqual(0, len(urls)) # with service_id we get back both public endpoints urls = auth_ref.service_catalog.get_urls(service_type='compute', service_id=service_id, - endpoint_type='public') + interface='public') self.assertEqual(2, len(urls)) # with service_id and endpoint_id we get back the url we want urls = auth_ref.service_catalog.get_urls(service_type='compute', service_id=service_id, endpoint_id=endpoint_id, - endpoint_type='public') + interface='public') self.assertEqual((public_url, ), urls) # with service_id and endpoint_id we get back the url we want urls = auth_ref.service_catalog.get_urls(service_type='compute', endpoint_id=endpoint_id, - endpoint_type='public') + interface='public') self.assertEqual((public_url, ), urls) @@ -384,7 +384,7 @@ class ServiceCatalogV3Test(ServiceCatalogTest): s.add_endpoint('public', public_url) auth_ref = access.create(body=token) - urls = auth_ref.service_catalog.get_urls(endpoint_type='public') + urls = auth_ref.service_catalog.get_urls(interface='public') self.assertEqual(3, len(urls))