Merge "Support sys.argv in wsgi app"

This commit is contained in:
Zuul 2020-11-28 06:07:39 +00:00 committed by Gerrit Code Review
commit f526685104
3 changed files with 30 additions and 1 deletions

View File

@ -12,6 +12,7 @@
"""WSGI application initialization for Nova APIs."""
import os
import sys
from oslo_config import cfg
from oslo_log import log as logging
@ -76,7 +77,9 @@ def error_application(exc, name):
def init_application(name):
conf_files = _get_config_files()
config.parse_args([], default_config_files=conf_files)
# NOTE(gibi): sys.argv is set by the wsgi runner e.g. uwsgi sets it based
# on the --pyargv parameter of the uwsgi binary
config.parse_args(sys.argv, default_config_files=conf_files)
logging.setup(CONF, "nova")

View File

@ -19,11 +19,16 @@
Test WSGI basics and provide some helper functions for other WSGI tests.
"""
import sys
import mock
import routes
import webob
from nova.api.openstack import wsgi_app
from nova.api import wsgi
from nova import test
from nova import utils
class Test(test.NoDBTestCase):
@ -49,3 +54,15 @@ class Test(test.NoDBTestCase):
self.assertEqual(result.body, "Router result")
result = webob.Request.blank('/bad').get_response(Router())
self.assertNotEqual(result.body, "Router result")
@mock.patch('nova.api.openstack.wsgi_app._setup_service', new=mock.Mock())
@mock.patch('paste.deploy.loadapp', new=mock.Mock())
def test_init_application_passes_sys_argv_to_config(self):
with utils.temporary_mutation(sys, argv=mock.sentinel.argv):
with mock.patch('nova.config.parse_args') as mock_parse_args:
wsgi_app.init_application('test-app')
mock_parse_args.assert_called_once_with(
mock.sentinel.argv,
default_config_files=[
'/etc/nova/api-paste.ini', '/etc/nova/nova.conf'])

View File

@ -0,0 +1,9 @@
---
features:
- |
Now nova-api and nova-api-metadata WSGI services support command line
arguments similarly to other nova services. For example these services
now support specifying mutliple config files via --config-file parameter.
Please note that passing command line arguments to WSGI apps depends on
the given WSGI runner. For example uwsgi supports this via the --pyargv
parameter of the uwsgi binary.