Code refactor for ConfFixture
cfg.CONF is a global object, so we need not pass it to init a ConfFixture. We should import opts before use them in case that the opts have not been registered. Change-Id: I1a97df4d522325d9423b1c89cc9958de26704faa Closes-Bug: #1492084
This commit is contained in:
parent
7ed30d1989
commit
d08b44fb1c
|
@ -83,7 +83,7 @@ class TestCase(base.BaseTestCase):
|
|||
self.mock_make_context = p.start()
|
||||
self.addCleanup(p.stop)
|
||||
|
||||
self.useFixture(conf_fixture.ConfFixture(cfg.CONF))
|
||||
self.useFixture(conf_fixture.ConfFixture())
|
||||
|
||||
self._base_test_obj_backup = copy.copy(
|
||||
objects_base.MagnumObjectRegistry._registry._obj_classes)
|
||||
|
|
|
@ -20,19 +20,19 @@ from oslo_log import log
|
|||
|
||||
from magnum.common import config
|
||||
|
||||
cfg.CONF.import_opt('host', 'magnum.common.service')
|
||||
log.register_options(cfg.CONF)
|
||||
CONF = cfg.CONF
|
||||
CONF.import_opt('host', 'magnum.common.service')
|
||||
CONF.import_opt('connection', 'oslo_db.options', group='database')
|
||||
CONF.import_opt('sqlite_synchronous', 'oslo_db.options', group='database')
|
||||
|
||||
|
||||
class ConfFixture(fixtures.Fixture):
|
||||
"""Fixture to manage global conf settings."""
|
||||
|
||||
def __init__(self, conf):
|
||||
self.conf = conf
|
||||
|
||||
def _setUp(self):
|
||||
self.conf.set_default('host', 'fake-mini')
|
||||
self.conf.set_default('connection', "sqlite://", group='database')
|
||||
self.conf.set_default('sqlite_synchronous', False, group='database')
|
||||
log.register_options(cfg.CONF)
|
||||
CONF.set_default('host', 'fake-mini')
|
||||
CONF.set_default('connection', "sqlite://", group='database')
|
||||
CONF.set_default('sqlite_synchronous', False, group='database')
|
||||
config.parse_args([], default_config_files=[])
|
||||
self.addCleanup(self.conf.reset)
|
||||
self.addCleanup(CONF.reset)
|
||||
|
|
Loading…
Reference in New Issue