summaryrefslogtreecommitdiff
diff options
authorPierre Equoy <pierre.equoy@canonical.com>2017-02-23 12:30:16 +0800
committerPierre Equoy <pierre.equoy@canonical.com>2017-02-23 12:30:16 +0800
commitb53fb0ac87dd52f2157416dcf92230347604eece (patch)
tree524fca2e2df7a75dcaa4913c9a8b724e58ed94c0
parent6d190232a1ad63b0065d2de0483547d0675d2d45 (diff)
Add auto-unmount feature in the storage test
It's better to put things back into the state they were before we started the test. The storage test now unmount any partition it may have mounted itself and removes the temporary directory created to mount it into. LP: #1660386
-rwxr-xr-xbin/storage_test29
1 files changed, 27 insertions, 2 deletions
diff --git a/bin/storage_test b/bin/storage_test
index 40cc3f2..1aed0da 100755
--- a/bin/storage_test
+++ b/bin/storage_test
@@ -59,6 +59,7 @@ find_largest_partition() {
} # find_largest_partition()
disk=/dev/$1
+scripted_mount=0
if [ -b $disk ]
then
@@ -93,10 +94,13 @@ then
find_largest_partition
if [ -n "$largest_part" ]
then
- dest=/tmp/drive/$partition
+ dest=`mktemp -dq --tmpdir drive.XXX`
echo "Mounting $largest_part into $dest..."
- mkdir -p $dest
mount $largest_part $dest
+ if [[ $? == 0 ]]
+ then
+ scripted_mount=1
+ fi
else
echo "$disk has no partition. Please format this drive and re-launch the test."
exit 1
@@ -115,12 +119,33 @@ then
if [ $size_int -gt 10 ]
then
run_bonnie $disk
+ if [[ $scripted_mount == 1 ]]
+ then
+ echo "$largest_part was mounted by this script. Unmounting it now..."
+ umount $largest_part
+ echo "Removing temporary mount directory $dest..."
+ rm -rf $dest
+ fi
else
echo "$disk is too small to be used for testing."
+ if [[ $scripted_mount == 1 ]]
+ then
+ echo "$largest_part was mounted by this script. Unmounting it now..."
+ umount $largest_part
+ echo "Removing temporary mount directory $dest..."
+ rm -rf $dest
+ fi
exit 1
fi
else
run_bonnie $disk
+ if [[ $scripted_mount == 1 ]]
+ then
+ echo "$largest_part was mounted by this script. Unmounting it now..."
+ umount $largest_part
+ echo "Removing temporary mount directory $dest..."
+ rm -rf $dest
+ fi
fi
else
echo "$disk doesn't report a size."