From 8acbfca96557c740e491af5da52f6ea2dd75533f Mon Sep 17 00:00:00 2001 From: Pierre Equoy Date: Thu, 23 Feb 2017 12:30:16 +0800 Subject: 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 --- bin/storage_test | 29 +++++++++++++++++++++++++++-- 1 file 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." -- cgit v1.2.3