lib/apache: Use module paths instead of WSGI scripts

pbr's 'wsgi_scripts' entrypoint functionality is not long for this world
so we need to start working towards an alternative. We could start
packaging our own WSGI scripts in DevStack but using module paths seems
like a better option, particularly when it's supported by other WSGI
servers like gunicorn.

Currently only nova is migrated. We should switch additional projects as
they migrate and eventually remove the support for WSGI scripts
entirely.

Change-Id: I057dc635c01e54740ee04dfe7b39ef83db5dc180
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
Depends-on: https://review.opendev.org/c/openstack/nova/+/902687/
This commit is contained in:
Stephen Finucane 2023-12-06 10:22:30 +00:00
parent e2aeab1bc1
commit b6613b1e71
2 changed files with 32 additions and 9 deletions

View File

@ -237,13 +237,17 @@ function restart_apache_server {
restart_service $APACHE_NAME
}
# write_uwsgi_config() - Create a new uWSGI config file
function write_uwsgi_config {
local conf=$1
local wsgi=$2
local url=$3
local http=$4
local name=""
name=$(basename $wsgi)
local name=$5
if [ -z "$name" ]; then
name=$(basename $wsgi)
fi
# create a home for the sockets; note don't use /tmp -- apache has
# a private view of it on some platforms.
@ -259,7 +263,15 @@ function write_uwsgi_config {
# always cleanup given that we are using iniset here
rm -rf $conf
iniset "$conf" uwsgi wsgi-file "$wsgi"
# Set either the module path or wsgi script path depending on what we've
# been given. Note that the regex isn't exhaustive - neither Python modules
# nor Python variables can start with a number - but it's "good enough"
if [[ "$wsgi" =~ ^[a-zA-Z0-9_.]+:[a-zA-Z0-9_]+$ ]]; then
iniset "$conf" uwsgi module "$wsgi"
else
deprecated 'Configuring uWSGI with a WSGI file is deprecated, use module paths instead'
iniset "$conf" uwsgi wsgi-file "$wsgi"
fi
iniset "$conf" uwsgi processes $API_WORKERS
# This is running standalone
iniset "$conf" uwsgi master true
@ -306,14 +318,25 @@ function write_local_uwsgi_http_config {
local conf=$1
local wsgi=$2
local url=$3
name=$(basename $wsgi)
local name=$4
if [ -z "$name" ]; then
name=$(basename $wsgi)
fi
# create a home for the sockets; note don't use /tmp -- apache has
# a private view of it on some platforms.
# always cleanup given that we are using iniset here
rm -rf $conf
iniset "$conf" uwsgi wsgi-file "$wsgi"
# Set either the module path or wsgi script path depending on what we've
# been given
if [[ "$wsgi" =~ ^[a-zA-Z0-9_.]+:[a-zA-Z0-9_]+$ ]]; then
iniset "$conf" uwsgi module "$wsgi"
else
deprecated 'Configuring uWSGI with a WSGI file is deprecated, use module paths instead'
iniset "$conf" uwsgi wsgi-file "$wsgi"
fi
port=$(get_random_port)
iniset "$conf" uwsgi http-socket "$APACHE_LOCAL_HOST:$port"
iniset "$conf" uwsgi processes $API_WORKERS

View File

@ -53,8 +53,8 @@ NOVA_COND_CONF=$NOVA_CONF_DIR/nova.conf
NOVA_CPU_CONF=$NOVA_CONF_DIR/nova-cpu.conf
NOVA_FAKE_CONF=$NOVA_CONF_DIR/nova-fake.conf
NOVA_API_DB=${NOVA_API_DB:-nova_api}
NOVA_UWSGI=$NOVA_BIN_DIR/nova-api-wsgi
NOVA_METADATA_UWSGI=$NOVA_BIN_DIR/nova-metadata-wsgi
NOVA_UWSGI=nova.wsgi.osapi_compute:application
NOVA_METADATA_UWSGI=nova.wsgi.metadata:application
NOVA_UWSGI_CONF=$NOVA_CONF_DIR/nova-api-uwsgi.ini
NOVA_METADATA_UWSGI_CONF=$NOVA_CONF_DIR/nova-metadata-uwsgi.ini
@ -549,11 +549,11 @@ function create_nova_conf {
iniset $NOVA_CONF upgrade_levels compute "auto"
if is_service_enabled n-api; then
write_uwsgi_config "$NOVA_UWSGI_CONF" "$NOVA_UWSGI" "/compute"
write_uwsgi_config "$NOVA_UWSGI_CONF" "$NOVA_UWSGI" "/compute" "" "nova-api"
fi
if is_service_enabled n-api-meta; then
write_uwsgi_config "$NOVA_METADATA_UWSGI_CONF" "$NOVA_METADATA_UWSGI" "" "$SERVICE_LISTEN_ADDRESS:${METADATA_SERVICE_PORT}"
write_uwsgi_config "$NOVA_METADATA_UWSGI_CONF" "$NOVA_METADATA_UWSGI" "" "$SERVICE_LISTEN_ADDRESS:${METADATA_SERVICE_PORT}" "nova-metadata"
fi
if is_service_enabled ceilometer; then