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
This commit is contained in:
Chris Dent 2018-11-20 17:05:09 +00:00
parent 4a2a26bf78
commit 324e4f44da
3 changed files with 19 additions and 13 deletions

View File

@ -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

View File

@ -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)

View File

@ -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