wsgi: use environment variables through the application method
This is equivalent to the patch we used to resolve issues with the sqlite wsgi script [1]. Environment variables are not expected to be available from os.environ but instead from the environ variable of the application method. [1]: https://review.openstack.org/#/c/571699/ Change-Id: Icc76d67052e23ec1b529a914ba39a7cc401119c9
This commit is contained in:
parent
8678470229
commit
50789d4d59
31
ara/wsgi.py
31
ara/wsgi.py
|
@ -35,21 +35,6 @@ import logging
|
|||
import six
|
||||
import threading
|
||||
|
||||
if (int(os.getenv('ARA_WSGI_USE_VIRTUALENV', 0)) == 1 and
|
||||
os.getenv('ARA_WSGI_VIRTUALENV_PATH')):
|
||||
# Backwards compatibility, we did not always suffix activate_this.py
|
||||
activate_this = os.getenv('ARA_WSGI_VIRTUALENV_PATH')
|
||||
if 'activate_this.py' not in activate_this:
|
||||
activate_this = os.path.join(activate_this, 'bin/activate_this.py')
|
||||
|
||||
if six.PY2:
|
||||
execfile(activate_this, dict(__file__=activate_this)) # nosec
|
||||
else:
|
||||
exec(open(activate_this).read()) # nosec
|
||||
|
||||
from ara.webapp import create_app # flake8: noqa
|
||||
from flask import current_app # flake8: noqa
|
||||
|
||||
app = None
|
||||
app_making_lock = threading.Lock()
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -57,11 +42,27 @@ log = logging.getLogger(__name__)
|
|||
|
||||
def application(environ, start_response):
|
||||
global app
|
||||
|
||||
# Load virtualenv if necessary
|
||||
if (int(environ.get('ARA_WSGI_USE_VIRTUALENV', 0)) == 1 and
|
||||
environ.get('ARA_WSGI_VIRTUALENV_PATH')):
|
||||
# Backwards compatibility, we did not always suffix activate_this.py
|
||||
activate_this = environ.get('ARA_WSGI_VIRTUALENV_PATH')
|
||||
if 'activate_this.py' not in activate_this:
|
||||
activate_this = os.path.join(activate_this, 'bin/activate_this.py')
|
||||
if six.PY2:
|
||||
execfile(activate_this, dict(__file__=activate_this)) # nosec
|
||||
else:
|
||||
exec(open(activate_this).read()) # nosec
|
||||
|
||||
if 'ANSIBLE_CONFIG' in environ:
|
||||
os.environ['ANSIBLE_CONFIG'] = environ['ANSIBLE_CONFIG']
|
||||
else:
|
||||
if 'ANSIBLE_CONFIG' not in os.environ:
|
||||
log.warn('ANSIBLE_CONFIG environment variable not found.')
|
||||
|
||||
from ara.webapp import create_app # flake8: noqa
|
||||
from flask import current_app # flake8: noqa
|
||||
with app_making_lock:
|
||||
if app is None:
|
||||
app = create_app()
|
||||
|
|
Loading…
Reference in New Issue