Skip to content

Commit d92d093

Browse files
SeanMooneygibizer
authored andcommitted
Support multiple config file with mod_wsgi
Unlike uwsgi, apache mod_wsgi does not support passing commandline arguments to the python wsgi script it invokes. As a result while you can pass --config-file when hosting the api and metadata wsgi applications with uwsgi there is no way to use multiple config files with mod_wsgi. This change mirrors how this is supported in keystone today by intoducing a new OS_NOVA_CONFIG_FILES env var to allow operators to optional pass a ';' delimited list of config files to load. This change also add docs for this env var and the existing undocumented OS_NOVA_CONFIG_DIR. Closes-Bug: 1994056 Change-Id: I8e3ccd75cbb7f2e132b403cb38022787c2c0a37b (cherry picked from commit 73fe84f)
1 parent 0ebcc5f commit d92d093

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

doc/source/user/wsgi.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@ as Apache_ or nginx_).
88

99
The nova project provides two automatically generated entry points that
1010
support this: ``nova-api-wsgi`` and ``nova-metadata-wsgi``. These read
11-
``nova.conf`` and ``api-paste.ini`` and generate the required module-level
12-
``application`` that most WSGI servers require. If nova is installed using pip,
13-
these two scripts will be installed into whatever the expected ``bin``
14-
directory is for the environment.
11+
``nova.conf`` and ``api-paste.ini`` by default and generate the required
12+
module-level ``application`` that most WSGI servers require.
13+
If nova is installed using pip, these two scripts will be installed into
14+
whatever the expected ``bin`` directory is for the environment.
15+
16+
The config files and config directory can be overridden via the
17+
``OS_NOVA_CONFIG_FILES`` and ``OS_NOVA_CONFIG_DIR`` environment variables.
18+
File paths listed in ``OS_NOVA_CONFIG_FILES`` are relative to
19+
``OS_NOVA_CONFIG_DIR`` and delimited by ``;``.
20+
1521

1622
The new scripts replace older experimental scripts that could be found in the
1723
``nova/wsgi`` directory of the code repository. The new scripts are *not*

nova/api/openstack/wsgi_app.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ def _get_config_files(env=None):
4242
if env is None:
4343
env = os.environ
4444
dirname = env.get('OS_NOVA_CONFIG_DIR', '/etc/nova').strip()
45+
files = env.get('OS_NOVA_CONFIG_FILES', '').split(';')
46+
if files == ['']:
47+
files = CONFIG_FILES
4548
return [os.path.join(dirname, config_file)
46-
for config_file in CONFIG_FILES]
49+
for config_file in files]
4750

4851

4952
def _setup_service(host, name):

nova/tests/unit/api/openstack/test_wsgi_app.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,18 @@ def test_setup_service_version_workaround(self, mock_check_old, mock_get):
104104
'disable_compute_service_check_for_ffu', True,
105105
group='workarounds')
106106
wsgi_app._setup_service('myhost', 'api')
107+
108+
def test__get_config_files_empty_env(self):
109+
env = {}
110+
result = wsgi_app._get_config_files(env)
111+
expected = ['/etc/nova/api-paste.ini', '/etc/nova/nova.conf']
112+
self.assertEqual(result, expected)
113+
114+
def test__get_config_files_with_env(self):
115+
env = {
116+
"OS_NOVA_CONFIG_DIR": "/nova",
117+
"OS_NOVA_CONFIG_FILES": "api.conf",
118+
}
119+
result = wsgi_app._get_config_files(env)
120+
expected = ['/nova/api.conf']
121+
self.assertEqual(result, expected)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
fixes:
3+
- |
4+
apache mod_wsgi does not support passing commandline arguments to the wsgi
5+
application that it hosts. As a result when the nova api or metadata api
6+
where run under mod_wsgi it was not posible to use multiple config files
7+
or non-default file names i.e. nova-api.conf
8+
This has been adressed by the intoduction of a new, optional, envionment
9+
varible ``OS_NOVA_CONFIG_FILES``. ``OS_NOVA_CONFIG_FILES`` is a ``;``
10+
seperated list fo file path relitive to ``OS_NOVA_CONFIG_DIR``.
11+
When unset the default ``api-paste.ini`` and ``nova.conf`` will be used
12+
form ``/etc/nova``. This is supported for the nova api and nova metadata
13+
wsgi applications.
14+

0 commit comments

Comments
 (0)