From f7f52316771ad57bf899eb17b666224654530d9a Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Wed, 20 Mar 2019 22:16:04 +0000 Subject: [PATCH] Add register_opts param to PlacementFixture There are scenarios where it is useful to create a ConfigOpts and register_opts on it before ever calling the PlacementFixture. If that is done we don't want to re-register the opts within the fixture as this can lead to errors (especially when CLI opts are involved). The scenario that discovered this problem is in nova in a regression test [1] where a ConfigOpts is created and registered, the placement DatabaseFixture is started and then that same config is used in multiple instances of the PlacementFixture, each of which again register_opts(). Until commit b647919666a451092189f963786e367d0baa82be this wasn't a problem because the default opts in placement did not include any CLI options. Adding logging opts brought some in. This change adds a flag to the constructor for PlacementFixture, register_opts, defaulting to True, which lets the caller say no, I don't want do register. It also reverts the revert of b647919666a451092189f963786e367d0baa82be to perform oslo_log.log.register_opts() from a central location. [1] test_bug_1679750.TestLocalDeleteAllocations.test_local_delete_removes_allocations_after_compute_restart Change-Id: I360a306b5d05ada75274733038b73ec2f2bdc4d4 Needed-By: I042e41ac8c41c0e5f0389904eb548e0e97d54c60 Related-Bug: #1821092 --- placement/conf/__init__.py | 5 ++++- placement/tests/functional/fixtures/placement.py | 7 +++++-- placement/wsgi.py | 1 - 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/placement/conf/__init__.py b/placement/conf/__init__.py index 9bac2e802..12233c2cd 100644 --- a/placement/conf/__init__.py +++ b/placement/conf/__init__.py @@ -14,6 +14,8 @@ # under the License. from __future__ import absolute_import +from oslo_log import log as logging + from placement.conf import api from placement.conf import base from placement.conf import database @@ -21,7 +23,7 @@ from placement.conf import paths from placement.conf import placement -# To avoid global config, we require an existing ConfigOpts is passed +# To avoid global config, we require an existing ConfigOpts to be passed # to register_opts. Then the caller can have some assurance that the # config they are using will maintain some independence. def register_opts(conf): @@ -30,3 +32,4 @@ def register_opts(conf): database.register_opts(conf) paths.register_opts(conf) placement.register_opts(conf) + logging.register_options(conf) diff --git a/placement/tests/functional/fixtures/placement.py b/placement/tests/functional/fixtures/placement.py index ca008e074..073b71b4f 100644 --- a/placement/tests/functional/fixtures/placement.py +++ b/placement/tests/functional/fixtures/placement.py @@ -42,7 +42,7 @@ class PlacementFixture(fixtures.Fixture): Used by other services, including nova, for functional tests. """ def __init__(self, token='admin', conf_fixture=None, db=True, - use_intercept=True): + use_intercept=True, register_opts=True): """Create a Placement Fixture. :param token: The value to be used when passing an auth token @@ -52,18 +52,21 @@ class PlacementFixture(fixtures.Fixture): :param db: Whether to start the Database fixture. :param use_intercept: If true, install a wsgi-intercept of the placement WSGI app. + :param register_opts: If True, register configuration options. """ self.token = token self.db = db self.use_intercept = use_intercept self.conf_fixture = conf_fixture + self.register_opts = register_opts def setUp(self): super(PlacementFixture, self).setUp() if not self.conf_fixture: config = cfg.ConfigOpts() self.conf_fixture = self.useFixture(config_fixture.Config(config)) - conf.register_opts(self.conf_fixture.conf) + if self.register_opts: + conf.register_opts(self.conf_fixture.conf) if self.db: self.useFixture(db_fixture.Database(self.conf_fixture, diff --git a/placement/wsgi.py b/placement/wsgi.py index c94092f60..c3387d074 100644 --- a/placement/wsgi.py +++ b/placement/wsgi.py @@ -71,7 +71,6 @@ def _get_config_files(env=None): def _parse_args(config, argv, default_config_files): # register placement's config options conf.register_opts(config) - logging.register_options(config) if profiler: profiler.set_defaults(config)