From b1e1974fe83f8483887291ee8da7592b3e02167d Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Fri, 18 Feb 2022 02:19:29 +0000 Subject: [PATCH] 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 --- devstack/lib/wsgi | 36 ++++++++++++++++ devstack/plugin.sh | 43 +++++--------------- devstack/upgrade/from-xena/upgrade-designate | 27 ++++++++++++ devstack/upgrade/upgrade.sh | 4 ++ 4 files changed, 77 insertions(+), 33 deletions(-) create mode 100644 devstack/lib/wsgi create mode 100644 devstack/upgrade/from-xena/upgrade-designate diff --git a/devstack/lib/wsgi b/devstack/lib/wsgi new file mode 100644 index 000000000..37633c3e1 --- /dev/null +++ b/devstack/lib/wsgi @@ -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 +} diff --git a/devstack/plugin.sh b/devstack/plugin.sh index a7a209f55..69b5b1474 100755 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -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 diff --git a/devstack/upgrade/from-xena/upgrade-designate b/devstack/upgrade/from-xena/upgrade-designate new file mode 100644 index 000000000..cbad27c81 --- /dev/null +++ b/devstack/upgrade/from-xena/upgrade-designate @@ -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" +} diff --git a/devstack/upgrade/upgrade.sh b/devstack/upgrade/upgrade.sh index f8bdfc565..3f391d752 100755 --- a/devstack/upgrade/upgrade.sh +++ b/devstack/upgrade/upgrade.sh @@ -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