Merge "Clean up cinder volume group rather than remove it"

This commit is contained in:
Jenkins 2013-01-08 14:38:39 +00:00 committed by Gerrit Code Review
commit b2a1d7deae

View File

@ -48,6 +48,20 @@ fi
VOLUME_GROUP=${VOLUME_GROUP:-stack-volumes} VOLUME_GROUP=${VOLUME_GROUP:-stack-volumes}
VOLUME_NAME_PREFIX=${VOLUME_NAME_PREFIX:-volume-} VOLUME_NAME_PREFIX=${VOLUME_NAME_PREFIX:-volume-}
# _clean_volume_group removes all cinder volumes from the specified volume group
# _clean_volume_group $VOLUME_GROUP $VOLUME_NAME_PREFIX
function _clean_volume_group() {
local vg=$1
local vg_prefix=$2
# Clean out existing volumes
for lv in `sudo lvs --noheadings -o lv_name $vg`; do
# vg_prefix prefixes the LVs we want
if [[ "${lv#$vg_prefix}" != "$lv" ]]; then
sudo lvremove -f $vg/$lv
fi
done
}
# cleanup_cinder() - Remove residual data files, anything left over from previous # cleanup_cinder() - Remove residual data files, anything left over from previous
# runs that a clean run would need to clean up # runs that a clean run would need to clean up
function cleanup_cinder() { function cleanup_cinder() {
@ -84,7 +98,8 @@ function cleanup_cinder() {
stop_service tgtd stop_service tgtd
fi fi
sudo vgremove -f $VOLUME_GROUP # Campsite rule: leave behind a volume group at least as clean as we found it
_clean_volume_group $VOLUME_GROUP $VOLUME_NAME_PREFIX
} }
# configure_cinder() - Set config files, create data dirs, etc # configure_cinder() - Set config files, create data dirs, etc
@ -272,13 +287,8 @@ function init_cinder() {
# Remove iscsi targets # Remove iscsi targets
sudo tgtadm --op show --mode target | grep $VOLUME_NAME_PREFIX | grep Target | cut -f3 -d ' ' | sudo xargs -n1 tgt-admin --delete || true sudo tgtadm --op show --mode target | grep $VOLUME_NAME_PREFIX | grep Target | cut -f3 -d ' ' | sudo xargs -n1 tgt-admin --delete || true
# Clean out existing volumes # Start with a clean volume group
for lv in `sudo lvs --noheadings -o lv_name $VOLUME_GROUP`; do _clean_volume_group $VOLUME_GROUP $VOLUME_NAME_PREFIX
# VOLUME_NAME_PREFIX prefixes the LVs we want
if [[ "${lv#$VOLUME_NAME_PREFIX}" != "$lv" ]]; then
sudo lvremove -f $VOLUME_GROUP/$lv
fi
done
fi fi
fi fi