Skip to content

Commit

Permalink
Add reset function to cleanup docker-storage-setup configuration
Browse files Browse the repository at this point in the history
This script should cleanup devicemapper storage as well as
remove /etc/sysconfig/docker-storage

Closes: projectatomic#128
Approved by: rhvgoyal
  • Loading branch information
rhatdan authored and cgwalters-bot committed May 10, 2016
1 parent 9461ef9 commit 194eca2
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 10 deletions.
12 changes: 11 additions & 1 deletion docker-storage-setup.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -130,6 +137,9 @@ DATA_SIZE=8GB

.fi

.SH "SEE ALSO"
.BR atomic "(1)"

.SH HISTORY

.PP
Expand Down
41 changes: 32 additions & 9 deletions docker-storage-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
55 changes: 55 additions & 0 deletions tests/005-test-devmapper-cleanup.sh
Original file line number Diff line number Diff line change
@@ -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
44 changes: 44 additions & 0 deletions tests/006-test-overlay-cleanup.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 194eca2

Please sign in to comment.