From 6775c5710f5c0c28871fc7180413ba4500cf6362 Mon Sep 17 00:00:00 2001
From: Harald Hoyer <harald@redhat.com>
Date: Fri, 27 May 2016 10:52:28 +0200
Subject: [PATCH] use shutdown-emergency hook in testsuite to poweroff the
 machine

---
 modules.d/99base/dracut-lib.sh    | 6 +++++-
 test/TEST-01-BASIC/test.sh        | 2 +-
 test/TEST-02-SYSTEMD/test.sh      | 2 +-
 test/TEST-03-USR-MOUNT/test.sh    | 2 +-
 test/TEST-04-FULL-SYSTEMD/test.sh | 2 +-
 test/TEST-10-RAID/test.sh         | 2 +-
 test/TEST-11-LVM/test.sh          | 2 +-
 test/TEST-12-RAID-DEG/test.sh     | 2 +-
 test/TEST-13-ENC-RAID-LVM/test.sh | 2 +-
 test/TEST-14-IMSM/test.sh         | 2 +-
 test/TEST-15-BTRFSRAID/test.sh    | 2 +-
 test/TEST-16-DMSQUASH/test.sh     | 2 +-
 test/TEST-17-LVM-THIN/test.sh     | 2 +-
 test/TEST-20-NFS/test.sh          | 4 ++--
 test/TEST-30-ISCSI/test.sh        | 2 +-
 test/TEST-40-NBD/test.sh          | 4 ++--
 test/TEST-50-MULTINIC/test.sh     | 2 +-
 17 files changed, 23 insertions(+), 19 deletions(-)

diff --git a/modules.d/99base/dracut-lib.sh b/modules.d/99base/dracut-lib.sh
index 48fc83dc..94e4614c 100755
--- a/modules.d/99base/dracut-lib.sh
+++ b/modules.d/99base/dracut-lib.sh
@@ -457,7 +457,11 @@ die() {
 
     > /run/initramfs/.die
 
-    getargbool 0 "rd.shell=" && emergency_shell
+    if getargbool 0 "rd.shell"; then
+        emergency_shell
+    else
+        source_hook "shutdown-emergency"
+    fi
 
     if [ -n "$DRACUT_SYSTEMD" ]; then
         systemctl --no-block --force halt
diff --git a/test/TEST-01-BASIC/test.sh b/test/TEST-01-BASIC/test.sh
index 83320e27..959ac05d 100755
--- a/test/TEST-01-BASIC/test.sh
+++ b/test/TEST-01-BASIC/test.sh
@@ -89,7 +89,7 @@ test_setup() {
 	export initdir=$TESTDIR/overlay
 	. $basedir/dracut-init.sh
 	inst_multiple poweroff shutdown
-	inst_hook emergency 000 ./hard-off.sh
+	inst_hook shutdown-emergency 000 ./hard-off.sh
 	inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
     )
     sudo $basedir/dracut.sh -l -i $TESTDIR/overlay / \
diff --git a/test/TEST-02-SYSTEMD/test.sh b/test/TEST-02-SYSTEMD/test.sh
index 16f5c265..6dc6f42e 100755
--- a/test/TEST-02-SYSTEMD/test.sh
+++ b/test/TEST-02-SYSTEMD/test.sh
@@ -86,7 +86,7 @@ test_setup() {
 	export initdir=$TESTDIR/overlay
 	. $basedir/dracut-init.sh
 	inst_multiple poweroff shutdown
-	inst_hook emergency 000 ./hard-off.sh
+	inst_hook shutdown-emergency 000 ./hard-off.sh
 	inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
     )
     sudo $basedir/dracut.sh -l -i $TESTDIR/overlay / \
diff --git a/test/TEST-03-USR-MOUNT/test.sh b/test/TEST-03-USR-MOUNT/test.sh
index 61063fd5..0aca8cf1 100755
--- a/test/TEST-03-USR-MOUNT/test.sh
+++ b/test/TEST-03-USR-MOUNT/test.sh
@@ -124,7 +124,7 @@ test_setup() {
 	export initdir=$TESTDIR/overlay
 	. $basedir/dracut-init.sh
 	inst_multiple poweroff shutdown
-	inst_hook emergency 000 ./hard-off.sh
+	inst_hook shutdown-emergency 000 ./hard-off.sh
 	inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
     )
     sudo $basedir/dracut.sh -l -i $TESTDIR/overlay / \
diff --git a/test/TEST-04-FULL-SYSTEMD/test.sh b/test/TEST-04-FULL-SYSTEMD/test.sh
index c7e08bfb..884f4412 100755
--- a/test/TEST-04-FULL-SYSTEMD/test.sh
+++ b/test/TEST-04-FULL-SYSTEMD/test.sh
@@ -261,7 +261,7 @@ EOF
 	export initdir=$TESTDIR/overlay
 	. $basedir/dracut-init.sh
 	inst_multiple poweroff shutdown
-	inst_hook emergency 000 ./hard-off.sh
+	inst_hook shutdown-emergency 000 ./hard-off.sh
 	inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
     )
 
