clean up cinder on an unstack

cinder currently has issues that leave volumes around
after tempest tests. Make sure that cinder gets cleaned
up to a zero state on an unstack.sh so that we can reset
the environment.

Change-Id: I448340899bf0fae7d4d16fa26da17feafcef888f
diff --git a/lib/cinder b/lib/cinder
index 2b2f8f1..dadc8f1 100644
--- a/lib/cinder
+++ b/lib/cinder
@@ -51,8 +51,40 @@
 # cleanup_cinder() - Remove residual data files, anything left over from previous
 # runs that a clean run would need to clean up
 function cleanup_cinder() {
-    # This function intentionally left blank
-    :
+    # ensure the volume group is cleared up because fails might
+    # leave dead volumes in the group
+    TARGETS=$(sudo tgtadm --op show --mode target)
+    if [ $? -ne 0 ]; then
+        # If tgt driver isn't running this won't work obviously
+        # So check the response and restart if need be
+        echo "tgtd seems to be in a bad state, restarting..."
+        if is_ubuntu; then
+            restart_service tgt
+        else
+            restart_service tgtd
+        fi
+        TARGETS=$(sudo tgtadm --op show --mode target)
+    fi
+
+    if [[ -n "$TARGETS" ]]; then
+        iqn_list=( $(grep --no-filename -r iqn $SCSI_PERSIST_DIR | sed 's/<target //' | sed 's/>//') )
+        for i in "${iqn_list[@]}"; do
+            echo removing iSCSI target: $i
+            sudo tgt-admin --delete $i
+        done
+    fi
+
+    if is_service_enabled cinder; then
+        sudo rm -rf $CINDER_STATE_PATH/volumes/*
+    fi
+
+    if is_ubuntu; then
+        stop_service tgt
+    else
+        stop_service tgtd
+    fi
+
+    sudo vgremove -f $VOLUME_GROUP
 }
 
 # configure_cinder() - Set config files, create data dirs, etc