From 193374af3860e17ed03bb0431d823046079ae444 Mon Sep 17 00:00:00 2001 From: Jay Pipes Date: Tue, 13 Mar 2012 17:30:07 -0400 Subject: Fixes LP #954089 - Service list templated catalog * Adds missing test cases for the TemplatedCatalog * Adds a base CatalogTest that different backends can use * Updates kvs.Catalog to raise ServiceNotFound where appropriate * Updates the tests.test_keystoneclient_sql to actually test the SQL catalog backend * Removes old test for incorrect endpoints listing * Removes the keystone.catalog.core.Driver.service_exists method since it was only implemented in the SQL driver and wasn't required now that get_service and delete_service properly raise ServiceNotFound exception. Change-Id: I35690cc147e56007be27bacf94eeff360e727e5d --- tests/backend_sql.conf | 3 +++ tests/default_fixtures.py | 21 +++++++++++++++ tests/test_backend.py | 20 +++++++++++++++ tests/test_backend_kvs.py | 7 ++--- tests/test_backend_templated.py | 57 +++++++++++++++++++++++++++++++++++++++++ tests/test_keystoneclient.py | 8 ------ 6 files changed, 105 insertions(+), 11 deletions(-) create mode 100644 tests/test_backend_templated.py (limited to 'tests') diff --git a/tests/backend_sql.conf b/tests/backend_sql.conf index bbe4343a..a9ca1239 100644 --- a/tests/backend_sql.conf +++ b/tests/backend_sql.conf @@ -13,3 +13,6 @@ driver = keystone.token.backends.sql.Token [ec2] driver = keystone.contrib.ec2.backends.sql.Ec2 + +[catalog] +driver = keystone.catalog.backends.sql.Catalog diff --git a/tests/default_fixtures.py b/tests/default_fixtures.py index 90526ceb..a97a48d8 100644 --- a/tests/default_fixtures.py +++ b/tests/default_fixtures.py @@ -35,3 +35,24 @@ ROLES = [ {'id': 'keystone_admin', 'name': 'Keystone Admin'}, {'id': 'useless', 'name': 'Useless'}, ] + +SERVICES = [ + { + 'id': 'COMPUTE_ID', + 'type': 'compute', + 'name': 'Nova', + 'description': 'OpenStack Compute service' + }, + { + 'id': 'IDENTITY_ID', + 'type': 'identity', + 'name': 'Keystone', + 'description': 'OpenStack Identity service' + }, + { + 'id': 'IMAGE_ID', + 'type': 'image', + 'name': 'Glance', + 'description': 'OpenStack Image service' + }, +] diff --git a/tests/test_backend.py b/tests/test_backend.py index dc566252..25119122 100644 --- a/tests/test_backend.py +++ b/tests/test_backend.py @@ -302,3 +302,23 @@ class TokenTests(object): self.assertDictEquals(data_ref, data) new_data_ref = self.token_api.get_token(token_id) self.assertEqual(data_ref, new_data_ref) + + +class CatalogTests(object): + + def test_service_crud(self): + new_service = {'id': 'MY_SERVICE', 'type': 'myservice', + 'name': 'My Service', 'description': 'My description'} + res = self.catalog_api.create_service(new_service['id'], new_service) + self.assertDictEquals(res, new_service) + + service_id = new_service['id'] + self.catalog_api.delete_service(service_id) + self.assertRaises(exception.ServiceNotFound, + self.catalog_api.delete_service, service_id) + self.assertRaises(exception.ServiceNotFound, + self.catalog_api.get_service, service_id) + + def test_service_list(self): + services = self.catalog_api.list_services() + self.assertEqual(3, len(services)) diff --git a/tests/test_backend_kvs.py b/tests/test_backend_kvs.py index 0f24c429..6dc626e5 100644 --- a/tests/test_backend_kvs.py +++ b/tests/test_backend_kvs.py @@ -35,13 +35,14 @@ class KvsToken(test.TestCase, test_backend.TokenTests): self.token_api = token_kvs.Token(db={}) -class KvsCatalog(test.TestCase): +class KvsCatalog(test.TestCase, test_backend.CatalogTests): def setUp(self): super(KvsCatalog, self).setUp() self.catalog_api = catalog_kvs.Catalog(db={}) - self._load_fixtures() + self.load_fixtures(default_fixtures) + self._load_fake_catalog() - def _load_fixtures(self): + def _load_fake_catalog(self): self.catalog_foobar = self.catalog_api._create_catalog( 'foo', 'bar', {'RegionFoo': {'service_bar': {'foo': 'bar'}}}) diff --git a/tests/test_backend_templated.py b/tests/test_backend_templated.py new file mode 100644 index 00000000..3773cc99 --- /dev/null +++ b/tests/test_backend_templated.py @@ -0,0 +1,57 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2012 OpenStack LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import os + +from keystone import test +from keystone.catalog.backends import templated as catalog_templated + +import test_backend +import default_fixtures + +DEFAULT_CATALOG_TEMPLATES = os.path.abspath(os.path.join( + os.path.dirname(__file__), + 'default_catalog.templates')) + + +class TestTemplatedCatalog(test.TestCase, test_backend.CatalogTests): + + DEFAULT_FIXTURE = { + 'RegionOne': { + 'compute': { + 'adminURL': 'http://localhost:8774/v1.1/bar', + 'publicURL': 'http://localhost:8774/v1.1/bar', + 'internalURL': 'http://localhost:8774/v1.1/bar', + 'name': "'Compute Service'" + }, + 'identity': { + 'adminURL': 'http://localhost:35357/v2.0', + 'publicURL': 'http://localhost:5000/v2.0', + 'internalURL': 'http://localhost:35357/v2.0', + 'name': "'Identity Service'" + } + } + } + + def setUp(self): + super(TestTemplatedCatalog, self).setUp() + self.opt_in_group('catalog', template_file=DEFAULT_CATALOG_TEMPLATES) + self.catalog_api = catalog_templated.TemplatedCatalog() + self.load_fixtures(default_fixtures) + + def test_get_catalog(self): + catalog_ref = self.catalog_api.get_catalog('foo', 'bar') + self.assertDictEquals(catalog_ref, self.DEFAULT_FIXTURE) diff --git a/tests/test_keystoneclient.py b/tests/test_keystoneclient.py index 4029ea76..7241ca6b 100644 --- a/tests/test_keystoneclient.py +++ b/tests/test_keystoneclient.py @@ -175,14 +175,6 @@ class KeystoneClientTests(object): self.get_client, user_ref) - # TODO(termie): I'm not really sure that this is testing much - def test_endpoints(self): - raise nose.exc.SkipTest('Not implemented due to bug 933555') - - client = self.get_client(admin=True) - token = client.auth_token - endpoints = client.tokens.endpoints(token=token) - # FIXME(ja): this test should require the "keystone:admin" roled # (probably the role set via --keystone_admin_role flag) # FIXME(ja): add a test that admin endpoint is only sent to admin user -- cgit