]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: consolidate ts_device_has UUID or LABEL
authorRuediger Meier <ruediger.meier@ga-group.nl>
Sat, 10 Mar 2018 18:44:32 +0000 (19:44 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 19 Mar 2018 10:46:11 +0000 (11:46 +0100)
Regarding parallel root checks ...

 - fix: add a few missing "udevadm settle" where we are using LABELs or UUIDs

 - introduce ts_udevadm_settle():
    * Still trivial implementation. The idea is to use it in future for all
      tests instead of directly calling "udevadm settle". So we could add debug
      messages, wait for specific events, add code for non-udev systems or even
      use "udevadm --{start,stop}-exec-queue" to be really sure what we are
      doing and why using udevadm at all.
    * The currently unused args may be used in future and show the code reader
      already now why we are calling "udevadm settle" at all.
    * So far this patch only affects swapon/, mount/, libmount/ tests, and is
      only about UUIDs and LABELs, but may be continued later for "partitions",
      "md devices", whatever.
    * We are calling ts_udevadm_settle() right *before* we need a LABEL or
      UUID, not just *after* we created one. This may be a bit better for
      speed and shows the code reader which command would fail without settle.

 - function ts_device_has_uuid() is unused now, we trust blkid(1). Renamed to
   ts_is_uuid() in case we would need it again.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
15 files changed:
tests/functions.sh
tests/ts/libmount/tabfiles-tags
tests/ts/libmount/tabfiles-tags-py
tests/ts/mount/fstab-devname2label
tests/ts/mount/fstab-devname2uuid
tests/ts/mount/fstab-label
tests/ts/mount/fstab-label2devname
tests/ts/mount/fstab-label2uuid
tests/ts/mount/fstab-uuid
tests/ts/mount/fstab-uuid2devname
tests/ts/mount/fstab-uuid2label
tests/ts/mount/label
tests/ts/mount/uuid
tests/ts/swapon/label
tests/ts/swapon/uuid

index 66eaa9d6ef6fd54ae8bcee77a996739e32d4230b..0f991881a38d81be5d4e47cc0f765988f6cb0e21 100644 (file)
@@ -555,16 +555,34 @@ function ts_device_deinit {
        fi
 }
 
+function ts_blkidtag_by_devname()
+{
+       local tag=$1
+       local dev=$2
+       local out
+       local rval
+
+       out=$($TS_CMD_BLKID -p -s "$tag" -o value "$dev")
+       rval=$?
+       printf "%s\n" "$out"
+
+       test -n "$out" -a "$rval" = "0"
+       return $?
+}
+
 function ts_uuid_by_devname {
-       echo $($TS_CMD_BLKID -p -s UUID -o value $1)
+       ts_blkidtag_by_devname "UUID" "$1"
+       return $?
 }
 
 function ts_label_by_devname {
-       echo $($TS_CMD_BLKID -p -s LABEL -o value $1)
+       ts_blkidtag_by_devname "LABEL" "$1"
+       return $?
 }
 
 function ts_fstype_by_devname {
-       echo $($TS_CMD_BLKID -p -s TYPE -o value $1)
+       ts_blkidtag_by_devname "TYPE" "$1"
+       return $?
 }
 
 function ts_device_has {
@@ -573,24 +591,24 @@ function ts_device_has {
        local DEV="$3"
        local vl=""
 
-       case $TAG in
-               "TYPE") vl=$(ts_fstype_by_devname $DEV);;
-               "LABEL") vl=$(ts_label_by_devname $DEV);;
-               "UUID") vl=$(ts_uuid_by_devname $DEV);;
-               *) return 1;;
-       esac
-
-       if [ "$vl" == "$VAL" ]; then
-               return 0
-       fi
-       return 1
+       vl=$(ts_blkidtag_by_devname "$TAG" "$DEV")
+       test $? = 0 -a "$vl" = "$VAL"
+       return $?
 }
 
