Permalink
Browse files

Fix catalog when services have no URL

This fixes bug #1061736

Change-Id: Ic8f7a45dfabb2e3fb40f6aa6cd4c0f29c13f2c77
Signed-off-by: Julien Danjou <julien@danjou.info>
  • Loading branch information...
1 parent e7fdf93 commit ba1df90656f9bcff4d769b18042f731a6d295faa @jd jd committed Oct 4, 2012
@@ -156,14 +156,11 @@ def get_catalog(self, user_id, tenant_id, metadata=None):
catalog[region][srv_type] = {}
- internal_url = ep['internalurl'].replace('$(', '%(')
- public_url = ep['publicurl'].replace('$(', '%(')
- admin_url = ep['adminurl'].replace('$(', '%(')
srv_type = catalog[region][srv_type]
srv_type['id'] = ep['id']
srv_type['name'] = srv_name
- srv_type['publicURL'] = core.format_url(public_url, d)
- srv_type['adminURL'] = core.format_url(admin_url, d)
- srv_type['internalURL'] = core.format_url(internal_url, d)
+ srv_type['publicURL'] = core.format_url(ep.get('publicurl', ''), d)
+ srv_type['internalURL'] = core.format_url(ep.get('internalurl'), d)
+ srv_type['adminURL'] = core.format_url(ep.get('adminurl'), d)
return catalog
@@ -120,7 +120,6 @@ def get_catalog(self, user_id, tenant_id, metadata=None):
for service, service_ref in region_ref.iteritems():
o[region][service] = {}
for k, v in service_ref.iteritems():
- v = v.replace('$(', '%(')
o[region][service][k] = core.format_url(v, d)
return o
View
@@ -36,7 +36,9 @@
def format_url(url, data):
"""Helper Method for all Backend Catalog's to Deal with URLS"""
try:
- result = url % data
+ result = url.replace('$(', '%(') % data
+ except AttributeError:
+ return None
except KeyError as e:
LOG.error("Malformed endpoint %s - unknown key %s" %
(url, str(e)))
View
@@ -177,3 +177,41 @@ def test_malformed_catalog_throws_error(self):
"publicurl": badurl})
with self.assertRaises(exception.MalformedEndpoint):
self.catalog_api.get_catalog('fake-user', 'fake-tenant')
+
+ def test_get_catalog_without_endpoint(self):
+ new_service = {
+ 'id': uuid.uuid4().hex,
+ 'type': uuid.uuid4().hex,
+ 'name': uuid.uuid4().hex,
+ 'description': uuid.uuid4().hex,
+ }
+ self.catalog_api.create_service(
+ new_service['id'],
+ new_service.copy())
+ service_id = new_service['id']
+
+ new_endpoint = {
+ 'id': uuid.uuid4().hex,
+ 'region': uuid.uuid4().hex,
+ 'service_id': service_id,
+ }
+
+ self.catalog_api.create_endpoint(
+ new_endpoint['id'],
+ new_endpoint.copy())
+
+ catalog = self.catalog_api.get_catalog('user', 'tenant')
+
+ service_type = new_service['type']
+ region = new_endpoint['region']
+
+ self.assertEqual(catalog[region][service_type]['name'],
+ new_service['name'])
+ self.assertEqual(catalog[region][service_type]['id'],
+ new_endpoint['id'])
+ self.assertEqual(catalog[region][service_type]['publicURL'],
+ "")
+ self.assertEqual(catalog[region][service_type]['adminURL'],
+ None)
+ self.assertEqual(catalog[region][service_type]['internalURL'],
+ None)

0 comments on commit ba1df90

Please sign in to comment.