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

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