clean.sh updates

* Clean out data, log and state dirs
* Include lib/apache to clear is_apache_enabled_service not found error
* Clean errors removing tgt config files

* Clean errors removing VG backing file in lib/cinder

Change-Id: I33dfde17eb8daaaed7f7e76337fe6a8085a266bf
diff --git a/clean.sh b/clean.sh
index 480a812..e16bdb7 100755
--- a/clean.sh
+++ b/clean.sh
@@ -30,13 +30,17 @@
 # and ``DISTRO``
 GetDistro
 
+# Import apache functions
+source $TOP_DIR/lib/apache
+source $TOP_DIR/lib/ldap
 
 # Import database library
 source $TOP_DIR/lib/database
 source $TOP_DIR/lib/rpc_backend
 
-source $TOP_DIR/lib/oslo
 source $TOP_DIR/lib/tls
+
+source $TOP_DIR/lib/oslo
 source $TOP_DIR/lib/horizon
 source $TOP_DIR/lib/keystone
 source $TOP_DIR/lib/glance
@@ -47,7 +51,9 @@
 source $TOP_DIR/lib/heat
 source $TOP_DIR/lib/neutron
 source $TOP_DIR/lib/baremetal
-source $TOP_DIR/lib/ldap
+source $TOP_DIR/lib/ironic
+source $TOP_DIR/lib/trove
+
 
 # Extras Source
 # --------------
@@ -95,13 +101,6 @@
     cleanup_nova_hypervisor
 fi
 
-# cinder doesn't always 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
@@ -111,12 +110,19 @@
 sudo rm -rf /etc/keystone /etc/glance /etc/nova /etc/cinder /etc/swift
 
 # Clean out tgt
-sudo rm /etc/tgt/conf.d/*
+sudo rm -f /etc/tgt/conf.d/*
 
 # Clean up the message queue
 cleanup_rpc_backend
 cleanup_database
 
+# Clean out data, logs and status
+LOGDIR=$(dirname "$LOGFILE")
+sudo rm -rf $DATA_DIR $LOGDIR $DEST/status
+if [[ -n "$SCREEN_LOGDIR" ]] && [[ -d "$SCREEN_LOGDIR" ]]; then
+    sudo rm -rf $SCREEN_LOGDIR
+fi
+
 # Clean up networking...
 # should this be in nova?
 # FIXED_IP_ADDR in br100
diff --git a/lib/cinder b/lib/cinder
index cbe732e..45a9a25 100644
--- a/lib/cinder
+++ b/lib/cinder
@@ -109,8 +109,8 @@
     # of the backing file
     if [ -z "`sudo lvs --noheadings -o lv_name $vg`" ]; then
         # if the backing physical device is a loop device, it was probably setup by devstack
-        VG_DEV=$(sudo losetup -j $DATA_DIR/${vg}-backing-file | awk -F':' '/backing-file/ { print $1}')
-        if [[ -n "$VG_DEV" ]]; then
+        if [[ -n "$VG_DEV" ]] && [[ -e "$VG_DEV" ]]; then
+            VG_DEV=$(sudo losetup -j $DATA_DIR/${vg}-backing-file | awk -F':' '/backing-file/ { print $1}')
             sudo losetup -d $VG_DEV
             rm -f $DATA_DIR/${vg}-backing-file
         fi