Support standard config file path for monasca-api
The standard path is /etc/monasca/monasca-api.conf (instead of /etc/monasca/api.conf). /etc/monasca/api.conf and /etc/monasca/api-config.conf are still supported (in case the new file paths are not available) but a deprectation message is printed. Story: 2004708 Task: 28738 Depends-On: https://review.openstack.org/#/c/628936/ Change-Id: I94e853f869db7b0a434a1a05517255ae62131132
This commit is contained in:
parent
02b92c942a
commit
73b4c4ab41
|
@ -157,7 +157,7 @@ command_opt = cfg.SubCommandOpt('command',
|
||||||
def main():
|
def main():
|
||||||
CONF.register_cli_opt(command_opt)
|
CONF.register_cli_opt(command_opt)
|
||||||
CONF(args=sys.argv[1:],
|
CONF(args=sys.argv[1:],
|
||||||
default_config_files=monasca_api.config.get_config_file(None),
|
default_config_files=monasca_api.config.get_config_files(),
|
||||||
prog='api',
|
prog='api',
|
||||||
project='monasca',
|
project='monasca',
|
||||||
version=version.version_str)
|
version=version.version_str)
|
||||||
|
|
|
@ -29,7 +29,7 @@ _CONF_LOADED = False
|
||||||
_GUNICORN_MARKER = 'gunicorn'
|
_GUNICORN_MARKER = 'gunicorn'
|
||||||
|
|
||||||
|
|
||||||
def parse_args(argv=None, config_file=None):
|
def parse_args(argv=None):
|
||||||
"""Loads application configuration.
|
"""Loads application configuration.
|
||||||
|
|
||||||
Loads entire application configuration just once.
|
Loads entire application configuration just once.
|
||||||
|
@ -47,10 +47,10 @@ def parse_args(argv=None, config_file=None):
|
||||||
args = ([] if _is_running_under_gunicorn() else argv or [])
|
args = ([] if _is_running_under_gunicorn() else argv or [])
|
||||||
|
|
||||||
CONF(args=args,
|
CONF(args=args,
|
||||||
prog='api',
|
prog=sys.argv[1:],
|
||||||
project='monasca',
|
project='monasca',
|
||||||
version=version.version_str,
|
version=version.version_str,
|
||||||
default_config_files=get_config_file(config_file),
|
default_config_files=get_config_files(),
|
||||||
description='RESTful API for alarming in the cloud')
|
description='RESTful API for alarming in the cloud')
|
||||||
|
|
||||||
log.setup(CONF,
|
log.setup(CONF,
|
||||||
|
@ -62,19 +62,22 @@ def parse_args(argv=None, config_file=None):
|
||||||
_CONF_LOADED = True
|
_CONF_LOADED = True
|
||||||
|
|
||||||
|
|
||||||
def get_config_file(config_file):
|
def get_config_files():
|
||||||
"""Get config file in a format suitable for CONF constructor
|
"""Get the possible configuration files accepted by oslo.config
|
||||||
|
|
||||||
Returns the config file name as a single element array. If a config file
|
This also includes the deprecated ones
|
||||||
was explicitly, specified, that file's name is returned. If there isn't and a
|
|
||||||
legacy config file is present that one is returned. Otherwise we return
|
|
||||||
None. This is what the CONF constructor expects for its
|
|
||||||
default_config_files keyword argument.
|
|
||||||
"""
|
"""
|
||||||
if config_file is not None:
|
# default files
|
||||||
return [config_file]
|
conf_files = cfg.find_config_files(project='monasca', prog='monasca-api')
|
||||||
|
# deprecated config files (only used if standard config files are not there)
|
||||||
return _get_deprecated_config_file()
|
if len(conf_files) == 0:
|
||||||
|
for prog_name in ['api', 'api-config']:
|
||||||
|
old_conf_files = cfg.find_config_files(project='monasca', prog=prog_name)
|
||||||
|
if len(old_conf_files) > 0:
|
||||||
|
LOG.warning('Found deprecated old location "{}" '
|
||||||
|
'of main configuration file'.format(old_conf_files))
|
||||||
|
conf_files += old_conf_files
|
||||||
|
return conf_files
|
||||||
|
|
||||||
|
|
||||||
def _is_running_under_gunicorn():
|
def _is_running_under_gunicorn():
|
||||||
|
@ -82,23 +85,3 @@ def _is_running_under_gunicorn():
|
||||||
content = filter(lambda x: x != sys.executable and _GUNICORN_MARKER in x,
|
content = filter(lambda x: x != sys.executable and _GUNICORN_MARKER in x,
|
||||||
sys.argv or [])
|
sys.argv or [])
|
||||||
return len(list(content) if not isinstance(content, list) else content) > 0
|
return len(list(content) if not isinstance(content, list) else content) > 0
|
||||||
|
|
||||||
|
|
||||||
def _get_deprecated_config_file():
|
|
||||||
"""Get deprecated config file.
|
|
||||||
|
|
||||||
Responsible for keeping backward compatibility with old name of
|
|
||||||
the configuration file i.e. api-config.conf.
|
|
||||||
New name is => api.conf as prog=api.
|
|
||||||
|
|
||||||
Note:
|
|
||||||
Old configuration file name did not follow a convention
|
|
||||||
oslo_config expects.
|
|
||||||
|
|
||||||
"""
|
|
||||||
old_files = cfg.find_config_files(project='monasca', prog='api-config')
|
|
||||||
if old_files is not None and len(old_files) > 0:
|
|
||||||
LOG.warning('Detected old location "/etc/monasca/api-config.conf" '
|
|
||||||
'of main configuration file')
|
|
||||||
return [old_files[0]]
|
|
||||||
return None
|
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
deprecations:
|
||||||
|
- |
|
||||||
|
Configuration file path /etc/monasca/api-config.conf and
|
||||||
|
/etc/monasca/api.conf are deprecated. Use the standard path
|
||||||
|
/etc/monasca/monasca-api.conf or the configuration dir (supported via
|
||||||
|
oslo.config) /etc/monasca/monasca-api.conf.d/any_config_name.conf
|
Loading…
Reference in New Issue