Skip to content

Commit 3dc1803

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "clean up cinder on an unstack"
2 parents dcd3ffc + 252f2f5 commit 3dc1803

2 files changed

Lines changed: 35 additions & 32 deletions

File tree

lib/cinder

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff 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
5353
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
5688
}
5789

5890
# configure_cinder() - Set config files, create data dirs, etc

unstack.sh

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -71,36 +71,7 @@ SCSI_PERSIST_DIR=$CINDER_STATE_PATH/volumes/*
7171

7272
# Get the iSCSI volumes
7373
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
10475
fi
10576

10677
if [[ -n "$UNSTACK_ALL" ]]; then

0 commit comments

Comments
 (0)