From 0ca736e5da47413db6749053e6083b82cbb24825 Mon Sep 17 00:00:00 2001 From: Adrian Turjak Date: Tue, 17 Apr 2018 18:27:27 +1200 Subject: [PATCH] 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 --- .gitignore | 1 + doc/source/admin/customize-configure.rst | 8 ++--- doc/source/install/from-source.rst | 9 +++--- .../management/commands/make_web_conf.py | 8 ++++- openstack_dashboard/wsgi.py | 29 +++++++++++++++++++ openstack_dashboard/wsgi/django.wsgi | 9 +++++- ...ion-of-old-wsgi-file-7ffdeae78698ff93.yaml | 9 ++++++ 7 files changed, 63 insertions(+), 10 deletions(-) create mode 100644 openstack_dashboard/wsgi.py create mode 100644 releasenotes/notes/deprecation-of-old-wsgi-file-7ffdeae78698ff93.yaml diff --git a/.gitignore b/.gitignore index 71262df06c..90a371676d 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ diff --git a/doc/source/admin/customize-configure.rst b/doc/source/admin/customize-configure.rst index 1ba7890f19..26bc9d0e32 100644 --- a/doc/source/admin/customize-configure.rst +++ b/doc/source/admin/customize-configure.rst @@ -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/ - + # 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/ - + # For Apache http server 2.2 and earlier: Order allow,deny diff --git a/doc/source/install/from-source.rst b/doc/source/install/from-source.rst index 815d06e0ed..cacc405276 100644 --- a/doc/source/install/from-source.rst +++ b/doc/source/install/from-source.rst @@ -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 diff --git a/openstack_dashboard/management/commands/make_web_conf.py b/openstack_dashboard/management/commands/make_web_conf.py index f663ccfa4a..080e88f59e 100644 --- a/openstack_dashboard/management/commands/make_web_conf.py +++ b/openstack_dashboard/management/commands/make_web_conf.py @@ -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: diff --git a/openstack_dashboard/wsgi.py b/openstack_dashboard/wsgi.py new file mode 100644 index 0000000000..59f75dd683 --- /dev/null +++ b/openstack_dashboard/wsgi.py @@ -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() diff --git a/openstack_dashboard/wsgi/django.wsgi b/openstack_dashboard/wsgi/django.wsgi index fae25b374e..89fda5688a 100644 --- a/openstack_dashboard/wsgi/django.wsgi +++ b/openstack_dashboard/wsgi/django.wsgi @@ -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() diff --git a/releasenotes/notes/deprecation-of-old-wsgi-file-7ffdeae78698ff93.yaml b/releasenotes/notes/deprecation-of-old-wsgi-file-7ffdeae78698ff93.yaml new file mode 100644 index 0000000000..20a8ca4532 --- /dev/null +++ b/releasenotes/notes/deprecation-of-old-wsgi-file-7ffdeae78698ff93.yaml @@ -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.