diff options
Diffstat (limited to 'keystone-moon/keystone/tests/unit/test_catalog.py')
-rw-r--r-- | keystone-moon/keystone/tests/unit/test_catalog.py | 89 |
1 files changed, 86 insertions, 3 deletions
diff --git a/keystone-moon/keystone/tests/unit/test_catalog.py b/keystone-moon/keystone/tests/unit/test_catalog.py index 85acfedf..ada2de43 100644 --- a/keystone-moon/keystone/tests/unit/test_catalog.py +++ b/keystone-moon/keystone/tests/unit/test_catalog.py @@ -53,8 +53,7 @@ class V2CatalogTestCase(rest.RestfulTestCase): """Applicable only to JSON.""" return r.result['access']['token']['id'] - def _endpoint_create(self, expected_status=http_client.OK, - service_id=SERVICE_FIXTURE, + def _endpoint_create(self, expected_status=200, service_id=SERVICE_FIXTURE, publicurl='http://localhost:8080', internalurl='http://localhost:8080', adminurl='http://localhost:8080'): @@ -77,6 +76,18 @@ class V2CatalogTestCase(rest.RestfulTestCase): body=body) return body, r + def _region_create(self): + region_id = uuid.uuid4().hex + self.catalog_api.create_region({'id': region_id}) + return region_id + + def _service_create(self): + service_id = uuid.uuid4().hex + service = unit.new_service_ref() + service['id'] = service_id + self.catalog_api.create_service(service_id, service) + return service_id + def test_endpoint_create(self): req_body, response = self._endpoint_create() self.assertIn('endpoint', response.result) @@ -84,6 +95,78 @@ class V2CatalogTestCase(rest.RestfulTestCase): for field, value in req_body['endpoint'].items(): self.assertEqual(response.result['endpoint'][field], value) + def test_pure_v3_endpoint_with_publicurl_visible_from_v2(self): + """Test pure v3 endpoint can be fetched via v2 API. + + For those who are using v2 APIs, endpoints created by v3 API should + also be visible as there are no differences about the endpoints + except the format or the internal implementation. + And because public url is required for v2 API, so only the v3 endpoints + of the service which has the public interface endpoint will be + converted into v2 endpoints. + """ + region_id = self._region_create() + service_id = self._service_create() + # create a v3 endpoint with three interfaces + body = { + 'endpoint': unit.new_endpoint_ref(service_id, + default_region_id=region_id) + } + for interface in catalog.controllers.INTERFACES: + body['endpoint']['interface'] = interface + self.admin_request(method='POST', + token=self.get_scoped_token(), + path='/v3/endpoints', + expected_status=http_client.CREATED, + body=body) + + r = self.admin_request(token=self.get_scoped_token(), + path='/v2.0/endpoints') + # v3 endpoints having public url can be fetched via v2.0 API + self.assertEqual(1, len(r.result['endpoints'])) + v2_endpoint = r.result['endpoints'][0] + self.assertEqual(service_id, v2_endpoint['service_id']) + # check urls just in case. + # This is not the focus of this test, so no different urls are used. + self.assertEqual(body['endpoint']['url'], v2_endpoint['publicurl']) + self.assertEqual(body['endpoint']['url'], v2_endpoint['adminurl']) + self.assertEqual(body['endpoint']['url'], v2_endpoint['internalurl']) + self.assertNotIn('name', v2_endpoint) + + v3_endpoint = self.catalog_api.get_endpoint(v2_endpoint['id']) + # it's the v3 public endpoint's id as the generated v2 endpoint + self.assertEqual('public', v3_endpoint['interface']) + self.assertEqual(service_id, v3_endpoint['service_id']) + + def test_pure_v3_endpoint_without_publicurl_invisible_from_v2(self): + """Test pure v3 endpoint without public url can't be fetched via v2 API. + + V2 API will return endpoints created by v3 API, but because public url + is required for v2 API, so v3 endpoints without public url will be + ignored. + """ + region_id = self._region_create() + service_id = self._service_create() + # create a v3 endpoint without public interface + body = { + 'endpoint': unit.new_endpoint_ref(service_id, + default_region_id=region_id) + } + for interface in catalog.controllers.INTERFACES: + if interface == 'public': + continue + body['endpoint']['interface'] = interface + self.admin_request(method='POST', + token=self.get_scoped_token(), + path='/v3/endpoints', + expected_status=http_client.CREATED, + body=body) + + r = self.admin_request(token=self.get_scoped_token(), + path='/v2.0/endpoints') + # v3 endpoints without public url won't be fetched via v2.0 API + self.assertEqual(0, len(r.result['endpoints'])) + def test_endpoint_create_with_null_adminurl(self): req_body, response = self._endpoint_create(adminurl=None) self.assertIsNone(req_body['endpoint']['adminurl']) @@ -126,7 +209,7 @@ class V2CatalogTestCase(rest.RestfulTestCase): valid_url = 'http://127.0.0.1:8774/v1.1/$(tenant_id)s' # baseline tests that all valid URLs works - self._endpoint_create(expected_status=http_client.OK, + self._endpoint_create(expected_status=200, publicurl=valid_url, internalurl=valid_url, adminurl=valid_url) |