Add wsgi module to freezer-api

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

We migrate freezer to use wsgi modules to ensure consistent behavior
and achieve the community goal.

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

We also fix compatability with Falcon 4.1 which is a requirements for
2026.1

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

Change-Id: I6f73ee5fe6194d2a5390dfb5389e336719332cb1
Signed-off-by: Dmitriy Rabotyagov <noonedeadpunk@gmail.com>
This commit is contained in:
Dmitriy Rabotyagov
2025-11-21 13:30:57 +01:00
parent 1e6302cd1e
commit 28bdf236fe
9 changed files with 81 additions and 15 deletions

View File

@@ -143,6 +143,11 @@ function configure_freezer_api {
sudo chown $STACK_USER $FREEZER_API_AUTH_CACHE_DIR/registry
rm -f $FREEZER_API_AUTH_CACHE_DIR/registry/*
# configure logs
if [ -n "$BASE" ] && [ -d "$BASE/logs" ]; then
sudo ln -sf $FREEZER_API_LOG_DIR/freezer-api.log $BASE/logs/freezer-api-post.log
fi
# set keystone configuration
configure_auth_token_middleware $FREEZER_API_CONF freezer $FREEZER_API_AUTH_CACHE_DIR/api
@@ -299,7 +304,7 @@ function configure_uwsgi_freezer_api_app {
iniset $FREEZER_API_UWSGI_CONF 'uwsgi' http $local_http
iniset $FREEZER_API_UWSGI_CONF 'uwsgi' processes 2
iniset $FREEZER_API_UWSGI_CONF 'uwsgi' threads 2
iniset $FREEZER_API_UWSGI_CONF 'uwsgi' wsgi-file $FREEZER_API_DIR/freezer_api/cmd/wsgi.py
iniset $FREEZER_API_UWSGI_CONF 'uwsgi' wsgi freezer_api.wsgi:application
# Make sure the client doesn't try to re-use the connection.
iniset $FREEZER_API_UWSGI_CONF 'uwsgi' add-header "Connection: close"

View File

@@ -10,8 +10,8 @@ paste.app_factory = freezer_api.service:freezer_appv2_factory
[filter:authtoken]
paste.filter_factory = keystonemiddleware.auth_token:filter_factory
[filter:healthcheck]
paste.filter_factory = oslo_middleware:Healthcheck.factory
[app:healthcheck]
paste.app_factory = oslo_middleware:Healthcheck.app_factory
backends = disable_by_file
disable_by_file_path = /etc/freezer/healthcheck_disable
@@ -24,11 +24,21 @@ paste.filter_factory = freezer_api.api.versions:VersionNegotiator.factory
[filter:http_proxy_to_wsgi]
paste.filter_factory = oslo_middleware:HTTPProxyToWSGI.factory
[pipeline:main]
pipeline = healthcheck http_proxy_to_wsgi versionsNegotiator authtoken context backupapp
[composite:main]
use = egg:Paste#urlmap
/healthcheck = healthcheck
/ = api
[pipeline:unauthenticated_freezer_api]
pipeline = http_proxy_to_wsgi healthcheck freezer_app
[pipeline:api]
pipeline = http_proxy_to_wsgi versionsNegotiator authtoken context backupapp
[composite:unauthenticated_freezer_api]
use = egg:Paste#urlmap
/healthcheck = healthcheck
/ = unauthenticated_api
[pipeline:unauthenticated_api]
pipeline = http_proxy_to_wsgi freezer_app
[composite:backupapp]
paste.composite_factory = freezer_api.service:root_app_factory

View File

@@ -5,7 +5,7 @@ strict = true
http = :9090
processes = 2
threads = 2
wsgi-file = /opt/stack/freezer-api/freezer_api/cmd/wsgi.py
wsgi = freezer_api.wsgi:application
callable = app
master = true
add-header = Connection: close

View File

@@ -131,7 +131,8 @@ class RequireJSON(HookableMiddlewareMixin, object):
def process_request(self, req, resp):
if not req.client_accepts_json:
raise falcon.HTTPNotAcceptable(
'Freezer-api only supports responses encoded as JSON.',
description='Freezer-api only supports responses encoded '
'as JSON.',
href='http://docs.examples.com/api/json')

View File

@@ -38,5 +38,5 @@ class BaseResource(object):
json_data = json.loads(raw_json, encoding='utf-8')
except ValueError:
raise falcon.HTTPError(falcon.HTTP_753,
'Malformed JSON')
title='Malformed JSON')
return json_data

24
freezer_api/wsgi.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 freezer_api.service import initialize_app
application = None
lock = threading.Lock()
with lock:
if application is None:
application = initialize_app()

View File

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

View File

@@ -30,9 +30,9 @@ extensions = [
]
# openstackdocstheme options
repository_name = 'openstack/freezer-api'
bug_project = 'freezer'
bug_tag = 'release notes'
openstackdocs_repo_name = 'openstack/freezer-api'
openstackdocs_bug_project = 'freezer'
openstackdocs_bug_tag = 'release notes'
html_last_updated_fmt = '%Y-%m-%d %H:%M'

View File

@@ -50,8 +50,6 @@ console_scripts =
freezer-api = freezer_api.cmd.api:main
freezer-manage = freezer_api.cmd.manage:main
freezer-manager-status = freezer_api.cmd.status:main
wsgi_scripts =
freezer-api-wsgi = freezer_api.service:initialize_app
freezer.db.backends =
sqlalchemy = freezer_api.db.sqlalchemy.driver:SQLDriver