-function ts_device_has_uuid {
-       ts_uuid_by_devname "$1" | egrep -q '^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$'
+function ts_is_uuid()
+{
+       printf "%s\n" "$1" | egrep -q '^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$'
        return $?
 }
 
+function ts_udevadm_settle()
+{
+       local dev=$1 # optional, might be empty
+       shift        # all other args are tags, LABEL, UUID, ...
+       udevadm settle
+}
+
 function ts_mount {
        local out
        local result
index 4933876d4932b0e3045884224f8a57b63d1cae91..38858f47b05bc77a11fa6ad0d929b8bc2330a601 100755 (executable)
@@ -26,9 +26,8 @@ UUID="de1bc6e9-34ab-4151-a1d7-900042eee8d9"
 # Create filesystem
 #
 mkfs.ext3 -F -L $LABEL $TS_DEVICE -U $UUID &> /dev/null || ts_die "Cannot make ext3 on $TS_DEVICE"
-udevadm settle
-
-ts_device_has_uuid $TS_DEVICE || ts_die "Cannot find UUID on $TS_DEVICE"
+ts_device_has "LABEL" "$LABEL" "$TS_DEVICE" || ts_die "Cannot find  LABEL '$LABEL' on $TS_DEVICE"
+ts_device_has "UUID" "$UUID" "$TS_DEVICE" || ts_die "Cannot find $UUID on $TS_DEVICE"
 
 FSTAB="$TS_OUTDIR/fstab"
 
@@ -36,6 +35,7 @@ FSTAB="$TS_OUTDIR/fstab"
 # Label in fstab
 #
 echo "LABEL=$LABEL /mnt/mountpoint auto defaults" > $FSTAB
+ts_udevadm_settle "$TS_DEVICE" "LABEL" "UUID"
 
 ts_init_subtest "fstab-label2uuid"
 ts_run $TESTPROG --find-forward $FSTAB source "UUID=$UUID" &> $TS_OUTPUT
index c1ad596bfd7c088ab6a79886598721e2bd664ab2..5e72a6f907918d632744d5a5cb69c7bbe0e539fe 100755 (executable)
@@ -30,9 +30,8 @@ UUID="de1bc6e9-34ab-4151-a1d7-900042eee8d9"
 # Create filesystem
 #
 mkfs.ext3 -F -L $LABEL $TS_DEVICE -U $UUID &> /dev/null || ts_die "Cannot make ext3 on $TS_DEVICE"
-udevadm settle
-
-ts_device_has_uuid $TS_DEVICE || ts_die "Cannot find UUID on $TS_DEVICE"
+ts_device_has "LABEL" "$LABEL" "$TS_DEVICE" || ts_die "Cannot find  LABEL '$LABEL' on $TS_DEVICE"
+ts_device_has "UUID" "$UUID" "$TS_DEVICE" || ts_die "Cannot find $UUID on $TS_DEVICE"
 
 FSTAB="$TS_OUTDIR/fstab"
 
@@ -40,6 +39,7 @@ FSTAB="$TS_OUTDIR/fstab"
 # Label in fstab
 #
 echo "LABEL=$LABEL /mnt/mountpoint auto defaults" > $FSTAB
+ts_udevadm_settle "$DEVICE" "LABEL" "UUID"
 
 ts_init_subtest "fstab-label2uuid"
 $PYTHON $TESTPROG --find-forward $FSTAB source "UUID=$UUID" &> $TS_OUTPUT
index 380b91d03c683e94bb0a161bac2f9770fbc439fd..02ef1ef18d341d74118d7f3821492a2f5d9d96ba 100755 (executable)
@@ -33,13 +33,13 @@ ts_device_init
 DEVICE=$TS_LODEV
 
 mkfs.ext3 -L $LABEL $DEVICE &> /dev/null || ts_die "Cannot make ext3 on $DEVICE"
-
 ts_device_has "LABEL" $LABEL $DEVICE \
  || ts_die "Cannot find LABEL '$LABEL' on $DEVICE"
 
 [ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT
 
 ts_fstab_add "LABEL=$LABEL"
+ts_udevadm_settle "$DEVICE" "LABEL"
 
 $TS_CMD_MOUNT $DEVICE >> $TS_OUTPUT 2>&1
 ts_is_mounted $DEVICE || ts_die "Cannot find $DEVICE in /proc/mounts"
index 3ed19d2df80d4b9442948014a0f0c9b7de5cd710..4cd4f4502c30871f53c96d21b4ce9144f459aad6 100755 (executable)
@@ -32,14 +32,12 @@ ts_device_init
 DEVICE=$TS_LODEV
 
 mkfs.ext3 $DEVICE &> /dev/null || ts_die "Cannot make ext3 on $DEVICE"
-
-ts_device_has_uuid $DEVICE || ts_die "Cannot find UUID on $DEVICE"
-
-UUID=$(ts_uuid_by_devname $DEVICE)
+UUID=$(ts_uuid_by_devname "$DEVICE") || ts_die "Cannot find UUID on $DEVICE"
 
 [ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT
 
 ts_fstab_add "UUID=$UUID"
+ts_udevadm_settle "$DEVICE" "UUID"
 
 $TS_CMD_MOUNT $DEVICE >> $TS_OUTPUT 2>&1
 ts_is_mounted $DEVICE || ts_die "Cannot find $DEVICE in /proc/mounts"
index bc5a15f4f607d26a35f6d0563bb3125453e3184a..be6292d17ea196d650da8e80440e91405951bd51 100755 (executable)
@@ -33,13 +33,13 @@ ts_device_init
 DEVICE=$TS_LODEV
 
 mkfs.ext3 -L $LABEL $DEVICE &> /dev/null || ts_die "Cannot make ext3 on $DEVICE"
-
 ts_device_has "LABEL" $LABEL $DEVICE \
  || ts_die "Cannot find LABEL '$LABEL' on $DEVICE"
 
 [ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT
 
 ts_fstab_add "LABEL=$LABEL"
+ts_udevadm_settle "$DEVICE" "LABEL"
 
 # variant A)
 $TS_CMD_MOUNT $TS_MOUNTPOINT >> $TS_OUTPUT 2>&1
index 3dcaad54a91c27380383828c3b7c287f5e5a02fd..ee4642e250c1b7f7294c6e251c97c533323edc14 100755 (executable)
@@ -33,13 +33,13 @@ ts_device_init
 DEVICE=$TS_LODEV
 
 mkfs.ext3 -L $LABEL $DEVICE &> /dev/null || ts_die "Cannot make ext3 on $DEVICE"
-
 ts_device_has "LABEL" $LABEL $DEVICE \
  || ts_die "Cannot find LABEL '$LABEL' on $DEVICE"
 
 [ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT
 
 ts_fstab_add "$DEVICE"
+ts_udevadm_settle "$DEVICE" "LABEL"
 
 # variant A)
 $TS_CMD_MOUNT -L $LABEL >> $TS_OUTPUT 2>&1
index 486d0704134dfd5fe6588e797d0f0cab389b82ed..0d2b93154e1885a939136d1293f820bec690ec10 100755 (executable)
@@ -34,17 +34,14 @@ ts_device_init
 DEVICE=$TS_LODEV
 
 mkfs.ext3 -L $LABEL $DEVICE &> /dev/null || ts_die "Cannot make ext3 on $DEVICE"
-
 ts_device_has "LABEL" $LABEL $DEVICE \
  || ts_die "Cannot find LABEL '$LABEL' on $DEVICE"
-
-ts_device_has_uuid $DEVICE || ts_die "Cannot find UUID on $DEVICE"
-
-UUID=$(ts_uuid_by_devname $DEVICE)
+UUID=$(ts_uuid_by_devname "$DEVICE") || ts_die "Cannot find UUID on $DEVICE"
 
 [ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT
 
 ts_fstab_add "UUID=$UUID"
+ts_udevadm_settle "$DEVICE" "LABEL" "UUID"
 
 # variant A)
 $TS_CMD_MOUNT -L $LABEL >> $TS_OUTPUT 2>&1
index afe414dc4d7b745ee5d0e810b490d8c40cce6df0..1c588fc1b18578a04057e147b2b5e12ac7d42ec7 100755 (executable)
@@ -32,14 +32,12 @@ ts_device_init
 DEVICE=$TS_LODEV
 
 mkfs.ext3 $DEVICE &> /dev/null || ts_die "Cannot make ext3 on $DEVICE"
-
-ts_device_has_uuid $DEVICE || ts_die "Cannot find UUID on $DEVICE"
-
-UUID=$(ts_uuid_by_devname $DEVICE)
+UUID=$(ts_uuid_by_devname "$DEVICE") || ts_die "Cannot find UUID on $DEVICE"
 
 [ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT
 
 ts_fstab_add "UUID=$UUID"
+ts_udevadm_settle "$DEVICE" "UUID"
 
 # varian A)
 $TS_CMD_MOUNT $TS_MOUNTPOINT >> $TS_OUTPUT 2>&1
index 3197148bda5a8cba015fb6d6f76456d9d4bfa687..39aed65a93c42c52165fccb50119467c41197cf0 100755 (executable)
@@ -32,14 +32,12 @@ ts_device_init
 DEVICE=$TS_LODEV
 
 mkfs.ext3 $DEVICE &> /dev/null || ts_die "Cannot make ext3 on $DEVICE"
-
-ts_device_has_uuid $DEVICE || ts_die "Cannot find UUID on $DEVICE"
-
-UUID=$(ts_uuid_by_devname $DEVICE)
+UUID=$(ts_uuid_by_devname "$DEVICE") || ts_die "Cannot find UUID on $DEVICE"
 
 [ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT
 
 ts_fstab_add "$DEVICE"
+ts_udevadm_settle "$DEVICE" "UUID"
 
 # variant A)
 $TS_CMD_MOUNT -U $UUID >> $TS_OUTPUT 2>&1
index 22c5647ddea044d05680ebcd26ffe6638dfd10a6..4676c9a7b6330e415c59b6ad00ce86609c4fe112 100755 (executable)
@@ -33,17 +33,14 @@ ts_device_init
 DEVICE=$TS_LODEV
 
 mkfs.ext3 -L $LABEL $DEVICE &> /dev/null || ts_die "Cannot make ext3 on $DEVICE"
-
 ts_device_has "LABEL" $LABEL $DEVICE \
  || ts_die "Cannot find LABEL '$LABEL' on $DEVICE"
-
-ts_device_has_uuid $DEVICE || ts_die "Cannot find UUID on $DEVICE"
-
-UUID=$(ts_uuid_by_devname $DEVICE)
+UUID=$(ts_uuid_by_devname "$DEVICE") || ts_die "Cannot find UUID on $DEVICE"
 
 [ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT
 
 ts_fstab_add "LABEL=$LABEL"
+ts_udevadm_settle "$DEVICE" "LABEL" "UUID"
 
 # variant A)
 $TS_CMD_MOUNT -U $UUID >> $TS_OUTPUT 2>&1
index d3a571bc4c1233c9645db995327e9e9d96324e99..45da02b6efc44039f81cade8dba2e678e7932edb 100755 (executable)
@@ -34,11 +34,11 @@ ts_device_init
 DEVICE=$TS_LODEV
 
 mkfs.ext3 -L $LABEL $DEVICE &> /dev/null || ts_die "Cannot make ext3 on $DEVICE"
-udevadm settle
 ts_device_has "LABEL" $LABEL $DEVICE \
  || ts_die "Cannot find LABEL '$LABEL' on $DEVICE"
 
 [ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT
+ts_udevadm_settle "$DEVICE" "LABEL"
 
 # variant A)
 $TS_CMD_MOUNT -L $LABEL $TS_MOUNTPOINT >> $TS_OUTPUT 2>&1
index efd2774ed5d9288e790ae72a2503adeae6e0b3ae..36f75cef9b848de91d726914977617389731dc1c 100755 (executable)
@@ -32,12 +32,10 @@ ts_device_init
 DEVICE=$TS_LODEV
 
 mkfs.ext3 $DEVICE &> /dev/null || ts_die "Cannot make ext3 on $DEVICE"
-
-ts_device_has_uuid $DEVICE || ts_die "Cannot find UUID on $DEVICE"
-
-UUID=$(ts_uuid_by_devname $DEVICE)
+UUID=$(ts_uuid_by_devname "$DEVICE") || ts_die "Cannot find UUID on $DEVICE"
 
 [ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT
+ts_udevadm_settle "$DEVICE" "UUID"
 
 # variant A)
 $TS_CMD_MOUNT -U $UUID $TS_MOUNTPOINT >> $TS_OUTPUT 2>&1
index 210a12c9721f14d6677aecd1039c51e1d302ea05..1bb5dbb3ec5c27c97523942a98c31e532726c7bb 100755 (executable)
@@ -34,11 +34,9 @@ DEVICE=$TS_LODEV
 
 $TS_CMD_MKSWAP -L $LABEL $DEVICE > /dev/null 2>> $TS_OUTPUT \
  || ts_die "Cannot make swap on $DEVICE"
-
-udevadm settle
-
 ts_device_has "LABEL" $LABEL $DEVICE \
  || ts_die "Cannot find LABEL '$LABEL' on $DEVICE"
+ts_udevadm_settle "$DEVICE" "LABEL"
 
 $TS_CMD_SWAPON -L $LABEL >> $TS_OUTPUT 2>&1
 
index 65af6cb6deef417e6c2ee1113af37abc5de419e4..70e62d7f915660f4758f2ade12e185aeb4977da9 100755 (executable)
@@ -33,10 +33,8 @@ DEVICE=$TS_LODEV
 
 $TS_CMD_MKSWAP $DEVICE > /dev/null 2>> $TS_OUTPUT \
  || ts_die "Cannot make swap $DEVICE"
-
-ts_device_has_uuid $DEVICE || ts_die "Cannot find UUID on $DEVICE"
-
-UUID=$(ts_uuid_by_devname $DEVICE)
+UUID=$(ts_uuid_by_devname "$DEVICE") || ts_die "Cannot find UUID on $DEVICE"
+ts_udevadm_settle "$DEVICE" "UUID"
 
 $TS_CMD_SWAPON -U $UUID >> $TS_OUTPUT 2>&1