Using correct keyword for region in v3

Keystone v3 and v2 have different keywords in endpoint
dictionary. This patch adds ability for keystone client for correct
work with old and new API.

Change-Id: I886b4c7ac3cbe08ac1b88f490e9ca92a90256961
Closes-Bug: #1364463
This commit is contained in:
Sergey Kraynev
2014-11-21 09:57:23 -05:00
parent 32c18a83e2
commit 8311708907
4 changed files with 37 additions and 3 deletions

View File

@@ -28,7 +28,8 @@ class _Service(dict):
def add_endpoint(self, interface, url, region=None): def add_endpoint(self, interface, url, region=None):
data = {'interface': interface, data = {'interface': interface,
'url': url, 'url': url,
'region': region} 'region': region,
'region_id': region}
self.setdefault('endpoints', []).append(data) self.setdefault('endpoints', []).append(data)
return data return data

View File

@@ -49,6 +49,9 @@ class ServiceCatalog(object):
# to calls made to the service_catalog. Provide appropriate warning. # to calls made to the service_catalog. Provide appropriate warning.
return self._region_name return self._region_name
def _get_endpoint_region(self, endpoint):
return endpoint.get('region_id') or endpoint.get('region')
@abc.abstractmethod @abc.abstractmethod
def get_token(self): def get_token(self):
"""Fetch token details from service catalog. """Fetch token details from service catalog.
@@ -130,7 +133,8 @@ class ServiceCatalog(object):
if (endpoint_type and not if (endpoint_type and not
self._is_endpoint_type_match(endpoint, endpoint_type)): self._is_endpoint_type_match(endpoint, endpoint_type)):
continue continue
if region_name and region_name != endpoint.get('region'): if (region_name and
region_name != self._get_endpoint_region(endpoint)):
continue continue
sc[st].append(endpoint) sc[st].append(endpoint)

View File

@@ -233,5 +233,6 @@ class V3TokenTests(utils.TestCase):
self.assertEqual(service_type, service['type']) self.assertEqual(service_type, service['type'])
for interface, url in six.iteritems(endpoints): for interface, url in six.iteritems(endpoints):
endpoint = {'interface': interface, 'url': url, 'region': region} endpoint = {'interface': interface, 'url': url,
'region': region, 'region_id': region}
self.assertIn(endpoint, service['endpoints']) self.assertIn(endpoint, service['endpoints'])

View File

@@ -216,3 +216,31 @@ class ServiceCatalogTest(utils.TestCase):
self.assertRaises(exceptions.EndpointNotFound, ab_sc.url_for, self.assertRaises(exceptions.EndpointNotFound, ab_sc.url_for,
service_type='compute', service_name='NotExist', service_type='compute', service_name='NotExist',
endpoint_type='public') endpoint_type='public')
class ServiceCatalogV3Test(ServiceCatalogTest):
def test_building_a_service_catalog(self):
auth_ref = access.AccessInfo.factory(self.RESPONSE,
self.AUTH_RESPONSE_BODY)
sc = auth_ref.service_catalog
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'),
'https://compute.north.host/novapi/internal')
self.assertRaises(exceptions.EndpointNotFound, sc.url_for, 'region_id',
'South', service_type='compute')
def test_service_catalog_endpoints(self):
auth_ref = access.AccessInfo.factory(self.RESPONSE,
self.AUTH_RESPONSE_BODY)
sc = auth_ref.service_catalog
public_ep = sc.get_endpoints(service_type='compute',
endpoint_type='public')
self.assertEqual(public_ep['compute'][0]['region_id'], 'North')
self.assertEqual(public_ep['compute'][0]['url'],
'https://compute.north.host/novapi/public')