Make paste.ini file location configurable.

Add an optional paste_deploy.config_file variable to identify
a non-default location for the paste.ini file (the default for
/path/to/component.conf is /path/to/component-paste.ini).

Change-Id: Ibd7aefe95706fb50e4e353c14eb6dab0f948331f
This commit is contained in:
Eoghan Glynn 2012-01-13 15:28:46 +00:00
parent 5835b30cc2
commit 097ced8cb2
3 changed files with 41 additions and 10 deletions
doc/source
glance
common
tests/unit

@ -46,9 +46,14 @@ files distributed with Glance for example configuration files for each server
application with detailed comments on what each options does.
The PasteDeploy configuration (controlling the deployment of the WSGI
application for each component) may be found in <component>-paste.ini
alongside the main configuration file, <component>.conf. For example,
``glance-api-paste.ini`` corresponds to ``glance-api.conf``.
application for each component) may be found by default in
<component>-paste.ini alongside the main configuration file, <component>.conf.
For example, ``glance-api-paste.ini`` corresponds to ``glance-api.conf``.
This pathname for the paste config is configurable, as follows:
[paste_deploy]
config_file = /path/to/paste/config
Common Configuration Options in Glance
--------------------------------------

@ -34,6 +34,7 @@ from glance.common import wsgi
paste_deploy_group = cfg.OptGroup('paste_deploy')
paste_deploy_opts = [
cfg.StrOpt('flavor'),
cfg.StrOpt('config_file'),
]
@ -124,6 +125,24 @@ def _get_deployment_flavor(conf):
return '' if not flavor else ('-' + flavor)
def _get_deployment_config_file(conf):
"""
Retrieve the deployment_config_file config item, formatted as an
absolute pathname.
:param conf: a cfg.ConfigOpts object
"""
_register_paste_deploy_opts(conf)
config_file = conf.paste_deploy.config_file
if not config_file:
# Assume paste config is in a paste.ini file corresponding
# to the last config file
path = conf.config_file[-1].replace(".conf", "-paste.ini")
else:
path = config_file
return os.path.abspath(path)
def load_paste_app(conf, app_name=None):
"""
Builds and returns a WSGI app from a paste config file.
@ -144,10 +163,7 @@ def load_paste_app(conf, app_name=None):
# in order to identify the appropriate paste pipeline
app_name += _get_deployment_flavor(conf)
# Assume paste config is in a paste.ini file corresponding
# to the last config file
conf_file = os.path.abspath(conf.config_file[-1].replace(".conf",
"-paste.ini"))
conf_file = _get_deployment_config_file(conf)
try:
# Setup logging early

@ -40,6 +40,7 @@ class TestPasteApp(unittest.TestCase):
def _do_test_load_paste_app(self,
expected_app_type,
paste_group={},
paste_copy=True,
paste_append=None):
conf = test_utils.TestConfigOpts(groups=paste_group)
@ -50,10 +51,11 @@ class TestPasteApp(unittest.TestCase):
f.write(str or '')
f.flush()
paste_from = os.path.join(os.getcwd(), 'etc/glance-api-paste.ini')
paste_to = os.path.join(conf.temp_file.replace('.conf',
if paste_copy:
paste_from = os.path.join(os.getcwd(), 'etc/glance-api-paste.ini')
paste_to = os.path.join(conf.temp_file.replace('.conf',
'-paste.ini'))
_appendto(paste_from, paste_to, paste_append)
_appendto(paste_from, paste_to, paste_append)
app = config.load_paste_app(conf, 'glance-api')
@ -71,6 +73,14 @@ class TestPasteApp(unittest.TestCase):
type = context.ContextMiddleware
self._do_test_load_paste_app(type, paste_group, paste_append=pipeline)
def test_load_paste_app_with_paste_config_file(self):
paste_config_file = os.path.join(os.getcwd(),
'etc/glance-api-paste.ini')
paste_group = {'paste_deploy': {'config_file': paste_config_file}}
type = version_negotiation.VersionNegotiationFilter
self._do_test_load_paste_app(type, paste_group, paste_copy=False)
def test_load_paste_app_with_conf_name(self):
def fake_join(*args):
if len(args) == 2 and \