Fix leak from tempest.conf in fake_config fixture

The config fixture used in Tempest unit tests
(tests.fake_config.ConfigFixture) does not reset the
cfg.CONF/config.CONF values when the test class is initialized.
If config.CONF already exists (e.g. with values from tempest.conf file
that have been retrieved during test discovery/load), then incorrect
config settings might be used during a unit test.

There is a statement to (re)initialize cfg.CONF in the init of
tests.fake_config.FakePrivate (this is a stub for
config.TempestConfigPrivate). However if config.CONF already has
attribute _config (of type TempestConfigPrivate), then
TempestConfigPrivate is not called during the test (due to
logic in __getattr__ method in config.TempestConfigProxy class). So if
config.CONF was created before start of the unit test, stub FakePrivate
is not initialized and as a result cfg.CONF is not reset.

This patch moves the (re)initialization of cfg.CONF from FakePrivate to
ConfigFixture class to ensure that cfg.CONF/config.CONF reset is also
executed if config.CONF already exists before start of the unit test.

Partial-Bug: #1508815

Change-Id: I9525628ffd263dd2ed3ad2411f24548dfd50f747
This commit is contained in:
Johan Pas 2015-12-28 22:44:04 +01:00
parent 99da10d2e1
commit 0ae551fdf5
1 changed files with 2 additions and 2 deletions

View File

@ -24,6 +24,7 @@ from tempest import config
class ConfigFixture(conf_fixture.Config):
def __init__(self):
cfg.CONF([], default_config_files=[])
config.register_opts()
super(ConfigFixture, self).__init__()
@ -59,6 +60,5 @@ class ConfigFixture(conf_fixture.Config):
class FakePrivate(config.TempestConfigPrivate):
def __init__(self, parse_conf=True, config_path=None):
cfg.CONF([], default_config_files=[])
self._set_attrs()
self.lock_path = cfg.CONF.lock_path
self.lock_path = cfg.CONF.oslo_concurrency.lock_path