From d1f5adb7e1cb232d80817e1b824762de2a7995a1 Mon Sep 17 00:00:00 2001 From: Fei Long Wang Date: Tue, 31 Jan 2017 10:51:20 +1300 Subject: [PATCH] Support cold migration Add grenade plugin under devstack folder to support cold migration verified by grenade job. Implement blueprint: cold-migration Co-Authored-By: wangxiyuan Change-Id: I9c399ee7fcac0f9d3488084cb0c0718882952eaf --- devstack/gate/gate_hook.sh | 2 +- devstack/upgrade/resource.sh | 69 +++++++++++++++++ devstack/upgrade/settings | 19 +++++ devstack/upgrade/shutdown.sh | 26 +++++++ devstack/upgrade/upgrade.sh | 108 +++++++++++++++++++++++++++ zaqar_upgradetests/post_test_hook.sh | 0 zaqar_upgradetests/pre_test_hook.sh | 0 7 files changed, 223 insertions(+), 1 deletion(-) create mode 100755 devstack/upgrade/resource.sh create mode 100644 devstack/upgrade/settings create mode 100755 devstack/upgrade/shutdown.sh create mode 100755 devstack/upgrade/upgrade.sh create mode 100755 zaqar_upgradetests/post_test_hook.sh create mode 100755 zaqar_upgradetests/pre_test_hook.sh diff --git a/devstack/gate/gate_hook.sh b/devstack/gate/gate_hook.sh index 9d314be7a..82d50f67b 100755 --- a/devstack/gate/gate_hook.sh +++ b/devstack/gate/gate_hook.sh @@ -32,7 +32,7 @@ if [ "$DEVSTACK_GATE_ZAQAR_BACKEND" == "swift" ]; then OVERRIDE_ENABLED_SERVICES+=,s-proxy,s-object,s-container,s-account fi export DEVSTACK_LOCAL_CONFIG+=$" -export ZAQAR_BACKEND=$DEVSTACK_GATE_ZAQAR_BACKEND" +ZAQAR_BACKEND=$DEVSTACK_GATE_ZAQAR_BACKEND" export OVERRIDE_ENABLED_SERVICES function run_devstack_gate() { diff --git a/devstack/upgrade/resource.sh b/devstack/upgrade/resource.sh new file mode 100755 index 000000000..7018ba5bf --- /dev/null +++ b/devstack/upgrade/resource.sh @@ -0,0 +1,69 @@ +#!/bin/bash +# +# Copyright 2017 Catalyst IT Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +set -o errexit + +source $GRENADE_DIR/grenaderc +source $GRENADE_DIR/functions + +source $TOP_DIR/openrc admin admin + +ZAQAR_DEVSTACK_DIR=$(cd $(dirname "$0")/.. && pwd) +source $ZAQAR_DEVSTACK_DIR/settings + +set -o xtrace + + +function create { + # TODO(flwang): Create queue, create subscriptions, post messages, + # delete queue + : +} + +function verify { + # TODO(flwang): Get queue, get messages, get subscriptions + : +} + +function verify_noapi { + : +} + +function destroy { + # TODO(flwang): Purge queue, delete queue + : +} + +# Dispatcher +case $1 in + "create") + create + ;; + "verify") + verify + ;; + "verify_noapi") + verify_noapi + ;; + "destroy") + destroy + ;; + "force_destroy") + set +o errexit + destroy + ;; +esac + diff --git a/devstack/upgrade/settings b/devstack/upgrade/settings new file mode 100644 index 000000000..8ef7d4507 --- /dev/null +++ b/devstack/upgrade/settings @@ -0,0 +1,19 @@ +# Grenade needs to know that Zaqar has a Grenade plugin. This is done in the +# gate by setting GRENADE_PLUGINRC when using openstack-infra/devstack-gate. +# That means that in the project openstack-infra/project-config we will need to +# update the Zaqar grenade job(s) in jenkins/jobs/devstack-gate.yaml with +# this: +# export GRENADE_PLUGINRC="enable_grenade_plugin zaqar https://git.openstack.org/openstack/zaqar" +# If openstack-infra/project-config is not updated then the Grenade tests will +# never get run for Zaqar + +register_project_for_upgrade zaqar + + +if grep -q 'management_store *= *sqlalchemy' /etc/zaqar/zaqar.conf; then + register_db_to_save zaqar +fi + +devstack_localrc base enable_service zaqar-wsgi zaqar-websocket zaqar + +devstack_localrc target enable_service zaqar-wsgi zaqar-websocket zaqar \ No newline at end of file diff --git a/devstack/upgrade/shutdown.sh b/devstack/upgrade/shutdown.sh new file mode 100755 index 000000000..4df9d6157 --- /dev/null +++ b/devstack/upgrade/shutdown.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# +# + +set -o errexit + +source $GRENADE_DIR/grenaderc +source $GRENADE_DIR/functions + +# We need base DevStack functions for this +source $BASE_DEVSTACK_DIR/functions +source $BASE_DEVSTACK_DIR/stackrc # needed for status directory +source $BASE_DEVSTACK_DIR/lib/tls + +# Keep track of the DevStack directory +ZAQAR_DEVSTACK_DIR=$(dirname "$0")/.. +source $ZAQAR_DEVSTACK_DIR/settings +source $ZAQAR_DEVSTACK_DIR/plugin.sh + +set -o xtrace + +for serv in zaqar-websocket; do + stop_process $serv +done + +uwsgi --stop $ZAQAR_UWSGI_MASTER_PIDFILE \ No newline at end of file diff --git a/devstack/upgrade/upgrade.sh b/devstack/upgrade/upgrade.sh new file mode 100755 index 000000000..6fc24df80 --- /dev/null +++ b/devstack/upgrade/upgrade.sh @@ -0,0 +1,108 @@ +#!/usr/bin/env bash + +# ``upgrade-zaqar`` + +echo "*********************************************************************" +echo "Begin $0" +echo "*********************************************************************" + +# Clean up any resources that may be in use +cleanup() { + set +o errexit + + echo "*********************************************************************" + echo "ERROR: Abort $0" + echo "*********************************************************************" + + # Kill ourselves to signal any calling process + trap 2; kill -2 $$ +} + +trap cleanup SIGHUP SIGINT SIGTERM + +# Keep track of the grenade directory +RUN_DIR=$(cd $(dirname "$0") && pwd) + +# Source params +source $GRENADE_DIR/grenaderc + +source $TOP_DIR/openrc admin admin + +# Import common functions +source $GRENADE_DIR/functions + +# This script exits on an error so that errors don't compound and you see +# only the first error that occurred. +set -o errexit + +if grep -q 'management_store *= *mongodb' /etc/zaqar/zaqar.conf; then + mongodump --db zaqar_mgmt --out $SAVE_DIR/zaqar-mongodb-mgmt-dump.$BASE_RELEASE +fi + +if grep -q 'message_store *= *mongodb' /etc/zaqar/zaqar.conf; then + mongodump --db zaqar --out $SAVE_DIR/zaqar-mongodb-message-dump.$BASE_RELEASE +fi + +if grep -q 'message_store *= *redis' /etc/zaqar/zaqar.conf; then + redis-cli save + cp /var/lib/redis/dump.rdb $SAVE_DIR/zaqar-redis-message-dump-$BASE_RELEASE.rdb +fi + +# Upgrade Zaqar +# ============= + +# Duplicate some setup bits from target DevStack +source $TARGET_DEVSTACK_DIR/stackrc +source $TARGET_DEVSTACK_DIR/lib/tls + +# Keep track of the DevStack directory +ZAQAR_DEVSTACK_DIR=$(dirname "$0")/.. +source $ZAQAR_DEVSTACK_DIR/settings +source $ZAQAR_DEVSTACK_DIR/plugin.sh + +# Print the commands being run so that we can see the command that triggers +# an error. It is also useful for following allowing as the install occurs. +set -o xtrace + +function wait_for_keystone { + if ! wait_for_service $SERVICE_TIMEOUT ${KEYSTONE_AUTH_URI}/v$IDENTITY_API_VERSION/; then + die $LINENO "keystone did not start" + fi +} + +# Save current config files for posterity +[[ -d $SAVE_DIR/etc.zaqar ]] || cp -pr $ZAQAR_CONF_DIR $SAVE_DIR/etc.zaqar + +stack_install_service zaqar + +if grep -q 'management_store *= *sqlalchemy' /etc/zaqar/zaqar.conf; then + zaqar-sql-db-manage --config-file $ZAQAR_CONF upgrade head || die $LINENO "DB sync error" +fi + +# calls upgrade-zaqar for specific release +upgrade_project zaqar $RUN_DIR $BASE_DEVSTACK_BRANCH $TARGET_DEVSTACK_BRANCH + +start_zaqar +wait_for_keystone + + +# Don't succeed unless the services come up +ensure_services_started zaqar-server + +if grep -q 'management_store *= *mongodb' /etc/zaqar/zaqar.conf; then + mongodump --db zaqar_mgmt --out $SAVE_DIR/zaqar-mongodb-mgmt-dump.$TARGET_RELEASE +fi + +if grep -q 'message_store *= *mongodb' /etc/zaqar/zaqar.conf; then + mongodump --db zaqar --out $SAVE_DIR/zaqar-mongodb-message-dump.$TARGET_RELEASE +fi + +if grep -q 'message_store *= *redis' /etc/zaqar/zaqar.conf; then + redis-cli save + cp /var/lib/redis/dump.rdb $SAVE_DIR/zaqar-redis-message-dump-$TARGET_RELEASE.rdb +fi + +set +o xtrace +echo "*********************************************************************" +echo "SUCCESS: End $0" +echo "*********************************************************************" diff --git a/zaqar_upgradetests/post_test_hook.sh b/zaqar_upgradetests/post_test_hook.sh new file mode 100755 index 000000000..e69de29bb diff --git a/zaqar_upgradetests/pre_test_hook.sh b/zaqar_upgradetests/pre_test_hook.sh new file mode 100755 index 000000000..e69de29bb