diff options
author | Tim Rozet <trozet@redhat.com> | 2015-05-04 14:19:18 -0400 |
---|---|---|
committer | Tim Rozet <trozet@redhat.com> | 2015-05-04 14:27:07 -0400 |
commit | 4dbf7b17313cc545a6052fed8027b0d6e9ba6a79 (patch) | |
tree | 1c82bc73119590b9cac57e8a0c2acf07c3a5ecf3 | |
parent | 4266577cd0a7c0816cd3bf951522c7ad1633f02b (diff) |
Adds clean script for Foreman/QuickStack Install Server
Script should be executed on the jumphost baremetal to ensure the clean state of a POD.
clean.sh will do the following:
- IPMI power off all the nodes
- Vagrant destroy the VM
- Remove VirtualBox Package
- Remove VirtualBox kernel modules from the host
JIRA: BGS-31
Change-Id: Iaf3dfc65b654cbcd19cc8326f328447ab017717e
Signed-off-by: Tim Rozet <trozet@redhat.com>
-rwxr-xr-x | foreman/ci/clean.sh | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/foreman/ci/clean.sh b/foreman/ci/clean.sh new file mode 100755 index 0000000..25352a8 --- /dev/null +++ b/foreman/ci/clean.sh @@ -0,0 +1,151 @@ +#!/usr/bin/env bash + +#Clean script to uninstall provisioning server for Foreman/QuickStack +#author: Tim Rozet (trozet@redhat.com) +# +#Uses Vagrant and VirtualBox +# +#Destroys Vagrant VM running in /tmp/bgs_vagrant +#Shuts down all nodes found in Khaleesi settings +#Removes hypervisor kernel modules (VirtualBox) + +##VARS +reset=`tput sgr0` +blue=`tput setaf 4` +red=`tput setaf 1` +green=`tput setaf 2` +##END VARS + +##FUNCTIONS +display_usage() { + echo -e "\n\n${blue}This script is used to uninstall Foreman/QuickStack Installer and Clean OPNFV Target System${reset}\n\n" + echo -e "\nUsage:\n$0 [arguments] \n" + echo -e "\n -no_parse : No variable parsing into config. Flag. \n" + echo -e "\n -base_config : Full path of ksgen settings file to parse. Required. Will provide BMC info to shutdown hosts. Example: -base_config /opt/myinventory.yml \n" +} + +##END FUNCTIONS + +if [[ ( $1 == "--help") || $1 == "-h" ]]; then + display_usage + exit 0 +fi + +echo -e "\n\n${blue}This script is used to uninstall Foreman/QuickStack Installer and Clean OPNFV Target System${reset}\n\n" +echo "Use -h to display help" +sleep 2 + +while [ "`echo $1 | cut -c1`" = "-" ] +do + echo $1 + case "$1" in + -base_config) + base_config=$2 + shift 2 + ;; + *) + display_usage + exit 1 + ;; +esac +done + + +##install ipmitool +if ! yum list installed | grep -i ipmitool; then + if ! yum -y install ipmitool; then + echo "${red}Unable to install ipmitool!${reset}" + exit 1 + fi +else + echo "${blue}Skipping ipmitool as it is already installed!${reset}" +fi + +###find all the bmc IPs and number of nodes +node_counter=0 +output=`grep bmc_ip $base_config | grep -Eo '[0-9]+.[0-9]+.[0-9]+.[0-9]+'` +for line in ${output} ; do + bmc_ip[$node_counter]=$line + ((node_counter++)) +done + +max_nodes=$((node_counter-1)) + +###find bmc_users per node +node_counter=0 +output=`grep bmc_user $base_config | sed 's/\s*bmc_user:\s*//'` +for line in ${output} ; do + bmc_user[$node_counter]=$line + ((node_counter++)) +done + +###find bmc_pass per node +node_counter=0 +output=`grep bmc_pass $base_config | sed 's/\s*bmc_pass:\s*//'` +for line in ${output} ; do + bmc_pass[$node_counter]=$line + ((node_counter++)) +done + +for mynode in `seq 0 $max_nodes`; do + echo "${blue}Node: ${bmc_ip[$mynode]} ${bmc_user[$mynode]} ${bmc_pass[$mynode]} ${reset}" + if ipmitool -I lanplus -P ${bmc_pass[$mynode]} -U ${bmc_user[$mynode]} -H ${bmc_ip[$mynode]} chassis power off; then + echo "${blue}Node: $mynode, ${bmc_ip[$mynode]} powered off!${reset}" + else + echo "${red}Error: Unable to power off $mynode, ${bmc_ip[$mynode]} ${reset}" + exit 1 + fi +done + +###check to see if vbox is installed +vboxpkg=`rpm -qa | grep VirtualBox` +if [ $? -eq 0 ]; then + skip_vagrant=0 +else + skip_vagrant=1 +fi + +###destroy vagrant +if [ $skip_vagrant -eq 0 ]; then + cd /tmp/bgs_vagrant + if vagrant destroy -f; then + echo "${blue}Successfully destroyed Foreman VM ${reset}" + else + echo "${red}Unable to destroy Foreman VM ${reset}" + echo "${blue}Checking if vagrant was already destroyed and no process is active...${reset}" + if ps axf | grep vagrant; then + echo "${red}Vagrant VM still exists...exiting ${reset}" + exit 1 + else + echo "${blue}Vagrant process doesn't exist. Moving on... ${reset}" + fi + fi + + ###kill virtualbox + echo "${blue}Killing VirtualBox ${reset}" + killall virtualbox + killall VboxHeadless + + ###remove virtualbox + echo "${blue}Removing VirtualBox ${reset}" + yum -y remove $vboxpkg + +else + echo "${blue}Skipping Vagrant destroy + Vbox Removal as VirtualBox package is already removed ${reset}" +fi + + +###remove kernel modules +echo "${blue}Removing kernel modules ${reset}" +for kernel_mod in vboxnetadp vboxnetflt vboxpci vboxdrv; do + if ! rmmod $kernel_mod; then + if rmmod $kernel_mod 2>&1 | grep -i 'not currently loaded'; then + echo "${blue} $kernel_mod is not currently loaded! ${reset}" + else + echo "${red}Error trying to remove Kernel Module: $kernel_mod ${reset}" + exit 1 + fi + else + echo "${blue}Removed Kernel Module: $kernel_mod ${reset}" + fi +done |