Make service catalog include service name

If a service name is available then it should be included as part of a
token's service catalog. This functionality was present in the V2 api
and is already relied upon by various clients. It will make it much
easier to transition these clients if we can keep this functionality.

Change-Id: I0d824d73c375ffbc5a6b44c10992967f59742b01
Closes-Bug: #1288098
This commit is contained in:
Jamie Lennox 2014-03-05 17:51:42 +10:00
parent 724d056851
commit d61ba6cac7
2 changed files with 36 additions and 5 deletions

View File

@ -287,13 +287,17 @@ class Catalog(catalog.Driver):
all())
def make_v3_endpoint(endpoint):
endpoint = endpoint.to_dict()
del endpoint['service_id']
endpoint['url'] = core.format_url(endpoint['url'], d)
return endpoint
catalog = [{'endpoints': [make_v3_endpoint(ep.to_dict())
for ep in svc.endpoints if ep.enabled],
'id': svc.id,
'type': svc.type} for svc in services]
def make_v3_service(svc):
eps = [make_v3_endpoint(ep) for ep in svc.endpoints if ep.enabled]
service = {'endpoints': eps, 'id': svc.id, 'type': svc.type}
name = svc.extra.get('name')
if name:
service['name'] = name
return service
return catalog
return [make_v3_service(svc) for svc in services]

View File

@ -1647,6 +1647,33 @@ class TestAuthJSON(test_v3.RestfulTestCase):
self.assertEqual(r.result['token']['project']['id'],
self.project['id'])
def test_auth_catalog_attributes(self):
if self.content_type == 'xml':
self.skipTest('XML catalog parsing is just broken')
auth_data = self.build_authentication_request(
user_id=self.user['id'],
password=self.user['password'],
project_id=self.project['id'])
r = self.post('/auth/tokens', body=auth_data)
catalog = r.result['token']['catalog']
self.assertEqual(1, len(catalog))
catalog = catalog[0]
self.assertEqual(self.service['id'], catalog['id'])
self.assertEqual(self.service['name'], catalog['name'])
self.assertEqual(self.service['type'], catalog['type'])
endpoint = catalog['endpoints']
self.assertEqual(1, len(endpoint))
endpoint = endpoint[0]
self.assertEqual(self.endpoint['id'], endpoint['id'])
self.assertEqual(self.endpoint['interface'], endpoint['interface'])
self.assertEqual(self.endpoint['region'], endpoint['region'])
self.assertEqual(self.endpoint['url'], endpoint['url'])
def _check_disabled_endpoint_result(self, catalog, disabled_endpoint_id):
endpoints = catalog[0]['endpoints']
endpoint_ids = [ep['id'] for ep in endpoints]