Skip to content

Commit b6613b1

Browse files
committed
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/
1 parent e2aeab1 commit b6613b1

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

lib/apache

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,17 @@ function restart_apache_server {
237237
restart_service $APACHE_NAME
238238
}
239239

240+
# write_uwsgi_config() - Create a new uWSGI config file
240241
function write_uwsgi_config {
241242
local conf=$1
242243
local wsgi=$2
243244
local url=$3
244245
local http=$4
245-
local name=""
246-
name=$(basename $wsgi)
246+
local name=$5
247+
248+
if [ -z "$name" ]; then
249+
name=$(basename $wsgi)
250+
fi
247251

248252
# create a home for the sockets; note don't use /tmp -- apache has
249253
# a private view of it on some platforms.
@@ -259,7 +263,15 @@ function write_uwsgi_config {
259263

260264
# always cleanup given that we are using iniset here
261265
rm -rf $conf
262-
iniset "$conf" uwsgi wsgi-file "$wsgi"
266+
# Set either the module path or wsgi script path depending on what we've
267+
# been given. Note that the regex isn't exhaustive - neither Python modules
268+
# nor Python variables can start with a number - but it's "good enough"
269+
if [[ "$wsgi" =~ ^[a-zA-Z0-9_.]+:[a-zA-Z0-9_]+$ ]]; then
270+
iniset "$conf" uwsgi module "$wsgi"
271+
else
272+
deprecated 'Configuring uWSGI with a WSGI file is deprecated, use module paths instead'
273+
iniset "$conf" uwsgi wsgi-file "$wsgi"
274+
fi
263275
iniset "$conf" uwsgi processes $API_WORKERS
264276
# This is running standalone
265277
iniset "$conf" uwsgi master true
@@ -306,14 +318,25 @@ function write_local_uwsgi_http_config {
306318
local conf=$1
307319
local wsgi=$2
308320
local url=$3
309-
name=$(basename $wsgi)
321+
local name=$4
322+
323+
if [ -z "$name" ]; then
324+
name=$(basename $wsgi)
325+
fi
310326

311327
# create a home for the sockets; note don't use /tmp -- apache has
312328
# a private view of it on some platforms.
313329

314330
# always cleanup given that we are using iniset here
315331
rm -rf $conf
316-
iniset "$conf" uwsgi wsgi-file "$wsgi"
332+
# Set either the module path or wsgi script path depending on what we've
333+
# been given
334+
if [[ "$wsgi" =~ ^[a-zA-Z0-9_.]+:[a-zA-Z0-9_]+$ ]]; then
335+
iniset "$conf" uwsgi module "$wsgi"
336+
else
337+
deprecated 'Configuring uWSGI with a WSGI file is deprecated, use module paths instead'
338+
iniset "$conf" uwsgi wsgi-file "$wsgi"
339+
fi
317340
port=$(get_random_port)
318341
iniset "$conf" uwsgi http-socket "$APACHE_LOCAL_HOST:$port"
319342
iniset "$conf" uwsgi processes $API_WORKERS

lib/nova

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ NOVA_COND_CONF=$NOVA_CONF_DIR/nova.conf
5353
NOVA_CPU_CONF=$NOVA_CONF_DIR/nova-cpu.conf
5454
NOVA_FAKE_CONF=$NOVA_CONF_DIR/nova-fake.conf
5555
NOVA_API_DB=${NOVA_API_DB:-nova_api}
56-
NOVA_UWSGI=$NOVA_BIN_DIR/nova-api-wsgi
57-
NOVA_METADATA_UWSGI=$NOVA_BIN_DIR/nova-metadata-wsgi
56+
NOVA_UWSGI=nova.wsgi.osapi_compute:application
57+
NOVA_METADATA_UWSGI=nova.wsgi.metadata:application
5858
NOVA_UWSGI_CONF=$NOVA_CONF_DIR/nova-api-uwsgi.ini
5959
NOVA_METADATA_UWSGI_CONF=$NOVA_CONF_DIR/nova-metadata-uwsgi.ini
6060

@@ -549,11 +549,11 @@ function create_nova_conf {
549549
iniset $NOVA_CONF upgrade_levels compute "auto"
550550

551551
if is_service_enabled n-api; then
552-
write_uwsgi_config "$NOVA_UWSGI_CONF" "$NOVA_UWSGI" "/compute"
552+
write_uwsgi_config "$NOVA_UWSGI_CONF" "$NOVA_UWSGI" "/compute" "" "nova-api"
553553
fi
554554

555555
if is_service_enabled n-api-meta; then
556-
write_uwsgi_config "$NOVA_METADATA_UWSGI_CONF" "$NOVA_METADATA_UWSGI" "" "$SERVICE_LISTEN_ADDRESS:${METADATA_SERVICE_PORT}"
556+
write_uwsgi_config "$NOVA_METADATA_UWSGI_CONF" "$NOVA_METADATA_UWSGI" "" "$SERVICE_LISTEN_ADDRESS:${METADATA_SERVICE_PORT}" "nova-metadata"
557557
fi
558558

559559
if is_service_enabled ceilometer; then

0 commit comments

Comments
 (0)