diff --git a/gnocchi/tests/gabbi/fixtures.py b/gnocchi/tests/gabbi/fixtures.py index 7491143..75ad3a1 100644 --- a/gnocchi/tests/gabbi/fixtures.py +++ b/gnocchi/tests/gabbi/fixtures.py @@ -30,7 +30,17 @@ from gnocchi.rest import app from gnocchi import service -class ConfigFixture(fixture.InterceptFixture): +# NOTE(chdent): Hack to restore semblance of global conf to pass to +# the WSGI app used per test suite. +CONF = None + + +def setup_app(): + global CONF + return app.setup_app(cfg=CONF) + + +class ConfigFixture(fixture.GabbiFixture): """Establish the relevant configuration fixture, per test file. Each test file gets its own oslo config and its own indexer and storage @@ -44,19 +54,22 @@ class ConfigFixture(fixture.InterceptFixture): """ def __init__(self): - super(ConfigFixture, self).__init__(None, None, app.setup_app) + self.conf = None self.db_url = None self.tmp_dir = None def start_fixture(self): """Create necessary temp files and do the config dance.""" + global CONF + data_tmp_dir = tempfile.mkdtemp(prefix='gnocchi') coordination_dir = os.path.join(data_tmp_dir, 'tooz') os.mkdir(coordination_dir) coordination_url = 'file://%s' % coordination_dir conf = service.prepare_service([]) + conf.set_override('policy_file', os.path.abspath('etc/gnocchi/policy.json')) conf.set_override('file_basepath', data_tmp_dir, 'storage') conf.set_override('driver', 'file', 'storage') conf.set_override('coordination_url', coordination_url, 'storage') @@ -67,13 +80,13 @@ class ConfigFixture(fixture.InterceptFixture): conf.set_override('middlewares', [], 'api') self.db_url = self._setup_database(conf) + CONF = self.conf = conf self.tmp_dir = data_tmp_dir - super(ConfigFixture, self).start_fixture() - def stop_fixture(self): """Clean up the config fixture and storage artifacts.""" - super(ConfigFixture, self).stop_fixture() + + self.conf.reset() if self.db_url: # Swallow noise from missing tables when dropping diff --git a/gnocchi/tests/gabbi/test_gabbi.py b/gnocchi/tests/gabbi/test_gabbi.py index c20f3a0..48c1edb 100644 --- a/gnocchi/tests/gabbi/test_gabbi.py +++ b/gnocchi/tests/gabbi/test_gabbi.py @@ -29,4 +29,5 @@ def load_tests(loader, tests, pattern): """Provide a TestSuite to the discovery process.""" test_dir = os.path.join(os.path.dirname(__file__), TESTS_DIR) return driver.build_tests(test_dir, loader, host=None, + intercept=fixtures.setup_app, fixture_module=fixtures)