diff --git a/test/TEST-10-RAID/test.sh b/test/TEST-10-RAID/test.sh
index 523b61a6..6ec77a68 100755
--- a/test/TEST-10-RAID/test.sh
+++ b/test/TEST-10-RAID/test.sh
@@ -86,7 +86,7 @@ test_setup() {
 	export initdir=$TESTDIR/overlay
 	. $basedir/dracut-init.sh
 	inst_multiple poweroff shutdown
-	inst_hook emergency 000 ./hard-off.sh
+	inst_hook shutdown-emergency 000 ./hard-off.sh
 	inst ./cryptroot-ask.sh /sbin/cryptroot-ask
         mkdir -p $initdir/etc
         echo "testluks UUID=$ID_FS_UUID /etc/key" > $initdir/etc/crypttab
diff --git a/test/TEST-11-LVM/test.sh b/test/TEST-11-LVM/test.sh
index 34c7736a..412a0658 100755
--- a/test/TEST-11-LVM/test.sh
+++ b/test/TEST-11-LVM/test.sh
@@ -79,7 +79,7 @@ test_setup() {
 	export initdir=$TESTDIR/overlay
 	. $basedir/dracut-init.sh
 	inst_multiple poweroff shutdown
-	inst_hook emergency 000 ./hard-off.sh
+	inst_hook shutdown-emergency 000 ./hard-off.sh
 	inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
     )
     sudo $basedir/dracut.sh -l -i $TESTDIR/overlay / \
diff --git a/test/TEST-12-RAID-DEG/test.sh b/test/TEST-12-RAID-DEG/test.sh
index f4ec2d00..444dca6d 100755
--- a/test/TEST-12-RAID-DEG/test.sh
+++ b/test/TEST-12-RAID-DEG/test.sh
@@ -129,7 +129,7 @@ test_setup() {
 	export initdir=$TESTDIR/overlay
 	. $basedir/dracut-init.sh
 	inst_multiple poweroff shutdown
-	inst_hook emergency 000 ./hard-off.sh
+	inst_hook shutdown-emergency 000 ./hard-off.sh
 	inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
 	inst ./cryptroot-ask.sh /sbin/cryptroot-ask
         mkdir -p $initdir/etc
diff --git a/test/TEST-13-ENC-RAID-LVM/test.sh b/test/TEST-13-ENC-RAID-LVM/test.sh
index ea816976..2a814f89 100755
--- a/test/TEST-13-ENC-RAID-LVM/test.sh
+++ b/test/TEST-13-ENC-RAID-LVM/test.sh
@@ -123,7 +123,7 @@ test_setup() {
 	export initdir=$TESTDIR/overlay
 	. $basedir/dracut-init.sh
 	inst_multiple poweroff shutdown
-	inst_hook emergency 000 ./hard-off.sh
+	inst_hook shutdown-emergency 000 ./hard-off.sh
 	inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
 	inst ./cryptroot-ask.sh /sbin/cryptroot-ask
         mkdir -p $initdir/etc
diff --git a/test/TEST-14-IMSM/test.sh b/test/TEST-14-IMSM/test.sh
index f4ea7ae0..315bc5aa 100755
--- a/test/TEST-14-IMSM/test.sh
+++ b/test/TEST-14-IMSM/test.sh
@@ -113,7 +113,7 @@ test_setup() {
 	export initdir=$TESTDIR/overlay
 	. $basedir/dracut-init.sh
 	inst_multiple poweroff shutdown
-	inst_hook emergency 000 ./hard-off.sh
+	inst_hook shutdown-emergency 000 ./hard-off.sh
 	inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
     )
     sudo $basedir/dracut.sh -l -i $TESTDIR/overlay / \
diff --git a/test/TEST-15-BTRFSRAID/test.sh b/test/TEST-15-BTRFSRAID/test.sh
index 5a9b6e1f..8e2ea49e 100755
--- a/test/TEST-15-BTRFSRAID/test.sh
+++ b/test/TEST-15-BTRFSRAID/test.sh
@@ -87,7 +87,7 @@ test_setup() {
         export initdir=$TESTDIR/overlay
 	. $basedir/dracut-init.sh
 	inst_multiple poweroff shutdown
-	inst_hook emergency 000 ./hard-off.sh
+	inst_hook shutdown-emergency 000 ./hard-off.sh
 	inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
     )
     sudo $basedir/dracut.sh -l -i $TESTDIR/overlay / \
diff --git a/test/TEST-16-DMSQUASH/test.sh b/test/TEST-16-DMSQUASH/test.sh
index 53a45d69..b255492e 100755
--- a/test/TEST-16-DMSQUASH/test.sh
+++ b/test/TEST-16-DMSQUASH/test.sh
@@ -43,7 +43,7 @@ test_setup() {
 	export initdir="$TESTDIR"/overlay
 	. "$basedir"/dracut-init.sh
 	inst_multiple poweroff shutdown
-	inst_hook emergency 000 ./hard-off.sh
+	inst_hook shutdown-emergency 000 ./hard-off.sh
 	inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
     )
 
diff --git a/test/TEST-17-LVM-THIN/test.sh b/test/TEST-17-LVM-THIN/test.sh
index 859d4dc0..e3375918 100755
--- a/test/TEST-17-LVM-THIN/test.sh
+++ b/test/TEST-17-LVM-THIN/test.sh
@@ -79,7 +79,7 @@ test_setup() {
 	export initdir=$TESTDIR/overlay
 	. $basedir/dracut-init.sh
 	inst_multiple poweroff shutdown
-	inst_hook emergency 000 ./hard-off.sh
+	inst_hook shutdown-emergency 000 ./hard-off.sh
 	inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
     )
     sudo $basedir/dracut.sh -l -i $TESTDIR/overlay / \
diff --git a/test/TEST-20-NFS/test.sh b/test/TEST-20-NFS/test.sh
index ceca1f08..1dfdfc4e 100755
--- a/test/TEST-20-NFS/test.sh
+++ b/test/TEST-20-NFS/test.sh
@@ -141,7 +141,7 @@ test_nfsv3() {
 
     # This test must fail: nfsroot= requires root=/dev/nfs
     client_test "NFSv3 Invalid root=dhcp nfsroot=/nfs/client" 52:54:00:12:34:04 \
-        "root=dhcp nfsroot=/nfs/client failme" 192.168.50.1 -wsize=4096 && return 1
+        "root=dhcp nfsroot=/nfs/client failme rd.debug" 192.168.50.1 -wsize=4096 && return 1
 
     client_test "NFSv3 root=dhcp DHCP path,options" \
         52:54:00:12:34:05 "root=dhcp" 192.168.50.1 wsize=4096 || return 1
@@ -334,7 +334,7 @@ test_setup() {
         . $basedir/dracut-init.sh
         mkdir $TESTDIR/overlay
         inst_multiple poweroff shutdown
-        inst_hook emergency 000 ./hard-off.sh
+        inst_hook shutdown-emergency 000 ./hard-off.sh
         inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
     )
 
diff --git a/test/TEST-30-ISCSI/test.sh b/test/TEST-30-ISCSI/test.sh
index 940edb6b..1c06b06d 100755
--- a/test/TEST-30-ISCSI/test.sh
+++ b/test/TEST-30-ISCSI/test.sh
@@ -213,7 +213,7 @@ test_setup() {
         export initdir=$TESTDIR/overlay
         . $basedir/dracut-init.sh
         inst_multiple poweroff shutdown
-        inst_hook emergency 000 ./hard-off.sh
+        inst_hook shutdown-emergency 000 ./hard-off.sh
         inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
     )
     sudo $basedir/dracut.sh -l -i $TESTDIR/overlay / \
diff --git a/test/TEST-40-NBD/test.sh b/test/TEST-40-NBD/test.sh
index 28ba6aa3..2061392a 100755
--- a/test/TEST-40-NBD/test.sh
+++ b/test/TEST-40-NBD/test.sh
@@ -226,7 +226,7 @@ make_encrypted_root() {
             done
         )
         inst_multiple mke2fs poweroff cp umount tune2fs
-        inst_hook emergency 000 ./hard-off.sh
+        inst_hook shutdown-emergency 000 ./hard-off.sh
         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
@@ -362,7 +362,7 @@ test_setup() {
         export initdir=$TESTDIR/overlay
         . $basedir/dracut-init.sh
         inst_multiple poweroff shutdown
-        inst_hook emergency 000 ./hard-off.sh
+        inst_hook shutdown-emergency 000 ./hard-off.sh
         inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
         inst ./cryptroot-ask.sh /sbin/cryptroot-ask
 
diff --git a/test/TEST-50-MULTINIC/test.sh b/test/TEST-50-MULTINIC/test.sh
index 484ebeed..e0bf7d2f 100755
--- a/test/TEST-50-MULTINIC/test.sh
+++ b/test/TEST-50-MULTINIC/test.sh
@@ -269,7 +269,7 @@ test_setup() {
         export initdir="$TESTDIR"/overlay
         . "$basedir"/dracut-init.sh
         inst_multiple poweroff shutdown
-        inst_hook emergency 000 ./hard-off.sh
+        inst_hook shutdown-emergency 000 ./hard-off.sh
         inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
     )
 
