From 995eb927f76d9c30984fb416a6cb59b9247c6812 Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Thu, 7 Mar 2013 16:11:40 -0600 Subject: [PATCH] Add clean.sh clean.sh gets rid of all residue of running DevStack except installed packages and pip modules. And it eradicates rabbitmq-server and ts erlang dependencies as well as the other RPC backends and databases. Change-Id: I2b9a251a0a151c012bae85a5a2f9c2f72e7700be --- clean.sh | 91 ++++++++++++++++++++++++++++++++++++++++ functions | 15 +++++++ lib/database | 5 +++ lib/databases/mysql | 18 ++++++++ lib/databases/postgresql | 14 +++++++ lib/glance | 3 +- lib/nova | 5 +-- lib/quantum | 6 +-- lib/rpc_backend | 32 ++++++++++++++ lib/swift | 4 +- stack.sh | 2 + 11 files changed, 185 insertions(+), 10 deletions(-) create mode 100755 clean.sh diff --git a/clean.sh b/clean.sh new file mode 100755 index 0000000000..cf24f278b8 --- /dev/null +++ b/clean.sh @@ -0,0 +1,91 @@ +#!/usr/bin/env bash + +# **clean.sh** + +# ``clean.sh`` does its best to eradicate traces of a Grenade +# run except for the following: +# - both base and target code repos are left alone +# - packages (system and pip) are left alone + +# This means that all data files are removed. More?? + +# Keep track of the current devstack directory. +TOP_DIR=$(cd $(dirname "$0") && pwd) + +# Import common functions +source $TOP_DIR/functions + +# Load local configuration +source $TOP_DIR/stackrc + +# Get the variables that are set in stack.sh +source $TOP_DIR/.stackenv + +# Determine what system we are running on. This provides ``os_VENDOR``, +# ``os_RELEASE``, ``os_UPDATE``, ``os_PACKAGE``, ``os_CODENAME`` +# and ``DISTRO`` +GetDistro + + +# Import database library +source $TOP_DIR/lib/database +source $TOP_DIR/lib/rpc_backend + +source $TOP_DIR/lib/tls +source $TOP_DIR/lib/horizon +source $TOP_DIR/lib/keystone +source $TOP_DIR/lib/glance +source $TOP_DIR/lib/nova +source $TOP_DIR/lib/cinder +source $TOP_DIR/lib/swift +source $TOP_DIR/lib/ceilometer +source $TOP_DIR/lib/heat +source $TOP_DIR/lib/quantum +source $TOP_DIR/lib/baremetal +source $TOP_DIR/lib/ldap + + +# See if there is anything running... +# need to adapt when run_service is merged +SESSION=$(screen -ls | awk '/[0-9].stack/ { print $1 }') +if [[ -n "$SESSION" ]]; then + # Let unstack.sh do its thing first + $TOP_DIR/unstack.sh --all +fi + +# Clean projects +cleanup_cinder +cleanup_glance +cleanup_keystone +cleanup_nova +cleanup_quantum +cleanup_swift + +# cinder doesn't clean up the volume group as it might be used elsewhere... +# clean it up if it is a loop device +VG_DEV=$(sudo losetup -j $DATA_DIR/${VOLUME_GROUP}-backing-file | awk -F':' '/backing-file/ { print $1}') +if [[ -n "$VG_DEV" ]]; then + sudo losetup -d $VG_DEV +fi + +#if mount | grep $DATA_DIR/swift/drives; then +# sudo umount $DATA_DIR/swift/drives/sdb1 +#fi + + +# Clean out /etc +sudo rm -rf /etc/keystone /etc/glance /etc/nova /etc/cinder /etc/swift + +# Clean out tgt +sudo rm /etc/tgt/conf.d/* + +# Clean up the message queue +cleanup_rpc_backend +cleanup_database + +# Clean up networking... +# should this be in nova? +# FIXED_IP_ADDR in br100 + +# Clean up files +#rm -f .stackenv diff --git a/functions b/functions index 220da9d3af..f8f63c5df4 100644 --- a/functions +++ b/functions @@ -775,6 +775,21 @@ function install_package() { } +# Distro-agnostic package uninstaller +# uninstall_package package [package ...] +function uninstall_package() { + if is_ubuntu; then + apt_get purge "$@" + elif is_fedora; then + yum remove -y "$@" + elif is_suse; then + rpm -e "$@" + else + exit_distro_not_supported "uninstalling packages" + fi +} + + # Distro-agnostic function to tell if a package is installed # is_package_installed package [package ...] function is_package_installed() { diff --git a/lib/database b/lib/database index ebab3331fb..79b77a267b 100644 --- a/lib/database +++ b/lib/database @@ -42,6 +42,11 @@ done # This is not an error as multi-node installs will do this on the compute nodes +# Get rid of everything enough to cleanly change database backends +function cleanup_database { + cleanup_database_$DATABASE_TYPE +} + # Set the database type based on the configuration function initialize_database_backends { for backend in $DATABASE_BACKENDS; do diff --git a/lib/databases/mysql b/lib/databases/mysql index ec65c36396..0633ab046e 100644 --- a/lib/databases/mysql +++ b/lib/databases/mysql @@ -10,6 +10,24 @@ set +o xtrace register_database mysql +# Get rid of everything enough to cleanly change database backends +function cleanup_database_mysql { + if is_ubuntu; then + # Get ruthless with mysql + stop_service $MYSQL + sudo aptitude purge -y ~nmysql-server + sudo rm -rf /var/lib/mysql + return + elif is_fedora; then + MYSQL=mysqld + elif is_suse; then + MYSQL=mysql + else + return + fi + stop_service $MYSQL +} + function recreate_database_mysql { local db=$1 local charset=$2 diff --git a/lib/databases/postgresql b/lib/databases/postgresql index 7d4a6c57e1..efc206fa27 100644 --- a/lib/databases/postgresql +++ b/lib/databases/postgresql @@ -10,6 +10,20 @@ set +o xtrace register_database postgresql +# Get rid of everything enough to cleanly change database backends +function cleanup_database_postgresql { + stop_service postgresql + if is_ubuntu; then + # Get ruthless with mysql + sudo aptitude purge -y ~npostgresql + return + elif is_fedora; then + uninstall_package postgresql-server + else + return + fi +} + function recreate_database_postgresql { local db=$1 local charset=$2 diff --git a/lib/glance b/lib/glance index 9ec2112962..edf6982a63 100644 --- a/lib/glance +++ b/lib/glance @@ -59,8 +59,7 @@ GLANCE_HOSTPORT=${GLANCE_HOSTPORT:-$SERVICE_HOST:9292} function cleanup_glance() { # kill instances (nova) # delete image files (glance) - # This function intentionally left blank - : + sudo rm -rf $GLANCE_CACHE_DIR $GLANCE_IMAGE_DIR $GLANCE_AUTH_CACHE_DIR } # configure_glanceclient() - Set config files, create data dirs, etc diff --git a/lib/nova b/lib/nova index 906a635db8..23346b7716 100644 --- a/lib/nova +++ b/lib/nova @@ -106,6 +106,8 @@ function cleanup_nova() { # Clean out the instances directory. sudo rm -rf $NOVA_INSTANCES_PATH/* fi + + sudo rm -rf $NOVA_STATE_PATH $NOVA_AUTH_CACHE_DIR } # configure_novaclient() - Set config files, create data dirs, etc @@ -308,9 +310,6 @@ EOF" sudo chown -R $STACK_USER $NOVA_INSTANCES_PATH fi fi - - # Clean up old instances - cleanup_nova fi } diff --git a/lib/quantum b/lib/quantum index 66360d4f0e..862ba8486d 100644 --- a/lib/quantum +++ b/lib/quantum @@ -211,8 +211,6 @@ function configure_quantum() { fi _configure_quantum_debug_command - - _cleanup_quantum } function create_nova_conf_quantum() { @@ -385,9 +383,9 @@ function stop_quantum() { fi } -# _cleanup_quantum() - Remove residual data files, anything left over from previous +# cleanup_quantum() - Remove residual data files, anything left over from previous # runs that a clean run would need to clean up -function _cleanup_quantum() { +function cleanup_quantum() { : } diff --git a/lib/rpc_backend b/lib/rpc_backend index 02614eabb5..bbd51f0cdf 100644 --- a/lib/rpc_backend +++ b/lib/rpc_backend @@ -43,6 +43,38 @@ function check_rpc_backend() { fi } +# clean up after rpc backend - eradicate all traces so changing backends +# produces a clean switch +function cleanup_rpc_backend { + if is_service_enabled rabbit; then + # Obliterate rabbitmq-server + uninstall_package rabbitmq-server + sudo killall epmd + if is_ubuntu; then + # And the Erlang runtime too + sudo aptitude purge -y ~nerlang + fi + elif is_service_enabled qpid; then + if is_fedora; then + uninstall_package qpid-cpp-server-daemon + elif is_ubuntu; then + uninstall_package qpidd + else + exit_distro_not_supported "qpid installation" + fi + elif is_service_enabled zeromq; then + if is_fedora; then + uninstall_package zeromq python-zmq + elif is_ubuntu; then + uninstall_package libzmq1 python-zmq + elif is_suse; then + uninstall_package libzmq1 python-pyzmq + else + exit_distro_not_supported "zeromq installation" + fi + fi +} + # install rpc backend function install_rpc_backend() { if is_service_enabled rabbit; then diff --git a/lib/swift b/lib/swift index 5c4ceabb4a..04a54c3617 100644 --- a/lib/swift +++ b/lib/swift @@ -388,9 +388,11 @@ function start_swift() { # stop_swift() - Stop running processes (non-screen) function stop_swift() { # screen normally killed by unstack.sh - if type -p swift-init >/dev/null;then + if type -p swift-init >/dev/null; then swift-init --run-dir=${SWIFT_DATA_DIR}/run all stop || true fi + # Dump the proxy server + sudo pkill -f swift-proxy-server } # Restore xtrace diff --git a/stack.sh b/stack.sh index 7b4b3b778c..14bb1610f0 100755 --- a/stack.sh +++ b/stack.sh @@ -725,6 +725,8 @@ fi configure_glanceclient if is_service_enabled nova; then + # First clean up old instances + cleanup_nova configure_nova fi if is_service_enabled horizon; then