From 252f2f533ba8cb6607ddbbcdd1c4aff01dbfb5c3 Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Thu, 20 Dec 2012 16:41:57 -0500 Subject: [PATCH] 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 --- lib/cinder | 36 ++++++++++++++++++++++++++++++++++-- unstack.sh | 31 +------------------------------ 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/lib/cinder b/lib/cinder index 2b2f8f1b06..dadc8f142e 100644 --- a/lib/cinder +++ b/lib/cinder @@ -51,8 +51,40 @@ VOLUME_NAME_PREFIX=${VOLUME_NAME_PREFIX:-volume-} # 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///') ) + 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 diff --git a/unstack.sh b/unstack.sh index 09e0de6bef..949745e5a7 100755 --- a/unstack.sh +++ b/unstack.sh @@ -71,36 +71,7 @@ SCSI_PERSIST_DIR=$CINDER_STATE_PATH/volumes/* # Get the iSCSI volumes if is_service_enabled cinder; then - 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///') ) - 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 + cleanup_cinder fi if [[ -n "$UNSTACK_ALL" ]]; then