summaryrefslogtreecommitdiff
diff options
authorPierre Equoy <pierre.equoy@canonical.com>2017-02-16 15:04:59 +0800
committerSylvain Pineau <sylvain.pineau@canonical.com>2017-04-03 09:39:22 +0200
commit218669e55de18313cb31e9f67c5b7b73f0fa755e (patch)
treeabae5e5033c939c5d319db881e7d45923f54aba4
parentd5e45e020c895b03d358a6d846d9c84ef336909b (diff)
Automatically mount drives when running storage tests
When running disk/storage_device_* jobs, if the drive is not mounted, we now check if it can be mounted (i.e. if it has a partition) and if possible we mount it to a dedicated temporary location in order to perform the storage tests. LP: #1660386
-rwxr-xr-xbin/storage_test40
1 files changed, 39 insertions, 1 deletions
diff --git a/bin/storage_test b/bin/storage_test
index ef19c5e..40cc3f2 100755
--- a/bin/storage_test
+++ b/bin/storage_test
@@ -30,6 +30,34 @@ function run_bonnie() {
fi
}
+# Find the largest partition that holds a supported filesystem on $disk_device.
+# This code is adapted from a similar function in `disk_stress_ng`.
+# Output:
+# $largest_part -- Device filename of largest qualifying partition or logical volume
+# $largest_size -- Size of largest qualifying partition or logical volume
+# $largest_fs -- Filesystem (ext4, etc.) used on largest qualifying partition or logical volume
+# $unsupported_fs -- Empty or contains name of unsupported filesystem found on disk
+find_largest_partition() {
+ largest_part=""
+ largest_size=0
+ partitions=$(lsblk -b -l -n -o NAME,SIZE,TYPE,MOUNTPOINT $disk | grep part | tr -s " ")
+ unsupported_fs=""
+ for partition in $(echo "$partitions" | cut -d " " -f 1) ; do
+ part_size=$(echo "$partitions" | grep "$partition " | cut -d " " -f 2)
+ local blkid_info=$(blkid -s TYPE /dev/$partition | grep -E ext2\|ext3\|ext4\|xfs\|jfs\|btrfs)
+ if [ "$part_size" -gt "$largest_size" ] && [ -n "$blkid_info" ] ; then
+ largest_size=$part_size
+ largest_part="/dev/$partition"
+ largest_fs=$(blkid -s TYPE "/dev/$partition" | cut -d "=" -f 2)
+ fi
+ local blkid_info=$(blkid -s TYPE /dev/$partition | grep -E ntfs\|vfat\|hfs)
+ if [ -n "$blkid_info" ] ; then
+ # If there's an NTFS, HFS+, or FAT filesystem on the disk make note of it....
+ unsupported_fs=$(blkid -s TYPE "/dev/$partition" | cut -d "=" -f 2)
+ fi
+ done
+} # find_largest_partition()
+
disk=/dev/$1
if [ -b $disk ]
@@ -62,7 +90,17 @@ then
echo "$disk is mounted, proceeding."
else
echo "$disk is not mounted. It must be mounted before testing."
- exit 1
+ find_largest_partition
+ if [ -n "$largest_part" ]
+ then
+ dest=/tmp/drive/$partition
+ echo "Mounting $largest_part into $dest..."
+ mkdir -p $dest
+ mount $largest_part $dest
+ else
+ echo "$disk has no partition. Please format this drive and re-launch the test."
+ exit 1
+ fi
fi