From 61b81d0c735f7d4ccbde4f4c818e4a7320ea544a Mon Sep 17 00:00:00 2001 From: Vasyl Saienko Date: Mon, 25 Sep 2017 10:44:09 +0300 Subject: [PATCH] Add uWSGI support This patch implements uWSGI support for ironic API service. ironic/api/app.wsgi is deprecated in favor of pbr generated ironic-api-wsgi Co-Authored-By: anascko Change-Id: Ieb68c1042e31b77f9a549fd90afe31a65008deca Closes-Bug: #1719260 Closes-Bug: #1668966 --- .../include/configure-ironic-api-mod_wsgi.rst | 9 ++-- etc/apache2/ironic | 5 ++- ironic/api/app.wsgi | 22 +--------- ironic/api/wsgi.py | 41 +++++++++++++++++++ .../wsgi-applications-5d36cf2a8885a56d.yaml | 10 +++++ setup.cfg | 3 ++ 6 files changed, 64 insertions(+), 26 deletions(-) create mode 100644 ironic/api/wsgi.py create mode 100644 releasenotes/notes/wsgi-applications-5d36cf2a8885a56d.yaml diff --git a/doc/source/install/include/configure-ironic-api-mod_wsgi.rst b/doc/source/install/include/configure-ironic-api-mod_wsgi.rst index 2130842c7a..e23acc3cbb 100644 --- a/doc/source/install/include/configure-ironic-api-mod_wsgi.rst +++ b/doc/source/install/include/configure-ironic-api-mod_wsgi.rst @@ -43,8 +43,9 @@ Bare Metal service comes with an example file for configuring the ``APACHE_RUN_GROUP`` directives to set the user and group values to an appropriate user on your server. - #. Modify the ``WSGIScriptAlias`` directive to point to the - ``ironic/api/app.wsgi`` script. + #. Modify the ``WSGIScriptAlias`` directive to point to the automatically + generated ``ironic-api-wsgi`` script that is located in `IRONIC_BIN` + directory. #. Modify the ``Directory`` directive to set the path to the Ironic API code. @@ -68,5 +69,5 @@ Bare Metal service comes with an example file for configuring the sudo systemctl reload apache2 .. note:: - The file ``ironic/api/app.wsgi`` is installed with the rest of the Bare Metal - service application code, and should not need to be modified. + The file ``ironic-api-wsgi`` is automatically generated by pbr and is + available in `IRONIC_BIN` directory. It should not be modified. diff --git a/etc/apache2/ironic b/etc/apache2/ironic index 290b3c548f..c1640393b7 100644 --- a/etc/apache2/ironic +++ b/etc/apache2/ironic @@ -12,13 +12,14 @@ # This is an example Apache2 configuration file for using the # Ironic API through mod_wsgi. This version assumes you are -# running devstack to configure the software. +# running devstack to configure the software, and PBR has generated +# and installed the ironic-api-wsgi script while installing ironic. Listen 6385 WSGIDaemonProcess ironic user=stack group=stack threads=10 display-name=%{GROUP} - WSGIScriptAlias / /opt/stack/ironic/ironic/api/app.wsgi + WSGIScriptAlias / /usr/local/bin/ironic-api-wsgi SetEnv APACHE_RUN_USER stack SetEnv APACHE_RUN_GROUP stack diff --git a/ironic/api/app.wsgi b/ironic/api/app.wsgi index 5c26248ecd..d9e5c053b3 100644 --- a/ironic/api/app.wsgi +++ b/ironic/api/app.wsgi @@ -16,24 +16,6 @@ Use this file for deploying the API service under Apache2 mod_wsgi. """ -import sys +from ironic.api import wsgi -from oslo_config import cfg -import oslo_i18n as i18n -from oslo_log import log - -from ironic.api import app -from ironic.common import service - - -CONF = cfg.CONF - -i18n.install('ironic') - -service.prepare_service(sys.argv) - -LOG = log.getLogger(__name__) -LOG.debug("Configuration:") -CONF.log_opt_values(LOG, log.DEBUG) - -application = app.VersionSelectorApplication() +application = wsgi.initialize_wsgi_app(show_deprecated=True) diff --git a/ironic/api/wsgi.py b/ironic/api/wsgi.py new file mode 100644 index 0000000000..7daf19980c --- /dev/null +++ b/ironic/api/wsgi.py @@ -0,0 +1,41 @@ +# 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 script for Ironic API, installed by pbr.""" + +import sys + +from oslo_config import cfg +import oslo_i18n as i18n +from oslo_log import log + +from ironic.api import app +from ironic.common import service + + +CONF = cfg.CONF +LOG = log.getLogger(__name__) + + +def initialize_wsgi_app(show_deprecated=False): + i18n.install('ironic') + + service.prepare_service(sys.argv) + + LOG.debug("Configuration:") + CONF.log_opt_values(LOG, log.DEBUG) + + if show_deprecated: + LOG.warning("Using ironic/api/app.wsgi is deprecated and it will " + "be removed in Rocky release. Please use automatically " + "generated ironic-api-wsgi instead.") + + return app.VersionSelectorApplication() diff --git a/releasenotes/notes/wsgi-applications-5d36cf2a8885a56d.yaml b/releasenotes/notes/wsgi-applications-5d36cf2a8885a56d.yaml new file mode 100644 index 0000000000..06f75cbbfa --- /dev/null +++ b/releasenotes/notes/wsgi-applications-5d36cf2a8885a56d.yaml @@ -0,0 +1,10 @@ +--- +upgrade: + - An Ironic API WSGI application script ``ironic-api-wsgi`` is now available. + It is auto-generated by ``pbr`` and allows to run the API service + using WSGI server (for example Nginx and uWSGI or Apache with mod_wsgi). +deprecations: + - Using ``ironic/api/app.wsgi`` script is deprecated and it will be removed + in Rocky release. + Please switch to automatically generated ``ironic-api-wsgi`` script + instead. diff --git a/setup.cfg b/setup.cfg index 9ed647b558..e2153f4d42 100644 --- a/setup.cfg +++ b/setup.cfg @@ -44,6 +44,9 @@ console_scripts = ironic-conductor = ironic.cmd.conductor:main ironic-rootwrap = oslo_rootwrap.cmd:main +wsgi_scripts = + ironic-api-wsgi = ironic.api.wsgi:initialize_wsgi_app + ironic.dhcp = neutron = ironic.dhcp.neutron:NeutronDHCPApi none = ironic.dhcp.none:NoneDHCPApi