diff --git a/docker-storage-setup.1 b/docker-storage-setup.1 index 2ddac7f..e255a3a 100644 --- a/docker-storage-setup.1 +++ b/docker-storage-setup.1 @@ -7,9 +7,16 @@ docker\-storage\-setup - Grows the root filesystem and sets up storage for docke \f[B]docker-storage-setup\f[] [OPTIONS] .SH OPTIONS .PP -\f[B]-h, --help\f[] +\f[B]--help\f[] Print usage statement +\f[B]--reset\f[] + Reset your docker storage to init state. Reset does not try to remove volume groups or try to remove any of the disks added previously. + +Note: The +\f[B]--reset\f[] +command is not sufficient to cleanup your docker environment. This option is used by other tools. (\f[B]atomic storage reset\f[]) + .SH EXAMPLES Run \f[B]docker-storage-setup\f[] after setting up your configuration in /etc/sysconfig/docker-storage-setup. One can look at @@ -130,6 +137,9 @@ DATA_SIZE=8GB .fi +.SH "SEE ALSO" +.BR atomic "(1)" + .SH HISTORY .PP diff --git a/docker-storage-setup.sh b/docker-storage-setup.sh index 5cc665c..f3ad571 100755 --- a/docker-storage-setup.sh +++ b/docker-storage-setup.sh @@ -390,6 +390,13 @@ check_docker_storage_metadata() { exit 1 } +reset_lvm_thin_pool () { + if lvm_pool_exists; then + lvchange -an $VG/${POOL_LV_NAME} + lvremove $VG/${POOL_LV_NAME} + fi +} + setup_lvm_thin_pool () { local tpool @@ -834,24 +841,25 @@ setup_storage() { fi } +reset_storage() { + if [ "$STORAGE_DRIVER" == "devicemapper" ]; then + reset_lvm_thin_pool + fi + rm -f $DOCKER_STORAGE +} + usage() { - cat >&2 <<-FOE + cat <<-FOE Usage: $1 [OPTIONS] Grows the root filesystem and sets up storage for docker Options: - -h, --help Print help message + --help Print help message + --reset Reset your docker storage to init state. FOE } -# Main Script - -if [ $# -gt 0 ]; then - usage $(basename $0) - exit 0 -fi - # Source library. If there is a library present in same dir as d-s-s, source # that otherwise fall back to standard library. This is useful when modifyin # libdss.sh in git tree and testing d-s-s. @@ -899,6 +907,21 @@ else fi fi +# Main Script + +if [ $# -gt 0 ]; then + if [ "$1" == "--help" ]; then + usage $(basename $0) + exit 0 + elif [ "$1" == "--reset" ]; then + reset_storage + exit 0 + else + usage $(basename $0) >&2 + exit 1 + fi +fi + # If there is no volume group specified or no root volume group, there is # nothing to do in terms of dealing with disks. if [[ -n "$DEVS" && -n "$VG" ]]; then diff --git a/tests/005-test-devmapper-cleanup.sh b/tests/005-test-devmapper-cleanup.sh new file mode 100755 index 0000000..f820eba --- /dev/null +++ b/tests/005-test-devmapper-cleanup.sh @@ -0,0 +1,55 @@ +source $SRCDIR/libtest.sh + +# Test "docker-storage-setup reset". Returns 0 on success and 1 on failure. +test_reset_devmapper() { + local devs=${TEST_DEVS} + local test_status + local testname=`basename "$0"` + local vg_name="dss-test-foo" + + # Error out if any pre-existing volume group vg named dss-test-foo + for vg in $(vgs --noheadings -o vg_name); do + if [ "$vg" == "$vg_name" ]; then + echo "ERROR: $testname: Volume group $vg_name already exists." + return 1 + fi + done + + # Create config file + clean_config_files + cat << EOF > /etc/sysconfig/docker-storage-setup +DEVS="$devs" +VG=$vg_name +EOF + + # Run docker-storage-setup + $DSSBIN >> $LOGS 2>&1 + + # Test failed. + if [ $? -ne 0 ]; then + echo "ERROR: $testname: $DSSBIN Failed." >> $LOGS + cleanup $vg_name "$devs" + return 1 + fi + + test_status=1 + $DSSBIN --reset >> $LOGS 2>&1 + # Test failed. + if [ $? -eq 0 ]; then + if [ ! -e /etc/sysconfig/docker-storage ]; then + test_status=0 + fi + fi + if [ ${test_status} -eq 1 ]; then + echo "ERROR: $testname: $DSSBIN --reset Failed." >> $LOGS + fi + + cleanup $vg_name "$devs" + + return $test_status +} + +# Create a devicemapper docker backend and then make sure the +# `docker-storage-setup --reset` +# cleans it up properly. +test_reset_devmapper diff --git a/tests/006-test-overlay-cleanup.sh b/tests/006-test-overlay-cleanup.sh new file mode 100755 index 0000000..16b2874 --- /dev/null +++ b/tests/006-test-overlay-cleanup.sh @@ -0,0 +1,44 @@ +source $SRCDIR/libtest.sh + +# Test "docker-storage-setup reset". Returns 0 on success and 1 on failure. +test_reset_overlay() { + local test_status + local testname=`basename "$0"` + + # Create config file + clean_config_files + cat << EOF > /etc/sysconfig/docker-storage-setup +STORAGE_DRIVER=overlay +EOF + + # Run docker-storage-setup + $DSSBIN >> $LOGS 2>&1 + + # Test failed. + if [ $? -ne 0 ]; then + echo "ERROR: $testname: $DSSBIN Failed." >> $LOGS + clean_config_files + return 1 + fi + + test_status=0 + $DSSBIN --reset >> $LOGS 2>&1 + if [ $? -ne 0 ]; then + # Test failed. + test_status=1 + elif [ -e /etc/sysconfig/docker-storage ]; then + # Test failed. + test_status=1 + fi + if [ ${test_status} -eq 1 ]; then + echo "ERROR: $testname: $DSSBIN --reset Failed." >> $LOGS + fi + + clean_config_files + return $test_status +} + +# Create a overlay docker backend and then make sure the +# docker-storage-setup --reset +# cleans it up properly. +test_reset_overlay