From e2592e4d0678da52ef182372a2768374d8abb18c Mon Sep 17 00:00:00 2001 From: Antony Messerli Date: Tue, 26 Sep 2017 09:22:01 -0500 Subject: [PATCH] Allow for Leapfrogs from other Releases Leapfrogs currently only work with Juno/Kilo releases as certain parts are hard coded. This patch adds support for handling multiple releases and attempts to remove some duplicate code with loops. Also adds a UPGRADES_TO_TODOLIST variable check on migration.sh and upgrade.sh to ensure the list of releases to be ugpraded to are set if the commands are ran individually. Change-Id: Ia56f073863533d4b6fa58b78b59b5086c7f9a331 --- leap-upgrades/lib/functions.sh | 21 ++++++++++- leap-upgrades/lib/vars.sh | 1 - leap-upgrades/migrations.sh | 69 +++++++++++++--------------------- leap-upgrades/prep.sh | 46 ++++++++--------------- leap-upgrades/upgrade.sh | 3 ++ 5 files changed, 64 insertions(+), 76 deletions(-) diff --git a/leap-upgrades/lib/functions.sh b/leap-upgrades/lib/functions.sh index 72719acb..b40804e7 100644 --- a/leap-upgrades/lib/functions.sh +++ b/leap-upgrades/lib/functions.sh @@ -39,6 +39,19 @@ function tag_leap_success { debug "LEAP ${1} marked as success" } +function check_for_todolist { + if [[ -v UPGRADES_TO_TODOLIST ]]; then + notice "UPGRADES_TO_TODOLIST is set, continuing..." + else + notice "Please export UPGRADES_TO_TODOLIST variable before continuing" + notice "This variable is set via the prep.sh script and details the" + notice "incremental RELEASES that need to run for the leap." + notice "" + notice "example: export UPGRADES_TO_TODOLIST=\"MITAKA NEWTON\"" + exit 99 + fi +} + function run_lock { set +e @@ -291,6 +304,12 @@ function pre_flight { discover_code_version + # set config directory here since we need to check if existing redeploy + # has been kicked off before prompting for the release, JUNO is the only + # other directory that may differ but since we aren't leaping to JUNO, + # this should be safe to set here + CONFIG_DIR="/etc/openstack_deploy" + if [[ -f "${CONFIG_DIR}/upgrade-leap/redeploy-started.complete" && ! -f "${CONFIG_DIR}/upgrade-leap/osa-leap.complete" ]]; then resume_incomplete_leap elif [ "${VALIDATE_UPGRADE_INPUT}" == "TRUE" ]; then @@ -419,7 +438,7 @@ function run_venv_prep { if [[ -e "/etc/rpc_deploy" ]]; then PB_DIR="/opt/leap42/openstack-ansible-${JUNO_RELEASE}/rpc_deployment" else - PB_DIR="/opt/leap42/openstack-ansible-${KILO_RELEASE}/playbooks" + PB_DIR="/opt/leap42/openstack-ansible-${RELEASE}/playbooks" fi pushd "${PB_DIR}" diff --git a/leap-upgrades/lib/vars.sh b/leap-upgrades/lib/vars.sh index 1b4dd18a..a12b0344 100644 --- a/leap-upgrades/lib/vars.sh +++ b/leap-upgrades/lib/vars.sh @@ -40,7 +40,6 @@ export UPGRADE_UTILS="${UPGRADE_UTILS:-${SYSTEM_PATH}/upgrade-utilities}" export VENV_URL="${VENV_URL:-https://rpc-repo.rackspace.com/venvs/leap-bundles}" export VALIDATE_UPGRADE_INPUT="${VALIDATE_UPGRADE_INPUT:-TRUE}" -export UPGRADES_TO_TODOLIST="${UPGRADES_TO_TODOLIST:-''}" export CODE_UPGRADE_FROM="" # Bootstrap ansible tool, see also bootstrap_recent_ansible diff --git a/leap-upgrades/migrations.sh b/leap-upgrades/migrations.sh index b5df8d96..eeeec7cf 100755 --- a/leap-upgrades/migrations.sh +++ b/leap-upgrades/migrations.sh @@ -21,6 +21,9 @@ set -e -u source lib/vars.sh source lib/functions.sh +## Ensure UPGRADES_TO_TODOLIST is set +check_for_todolist + ### Run the DB migrations # Stop the services to ensure DB and application consistency if [[ ! -f "/opt/leap42/openstack-ansible-poweroff.leap" ]]; then @@ -35,46 +38,26 @@ if [[ ! -f "/opt/leap42/openstack-ansible-poweroff.leap" ]]; then tag_leap_success "poweroff" fi -# Kilo migrations -if [[ ! -f "/opt/leap42/openstack-ansible-${KILO_RELEASE}-db.leap" ]]; then - notice "Running Kilo DB Migrations" - link_release "/opt/leap42/openstack-ansible-${KILO_RELEASE}" - RUN_TASKS=() - RUN_TASKS+=("${UPGRADE_UTILS}/db-migrations-kilo.yml -e 'venv_tar_location=/opt/leap42/venvs/openstack-ansible-${KILO_RELEASE}.tgz'") - run_items "/opt/leap42/openstack-ansible-${KILO_RELEASE}" - tag_leap_success "${KILO_RELEASE}-db" -fi - -# Liberty migrations -if [[ ! -f "/opt/leap42/openstack-ansible-${LIBERTY_RELEASE}-db.leap" ]]; then - notice "Running Liberty DB Migrations" - link_release "/opt/leap42/openstack-ansible-${LIBERTY_RELEASE}" - RUN_TASKS=() - RUN_TASKS+=("${UPGRADE_UTILS}/db-migrations-liberty.yml -e 'venv_tar_location=/opt/leap42/venvs/openstack-ansible-${LIBERTY_RELEASE}.tgz'") - RUN_TASKS+=("${UPGRADE_UTILS}/glance-db-storage-url-fix.yml") - run_items "/opt/leap42/openstack-ansible-${LIBERTY_RELEASE}" - tag_leap_success "${LIBERTY_RELEASE}-db" -fi - -# Mitaka migrations -if [[ ! -f "/opt/leap42/openstack-ansible-${MITAKA_RELEASE}-db.leap" ]]; then - notice "Running Mitaka DB Migrations" - link_release "/opt/leap42/openstack-ansible-${MITAKA_RELEASE}" - RUN_TASKS=() - RUN_TASKS+=("${UPGRADE_UTILS}/db-migrations-mitaka.yml -e 'venv_tar_location=/opt/leap42/venvs/openstack-ansible-${MITAKA_RELEASE}.tgz'") - RUN_TASKS+=("${UPGRADE_UTILS}/neutron-mtu-migration.yml") - run_items "/opt/leap42/openstack-ansible-${MITAKA_RELEASE}" - tag_leap_success "${MITAKA_RELEASE}-db" -fi - -# Newton migrations -if [[ ! -f "/opt/leap42/openstack-ansible-${NEWTON_RELEASE}-db.leap" ]]; then - notice "Running Newton DB Migrations" - link_release "/opt/leap42/openstack-ansible-${NEWTON_RELEASE}" - RUN_TASKS=() - RUN_TASKS+=("${UPGRADE_UTILS}/db-collation-alter.yml") - RUN_TASKS+=("${UPGRADE_UTILS}/db-migrations-newton.yml -e 'venv_tar_location=/opt/leap42/venvs/openstack-ansible-${NEWTON_RELEASE}.tgz'") - run_items "/opt/leap42/openstack-ansible-${NEWTON_RELEASE}" - tag_leap_success "${NEWTON_RELEASE}-db" -fi -### Run the DB migrations +# Run Migrations for Each Release in the TODO +for RELEASES in ${UPGRADES_TO_TODOLIST}; do + RELEASE_NAME=${RELEASES}_RELEASE + if [[ ! -f "/opt/leap42/openstack-ansible-${!RELEASE_NAME}-db.leap" ]]; then + notice "Running ${RELEASES} DB Migrations" + link_release "/opt/leap42/openstack-ansible-${!RELEASE_NAME}" + RUN_TASKS=() + if [[ "${RELEASES}" == "JUNO" ]]; then + RUN_TASKS+=("${UPGRADE_UTILS}/db-migrations-kilo.yml -e 'venv_tar_location=/opt/leap42/venvs/openstack-ansible-${!RELEASE_NAME}.tgz'") + elif [[ "${RELEASES}" == "LIBERTY" ]]; then + RUN_TASKS+=("${UPGRADE_UTILS}/db-migrations-liberty.yml -e 'venv_tar_location=/opt/leap42/venvs/openstack-ansible-${!RELEASE_NAME}.tgz'") + RUN_TASKS+=("${UPGRADE_UTILS}/glance-db-storage-url-fix.yml") + elif [[ "${RELEASES}" == "MITAKA" ]]; then + RUN_TASKS+=("${UPGRADE_UTILS}/db-migrations-mitaka.yml -e 'venv_tar_location=/opt/leap42/venvs/openstack-ansible-${!RELEASE_NAME}.tgz'") + RUN_TASKS+=("${UPGRADE_UTILS}/neutron-mtu-migration.yml") + elif [[ "${RELEASES}" == "NEWTON" ]]; then + RUN_TASKS+=("${UPGRADE_UTILS}/db-collation-alter.yml") + RUN_TASKS+=("${UPGRADE_UTILS}/db-migrations-newton.yml -e 'venv_tar_location=/opt/leap42/venvs/openstack-ansible-${!RELEASE_NAME}.tgz'") + fi + run_items "/opt/leap42/openstack-ansible-${!RELEASE_NAME}" + tag_leap_success "${!RELEASE_NAME}-db" + fi +done diff --git a/leap-upgrades/prep.sh b/leap-upgrades/prep.sh index 2012196d..8b29fd60 100755 --- a/leap-upgrades/prep.sh +++ b/leap-upgrades/prep.sh @@ -24,38 +24,22 @@ source lib/functions.sh # Execute a preflight check pre_flight -# Clone the Juno release so we have a clean copy of the source code. -if [[ ! -f "/opt/leap42/openstack-ansible-${JUNO_RELEASE}-prep.leap" ]]; then - clone_release ${JUNO_RELEASE} - touch "/opt/leap42/openstack-ansible-${JUNO_RELEASE}-prep.leap" -fi - -# Build the releases. This will clone all of the releases and check them out -# separately in addition to creating all of the venvs needed for a successful migration. -if [[ ! -f "/opt/leap42/openstack-ansible-${KILO_RELEASE}-prep.leap" ]]; then - clone_release ${KILO_RELEASE} - get_venv ${KILO_RELEASE} - touch "/opt/leap42/openstack-ansible-${KILO_RELEASE}-prep.leap" -fi - -if [[ ! -f "/opt/leap42/openstack-ansible-${LIBERTY_RELEASE}-prep.leap" ]]; then - clone_release ${LIBERTY_RELEASE} - get_venv ${LIBERTY_RELEASE} - touch "/opt/leap42/openstack-ansible-${LIBERTY_RELEASE}-prep.leap" -fi - -if [[ ! -f "/opt/leap42/openstack-ansible-${MITAKA_RELEASE}-prep.leap" ]]; then - clone_release ${MITAKA_RELEASE} - get_venv ${MITAKA_RELEASE} - touch "/opt/leap42/openstack-ansible-${MITAKA_RELEASE}-prep.leap" -fi - -if [[ ! -f "/opt/leap42/openstack-ansible-${NEWTON_RELEASE}-prep.leap" ]]; then - clone_release ${NEWTON_RELEASE} - get_venv ${NEWTON_RELEASE} - touch "/opt/leap42/openstack-ansible-${NEWTON_RELEASE}-prep.leap" -fi +# assemble list of versions to check out +TODO="${CODE_UPGRADE_FROM}" +TODO+=" ${UPGRADES_TO_TODOLIST}" +# Build the releases. This will loop through the TODO variable, check out the +# releases, and create all of the venvs needed for a successful migration +for RELEASES in ${TODO}; do + RELEASE_NAME=${RELEASES}_RELEASE + if [[ ! -f "/opt/leap42/openstack-ansible-${!RELEASE_NAME}-prep.leap" ]]; then + clone_release ${!RELEASE_NAME} + if [[ "${RELEASES}" != "JUNO" ]]; then + get_venv ${!RELEASE_NAME} + fi + touch "/opt/leap42/openstack-ansible-${!RELEASE_NAME}-prep.leap" + fi +done if [[ ! -f "/opt/leap42/openstack-ansible-prep-finalsteps.leap" ]]; then RUN_TASKS=() diff --git a/leap-upgrades/upgrade.sh b/leap-upgrades/upgrade.sh index b1175cde..8a1c6b4c 100755 --- a/leap-upgrades/upgrade.sh +++ b/leap-upgrades/upgrade.sh @@ -21,6 +21,9 @@ set -e -u source lib/vars.sh source lib/functions.sh +## Ensure UPGRADES_TO_TODOLIST is set +check_for_todolist + ### Kilo System migration # Run tasks UPGRADE_SCRIPTS="${UPGRADE_UTILS}-kilo/scripts"