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
This commit is contained in:
Matthew Treinish 2014-03-20 19:30:08 +00:00 committed by Andrea Frittoli
parent e2fc922c21
commit 827a6fba4d
2 changed files with 10 additions and 0 deletions

View File

@ -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

View File

@ -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):