Fix grenade job for mod_wsgi to uwsgi transition

This patch updates the grenade job to migrate from using Apache mod_wsgi
to using uwsgi for the Designate API when upgrading from Xena to Yoga.

It also splits out the wsgi devstack configuration into a library file.

Change-Id: Icf8ee4a8e7e2dff67257b0e5f82fbeab6cb7e0b8
This commit is contained in:
Michael Johnson 2022-02-18 02:19:29 +00:00
parent 5c3975b8a8
commit b1e1974fe8
4 changed files with 77 additions and 33 deletions

36
devstack/lib/wsgi Normal file
View File

@ -0,0 +1,36 @@
function designate_configure_uwsgi {
write_uwsgi_config "$DESIGNATE_UWSGI_CONF" "$DESIGNATE_UWSGI" "/dns"
# We are using the http transport to work around an issue with
# broken connections when using the uwsgi protocol of a local socket
# See bug: https://github.com/unbit/uwsgi/issues/2368
wsgi_conf=$(apache_site_config_for designate-api-wsgi)
echo 'ProxyPass "/dns" "http://127.0.0.1:60053" retry=0' | sudo tee $wsgi_conf
iniset $DESIGNATE_UWSGI_CONF uwsgi http-socket 127.0.0.1:60053
}
function designate_configure_mod_wsgi {
local designate_api_apache_conf
local venv_path=""
local designate_bin_dir=""
designate_bin_dir=$(get_python_exec_prefix)
designate_api_apache_conf=$(apache_site_config_for designate-api)
if [[ ${USE_VENV} = True ]]; then
venv_path="python-path=${PROJECT_VENV["designate"]}/lib/$(python_version)/site-packages"
designate_bin_dir=${PROJECT_VENV["designate"]}/bin
fi
sudo cp $DESIGNATE_DIR/devstack/files/apache-designate-api.template $designate_api_apache_conf
sudo sed -e "
s|%APACHE_NAME%|$APACHE_NAME|g;
s|%DESIGNATE_BIN_DIR%|$designate_bin_dir|g;
s|%SSLENGINE%|$designate_ssl|g;
s|%SSLCERTFILE%|$designate_certfile|g;
s|%SSLKEYFILE%|$designate_keyfile|g;
s|%USER%|$STACK_USER|g;
s|%VIRTUALENV%|$venv_path|g;
s|%APIWORKERS%|$API_WORKERS|g;
" -i $designate_api_apache_conf
}

View File

