diff options
author | Pierre Equoy <pierre.equoy@canonical.com> | 2017-02-23 12:30:16 +0800 |
---|---|---|
committer | Sylvain Pineau <sylvain.pineau@canonical.com> | 2017-04-03 09:39:22 +0200 |
commit | 8acbfca96557c740e491af5da52f6ea2dd75533f (patch) | |
tree | 524fca2e2df7a75dcaa4913c9a8b724e58ed94c0 | |
parent | 218669e55de18313cb31e9f67c5b7b73f0fa755e (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-x | bin/storage_test | 29 |
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." |