Skip to content

Commit

Permalink
ci: use /dev/disk/by-id
Browse files Browse the repository at this point in the history
Due to parallel probing of the linux kernel `/dev/sd*` can't be used to
reliably address a hard disk. This can be seen by the many spurious
failures of the dracut CI, where `mdadm` failed with error 524 or tests
failed due to the success marker message written to the wrong disk.

* don't rely on `/dev/sd*` but use disk ids and `/dev/disk/by-id/ata-disk_<name>`

* specify the exact qemu machine architecture `-M q35` needed for the
  disk ids. A later patch will move this to `run-qemu`, when all tests are converted

* due to `-M q35` the interface names have changed from
  `ens2` -> `enp0s1` and `ens3` -> `enp0s2`
  • Loading branch information
haraldh committed Apr 22, 2021
1 parent 5912f4f commit b80ee08
Show file tree
Hide file tree
Showing 81 changed files with 918 additions and 840 deletions.
8 changes: 0 additions & 8 deletions test/TEST-01-BASIC/99-idesymlinks.rules

This file was deleted.

20 changes: 9 additions & 11 deletions test/TEST-01-BASIC/create-root.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
#!/bin/sh

trap 'poweroff -f' EXIT

# don't let udev and this script step on eachother's toes
for x in 64-lvm.rules 70-mdadm.rules 99-mount-rules; do
: > "/etc/udev/rules.d/$x"
done
rm -f -- /etc/lvm/lvm.conf
udevadm control --reload
set -e
# save a partition at the beginning for future flagging purposes
sfdisk /dev/sda << EOF
,1M
,
EOF

udevadm settle
mkfs.ext3 -L ' rdinit=/bin/sh' /dev/sda2

set -ex

