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
diff --git a/clean.sh b/clean.sh
new file mode 100755
index 0000000..cf24f27
--- /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 220da9d..f8f63c5 100644
--- a/functions
+++ b/functions
@@ -775,6 +775,21 @@
}
+# 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 ebab333..79b77a2 100644
--- a/lib/database
+++ b/lib/database
@@ -42,6 +42,11 @@
# 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 ec65c36..0633ab0 100644
--- a/lib/databases/mysql
+++ b/lib/databases/mysql
@@ -10,6 +10,24 @@
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 7d4a6c5..efc206f 100644
--- a/lib/databases/postgresql
+++ b/lib/databases/postgresql
@@ -10,6 +10,20 @@
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 9ec2112..edf6982 100644
--- a/lib/glance
+++ b/lib/glance
@@ -59,8 +59,7 @@
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 906a635..23346b7 100644
--- a/lib/nova
+++ b/lib/nova
@@ -106,6 +106,8 @@
# 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 @@
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 66360d4..862ba84 100644
--- a/lib/quantum
+++ b/lib/quantum
@@ -211,8 +211,6 @@
fi
_configure_quantum_debug_command
-
- _cleanup_quantum
}
function create_nova_conf_quantum() {
@@ -385,9 +383,9 @@
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 02614ea..bbd51f0 100644
--- a/lib/rpc_backend
+++ b/lib/rpc_backend
@@ -43,6 +43,38 @@
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 5c4ceab..04a54c3 100644
--- a/lib/swift
+++ b/lib/swift
@@ -388,9 +388,11 @@
# 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 7b4b3b7..14bb161 100755
--- a/stack.sh
+++ b/stack.sh
@@ -725,6 +725,8 @@
configure_glanceclient
if is_service_enabled nova; then
+ # First clean up old instances
+ cleanup_nova
configure_nova
fi
if is_service_enabled horizon; then