Fixes clean bug where $vm_dir is assumed to exist
[genesis.git] / foreman / ci / clean.sh
index 25352a8..0dc34ed 100755 (executable)
@@ -5,7 +5,7 @@
 #
 #Uses Vagrant and VirtualBox
 #
-#Destroys Vagrant VM running in /tmp/bgs_vagrant
+#Destroys Vagrant VM running in $vm_dir/foreman_vm
 #Shuts down all nodes found in Khaleesi settings
 #Removes hypervisor kernel modules (VirtualBox)
 
@@ -14,6 +14,8 @@ reset=`tput sgr0`
 blue=`tput setaf 4`
 red=`tput setaf 1`
 green=`tput setaf 2`
+
+vm_dir=/var/opt/opnfv
 ##END VARS
 
 ##FUNCTIONS
@@ -51,9 +53,10 @@ esac
 done
 
 
-##install ipmitool
+# Install ipmitool
+# Major version is pinned to force some consistency for Arno
 if ! yum list installed | grep -i ipmitool; then
-  if ! yum -y install ipmitool; then
+  if ! yum -y install ipmitool-1*; then
     echo "${red}Unable to install ipmitool!${reset}"
     exit 1
   fi
@@ -105,26 +108,36 @@ else
   skip_vagrant=1
 fi
 
+###legacy VM location check
+###remove me later
+if [ -d /tmp/bgs_vagrant ]; then
+  cd /tmp/bgs_vagrant
+  vagrant destroy -f
+  rm -rf /tmp/bgs_vagrant
+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
+  if [ -d $vm_dir/foreman_vm ]; then
+    cd $vm_dir/foreman_vm
+    if vagrant destroy -f; then
+      echo "${blue}Successfully destroyed Foreman VM ${reset}"
     else
-      echo "${blue}Vagrant process doesn't exist.  Moving on... ${reset}"
+      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
   fi
 
   ###kill virtualbox
   echo "${blue}Killing VirtualBox ${reset}"
   killall virtualbox
-  killall VboxHeadless
+  killall VBoxHeadless
 
   ###remove virtualbox
   echo "${blue}Removing VirtualBox ${reset}"
@@ -134,6 +147,8 @@ else
   echo "${blue}Skipping Vagrant destroy + Vbox Removal as VirtualBox package is already removed ${reset}"
 fi
 
+###remove working vm directory
+rm -rf $vm_dir
 
 ###remove kernel modules
 echo "${blue}Removing kernel modules ${reset}"