Remove service_type requirement from catalog searching
The standard reason to search the catalog is that you want to know how to find a particular service type. However with service_id and endpoint_id you may not want to specify a service_type. Allow searching for a url without specifying a service_type. Change-Id: I038fe5b0e04b689f1072db659219639d5193f558changes/68/210268/3
parent
2aa4d8384d
commit
65cbe5012d
|
@ -117,6 +117,19 @@ class ServiceCatalog(object):
|
|||
|
||||
return sc
|
||||
|
||||
def _get_service_endpoints(self, service_type=None, **kwargs):
|
||||
sc_endpoints = self.get_endpoints(service_type=service_type, **kwargs)
|
||||
|
||||
if service_type:
|
||||
endpoints = sc_endpoints.get(service_type, [])
|
||||
else:
|
||||
# flatten list of lists
|
||||
endpoints = [x
|
||||
for endpoint in six.itervalues(sc_endpoints)
|
||||
for x in endpoint]
|
||||
|
||||
return endpoints
|
||||
|
||||
@abc.abstractmethod
|
||||
@utils.positional()
|
||||
def get_urls(self, service_type=None, endpoint_type='public',
|
||||
|
@ -233,17 +246,12 @@ class ServiceCatalogV2(ServiceCatalog):
|
|||
service_id=None, endpoint_id=None):
|
||||
endpoint_type = self.normalize_endpoint_type(endpoint_type)
|
||||
|
||||
sc_endpoints = self.get_endpoints(service_type=service_type,
|
||||
endpoint_type=endpoint_type,
|
||||
region_name=region_name,
|
||||
service_name=service_name,
|
||||
service_id=service_id,
|
||||
endpoint_id=endpoint_id)
|
||||
|
||||
try:
|
||||
endpoints = sc_endpoints[service_type]
|
||||
except KeyError:
|
||||
return
|
||||
endpoints = self._get_service_endpoints(service_type=service_type,
|
||||
endpoint_type=endpoint_type,
|
||||
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])
|
||||
|
||||
|
@ -277,16 +285,11 @@ class ServiceCatalogV3(ServiceCatalog):
|
|||
def get_urls(self, service_type=None, endpoint_type='publicURL',
|
||||
region_name=None, service_name=None,
|
||||
service_id=None, endpoint_id=None):
|
||||
sc_endpoints = self.get_endpoints(service_type=service_type,
|
||||
endpoint_type=endpoint_type,
|
||||
region_name=region_name,
|
||||
service_name=service_name,
|
||||
service_id=service_id,
|
||||
endpoint_id=endpoint_id)
|
||||
|
||||
try:
|
||||
endpoints = sc_endpoints[service_type]
|
||||
except KeyError:
|
||||
return None
|
||||
endpoints = self._get_service_endpoints(service_type=service_type,
|
||||
endpoint_type=endpoint_type,
|
||||
region_name=region_name,
|
||||
service_name=service_name,
|
||||
service_id=service_id,
|
||||
endpoint_id=endpoint_id)
|
||||
|
||||
return tuple([endpoint['url'] for endpoint in endpoints])
|
||||
|
|
|
@ -186,7 +186,7 @@ class ServiceCatalogTest(utils.TestCase):
|
|||
urls = sc.get_urls(service_type='image', service_name='Servers',
|
||||
endpoint_type='public')
|
||||
|
||||
self.assertIsNone(urls)
|
||||
self.assertEqual(0, len(urls))
|
||||
|
||||
def test_service_catalog_multiple_service_types(self):
|
||||
token = fixture.V2Token()
|
||||
|
@ -225,27 +225,45 @@ 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(service_type='compute',
|
||||
endpoint_type='public')
|
||||
urls = auth_ref.service_catalog.get_urls(endpoint_type='public')
|
||||
self.assertEqual(2, len(urls))
|
||||
|
||||
urls = auth_ref.service_catalog.get_urls(service_type='compute',
|
||||
endpoint_id=endpoint_id,
|
||||
urls = auth_ref.service_catalog.get_urls(endpoint_id=endpoint_id,
|
||||
endpoint_type='public')
|
||||
|
||||
self.assertEqual((public_url, ), urls)
|
||||
|
||||
# with bad endpoint_id nothing should be found
|
||||
urls = auth_ref.service_catalog.get_urls(service_type='compute',
|
||||
endpoint_id=uuid.uuid4().hex,
|
||||
urls = auth_ref.service_catalog.get_urls(endpoint_id=uuid.uuid4().hex,
|
||||
endpoint_type='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(service_type='compute',
|
||||
endpoint_id=endpoint_id,
|
||||
urls = auth_ref.service_catalog.get_urls(endpoint_id=endpoint_id,
|
||||
service_id=uuid.uuid4().hex,
|
||||
endpoint_type='public')
|
||||
|
||||
self.assertEqual((public_url, ), urls)
|
||||
|
||||
def test_service_catalog_without_service_type(self):
|
||||
token = fixture.V2Token()
|
||||
token.set_scope()
|
||||
|
||||
public_urls = []
|
||||
|
||||
for i in range(0, 3):
|
||||
public_url = uuid.uuid4().hex
|
||||
public_urls.append(public_url)
|
||||
|
||||
s = token.add_service(uuid.uuid4().hex)
|
||||
s.add_endpoint(public=public_url)
|
||||
|
||||
auth_ref = access.create(body=token)
|
||||
urls = auth_ref.service_catalog.get_urls(service_type=None,
|
||||
endpoint_type='public')
|
||||
|
||||
self.assertEqual(3, len(urls))
|
||||
|
||||
for p in public_urls:
|
||||
self.assertIn(p, urls)
|
||||
|
|
|
@ -203,10 +203,11 @@ class ServiceCatalogTest(utils.TestCase):
|
|||
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',
|
||||
urls = sc.get_urls(service_type='image',
|
||||
service_name='Servers',
|
||||
endpoint_type='public')
|
||||
|
||||
self.assertIsNone(urls)
|
||||
self.assertEqual(0, len(urls))
|
||||
|
||||
def test_service_catalog_without_name(self):
|
||||
f = fixture.V3Token(audit_chain_id=uuid.uuid4().hex)
|
||||
|
@ -368,3 +369,24 @@ class ServiceCatalogV3Test(ServiceCatalogTest):
|
|||
endpoint_type='public')
|
||||
|
||||
self.assertEqual((public_url, ), urls)
|
||||
|
||||
def test_service_catalog_without_service_type(self):
|
||||
token = fixture.V3Token()
|
||||
token.set_project_scope()
|
||||
|
||||
public_urls = []
|
||||
|
||||
for i in range(0, 3):
|
||||
public_url = uuid.uuid4().hex
|
||||
public_urls.append(public_url)
|
||||
|
||||
s = token.add_service(uuid.uuid4().hex)
|
||||
s.add_endpoint('public', public_url)
|
||||
|
||||
auth_ref = access.create(body=token)
|
||||
urls = auth_ref.service_catalog.get_urls(endpoint_type='public')
|
||||
|
||||
self.assertEqual(3, len(urls))
|
||||
|
||||
for p in public_urls:
|
||||
self.assertIn(p, urls)
|
||||
|
|
Loading…
Reference in New Issue