From b6de4720db0c0e23ac2bd6d26b585c8dc8ca612d Mon Sep 17 00:00:00 2001 From: Winson Chan Date: Wed, 10 May 2017 21:31:42 +0000 Subject: [PATCH] Fix WSGI script for gunicorn The previous patch to add support for apache breaks gunicorn. The gunicorn setup loads the mistral.api.wsgi module and requires the application variable be assigned. The support for apache make the assumption that the mistral.api.wsgi be called as a python script. This patch moves the init function required by apache to a different location. Change-Id: Ib5af50a55d3f3bb9d0fa0d1ee6b8e7564f909d70 Closes-Bug: #1689943 --- mistral/api/app.py | 9 +++++++++ mistral/api/wsgi.py | 14 +------------- setup.cfg | 2 +- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/mistral/api/app.py b/mistral/api/app.py index 3156e2697..d3fdf02bb 100644 --- a/mistral/api/app.py +++ b/mistral/api/app.py @@ -83,3 +83,12 @@ def setup_app(config=None): # Create a CORS wrapper, and attach mistral-specific defaults that must be # included in all CORS responses. return cors_middleware.CORS(app, cfg.CONF) + + +def init_wsgi(): + # By default, oslo.config parses the CLI args if no args is provided. + # As a result, invoking this wsgi script from gunicorn leads to the error + # with argparse complaining that the CLI options have already been parsed. + m_config.parse_args(args=[]) + + return setup_app() diff --git a/mistral/api/wsgi.py b/mistral/api/wsgi.py index 949d9b522..27866f0c1 100644 --- a/mistral/api/wsgi.py +++ b/mistral/api/wsgi.py @@ -13,17 +13,5 @@ # limitations under the License. from mistral.api import app -from mistral import config - -# By default, oslo.config parses the CLI args if no args is provided. -# As a result, invoking this wsgi script from gunicorn leads to the error -# with argparse complaining that the CLI options have already been parsed. -def init_application(): - config.parse_args(args=[]) - - return app.setup_app() - - -if __name__ == '__main__': - application = init_application() +application = app.init_wsgi() diff --git a/setup.cfg b/setup.cfg index b9bfc51dd..d58f95b95 100644 --- a/setup.cfg +++ b/setup.cfg @@ -38,7 +38,7 @@ console_scripts = mistral-db-manage = mistral.db.sqlalchemy.migration.cli:main wsgi_scripts = - mistral-wsgi-api = mistral.api.wsgi:init_application + mistral-wsgi-api = mistral.api.app:init_wsgi mistral.rpc.backends = oslo_client = mistral.rpc.oslo.oslo_client:OsloRPCClient