Add wsgi module to blazar

Changes in python packaging tooling mean that the wsgi_scripts
functionality via PBR may not longer function.

This patch switches blazar from using the PBR wsgi_scripts method to
using a new wsgi module that provides the same behavior as the generated
wsgi scripts provided.

A related devstack patch enables devstack to setup uWSGI to use the new
module path instead of the generated wsgi scripts.

For more details see the proposed OpenStack goal [1].

[1] https://review.opendev.org/c/openstack/governance/+/902807

Change-Id: Ib16d5d1ea5d7416d7b1f026f771d6c2b77657970
This commit is contained in:
Pierre Riteau
2025-05-13 09:09:52 +02:00
parent 2fc005e0e6
commit 3ccbf2ea5c
5 changed files with 55 additions and 2 deletions

0
blazar/wsgi/__init__.py Normal file
View File

24
blazar/wsgi/api.py Normal file
View File

@@ -0,0 +1,24 @@
# 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 application entry-point for the Blazar API."""
import threading
from blazar.api import wsgi_app
application = None
lock = threading.Lock()
with lock:
if application is None:
application = wsgi_app.init_app()

View File

@@ -80,7 +80,7 @@ function configure_blazar {
iniadd $NOVA_CONF filter_scheduler available_filters "blazarnova.scheduler.filters.blazar_filter.BlazarFilter"
if [[ "$BLAZAR_USE_MOD_WSGI" == "True" ]]; then
write_uwsgi_config "$BLAZAR_UWSGI_CONF" "$BLAZAR_UWSGI" "/reservation"
write_uwsgi_config "$BLAZAR_UWSGI_CONF" "$BLAZAR_UWSGI" "/reservation" "" "blazar"
fi
# Database

View File

@@ -31,7 +31,7 @@ BLAZAR_DASHBOARD_DIR=$DEST/blazar-dashboard
# wsgi deployment
BLAZAR_USE_MOD_WSGI=${BLAZAR_USE_MOD_WSGI:-True}
BLAZAR_BIN_DIR=$(get_python_exec_prefix)
BLAZAR_UWSGI=$BLAZAR_BIN_DIR/blazar-api-wsgi
BLAZAR_UWSGI=blazar.wsgi.api:application
BLAZAR_UWSGI_CONF=$BLAZAR_CONF_DIR/blazar-api-uwsgi.ini
BLAZAR_SERVICE_HOST=${BLAZAR_SERVICE_HOST:-$SERVICE_HOST}

View File

@@ -0,0 +1,29 @@
---
features:
- |
A new module, ``blazar.wsgi``, has been added as a place to gather WSGI
``application`` objects. This is intended to ease deployment by providing a
consistent location for these objects. For example, if using uWSGI then
instead of:
.. code-block:: ini
[uwsgi]
wsgi-file = /bin/blazar-api-wsgi
You can now use:
.. code-block:: ini
[uwsgi]
module = blazar.wsgi.api:application
This also simplifies deployment with other WSGI servers that expect module
paths such as gunicorn.
upgrade:
- |
The WSGI script ``blazar-api-wsgi`` has been removed. Deployment tooling
should instead reference the Python module path for the wsgi module in
Blazar, ``blazar.wsgi.api:application`` if their chosen WSGI server
supports this (gunicorn, uWSGI, etc.) or implement a .wsgi script
themselves if not (mod_wsgi).