@ -4,6 +4,10 @@
XTRACE=$(set +o | grep xtrace)
set +o xtrace
LIBDIR=$DEST/designate/devstack/lib
source $LIBDIR/wsgi
# Get backend configuration
# -------------------------
if is_service_enabled designate && [[ -r $DESIGNATE_PLUGINS/backend-$DESIGNATE_BACKEND_DRIVER ]]; then
@ -121,43 +125,12 @@ function configure_designate {
configure_designate_backend
if [[ "$DESIGNATE_WSGI_MODE" == "uwsgi" ]]; then
write_uwsgi_config "$DESIGNATE_UWSGI_CONF" "$DESIGNATE_UWSGI" "/dns"
# We are using the http transport to work around an issue with
# broken connections when using the uwsgi protocol of a local socket
# See bug: https://github.com/unbit/uwsgi/issues/2368
wsgi_conf=$(apache_site_config_for designate-api-wsgi)
echo 'ProxyPass "/dns" "http://127.0.0.1:60053" retry=0' | sudo tee $wsgi_conf
iniset $DESIGNATE_UWSGI_CONF uwsgi http-socket 127.0.0.1:60053
designate_configure_uwsgi
else
_config_designate_apache_wsgi
designate_configure_mod_wsgi
fi
}
function _config_designate_apache_wsgi {
local designate_api_apache_conf
local venv_path=""
local designate_bin_dir=""
designate_bin_dir=$(get_python_exec_prefix)
designate_api_apache_conf=$(apache_site_config_for designate-api)
if [[ ${USE_VENV} = True ]]; then
venv_path="python-path=${PROJECT_VENV["designate"]}/lib/$(python_version)/site-packages"
designate_bin_dir=${PROJECT_VENV["designate"]}/bin
fi
sudo cp $DESIGNATE_DIR/devstack/files/apache-designate-api.template $designate_api_apache_conf
sudo sed -e "
s|%APACHE_NAME%|$APACHE_NAME|g;
s|%DESIGNATE_BIN_DIR%|$designate_bin_dir|g;
s|%SSLENGINE%|$designate_ssl|g;
s|%SSLCERTFILE%|$designate_certfile|g;
s|%SSLKEYFILE%|$designate_keyfile|g;
s|%USER%|$STACK_USER|g;
s|%VIRTUALENV%|$venv_path|g;
s|%APIWORKERS%|$API_WORKERS|g;
" -i $designate_api_apache_conf
}
function configure_designatedashboard {
# Compile message catalogs
if [ -d ${DESIGNATEDASHBOARD_DIR}/designatedashboard/locale ]; then
@ -311,6 +284,8 @@ function start_designate {
if [[ "$DESIGNATE_WSGI_MODE" == "uwsgi" ]]; then
run_process "designate-api" "$(which uwsgi) --procname-prefix designate-api --ini $DESIGNATE_UWSGI_CONF"
enable_apache_site designate-api-wsgi
restart_apache_server
else
enable_apache_site designate-api
restart_apache_server
@ -326,6 +301,8 @@ function start_designate {
function stop_designate {
if [[ "$DESIGNATE_WSGI_MODE" == "uwsgi" ]]; then
stop_process "designate-api"
disable_apache_site designate-api-wsgi
restart_apache_server
else
disable_apache_site designate-api
restart_apache_server

View File

@ -0,0 +1,27 @@
#!/usr/bin/env bash
# Designate moved from using mod_wsgi to running uwsgi with an Apache proxy
# pass-through for devstack in the yoga release cycle.
# This upgrade script updates the Apache configuration to switch the wsgi
# approach during a xena->yoga grenade test.
# Since this is a from-* script, it will run after installing the new code
# but before the upgraded code is started.
function configure_designate_upgrade {
source $GRENADE_DIR/functions
source ${TARGET_DEVSTACK_DIR}/lib/apache
DESIGNATE_DEVSTACK_DIR=$(dirname $(dirname $0))
source $DESIGNATE_DEVSTACK_DIR/lib/wsgi
# Disable the old site using mod_wsgi
disable_apache_site designate-api
# Setup the apache uswgi site "designate-api-wsgi"
designate_configure_uwsgi
enable_apache_site designate-api-wsgi
restart_apache_server
# Switch designate-api to run under uwsgi
stop_process designate-api
run_process "designate-api" "$(which uwsgi) --procname-prefix designate-api --ini $DESIGNATE_UWSGI_CONF"
}

View File

@ -29,6 +29,9 @@ source $GRENADE_DIR/grenaderc
# Import common functions
source $GRENADE_DIR/functions
# Get the Apache functions
source ${TARGET_DEVSTACK_DIR}/lib/apache
# This script exits on an error so that errors don't compound and you see
# only the first error that occurred.
set -o errexit
@ -82,6 +85,7 @@ run_process designate-worker "$DESIGNATE_BIN_DIR/designate-worker --config-file
run_process designate-mdns "$DESIGNATE_BIN_DIR/designate-mdns --config-file $DESIGNATE_CONF"
run_process designate-agent "$DESIGNATE_BIN_DIR/designate-agent --config-file $DESIGNATE_CONF"
run_process designate-sink "$DESIGNATE_BIN_DIR/designate-sink --config-file $DESIGNATE_CONF"
restart_apache_server
# Start proxies if enabled
if is_service_enabled designate-api && is_service_enabled tls-proxy; then