From d1b087d59ea39af0323d263b3078d3b2f3d47f2d Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Wed, 25 Jul 2018 13:49:30 +0100 Subject: [PATCH] [placement] Extract base functional test case from test_direct In subsequent patches this will be used for making the rest of the placement functional tests either not-use or centralized their dependence on nova test fixtures and base classes. blueprint: placement-extract Change-Id: I24d9fb2d06bf5c99bcea6c9f138ce31713bb8356 --- .../api/openstack/placement/base.py | 56 +++++++++++++++++++ .../api/openstack/placement/test_direct.py | 21 +------ 2 files changed, 58 insertions(+), 19 deletions(-) create mode 100644 nova/tests/functional/api/openstack/placement/base.py diff --git a/nova/tests/functional/api/openstack/placement/base.py b/nova/tests/functional/api/openstack/placement/base.py new file mode 100644 index 000000000000..60b1bb89edc6 --- /dev/null +++ b/nova/tests/functional/api/openstack/placement/base.py @@ -0,0 +1,56 @@ +# 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. + +from oslo_config import cfg +from oslo_config import fixture as config_fixture +import testtools + +from nova.api.openstack.placement.objects import resource_provider +from nova import config +from nova import context +from nova.tests import fixtures +from nova.tests.unit import policy_fixture + + +CONF = cfg.CONF + + +class TestCase(testtools.TestCase): + """A base test case for placement functional tests. + + Sets up minimum configuration for database and policy handling + and establishes the placement database. + """ + + def setUp(self): + super(TestCase, self).setUp() + + # Manage required configuration + conf_fixture = self.useFixture(config_fixture.Config(CONF)) + conf_fixture.conf.set_default( + 'connection', "sqlite://", group='placement_database') + conf_fixture.conf.set_default( + 'sqlite_synchronous', False, group='placement_database') + config.parse_args([], default_config_files=[], configure_db=False, + init_rpc=False) + + self.useFixture(policy_fixture.PlacementPolicyFixture()) + self.placement_db = self.useFixture( + fixtures.Database(database='placement')) + self._reset_traits_synced() + self.context = context.get_admin_context() + self.addCleanup(self._reset_traits_synced) + + @staticmethod + def _reset_traits_synced(): + """Reset the _TRAITS_SYNCED boolean to base state.""" + resource_provider._TRAITS_SYNCED = False diff --git a/nova/tests/functional/api/openstack/placement/test_direct.py b/nova/tests/functional/api/openstack/placement/test_direct.py index bdf8e5b15c03..829c5e3eee4e 100644 --- a/nova/tests/functional/api/openstack/placement/test_direct.py +++ b/nova/tests/functional/api/openstack/placement/test_direct.py @@ -12,32 +12,15 @@ from oslo_config import cfg -from nova.api.openstack.placement import context from nova.api.openstack.placement import direct -from nova.api.openstack.placement.objects import resource_provider -from nova import test -from nova.tests import fixtures +from nova.tests.functional.api.openstack.placement import base from nova.tests import uuidsentinel CONF = cfg.CONF -# FIXME(cdent): some dupes with db/test_base.py -class TestDirect(test.NoDBTestCase): - USES_DB_SELF = True - - def setUp(self): - super(TestDirect, self).setUp() - self.api_db = self.useFixture(fixtures.Database(database='placement')) - self._reset_traits_synced() - self.context = context.RequestContext() - self.addCleanup(self._reset_traits_synced) - - @staticmethod - def _reset_traits_synced(): - """Reset the _TRAITS_SYNCED boolean to base state.""" - resource_provider._TRAITS_SYNCED = False +class TestDirect(base.TestCase): def test_direct_is_there(self): with direct.PlacementDirect(CONF) as client: