Blame SOURCES/0034-tests-Use-wait_for_dev_to_-functions.patch

9e7f5d
From 4182428d60496b7fe61f0599156f871e3cd63f89 Mon Sep 17 00:00:00 2001
9e7f5d
From: "Brian C. Lane" <bcl@redhat.com>
9e7f5d
Date: Fri, 7 Aug 2015 11:43:17 -0700
9e7f5d
Subject: [PATCH 34/35] tests: Use wait_for_dev_to_ functions
9e7f5d
9e7f5d
Recent changes to udev have made some long-standing problems appear more
9e7f5d
frequently. udev executes various actions when changes are made to
9e7f5d
devices. Sometimes this can result in device nodes not appearing
9e7f5d
immediately. Other times it can result in EBUSY being returned. This
9e7f5d
patch only addresses devices that are slow to appear/disappear.
9e7f5d
9e7f5d
It is best to use the wait_for_dev_to_appear_ and
9e7f5d
wait_for_dev_to_disappear_ functions than to test for existance. These
9e7f5d
will loop and wait for up to 2 seconds for it to appear.
9e7f5d
9e7f5d
This also changes t9041 to fail if mkfs doesn't work since using skip
9e7f5d
here may hide cases when the device node doesn't appear.
9e7f5d
9e7f5d
Related: rhbz#1245144
9e7f5d
---
9e7f5d
 tests/t1100-busy-label.sh                       | 10 ++--------
9e7f5d
 tests/t6001-psep.sh                             |  4 ++--
9e7f5d
 tests/t6002-dm-many-partitions.sh               |  6 ++----
9e7f5d
 tests/t6004-dm-512b-sectors.sh                  |  1 +
9e7f5d
 tests/t6100-mdraid-partitions.sh                |  5 +++--
9e7f5d
 tests/t9041-undetected-in-use-16th-partition.sh |  2 +-
9e7f5d
 6 files changed, 11 insertions(+), 17 deletions(-)
9e7f5d
9e7f5d
diff --git a/tests/t1100-busy-label.sh b/tests/t1100-busy-label.sh
9e7f5d
index 9e371da..93229a7 100755
9e7f5d
--- a/tests/t1100-busy-label.sh
9e7f5d
+++ b/tests/t1100-busy-label.sh
9e7f5d
@@ -27,22 +27,16 @@ dev=$(cat dev-name)
9e7f5d
 
9e7f5d
 parted -s "$dev" mklabel msdos mkpart primary fat32 1 40 > out 2>&1 || fail=1
9e7f5d
 compare /dev/null out || fail=1
9e7f5d
-mkfs.vfat ${dev}1 || skip_ "mkfs.vfat failed"
9e7f5d
+wait_for_dev_to_appear_ ${dev}1 || fail=1
9e7f5d
+mkfs.vfat ${dev}1 || fail=1
9e7f5d
 
9e7f5d
 mount_point="`pwd`/mnt"
9e7f5d
 
9e7f5d
 # Be sure to unmount upon interrupt, failure, etc.
9e7f5d
 cleanup_fn_() { umount "${dev}1" > /dev/null 2>&1; }
9e7f5d
 
9e7f5d
-# There's a race condition here: on udev-based systems, the partition#1
9e7f5d
-# device, ${dev}1 (i.e., /dev/sdd1) is not created immediately, and
9e7f5d
-# without some delay, this mount command would fail.  Using a flash card
9e7f5d
-# as $dev, the loop below typically iterates 7-20 times.
9e7f5d
-
9e7f5d
 # create mount point dir. and mount the just-created partition on it
9e7f5d
 mkdir $mount_point || fail=1
9e7f5d
-i=0; while :; do test -e "${dev}1" && break; test $i = 90 && break;
9e7f5d
-  i=$(expr $i + 1); done;
9e7f5d
 mount "${dev}1" $mount_point || fail=1
9e7f5d
 
9e7f5d
 # now that a partition is mounted, mklabel attempt must fail
9e7f5d
diff --git a/tests/t6001-psep.sh b/tests/t6001-psep.sh
9e7f5d
index 0c1ab99..b747732 100644
9e7f5d
--- a/tests/t6001-psep.sh
9e7f5d
+++ b/tests/t6001-psep.sh
9e7f5d
@@ -55,7 +55,7 @@ parted -s $dev mklabel msdos mkpart primary fat32 1m 5m > out 2>&1 || fail=1
9e7f5d
 compare /dev/null out || fail=1
9e7f5d
 
9e7f5d
 #make sure device name is correct
9e7f5d
-test -e ${dev}p1 || fail=1
9e7f5d
+wait_for_dev_to_appear_ ${dev}p1 || fail=1
9e7f5d
 
9e7f5d
 #repeat on name not ending in a digit
9e7f5d
 # setup: create a mapping
9e7f5d
@@ -67,7 +67,7 @@ parted -s $dev mklabel msdos mkpart primary fat32 1m 5m > out 2>&1 || fail=1
9e7f5d
 compare /dev/null out || fail=1
9e7f5d
 
9e7f5d
 #make sure device name is correct
9e7f5d
-test -e ${dev}1 || fail=1
9e7f5d
+wait_for_dev_to_appear_ ${dev}1 || fail=1
9e7f5d
 
9e7f5d
 if [ -n "$fail" ]; then
9e7f5d
     ls /dev/mapper
9e7f5d
diff --git a/tests/t6002-dm-many-partitions.sh b/tests/t6002-dm-many-partitions.sh
9e7f5d
index 4d08e72..247c9ee 100755
9e7f5d
--- a/tests/t6002-dm-many-partitions.sh
9e7f5d
+++ b/tests/t6002-dm-many-partitions.sh
9e7f5d
@@ -49,10 +49,8 @@ parted -m -a min -s /dev/mapper/$dm_name mklabel gpt $cmd > /dev/null 2>&1 || fa
9e7f5d
 
9e7f5d
 # Make sure all the partitions appeared under /dev/mapper/
9e7f5d
 for ((i=1; i<=$n_partitions; i+=1)); do
9e7f5d
-    if [ ! -e "/dev/mapper/${dm_name}p$i" ]; then
9e7f5d
-        fail=1
9e7f5d
-        break
9e7f5d
-    fi
9e7f5d
+    wait_for_dev_to_appear_ "/dev/mapper/${dm_name}p$i" || { fail=1; break; }
9e7f5d
+
9e7f5d
     # remove the partitions as we go, otherwise cleanup won't work.
9e7f5d
     dmsetup remove /dev/mapper/${dm_name}p$i
9e7f5d
 done
9e7f5d
diff --git a/tests/t6004-dm-512b-sectors.sh b/tests/t6004-dm-512b-sectors.sh
9e7f5d
index 31abba9..c3045af 100644
9e7f5d
--- a/tests/t6004-dm-512b-sectors.sh
9e7f5d
+++ b/tests/t6004-dm-512b-sectors.sh
9e7f5d
@@ -60,6 +60,7 @@ dev="/dev/mapper/$linear_"
9e7f5d
 # Create msdos partition table with a partition from 1MiB to 100MiB
9e7f5d
 parted -s $dev mklabel msdos mkpart primary ext2 1MiB 101MiB > out 2>&1 || fail=1
9e7f5d
 compare /dev/null out || fail=1
9e7f5d
+wait_for_dev_to_appear_ ${dev}1 || fail=1
9e7f5d
 
9e7f5d
 # The size of the partition should be 100MiB, or 204800 512b sectors
9e7f5d
 p1_size=$(blockdev --getsz ${dev}1) || framework_failure
9e7f5d
diff --git a/tests/t6100-mdraid-partitions.sh b/tests/t6100-mdraid-partitions.sh
9e7f5d
index aedf69b..d7e7d6a 100755
9e7f5d
--- a/tests/t6100-mdraid-partitions.sh
9e7f5d
+++ b/tests/t6100-mdraid-partitions.sh
9e7f5d
@@ -54,13 +54,14 @@ parted -s $md_dev mklabel gpt \
9e7f5d
 compare /dev/null out || fail=1
9e7f5d
 
9e7f5d
 # Verify that kernel has been informed about the second device.
9e7f5d
-grep "${md_name}p2" /proc/partitions || { fail=1; cat /proc/partitions; }
9e7f5d
+wait_for_dev_to_appear_ ${md_dev}p2 || { fail=1; cat /proc/partitions; }
9e7f5d
 
9e7f5d
 # Remove partitions from the raid device.
9e7f5d
 parted -s $md_dev rm 2 rm 1 > out 2>&1 || fail=1
9e7f5d
 compare /dev/null out || fail=1
9e7f5d
 
9e7f5d
 # Verify that kernel has been informed about those removals.
9e7f5d
-grep "${md_name}p[12]" /proc/partitions && { fail=1; cat /proc/partitions; }
9e7f5d
+wait_for_dev_to_disappear_ ${md_dev}p1 2 || { fail=1; cat /proc/partitions; }
9e7f5d
+wait_for_dev_to_disappear_ ${md_dev}p2 2 || { fail=1; cat /proc/partitions; }
9e7f5d
 
9e7f5d
 Exit $fail
9e7f5d
diff --git a/tests/t9041-undetected-in-use-16th-partition.sh b/tests/t9041-undetected-in-use-16th-partition.sh
9e7f5d
index 6ddc7d8..0b22b0e 100644
9e7f5d
--- a/tests/t9041-undetected-in-use-16th-partition.sh
9e7f5d
+++ b/tests/t9041-undetected-in-use-16th-partition.sh
9e7f5d
@@ -72,7 +72,7 @@ wait_for_dev_to_appear_ ${scsi_dev}16 || fail_ ${scsi_dev}16 did not appear
9e7f5d
 
9e7f5d
 partitions="${scsi_dev}14 ${scsi_dev}15 ${scsi_dev}16"
9e7f5d
 for i in $partitions; do
9e7f5d
-  mkfs.ext3 $i || skip_ mkfs.ext3 $i failed
9e7f5d
+  mkfs.ext3 $i || fail=1
9e7f5d
 done
9e7f5d
 
9e7f5d
 # be sure to unmount upon interrupt, failure, etc.
9e7f5d
-- 
9e7f5d
2.4.3
9e7f5d