From 334b22929cc5c37ba48d86addca74ea087499afd Mon Sep 17 00:00:00 2001 From: Sirushti Murugesan Date: Thu, 4 Jun 2015 00:29:47 +0530 Subject: [PATCH] In-tree grenade support for Heat The following implements in tree support for grenade upgrade testing for heat. It includes the expected directory structure to be used for the external plugin. For now, we create a simple OS::Heat::RandomString resource and check whether the stack survives the upgrade. We should add better tests for upgrades in the future. Co-Authored-By: Steven Hardy Co-Authored-By: Sergey Kraynev Co-Authored-By: Emilien Macchi partial blueprint upgrade-tests Change-Id: I0847004a8ac023a113cabaee46896abc823a01da --- devstack/upgrade/resources.sh | 97 +++++++++++++++++++ devstack/upgrade/settings | 4 + devstack/upgrade/shutdown.sh | 33 +++++++ devstack/upgrade/templates/random_string.yaml | 4 + devstack/upgrade/upgrade.sh | 88 +++++++++++++++++ heat_upgradetests/post_test_hook.sh | 0 heat_upgradetests/pre_test_hook.sh | 0 7 files changed, 226 insertions(+) create mode 100755 devstack/upgrade/resources.sh create mode 100644 devstack/upgrade/settings create mode 100755 devstack/upgrade/shutdown.sh create mode 100644 devstack/upgrade/templates/random_string.yaml create mode 100755 devstack/upgrade/upgrade.sh create mode 100755 heat_upgradetests/post_test_hook.sh create mode 100755 heat_upgradetests/pre_test_hook.sh diff --git a/devstack/upgrade/resources.sh b/devstack/upgrade/resources.sh new file mode 100755 index 0000000000..2a0d1bf95a --- /dev/null +++ b/devstack/upgrade/resources.sh @@ -0,0 +1,97 @@ +#!/bin/bash +# +# 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 + +set -o xtrace + +HEAT_USER=heat_grenade +HEAT_PROJECT=heat_grenade +HEAT_PASS=pass + +function _heat_set_user { + OS_TENANT_NAME=$HEAT_PROJECT + OS_USERNAME=$HEAT_USER + OS_PASSWORD=$HEAT_PASS +} + +function create { + # creates a tenant for the server + eval $(openstack project create -f shell -c id $HEAT_PROJECT) + if [[ -z "$id" ]]; then + die $LINENO "Didn't create $HEAT_PROJECT project" + fi + resource_save heat project_id $id + + # creates the user, and sets $id locally + eval $(openstack user create $HEAT_USER \ + --project $id \ + --password $HEAT_PASS \ + -f shell -c id) + if [[ -z "$id" ]]; then + die $LINENO "Didn't create $HEAT_USER user" + fi + resource_save heat user_id $id + _heat_set_user + + local stack_name='grenadine' + resource_save heat stack_name $stack_name + local loc=`dirname $BASH_SOURCE` + heat stack-create -f $loc/templates/random_string.yaml $stack_name +} + +function verify { + _heat_set_user + stack_name=$(resource_get heat stack_name) + heat stack-show $stack_name + # TODO(sirushtim): Create more granular checks for Heat. +} + +function verify_noapi { + # TODO(sirushtim): Write tests to validate liveness of the resources + # it creates during possible API downtime. + : +} + +function destroy { + _heat_set_user + heat stack-delete $(resource_get heat stack_name) + + source $TOP_DIR/openrc admin admin + local user_id=$(resource_get heat user_id) + local project_id=$(resource_get heat project_id) + openstack user delete $user_id + openstack project delete $project_id +} + +# Dispatcher +case $1 in + "create") + create + ;; + "verify_noapi") + verify_noapi + ;; + "verify") + verify + ;; + "destroy") + destroy + ;; +esac diff --git a/devstack/upgrade/settings b/devstack/upgrade/settings new file mode 100644 index 0000000000..9d05220e1c --- /dev/null +++ b/devstack/upgrade/settings @@ -0,0 +1,4 @@ +register_project_for_upgrade heat +register_db_to_save heat +devstack_localrc base enable_service h-api h-api-cfn h-api-cw h-eng heat tempest ceilometer-alarm-evaluator ceilometer-alarm-notifier ceilometer-anotification +devstack_localrc target enable_service h-api h-api-cfn h-api-cw h-eng heat tempest ceilometer-alarm-evaluator ceilometer-alarm-notifier ceilometer-anotification diff --git a/devstack/upgrade/shutdown.sh b/devstack/upgrade/shutdown.sh new file mode 100755 index 0000000000..7e2f9ebb49 --- /dev/null +++ b/devstack/upgrade/shutdown.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# +# 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 + +# 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 +source $BASE_DEVSTACK_DIR/lib/heat + +set -o xtrace + +stop_heat + +SERVICES_DOWN="heat-api heat-engine heat-api-cfn heat-api-cloudwatch" + +# sanity check that services are actually down +ensure_services_stopped $SERVICES_DOWN diff --git a/devstack/upgrade/templates/random_string.yaml b/devstack/upgrade/templates/random_string.yaml new file mode 100644 index 0000000000..df1e5c3b0b --- /dev/null +++ b/devstack/upgrade/templates/random_string.yaml @@ -0,0 +1,4 @@ +heat_template_version: 2014-10-16 +resources: + random_string: + type: OS::Heat::RandomString diff --git a/devstack/upgrade/upgrade.sh b/devstack/upgrade/upgrade.sh new file mode 100755 index 0000000000..527512bde3 --- /dev/null +++ b/devstack/upgrade/upgrade.sh @@ -0,0 +1,88 @@ +#!/bin/bash +# +# 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. +# +# ``upgrade-heat`` + +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 + +# 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 + +# Upgrade Heat +# ============ + +# Duplicate some setup bits from target DevStack +source $TARGET_DEVSTACK_DIR/functions +source $TARGET_DEVSTACK_DIR/stackrc +source $TARGET_DEVSTACK_DIR/lib/tls +source $TARGET_DEVSTACK_DIR/lib/stack +source $TARGET_DEVSTACK_DIR/lib/heat + +# 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 + +# Save current config files for posterity +[[ -d $SAVE_DIR/etc.heat ]] || cp -pr $HEAT_CONF_DIR $SAVE_DIR/etc.heat + +# install_heat() +stack_install_service heat +install_heatclient +install_heat_other + +# calls upgrade-heat for specific release +upgrade_project heat $RUN_DIR $BASE_DEVSTACK_BRANCH $TARGET_DEVSTACK_BRANCH + +# Simulate init_heat() +create_heat_cache_dir + +HEAT_BIN_DIR=$(dirname $(which heat-manage)) +$HEAT_BIN_DIR/heat-manage --config-file $HEAT_CONF db_sync || die $LINENO "DB sync error" + +# Start Heat +start_heat + +# Don't succeed unless the services come up +ensure_services_started heat-api heat-engine heat-api-cloudwatch heat-api-cfn + +set +o xtrace +echo "*********************************************************************" +echo "SUCCESS: End $0" +echo "*********************************************************************" diff --git a/heat_upgradetests/post_test_hook.sh b/heat_upgradetests/post_test_hook.sh new file mode 100755 index 0000000000..e69de29bb2 diff --git a/heat_upgradetests/pre_test_hook.sh b/heat_upgradetests/pre_test_hook.sh new file mode 100755 index 0000000000..e69de29bb2