mkfs.ext3 -L ' rdinit=/bin/sh' /dev/disk/by-id/ata-disk_root
mkdir -p /root
mount /dev/sda2 /root
mount /dev/disk/by-id/ata-disk_root /root
cp -a -t /root /source/*
mkdir -p /root/run
umount /root
echo "dracut-root-block-created" | dd oflag=direct,dsync of=/dev/sda1
sync
echo "dracut-root-block-created" | dd oflag=direct,dsync of=/dev/disk/by-id/ata-disk_marker
poweroff -f
4 changes: 2 additions & 2 deletions test/TEST-01-BASIC/test-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export PATH=/sbin:/bin:/usr/sbin:/usr/bin
command -v plymouth > /dev/null 2>&1 && plymouth --quit
exec > /dev/console 2>&1

echo "dracut-root-block-success" | dd oflag=direct,dsync of=/dev/sdb
echo "dracut-root-block-success" | dd oflag=direct,dsync of=/dev/disk/by-id/ata-disk_marker

export TERM=linux
export PS1='initramfs-test:\w\$ '
[ -f /etc/mtab ] || ln -sfn /proc/mounts /etc/mtab
Expand All @@ -20,5 +21,4 @@ if getargbool 0 rd.shell; then
fi
echo "Powering down."
mount -n -o remount,ro /
sync
poweroff -f
35 changes: 22 additions & 13 deletions test/TEST-01-BASIC/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@ KVERSION=${KVERSION-$(uname -r)}
# DEBUGFAIL="rd.shell rd.break"

test_run() {
dd if=/dev/zero of="$TESTDIR"/result bs=1M count=1
dd if=/dev/zero of="$TESTDIR"/marker.img bs=1MiB count=1
declare -a disk_args=()
# shellcheck disable=SC2034
declare -i disk_index=0
qemu_add_drive_args disk_index disk_args "$TESTDIR"/marker.img marker
qemu_add_drive_args disk_index disk_args "$TESTDIR"/root.img root

"$testdir"/run-qemu \
-drive format=raw,index=0,media=disk,file="$TESTDIR"/root.ext3 \
-drive format=raw,index=1,media=disk,file="$TESTDIR"/result \
"${disk_args[@]}" \
-watchdog i6300esb -watchdog-action poweroff \
-append "panic=1 systemd.crash_reboot \"root=LABEL= rdinit=/bin/sh\" rw systemd.log_level=debug systemd.log_target=console rd.retry=3 rd.debug console=ttyS0,115200n81 rd.shell=0 $DEBUGFAIL" \
-initrd "$TESTDIR"/initramfs.testing || return 1
grep -U --binary-files=binary -F -m 1 -q dracut-root-block-success "$TESTDIR"/result || return 1

grep -U --binary-files=binary -F -m 1 -q dracut-root-block-success "$TESTDIR"/marker.img
}

test_setup() {
rm -f -- "$TESTDIR"/root.ext3
# Create the blank file to use as a root filesystem
dd if=/dev/zero of="$TESTDIR"/root.ext3 bs=1M count=80

kernel=$KVERSION
# Create what will eventually be our root filesystem onto an overlay
(
Expand Down Expand Up @@ -72,7 +74,6 @@ test_setup() {
inst_multiple sfdisk mkfs.ext3 poweroff cp umount sync dd
inst_hook initqueue 01 ./create-root.sh
inst_hook initqueue/finished 01 ./finished-false.sh
inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
)

# create an initramfs that will create the target root filesystem.
Expand All @@ -85,13 +86,22 @@ test_setup() {
--no-hostonly-cmdline -N \
-f "$TESTDIR"/initramfs.makeroot "$KVERSION" || return 1
rm -rf -- "$TESTDIR"/overlay
# Invoke KVM and/or QEMU to actually create the target filesystem.

dd if=/dev/zero of="$TESTDIR"/root.img bs=1MiB count=80
dd if=/dev/zero of="$TESTDIR"/marker.img bs=1MiB count=1
declare -a disk_args=()
# shellcheck disable=SC2034
declare -i disk_index=0
qemu_add_drive_args disk_index disk_args "$TESTDIR"/marker.img marker
qemu_add_drive_args disk_index disk_args "$TESTDIR"/root.img root

# Invoke KVM and/or QEMU to actually create the target filesystem.
"$testdir"/run-qemu \
-drive format=raw,index=0,media=disk,file="$TESTDIR"/root.ext3 \
"${disk_args[@]}" \
-append "root=/dev/dracut/root rw rootfstype=ext3 quiet console=ttyS0,115200n81 selinux=0" \
-initrd "$TESTDIR"/initramfs.makeroot || return 1
grep -U --binary-files=binary -F -m 1 -q dracut-root-block-created "$TESTDIR"/root.ext3 || return 1
grep -U --binary-files=binary -F -m 1 -q dracut-root-block-created "$TESTDIR"/marker.img || return 1
rm -- "$TESTDIR"/marker.img

(
# shellcheck disable=SC2031
Expand All @@ -101,7 +111,6 @@ test_setup() {
inst_multiple poweroff shutdown dd
inst_hook shutdown-emergency 000 ./hard-off.sh
inst_hook emergency 000 ./hard-off.sh
inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
)
"$basedir"/dracut.sh -l -i "$TESTDIR"/overlay / \
-a "debug watchdog" \
Expand Down
8 changes: 0 additions & 8 deletions test/TEST-02-SYSTEMD/99-idesymlinks.rules

This file was deleted.

14 changes: 6 additions & 8 deletions test/TEST-02-SYSTEMD/create-root.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
#!/bin/sh

trap 'poweroff -f' EXIT

# don't let udev and this script step on eachother's toes
for x in 64-lvm.rules 70-mdadm.rules 99-mount-rules; do
: > "/etc/udev/rules.d/$x"
done
rm -f -- /etc/lvm/lvm.conf
udevadm control --reload
set -e
# save a partition at the beginning for future flagging purposes
sfdisk /dev/sda << EOF
,1M
,
EOF

udevadm settle
mkfs.ext3 -L dracut /dev/sda2
mkfs.ext3 -L dracut /dev/disk/by-id/ata-disk_root
mkdir -p /root
mount /dev/sda2 /root
mount /dev/disk/by-id/ata-disk_root /root
cp -a -t /root /source/*
mkdir -p /root/run
umount /root
echo "dracut-root-block-created" | dd oflag=direct,dsync of=/dev/sda1
echo "dracut-root-block-created" | dd oflag=direct,dsync of=/dev/disk/by-id/ata-disk_marker
poweroff -f
6 changes: 4 additions & 2 deletions test/TEST-02-SYSTEMD/test-init.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/bin/sh
: > /dev/watchdog

. /lib/dracut-lib.sh

export PATH=/sbin:/bin:/usr/sbin:/usr/bin
command -v plymouth > /dev/null 2>&1 && plymouth --quit
exec > /dev/console 2>&1

echo "dracut-root-block-success" | dd oflag=direct,dsync of=/dev/sda1
echo "dracut-root-block-success" | dd oflag=direct,dsync of=/dev/disk/by-id/ata-disk_marker

export TERM=linux
export PS1='initramfs-test:\w\$ '
[ -f /etc/mtab ] || ln -sfn /proc/mounts /etc/mtab
Expand All @@ -18,5 +21,4 @@ if getargbool 0 rd.shell; then
fi
echo "Powering down."
mount -n -o remount,ro /
sync
poweroff -f
35 changes: 23 additions & 12 deletions test/TEST-02-SYSTEMD/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@ KVERSION="${KVERSION-$(uname -r)}"
# Uncomment this to debug failures
#DEBUGFAIL="rd.shell=1 rd.break=pre-mount"
test_run() {
dd if=/dev/zero of="$TESTDIR"/marker.img bs=1MiB count=1
declare -a disk_args=()
# shellcheck disable=SC2034
declare -i disk_index=0
qemu_add_drive_args disk_index disk_args "$TESTDIR"/marker.img marker
qemu_add_drive_args disk_index disk_args "$TESTDIR"/root.img root

"$testdir"/run-qemu \
-drive format=raw,index=0,media=disk,file="$TESTDIR"/root.ext3 \
"${disk_args[@]}" \
-append "panic=1 systemd.crash_reboot root=LABEL=dracut rw loglevel=77 systemd.log_level=debug systemd.log_target=console rd.retry=3 rd.info console=ttyS0,115200n81 selinux=0 init=/sbin/init rd.shell=0 $DEBUGFAIL" \
-initrd "$TESTDIR"/initramfs.testing
grep -U --binary-files=binary -F -m 1 -q dracut-root-block-success "$TESTDIR"/root.ext3 || return 1
-initrd "$TESTDIR"/initramfs.testing || return 1

grep -U --binary-files=binary -F -m 1 -q dracut-root-block-success "$TESTDIR"/marker.img
}

test_setup() {
rm -f -- "$TESTDIR"/root.ext3
# Create the blank file to use as a root filesystem
dd if=/dev/zero of="$TESTDIR"/root.ext3 bs=1M count=80

kernel=$KVERSION
# Create what will eventually be our root filesystem onto an overlay
(
Expand Down Expand Up @@ -69,7 +73,6 @@ test_setup() {
inst_multiple sfdisk mkfs.ext3 poweroff cp umount dd
inst_hook initqueue 01 ./create-root.sh
inst_hook initqueue/finished 01 ./finished-false.sh
inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
)

# create an initramfs that will create the target root filesystem.
Expand All @@ -82,13 +85,22 @@ test_setup() {
--no-hostonly-cmdline -N \
-f "$TESTDIR"/initramfs.makeroot "$KVERSION" || return 1
rm -rf -- "$TESTDIR"/overlay
# Invoke KVM and/or QEMU to actually create the target filesystem.

dd if=/dev/zero of="$TESTDIR"/root.img bs=1MiB count=80
dd if=/dev/zero of="$TESTDIR"/marker.img bs=1MiB count=1
declare -a disk_args=()
# shellcheck disable=SC2034
declare -i disk_index=0
qemu_add_drive_args disk_index disk_args "$TESTDIR"/marker.img marker
qemu_add_drive_args disk_index disk_args "$TESTDIR"/root.img root

# Invoke KVM and/or QEMU to actually create the target filesystem.
"$testdir"/run-qemu \
-drive format=raw,index=0,media=disk,file="$TESTDIR"/root.ext3 \
"${disk_args[@]}" \
-append "root=/dev/fakeroot rw rootfstype=ext3 quiet console=ttyS0,115200n81 selinux=0" \
-initrd "$TESTDIR"/initramfs.makeroot || return 1
grep -U --binary-files=binary -F -m 1 -q dracut-root-block-created "$TESTDIR"/root.ext3 || return 1
grep -U --binary-files=binary -F -m 1 -q dracut-root-block-created "$TESTDIR"/marker.img || return 1
rm -- "$TESTDIR"/marker.img

(
# shellcheck disable=SC2031
Expand All @@ -99,7 +111,6 @@ test_setup() {
inst_hook shutdown-emergency 000 ./hard-off.sh
inst_hook pre-pivot 000 ./systemd-analyze.sh
inst_hook emergency 000 ./hard-off.sh
inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
)
"$basedir"/dracut.sh -l -i "$TESTDIR"/overlay / \
-a "debug systemd" \
Expand Down
8 changes: 0 additions & 8 deletions test/TEST-03-USR-MOUNT/99-idesymlinks.rules

This file was deleted.

33 changes: 11 additions & 22 deletions test/TEST-03-USR-MOUNT/create-root.sh
Original file line number Diff line number Diff line change
@@ -1,44 +1,33 @@
#!/bin/sh

trap 'poweroff -f' EXIT

# don't let udev and this script step on eachother's toes
set -x
for x in 64-lvm.rules 70-mdadm.rules 99-mount-rules; do
: > "/etc/udev/rules.d/$x"
done
rm -f -- /etc/lvm/lvm.conf
udevadm control --reload
udevadm settle
set -e
# save a partition at the beginning for future flagging purposes
sfdisk /dev/sda << EOF
,1M
,
EOF

sfdisk /dev/sdb << EOF
,1M
,
EOF

udevadm settle
modprobe btrfs
mkfs.btrfs -L dracut /dev/sda2
mkfs.btrfs -L dracutusr /dev/sdb2
btrfs device scan /dev/sda2
btrfs device scan /dev/sdb2
mkfs.btrfs -L dracut /dev/disk/by-id/ata-disk_root
mkfs.btrfs -L dracutusr /dev/disk/by-id/ata-disk_usr
btrfs device scan /dev/disk/by-id/ata-disk_root
btrfs device scan /dev/disk/by-id/ata-disk_usr
mkdir -p /root
mount -t btrfs /dev/sda2 /root
mount -t btrfs /dev/disk/by-id/ata-disk_root /root
[ -d /root/usr ] || mkdir -p /root/usr
mount -t btrfs /dev/sdb2 /root/usr
mount -t btrfs /dev/disk/by-id/ata-disk_usr /root/usr
btrfs subvolume create /root/usr/usr
umount /root/usr
mount -t btrfs -o subvol=usr /dev/sdb2 /root/usr
mount -t btrfs -o subvol=usr /dev/disk/by-id/ata-disk_usr /root/usr
cp -a -t /root /source/*
mkdir -p /root/run
btrfs filesystem sync /root/usr
btrfs filesystem sync /root
umount /root/usr
umount /root
echo "dracut-root-block-created" | dd oflag=direct,dsync of=/dev/sda1
udevadm settle
sync
echo "dracut-root-block-created" | dd oflag=direct,dsync of=/dev/disk/by-id/ata-disk_marker
poweroff -f
4 changes: 2 additions & 2 deletions test/TEST-03-USR-MOUNT/fstab
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/dev/sda2 / btrfs defaults 0 0
/dev/sdb2 /usr btrfs subvol=usr,ro 0 0
/dev/disk/by-id/ata-disk_root / btrfs defaults 0 0
/dev/disk/by-id/ata-disk_usr /usr btrfs subvol=usr,ro 0 0
7 changes: 2 additions & 5 deletions test/TEST-03-USR-MOUNT/test-init.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/sh

: > /dev/watchdog

. /lib/dracut-lib.sh
Expand All @@ -8,9 +7,8 @@ export PATH=/sbin:/bin:/usr/sbin:/usr/bin
command -v plymouth > /dev/null 2>&1 && plymouth --quit
exec > /dev/console 2>&1

if ismounted /usr; then
echo "dracut-root-block-success" | dd oflag=direct,dsync of=/dev/sdc
fi
echo "dracut-root-block-success" | dd oflag=direct,dsync of=/dev/disk/by-id/ata-disk_marker

export TERM=linux
export PS1='initramfs-test:\w\$ '
[ -f /etc/mtab ] || ln -sfn /proc/mounts /etc/mtab
Expand All @@ -23,5 +21,4 @@ if getargbool 0 rd.shell; then
fi
echo "Powering down."
mount -n -o remount,ro /
sync
poweroff -f
Loading

0 comments on commit b80ee08

Please sign in to comment.