Browse code

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

Sean Dague authored on 2012/12/21 06:41:57
Showing 2 changed files
... ...
@@ -51,8 +51,40 @@ VOLUME_NAME_PREFIX=${VOLUME_NAME_PREFIX:-volume-}
51 51
 # cleanup_cinder() - Remove residual data files, anything left over from previous
52 52
 # runs that a clean run would need to clean up
53 53
 function cleanup_cinder() {
54
-    # This function intentionally left blank
55
-    :
54
+    # ensure the volume group is cleared up because fails might
55
+    # leave dead volumes in the group
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 is_ubuntu; then
62
+            restart_service tgt
63
+        else
64
+            restart_service tgtd
65
+        fi
66
+        TARGETS=$(sudo tgtadm --op show --mode target)
67
+    fi
68
+
69
+    if [[ -n "$TARGETS" ]]; then
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_ubuntu; then
82
+        stop_service tgt
83
+    else
84
+        stop_service tgtd
85
+    fi
86
+
87
+    sudo vgremove -f $VOLUME_GROUP
56 88
 }
57 89
 
58 90
 # configure_cinder() - Set config files, create data dirs, etc
... ...
@@ -71,36 +71,7 @@ SCSI_PERSIST_DIR=$CINDER_STATE_PATH/volumes/*
71 71
 
72 72
 # Get the iSCSI volumes
73 73
 if is_service_enabled cinder; then
74
-    TARGETS=$(sudo tgtadm --op show --mode target)
75
-    if [ $? -ne 0 ]; then
76
-        # If tgt driver isn't running this won't work obviously
77
-        # So check the response and restart if need be
78
-        echo "tgtd seems to be in a bad state, restarting..."
79
-        if is_ubuntu; then
80
-            restart_service tgt
81
-        else
82
-            restart_service tgtd
83
-        fi
84
-        TARGETS=$(sudo tgtadm --op show --mode target)
85
-    fi
86
-
87
-    if [[ -n "$TARGETS" ]]; then
88
-        iqn_list=( $(grep --no-filename -r iqn $SCSI_PERSIST_DIR | sed 's/<target //' | sed 's/>//') )
89
-        for i in "${iqn_list[@]}"; do
90
-            echo removing iSCSI target: $i
91
-            sudo tgt-admin --delete $i
92
-        done
93
-    fi
94
-
95
-    if is_service_enabled cinder; then
96
-        sudo rm -rf $CINDER_STATE_PATH/volumes/*
97
-    fi
98
-
99
-    if is_ubuntu; then
100
-        stop_service tgt
101
-    else
102
-        stop_service tgtd
103
-    fi
74
+    cleanup_cinder
104 75
 fi
105 76
 
106 77
 if [[ -n "$UNSTACK_ALL" ]]; then