From 827a6fba4d3582dbae68ba4f21df3588c1ee7e8e Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Thu, 20 Mar 2014 19:30:08 +0000 Subject: [PATCH] Add config fixture support to unit tests This commit adds a new env variable OS_TEST_LOCK_PATH to the .testr.conf file to set the lock path for using oslo locks. Previously, if an external lock couldn't be used to isolate test cases because the unit tests do not have a config file. By getting a lock path with an env variable and setting the location in the config fixture external locks can be used by first invoking the config fixture. Partially implements bp unit-tests Change-Id: I08c27ab125183f5d055eaa45c4f0e0a527445475 --- .testr.conf | 1 + tempest/tests/fake_config.py | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/.testr.conf b/.testr.conf index abaf14a68c..4f6e0b37d2 100644 --- a/.testr.conf +++ b/.testr.conf @@ -2,6 +2,7 @@ test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \ OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \ OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-500} \ + OS_TEST_LOCK_PATH=${OS_TEST_LOCK_PATH:-${TMPDIR:-'/tmp'}} \ ${PYTHON:-python} -m subunit.run discover -t ./ ${OS_TEST_PATH:-./tempest/test_discover} $LISTOPT $IDOPTION test_id_option=--load-list $IDFILE test_list_option=--list diff --git a/tempest/tests/fake_config.py b/tempest/tests/fake_config.py index 8a8ebb0c32..4676cbd4a1 100644 --- a/tempest/tests/fake_config.py +++ b/tempest/tests/fake_config.py @@ -12,16 +12,21 @@ # License for the specific language governing permissions and limitations # under the License. +import os + from oslo.config import cfg from tempest import config from tempest.openstack.common.fixture import config as conf_fixture +from tempest.openstack.common import importutils class ConfigFixture(conf_fixture.Config): def __init__(self): config.register_opts() + # Register locking options + importutils.import_module('tempest.openstack.common.lockutils') super(ConfigFixture, self).__init__() def setUp(self): @@ -36,6 +41,10 @@ class ConfigFixture(conf_fixture.Config): group='identity') self.conf.set_default('neutron', True, group='service_available') self.conf.set_default('heat', True, group='service_available') + if not os.path.exists(str(os.environ.get('OS_TEST_LOCK_PATH'))): + os.mkdir(str(os.environ.get('OS_TEST_LOCK_PATH'))) + self.conf.set_default('lock_path', + str(os.environ.get('OS_TEST_LOCK_PATH'))) class FakePrivate(config.TempestConfigPrivate):