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

0cb0b9
From f72968f996372d923dbeded302395d8f08445b31 Mon Sep 17 00:00:00 2001
0cb0b9
From: "Brian C. Lane" <bcl@redhat.com>
0cb0b9
Date: Fri, 7 Aug 2015 11:43:17 -0700
0cb0b9
Subject: [PATCH 20/20] tests: Use wait_for_dev_to_ functions
0cb0b9
0cb0b9
Recent changes to udev have made some long-standing problems appear more
0cb0b9
frequently. udev executes various actions when changes are made to
0cb0b9
devices. Sometimes this can result in device nodes not appearing
0cb0b9
immediately. Other times it can result in EBUSY being returned. This
0cb0b9
patch only addresses devices that are slow to appear/disappear.
0cb0b9
0cb0b9
It is best to use the wait_for_dev_to_appear_ and
0cb0b9
wait_for_dev_to_disappear_ functions than to test for existance. These
0cb0b9
will loop and wait for up to 2 seconds for it to appear.
0cb0b9
0cb0b9
This also changes t9041 to fail if mkfs doesn't work since using skip
0cb0b9
here may hide cases when the device node doesn't appear.
0cb0b9
0cb0b9
(cherry picked from commit 1dc13965e1108ab513662450e0171c3ea3af3bd1)
0cb0b9
---
0cb0b9
 tests/t1100-busy-label.sh                       | 10 ++--------
0cb0b9
 tests/t1102-loop-label.sh                       | 25 +++++--------------------
0cb0b9
 tests/t2320-dos-extended-noclobber.sh           |  1 +
0cb0b9
 tests/t6001-psep.sh                             |  4 ++--
0cb0b9
 tests/t6004-dm-many-partitions.sh               |  6 ++----
0cb0b9
 tests/t6006-dm-512b-sectors.sh                  |  1 +
0cb0b9
 tests/t6100-mdraid-partitions.sh                |  5 +++--
0cb0b9
 tests/t9041-undetected-in-use-16th-partition.sh |  2 +-
0cb0b9
 8 files changed, 17 insertions(+), 37 deletions(-)
0cb0b9
0cb0b9
diff --git a/tests/t1100-busy-label.sh b/tests/t1100-busy-label.sh
0cb0b9
index 4e256d3..70e8ede 100755
0cb0b9
--- a/tests/t1100-busy-label.sh
0cb0b9
+++ b/tests/t1100-busy-label.sh
0cb0b9
@@ -27,22 +27,16 @@ dev=$(cat dev-name)
0cb0b9
 
0cb0b9
 parted -s "$dev" mklabel msdos mkpart primary fat32 1 40 > out 2>&1 || fail=1
0cb0b9
 compare /dev/null out || fail=1
0cb0b9
-mkfs.vfat ${dev}1 || skip_ "mkfs.vfat failed"
0cb0b9
+wait_for_dev_to_appear_ ${dev}1 || fail=1
0cb0b9
+mkfs.vfat ${dev}1 || fail=1
0cb0b9
 
0cb0b9
 mount_point="`pwd`/mnt"
0cb0b9
 
0cb0b9
 # Be sure to unmount upon interrupt, failure, etc.
0cb0b9
 cleanup_fn_() { umount "${dev}1" > /dev/null 2>&1; }
0cb0b9
 
0cb0b9
-# There's a race condition here: on udev-based systems, the partition#1
0cb0b9
-# device, ${dev}1 (i.e., /dev/sdd1) is not created immediately, and
0cb0b9
-# without some delay, this mount command would fail.  Using a flash card
0cb0b9
-# as $dev, the loop below typically iterates 7-20 times.
0cb0b9
-
0cb0b9
 # create mount point dir. and mount the just-created partition on it
0cb0b9
 mkdir $mount_point || fail=1
0cb0b9
-i=0; while :; do test -e "${dev}1" && break; test $i = 90 && break;
0cb0b9
-  i=$(expr $i + 1); done;
0cb0b9
 mount "${dev}1" $mount_point || fail=1
0cb0b9
 
0cb0b9
 # now that a partition is mounted, mklabel attempt must fail
0cb0b9
diff --git a/tests/t1102-loop-label.sh b/tests/t1102-loop-label.sh
0cb0b9
index 9752002..68b9af4 100644
0cb0b9
--- a/tests/t1102-loop-label.sh
0cb0b9
+++ b/tests/t1102-loop-label.sh
0cb0b9
@@ -44,15 +44,9 @@ mv out o2 && sed -e "s,$dev,DEVICE,;s/  *$//" o2 > out
0cb0b9
 
0cb0b9
 compare exp out || fail=1
0cb0b9
 parted -s $dev rm 1 || fail=1
0cb0b9
-if [ -e ${dev}1 ]; then
0cb0b9
-    echo "Partition should not exist on loop device"
0cb0b9
-    fail=1
0cb0b9
-fi
0cb0b9
+wait_for_dev_to_disappear_ ${dev}1 2 || fail=1
0cb0b9
 partprobe $dev || fail=1
0cb0b9
-if [ -e ${dev}1 ]; then
0cb0b9
-    echo "Partition should not exist on loop device"
0cb0b9
-    fail=1
0cb0b9
-fi
0cb0b9
+wait_for_dev_to_disappear_ ${dev}1 2 || fail=1
0cb0b9
 
0cb0b9
 mount_point="`pwd`/mnt"
0cb0b9
 
0cb0b9
@@ -80,24 +74,15 @@ umount "$mount_point"
0cb0b9
 
0cb0b9
 # make sure partprobe cleans up stale partition devices
0cb0b9
 parted -s $dev mklabel msdos mkpart primary ext2 0% 100% || fail=1
0cb0b9
-if [ ! -e ${dev}1 ]; then
0cb0b9
-    echo "Partition doesn't exist on loop device"
0cb0b9
-    fail=1
0cb0b9
-fi
0cb0b9
+wait_for_dev_to_appear_ ${dev}1 || fail=1
0cb0b9
 
0cb0b9
 mke2fs -F $dev
0cb0b9
 partprobe $dev || fail=1
0cb0b9
-if [ -e ${dev}1 ]; then
0cb0b9
-    echo "Partition should not exist on loop device"
0cb0b9
-    fail=1
0cb0b9
-fi
0cb0b9
+wait_for_dev_to_disappear_ ${dev}1 2 || fail=1
0cb0b9
 
0cb0b9
 # make sure new loop label removes old partitions > 1
0cb0b9
 parted -s $dev mklabel msdos mkpart primary ext2 0% 50% mkpart primary ext2 50% 100% || fail=1
0cb0b9
 parted -s $dev mklabel loop || fail=1
0cb0b9
-if [ -e ${dev}2 ]; then
0cb0b9
-    echo "Partition 2 not removed"
0cb0b9
-    fail=1
0cb0b9
-fi
0cb0b9
+wait_for_dev_to_disappear_ ${dev}2 2 || fail=1
0cb0b9
 
0cb0b9
 Exit $fail
0cb0b9
diff --git a/tests/t2320-dos-extended-noclobber.sh b/tests/t2320-dos-extended-noclobber.sh
0cb0b9
index 6f3dfff..bbc4f26 100644
0cb0b9
--- a/tests/t2320-dos-extended-noclobber.sh
0cb0b9
+++ b/tests/t2320-dos-extended-noclobber.sh
0cb0b9
@@ -32,6 +32,7 @@ scsi_dev=$(cat dev-name)
0cb0b9
 parted -s $scsi_dev mklabel msdos || fail=1
0cb0b9
 parted -s $scsi_dev mkpart extended 1 5 > out 2>&1 || fail=1
0cb0b9
 parted -s $scsi_dev mkpart primary 5 10 > out 2>&1 || fail=1
0cb0b9
+wait_for_dev_to_appear_ ${scsi_dev}1 || fail=1
0cb0b9
 
0cb0b9
 # Make sure the size of the extended partition is correct.
0cb0b9
 # 2 sectors for 512b and 1 sector for larger. /sys/.../size is in
0cb0b9
diff --git a/tests/t6001-psep.sh b/tests/t6001-psep.sh
0cb0b9
index f15090a..4c758e8 100644
0cb0b9
--- a/tests/t6001-psep.sh
0cb0b9
+++ b/tests/t6001-psep.sh
0cb0b9
@@ -54,7 +54,7 @@ parted -s $dev mklabel msdos mkpart primary fat32 1m 5m > out 2>&1 || fail=1
0cb0b9
 compare /dev/null out || fail=1
0cb0b9
 
0cb0b9
 #make sure device name is correct
0cb0b9
-test -e ${dev}p1 || fail=1
0cb0b9
+wait_for_dev_to_appear_ ${dev}p1 || fail=1
0cb0b9
 
0cb0b9
 #repeat on name not ending in a digit
0cb0b9
 # setup: create a mapping
0cb0b9
@@ -66,7 +66,7 @@ parted -s $dev mklabel msdos mkpart primary fat32 1m 5m > out 2>&1 || fail=1
0cb0b9
 compare /dev/null out || fail=1
0cb0b9
 
0cb0b9
 #make sure device name is correct
0cb0b9
-test -e ${dev}1 || fail=1
0cb0b9
+wait_for_dev_to_appear_ ${dev}1 || fail=1
0cb0b9
 
0cb0b9
 if [ -n "$fail" ]; then
0cb0b9
     ls /dev/mapper
0cb0b9
diff --git a/tests/t6004-dm-many-partitions.sh b/tests/t6004-dm-many-partitions.sh
0cb0b9
index 8d291ef..7ebc48a 100755
0cb0b9
--- a/tests/t6004-dm-many-partitions.sh
0cb0b9
+++ b/tests/t6004-dm-many-partitions.sh
0cb0b9
@@ -49,10 +49,8 @@ parted -m -a min -s /dev/mapper/$dm_name mklabel gpt $cmd > /dev/null 2>&1 || fa
0cb0b9
 
0cb0b9
 # Make sure all the partitions appeared under /dev/mapper/
0cb0b9
 for ((i=1; i<=$n_partitions; i+=1)); do
0cb0b9
-    if [ ! -e "/dev/mapper/${dm_name}p$i" ]; then
0cb0b9
-        fail=1
0cb0b9
-        break
0cb0b9
-    fi
0cb0b9
+    wait_for_dev_to_appear_ "/dev/mapper/${dm_name}p$i" || { fail=1; break; }
0cb0b9
+
0cb0b9
     # remove the partitions as we go, otherwise cleanup won't work.
0cb0b9
     dmsetup remove /dev/mapper/${dm_name}p$i
0cb0b9
 done
0cb0b9
diff --git a/tests/t6006-dm-512b-sectors.sh b/tests/t6006-dm-512b-sectors.sh
0cb0b9
index 31abba9..c3045af 100644
0cb0b9
--- a/tests/t6006-dm-512b-sectors.sh
0cb0b9
+++ b/tests/t6006-dm-512b-sectors.sh
0cb0b9
@@ -60,6 +60,7 @@ dev="/dev/mapper/$linear_"
0cb0b9
 # Create msdos partition table with a partition from 1MiB to 100MiB
0cb0b9
 parted -s $dev mklabel msdos mkpart primary ext2 1MiB 101MiB > out 2>&1 || fail=1
0cb0b9
 compare /dev/null out || fail=1
0cb0b9
+wait_for_dev_to_appear_ ${dev}1 || fail=1
0cb0b9
 
0cb0b9
 # The size of the partition should be 100MiB, or 204800 512b sectors
0cb0b9
 p1_size=$(blockdev --getsz ${dev}1) || framework_failure
0cb0b9
diff --git a/tests/t6100-mdraid-partitions.sh b/tests/t6100-mdraid-partitions.sh
0cb0b9
index 6f08442..dbc5986 100755
0cb0b9
--- a/tests/t6100-mdraid-partitions.sh
0cb0b9
+++ b/tests/t6100-mdraid-partitions.sh
0cb0b9
@@ -54,13 +54,14 @@ parted -s $md_dev mklabel gpt \
0cb0b9
 compare /dev/null out || fail=1
0cb0b9
 
0cb0b9
 # Verify that kernel has been informed about the second device.
0cb0b9
-grep "${md_name}p2" /proc/partitions || { fail=1; cat /proc/partitions; }
0cb0b9
+wait_for_dev_to_appear_ ${md_dev}p2 || { fail=1; cat /proc/partitions; }
0cb0b9
 
0cb0b9
 # Remove partitions from the raid device.
0cb0b9
 parted -s $md_dev rm 2 rm 1 > out 2>&1 || fail=1
0cb0b9
 compare /dev/null out || fail=1
0cb0b9
 
0cb0b9
 # Verify that kernel has been informed about those removals.
0cb0b9
-grep "${md_name}p[12]" /proc/partitions && { fail=1; cat /proc/partitions; }
0cb0b9
+wait_for_dev_to_disappear_ ${md_dev}p1 2 || { fail=1; cat /proc/partitions; }
0cb0b9
+wait_for_dev_to_disappear_ ${md_dev}p2 2 || { fail=1; cat /proc/partitions; }
0cb0b9
 
0cb0b9
 Exit $fail
0cb0b9
diff --git a/tests/t9041-undetected-in-use-16th-partition.sh b/tests/t9041-undetected-in-use-16th-partition.sh
0cb0b9
index edaae1b..673e508 100644
0cb0b9
--- a/tests/t9041-undetected-in-use-16th-partition.sh
0cb0b9
+++ b/tests/t9041-undetected-in-use-16th-partition.sh
0cb0b9
@@ -72,7 +72,7 @@ wait_for_dev_to_appear_ ${scsi_dev}16 || fail_ ${scsi_dev}16 did not appear
0cb0b9
 
0cb0b9
 partitions="${scsi_dev}14 ${scsi_dev}15 ${scsi_dev}16"
0cb0b9
 for i in $partitions; do
0cb0b9
-  mkfs.ext3 $i || skip_ mkfs.ext3 $i failed
0cb0b9
+  mkfs.ext3 $i || fail=1
0cb0b9
 done
0cb0b9
 
0cb0b9
 # be sure to unmount upon interrupt, failure, etc.
0cb0b9
-- 
0cb0b9
2.4.3
0cb0b9