File tree Expand file tree Collapse file tree 2 files changed +35
-32
lines changed
Expand file tree Collapse file tree 2 files changed +35
-32
lines changed Original file line number Diff line number Diff line change @@ -51,8 +51,40 @@ VOLUME_NAME_PREFIX=${VOLUME_NAME_PREFIX:-volume-}
5151# cleanup_cinder() - Remove residual data files, anything left over from previous
5252# runs that a clean run would need to clean up
5353function 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
5688}
5789
5890# configure_cinder() - Set config files, create data dirs, etc
Original file line number Diff line number Diff line change @@ -71,36 +71,7 @@ SCSI_PERSIST_DIR=$CINDER_STATE_PATH/volumes/*
7171
7272# Get the iSCSI volumes
7373if 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
10475fi
10576
10677if [[ -n " $UNSTACK_ALL " ]]; then
You can’t perform that action at this time.
0 commit comments