Support regionless/global services
In order to not fail while reading service catalogs which contain services which are configured to be global, meaning without a configured region, parse and normalize the catalog without mentioning a region for that service. Change-Id: Idf84dc0f44fecb41845bb8d57617d10cc6e0d77d
This commit is contained in:
@@ -74,7 +74,7 @@ class ServiceCatalog(object):
|
|||||||
if not filtration.match_service_name(service.get('name')):
|
if not filtration.match_service_name(service.get('name')):
|
||||||
continue
|
continue
|
||||||
for endpoint in service.get('endpoints', []):
|
for endpoint in service.get('endpoints', []):
|
||||||
if not filtration.match_region(endpoint.get('region')):
|
if not filtration.match_region(endpoint.get('region', None)):
|
||||||
continue
|
continue
|
||||||
if not filtration.match_visibility(endpoint.get('interface')):
|
if not filtration.match_visibility(endpoint.get('interface')):
|
||||||
continue
|
continue
|
||||||
@@ -137,6 +137,18 @@ class ServiceCatalog(object):
|
|||||||
|
|
||||||
class ServiceCatalogV2(ServiceCatalog):
|
class ServiceCatalogV2(ServiceCatalog):
|
||||||
"""The V2 service catalog from Keystone."""
|
"""The V2 service catalog from Keystone."""
|
||||||
|
|
||||||
|
def _extract_details(self, endpoint, interface):
|
||||||
|
value = {
|
||||||
|
'interface': interface,
|
||||||
|
'url': endpoint['%sURL' % interface]
|
||||||
|
}
|
||||||
|
region = endpoint.get('region', None)
|
||||||
|
if region:
|
||||||
|
value['region'] = region
|
||||||
|
|
||||||
|
return value
|
||||||
|
|
||||||
def _normalize(self):
|
def _normalize(self):
|
||||||
"""Handle differences in the way v2 and v3 catalogs specify endpoints.
|
"""Handle differences in the way v2 and v3 catalogs specify endpoints.
|
||||||
|
|
||||||
@@ -146,21 +158,9 @@ class ServiceCatalogV2(ServiceCatalog):
|
|||||||
eps = []
|
eps = []
|
||||||
for endpoint in service['endpoints']:
|
for endpoint in service['endpoints']:
|
||||||
if 'publicURL' in endpoint:
|
if 'publicURL' in endpoint:
|
||||||
eps += [{
|
eps += [self._extract_details(endpoint, "public")]
|
||||||
'interface': 'public',
|
|
||||||
'region': endpoint['region'],
|
|
||||||
'url': endpoint['publicURL'],
|
|
||||||
}]
|
|
||||||
if 'internalURL' in endpoint:
|
if 'internalURL' in endpoint:
|
||||||
eps += [{
|
eps += [self._extract_details(endpoint, "internal")]
|
||||||
'interface': 'internal',
|
|
||||||
'region': endpoint['region'],
|
|
||||||
'url': endpoint['internalURL'],
|
|
||||||
}]
|
|
||||||
if 'adminURL' in endpoint:
|
if 'adminURL' in endpoint:
|
||||||
eps += [{
|
eps += [self._extract_details(endpoint, "admin")]
|
||||||
'interface': 'admin',
|
|
||||||
'region': endpoint['region'],
|
|
||||||
'url': endpoint['adminURL'],
|
|
||||||
}]
|
|
||||||
service['endpoints'] = eps
|
service['endpoints'] = eps
|
||||||
|
|||||||
@@ -27,6 +27,14 @@ TEST_USER_ID = 'youid'
|
|||||||
|
|
||||||
TEST_SERVICE_CATALOG_V2 = [
|
TEST_SERVICE_CATALOG_V2 = [
|
||||||
{
|
{
|
||||||
|
"endpoints": [{
|
||||||
|
"adminURL": "http://compute.region0.admin/v1.1/",
|
||||||
|
"internalURL": "http://compute.region0.internal/v1.1/",
|
||||||
|
"publicURL": "http://compute.region0.public/v1.1/",
|
||||||
|
}],
|
||||||
|
"type": "compute",
|
||||||
|
"name": "nova0"
|
||||||
|
}, {
|
||||||
"endpoints": [{
|
"endpoints": [{
|
||||||
"adminURL": "http://compute.region2.admin/v1/",
|
"adminURL": "http://compute.region2.admin/v1/",
|
||||||
"region": "RegionTwo",
|
"region": "RegionTwo",
|
||||||
@@ -74,6 +82,22 @@ TEST_SERVICE_CATALOG_V2 = [
|
|||||||
}]
|
}]
|
||||||
TEST_SERVICE_CATALOG_NORMALIZED = [
|
TEST_SERVICE_CATALOG_NORMALIZED = [
|
||||||
{
|
{
|
||||||
|
"endpoints": [{
|
||||||
|
"interface": "public",
|
||||||
|
"url": "http://compute.region0.public/%(version)s",
|
||||||
|
'version': 'v1.1',
|
||||||
|
}, {
|
||||||
|
"interface": "internal",
|
||||||
|
"url": "http://compute.region0.internal/%(version)s",
|
||||||
|
'version': 'v1.1',
|
||||||
|
}, {
|
||||||
|
"interface": "admin",
|
||||||
|
"url": "http://compute.region0.admin/%(version)s",
|
||||||
|
'version': 'v1.1',
|
||||||
|
}],
|
||||||
|
"type": "compute",
|
||||||
|
"name": "nova0"
|
||||||
|
}, {
|
||||||
"endpoints": [{
|
"endpoints": [{
|
||||||
"interface": "public",
|
"interface": "public",
|
||||||
"region": "RegionTwo",
|
"region": "RegionTwo",
|
||||||
@@ -185,6 +209,19 @@ TEST_RESPONSE_DICT_V2 = {
|
|||||||
|
|
||||||
TEST_SERVICE_CATALOG_V3 = [
|
TEST_SERVICE_CATALOG_V3 = [
|
||||||
{
|
{
|
||||||
|
"endpoints": [{
|
||||||
|
"url": "http://compute.region0.public/v1.1/",
|
||||||
|
"interface": "public"
|
||||||
|
}, {
|
||||||
|
"url": "http://compute.region0.internal/v1.1/",
|
||||||
|
"interface": "internal"
|
||||||
|
}, {
|
||||||
|
"url": "http://compute.region0.admin/v1.1/",
|
||||||
|
"interface": "admin"
|
||||||
|
}],
|
||||||
|
"type": "compute",
|
||||||
|
"name": "nova0",
|
||||||
|
}, {
|
||||||
"endpoints": [{
|
"endpoints": [{
|
||||||
"url": "http://compute.region2.public/v1/",
|
"url": "http://compute.region2.public/v1/",
|
||||||
"region": "RegionTwo",
|
"region": "RegionTwo",
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ from openstack.tests.auth import common
|
|||||||
class TestServiceCatalog(testtools.TestCase):
|
class TestServiceCatalog(testtools.TestCase):
|
||||||
def get_urls(self, sot):
|
def get_urls(self, sot):
|
||||||
sf = service_filter.ServiceFilter(service_type='compute')
|
sf = service_filter.ServiceFilter(service_type='compute')
|
||||||
exp = ["http://compute.region2.public/v1",
|
exp = ["http://compute.region0.public/v1.1",
|
||||||
|
"http://compute.region2.public/v1",
|
||||||
"http://compute.region1.public/v2.0"]
|
"http://compute.region1.public/v2.0"]
|
||||||
self.assertEqual(exp, sot.get_urls(sf))
|
self.assertEqual(exp, sot.get_urls(sf))
|
||||||
sf = service_filter.ServiceFilter(service_type='image')
|
sf = service_filter.ServiceFilter(service_type='image')
|
||||||
@@ -130,7 +131,7 @@ class TestServiceCatalogV3(TestServiceCatalog):
|
|||||||
def test_get_versions(self):
|
def test_get_versions(self):
|
||||||
sot = catalog.ServiceCatalog(common.TEST_SERVICE_CATALOG_V3)
|
sot = catalog.ServiceCatalog(common.TEST_SERVICE_CATALOG_V3)
|
||||||
service = compute_service.ComputeService()
|
service = compute_service.ComputeService()
|
||||||
self.assertEqual(['v1', 'v2.0'], sot.get_versions(service))
|
self.assertEqual(['v1.1', 'v1', 'v2.0'], sot.get_versions(service))
|
||||||
service = identity_service.IdentityService()
|
service = identity_service.IdentityService()
|
||||||
self.assertEqual(['v1.1'], sot.get_versions(service))
|
self.assertEqual(['v1.1'], sot.get_versions(service))
|
||||||
service = image_service.ImageService()
|
service = image_service.ImageService()
|
||||||
|
|||||||
Reference in New Issue
Block a user