Create new wsgi.py file and deprecate old file

Django 1.4 stopped creating django.wsgi files and the common
practice now for a while has been a wsgi.py since it is actually
python code, and should actually be importable.

Right now someone has to copy and rename the existing file if they
want to use it with a server like gunicorn.

This patch adds a new file in location that is importable via python
and adds a deprecation log to the old one.

This also updates the wsgi generation commands to instead  create
'horizon_wsgi.py' and have the apache conf generation also use that
or the default wsgi file.

Change-Id: I0f8bd16c8973ad23bcd8f73b54584dc69e5aed0c
Closes-Bug: #1763204
This commit is contained in:
Adrian Turjak 2018-04-17 18:27:27 +12:00
parent 0080405eb5
commit 0ca736e5da
7 changed files with 63 additions and 10 deletions

1
.gitignore vendored
View File

@ -31,6 +31,7 @@ openstack_dashboard/test/.secret_key_store
openstack_dashboard/test/integration_tests/local-horizon.conf
openstack_dashboard/test/integration_tests/test_reports/
openstack_dashboard/wsgi/horizon.wsgi
openstack_dashboard/horizon_wsgi.py
doc/build/
/static/
integration_tests_screenshots/

View File

@ -341,10 +341,10 @@ Use a domain that fits your current setup.
.. code-block:: apacheconf
WSGIScriptAlias / /usr/share/openstack-dashboard/openstack_dashboard/wsgi/django.wsgi
WSGIScriptAlias / /usr/share/openstack-dashboard/openstack_dashboard/wsgi.py
WSGIDaemonProcess horizon user=www-data group=www-data processes=3 threads=10
Alias /static /usr/share/openstack-dashboard/openstack_dashboard/static/
<Directory /usr/share/openstack-dashboard/openstack_dashboard/wsgi>
<Directory /usr/share/openstack-dashboard/openstack_dashboard>
# For Apache http server 2.2 and earlier:
Order allow,deny
Allow from all
@ -385,10 +385,10 @@ Use a domain that fits your current setup.
# wire
Header add Strict-Transport-Security "max-age=15768000"
WSGIScriptAlias / /usr/share/openstack-dashboard/openstack_dashboard/wsgi/django.wsgi
WSGIScriptAlias / /usr/share/openstack-dashboard/openstack_dashboard/wsgi.py
WSGIDaemonProcess horizon user=www-data group=www-data processes=3 threads=10
Alias /static /usr/share/openstack-dashboard/openstack_dashboard/static/
<Directory /usr/share/openstack-dashboard/openstack_dashboard/wsgi>
<Directory /usr/share/openstack-dashboard/openstack_dashboard>
# For Apache http server 2.2 and earlier:
<ifVersion <2.4>
Order allow,deny

View File

@ -170,8 +170,8 @@ Deployment
$ sudo apt-get install apache2 libapache2-mod-wsgi
You can either use the provided ``openstack_dashboard/wsgi/django.wsgi`` or
generate a ``openstack_dashboard/wsgi/horizon.wsgi`` file with the following
You can either use the provided ``openstack_dashboard/wsgi.py`` or
generate a ``openstack_dashboard/horizon_wsgi.py`` file with the following
command (which detects if you use a virtual environment or not to
automatically build an adapted WSGI file)
@ -184,8 +184,9 @@ Deployment
``/etc/apache2/sites-available/horizon.conf``.
The template in DevStack is a good example of the file.
http://git.openstack.org/cgit/openstack-dev/devstack/tree/files/apache-horizon.template
Or, if you previously generated an ``openstack_dashboard/wsgi/horizon.wsgi``
you can automatically generate an apache configuration file
Or you can automatically generate an apache configuration file. If you
previously generated an ``openstack_dashboard/horizon_wsgi.py`` file it will
use that, otherwise will default to using ``openstack_dashboard/wsgi.py``
.. code-block:: console

View File

@ -85,8 +85,10 @@ context['PROJECT_DIR_NAME'] = os.path.basename(
context['PROJECT_PATH'].split(context['PROJECT_ROOT'])[1])
context['PROJECT_NAME'] = context['PROJECT_DIR_NAME']
context['DEFAULT_WSGI_FILE'] = os.path.join(
context['PROJECT_PATH'], 'wsgi.py')
context['WSGI_FILE'] = os.path.join(
context['PROJECT_PATH'], 'wsgi/horizon.wsgi')
context['PROJECT_PATH'], 'horizon_wsgi.py')
VHOSTNAME = context['HOSTNAME'].split('.')
VHOSTNAME[0] = context['PROJECT_NAME']
@ -316,6 +318,10 @@ location you desire, e.g.::
# Generate the apache configuration.
elif options.get('apache'):
# first check if custom wsgi file exists, if not, use default:
if not os.path.exists(context['WSGI_FILE']):
context['WSGI_FILE'] = context['DEFAULT_WSGI_FILE']
with open(
os.path.join(CURDIR, 'apache_vhost.conf.template'), 'r'
) as fp:

View File

@ -0,0 +1,29 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
WSGI config for openstack_dashboard project.
"""
import os
import sys
from django.core.wsgi import get_wsgi_application
# Add this file path to sys.path in order to import settings
sys.path.insert(0, os.path.normpath(os.path.join(
os.path.dirname(os.path.realpath(__file__)), '../..')))
os.environ['DJANGO_SETTINGS_MODULE'] = 'openstack_dashboard.settings'
sys.stdout = sys.stderr
application = get_wsgi_application()

View File

@ -17,6 +17,7 @@
WSGI config for openstack_dashboard project.
"""
import logging
import os
import sys
@ -28,6 +29,12 @@ sys.path.insert(0, os.path.normpath(os.path.join(
os.environ['DJANGO_SETTINGS_MODULE'] = 'openstack_dashboard.settings'
sys.stdout = sys.stderr
DEBUG = False
logging.warning(
"Use of this 'djano.wsgi' file has been deprecated since the Rocky "
"release in favor of 'wsgi.py' in the 'openstack_dashboard' module. This "
"file is a legacy naming from before Django 1.4 and an importable "
"'wsgi.py' is now the default. This file will be removed in the T release "
"cycle."
)
application = get_wsgi_application()

View File

@ -0,0 +1,9 @@
---
deprecations:
- |
[:bug:`1763204`]
Use of this 'djano.wsgi' file has been deprecated since the Rocky
release in favor of 'wsgi.py' in the 'openstack_dashboard' module. This
file is a legacy naming from before Django 1.4 and an importable
'wsgi.py' is now the default. This file will be removed in the T release
cycle.