Browse code

Merge "Enhance tgt cleanup in unstack.sh"

Jenkins authored on 2012/09/18 04:28:53
Showing 1 changed files
... ...
@@ -18,6 +18,13 @@ source $TOP_DIR/functions
18 18
 # Load local configuration
19 19
 source $TOP_DIR/stackrc
20 20
 
21
+# Destination path for service data
22
+DATA_DIR=${DATA_DIR:-${DEST}/data}
23
+
24
+# Get project function libraries
25
+source $TOP_DIR/lib/cinder
26
+source $TOP_DIR/lib/n-vol
27
+
21 28
 # Determine what system we are running on.  This provides ``os_VENDOR``,
22 29
 # ``os_RELEASE``, ``os_UPDATE``, ``os_PACKAGE``, ``os_CODENAME``
23 30
 GetOSVersion
... ...
@@ -45,14 +52,41 @@ if is_service_enabled horizon; then
45 45
     stop_service apache2
46 46
 fi
47 47
 
48
+SCSI_PERSIST_DIR=$CINDER_STATE_PATH/volumes/*
49
+
48 50
 # Get the iSCSI volumes
49 51
 if is_service_enabled cinder n-vol; then
52
+    if is_service_enabled n-vol; then
53
+        SCSI_PERSIST_DIR=$NOVA_STATE_PATH/volumes/*
54
+    fi
55
+
50 56
     TARGETS=$(sudo tgtadm --op show --mode target)
57
+    if [ $? -ne 0 ]; then
58
+        # If tgt driver isn't running this won't work obviously
59
+        # So check the response and restart if need be
60
+        echo "tgtd seems to be in a bad state, restarting..."
61
+        if [[ "$os_PACKAGE" = "deb" ]]; then
62
+            restart_service tgt
63
+        else
64
+            restart_service tgtd
65
+        fi
66
+        TARGETS=$(sudo tgtadm --op show --mode target)
67
+    fi
68
+
51 69
     if [[ -n "$TARGETS" ]]; then
52
-        # FIXME(dtroyer): this could very well require more here to
53
-        #                 clean up left-over volumes
54
-        echo "iSCSI target cleanup needed:"
55
-        echo "$TARGETS"
70
+        iqn_list=( $(grep --no-filename -r iqn $SCSI_PERSIST_DIR | sed 's/<target //' | sed 's/>//') )
71
+        for i in "${iqn_list[@]}"; do
72
+            echo removing iSCSI target: $i
73
+            sudo tgt-admin --delete $i
74
+        done
75
+    fi
76
+
77
+    if is_service_enabled cinder; then
78
+        sudo rm -rf $CINDER_STATE_PATH/volumes/*
79
+    fi
80
+
81
+    if is_service_enabled n-vol; then
82
+        sudo rm -rf $NOVA_STATE_PATH/volumes/*
56 83
     fi
57 84
 
58 85
     if [[ "$os_PACKAGE" = "deb" ]]; then