Allow handling multiple service_types

If the same service_type was mentioned in the catalog more than once
then only the last entry would be parsed and any possible other matches
would be lost.

This was something that novaclient used to do, and as we are pushing
sessions as the way that clients should all work we need to maintain
that compatibility.

Change-Id: I6964515ed1975bce1998897abfc02a1ec36e2584
Closes-Bug: #1425766
This commit is contained in:
Jamie Lennox
2015-02-26 12:07:11 +11:00
parent bd6fa327c8
commit 3e2035bf88
3 changed files with 52 additions and 2 deletions

View File

@@ -127,7 +127,7 @@ class ServiceCatalog(object):
if service_name != sn:
continue
sc[st] = []
endpoints = sc.setdefault(st, [])
for endpoint in service.get('endpoints', []):
if (endpoint_type and not
@@ -136,7 +136,7 @@ class ServiceCatalog(object):
if (region_name and
region_name != self._get_endpoint_region(endpoint)):
continue
sc[st].append(endpoint)
endpoints.append(endpoint)
return sc

View File

@@ -12,6 +12,7 @@
from keystoneclient import access
from keystoneclient import exceptions
from keystoneclient import fixture
from keystoneclient.tests.unit.v2_0 import client_fixtures
from keystoneclient.tests.unit.v2_0 import utils
@@ -173,3 +174,27 @@ class ServiceCatalogTest(utils.TestCase):
endpoint_type='public')
self.assertIsNone(urls)
def test_service_catalog_multiple_service_types(self):
token = fixture.V2Token()
token.set_scope()
for i in range(3):
s = token.add_service('compute')
s.add_endpoint(public='public-%d' % i,
admin='admin-%d' % i,
internal='internal-%d' % i,
region='region-%d' % i)
auth_ref = access.AccessInfo.factory(resp=None, body=token)
urls = auth_ref.service_catalog.get_urls(service_type='compute',
endpoint_type='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',
region_name='region-1')
self.assertEqual(('public-1', ), urls)

View File

@@ -12,6 +12,7 @@
from keystoneclient import access
from keystoneclient import exceptions
from keystoneclient import fixture
from keystoneclient.tests.unit.v3 import client_fixtures
from keystoneclient.tests.unit.v3 import utils
@@ -244,3 +245,27 @@ class ServiceCatalogV3Test(ServiceCatalogTest):
self.assertEqual(public_ep['compute'][0]['region_id'], 'North')
self.assertEqual(public_ep['compute'][0]['url'],
'https://compute.north.host/novapi/public')
def test_service_catalog_multiple_service_types(self):
token = fixture.V3Token()
token.set_project_scope()
for i in range(3):
s = token.add_service('compute')
s.add_standard_endpoints(public='public-%d' % i,
admin='admin-%d' % i,
internal='internal-%d' % i,
region='region-%d' % i)
auth_ref = access.AccessInfo.factory(resp=None, body=token)
urls = auth_ref.service_catalog.get_urls(service_type='compute',
endpoint_type='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',
region_name='region-1')
self.assertEqual(('public-1', ), urls)