From 324e4f44da372925b3fa44cbc6bd57f4deee6ba2 Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Tue, 20 Nov 2018 17:05:09 +0000 Subject: [PATCH] Allow placement to start without a config file With oslo.config 6.7.0 configuration options may be found in environment variables. Because of the small number of options that placement requires to run it is straightforward to source all config from the environment, useful in container-based environments. However, prior to this change, placement-the-wsgi-app required that a configuration file existed, placement.conf, either in /etc/placement or in a custom directory. This change makes it so that the placement.conf can be any of: * in the custom directory * in the default project locations (including /etc/placement) * nowhere The change maintains the behavior that if [placement_database]/connection is not set the application will fail to start. Though this change is orthogonal to the oslo.config change, requirements and lower-constraints are updated to ensure the desired behavior. Closes-Bug: #1802925 Change-Id: Iefa8ad22dcb6a128293ea71ab77c377db56e8d70 --- lower-constraints.txt | 2 +- placement/wsgi.py | 28 +++++++++++++++++----------- requirements.txt | 2 +- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/lower-constraints.txt b/lower-constraints.txt index 0dbb17383..c5cf99278 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -77,7 +77,7 @@ os-xenapi==0.3.3 osc-lib==1.10.0 oslo.cache==1.26.0 oslo.concurrency==3.26.0 -oslo.config==6.1.0 +oslo.config==6.7.0 oslo.context==2.19.2 oslo.db==4.40.0 oslo.i18n==3.15.3 diff --git a/placement/wsgi.py b/placement/wsgi.py index 4ad356122..56afbd120 100644 --- a/placement/wsgi.py +++ b/placement/wsgi.py @@ -51,12 +51,20 @@ def setup_logging(config): py_logging.captureWarnings(True) -def _get_config_file(env=None): +def _get_config_files(env=None): + """Return a list of one file or None describing config location. + + If None, that means oslo.config will look in the default locations + for a config file. + """ if env is None: env = os.environ - dirname = env.get('OS_PLACEMENT_CONFIG_DIR', '/etc/placement').strip() - return os.path.join(dirname, CONFIG_FILE) + dirname = env.get('OS_PLACEMENT_CONFIG_DIR', '').strip() + if dirname: + return [os.path.join(dirname, CONFIG_FILE)] + else: + return None def _parse_args(argv, default_config_files): @@ -100,19 +108,17 @@ def _set_middleware_defaults(): def init_application(): # initialize the config system - conffile = _get_config_file() + conffiles = _get_config_files() # NOTE(lyarwood): Call reset to ensure the ConfigOpts object doesn't # already contain registered options if the app is reloaded. conf.CONF.reset() - # This will raise cfg.ConfigFilesNotFoundError and cfg.RequiredOptError - # when either conffile is not there or some required option is not set - # (notably the database connection string). We want both of these to - # be a hard fail and prevent the application from starting so we hard - # fail here. The error will show up in the wsgi server's logs and the - # app will not start. - _parse_args([], default_config_files=[conffile]) + # This will raise cfg.RequiredOptError when a required option is not set + # (notably the database connection string). We want this to be a hard fail + # that prevents the application from starting. The error will show up in + # the wsgi server's logs. + _parse_args([], default_config_files=conffiles) # initialize the logging system setup_logging(conf.CONF) diff --git a/requirements.txt b/requirements.txt index b46d39918..2a8781954 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,7 +12,7 @@ requests>=2.14.2 # Apache-2.0 six>=1.10.0 # MIT setuptools!=24.0.0,!=34.0.0,!=34.0.1,!=34.0.2,!=34.0.3,!=34.1.0,!=34.1.1,!=34.2.0,!=34.3.0,!=34.3.1,!=34.3.2,!=36.2.0,>=21.0.0 # PSF/ZPL oslo.concurrency>=3.26.0 # Apache-2.0 -oslo.config>=6.1.0 # Apache-2.0 +oslo.config>=6.7.0 # Apache-2.0 oslo.context>=2.19.2 # Apache-2.0 oslo.log>=3.36.0 # Apache-2.0 oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0