Make root on local block device test completly automated.
authorVictor Lowther <victor.lowther@gmail.com>
Sun, 31 May 2009 02:23:55 +0000 (21:23 -0500)
committerVictor Lowther <victor.lowther@gmail.com>
Sun, 31 May 2009 02:23:55 +0000 (21:23 -0500)
We no longer require any user intervention when testing dracut on
a local block device in qemu, assuming everything passes.  If things fail,
we still might need to manually kill things.

test/TEST-10-RAID/create-root.sh
test/TEST-10-RAID/cryptroot-ask [new file with mode: 0755]
test/TEST-10-RAID/hard-off.sh [new file with mode: 0755]
test/TEST-10-RAID/test.sh
test/test-init

index 89f1515..2dc9a59 100755 (executable)
@@ -18,17 +18,17 @@ mdadm -W /dev/md0
 echo -n test >keyfile
 cryptsetup -q luksFormat /dev/md0 /keyfile
 echo "The passphrase is test"
-cryptsetup luksOpen /dev/md0 dracut_crypt_test </keyfile
-lvm pvcreate -ff  -y /dev/mapper/dracut_crypt_test
-lvm vgcreate dracut /dev/mapper/dracut_crypt_test
-lvm lvcreate -l 100%FREE -n root dracut
-lvm vgchange -ay
-[ -b /dev/dracut/root ] || emergency_shell
-mke2fs /dev/dracut/root
-mkdir -p /sysroot
-mount /dev/dracut/root /sysroot
-cp -a -t /sysroot /source/*
-umount /sysroot
-lvm lvchange -a n /dev/dracut/root
-cryptsetup luksClose /dev/mapper/dracut_crypt_test
+cryptsetup luksOpen /dev/md0 dracut_crypt_test </keyfile && \
+lvm pvcreate -ff  -y /dev/mapper/dracut_crypt_test && \
+lvm vgcreate dracut /dev/mapper/dracut_crypt_test && \
+lvm lvcreate -l 100%FREE -n root dracut && \
+lvm vgchange -ay && \
+mke2fs /dev/dracut/root && \
+mkdir -p /sysroot && \
+mount /dev/dracut/root /sysroot && \
+cp -a -t /sysroot /source/* && \
+umount /sysroot && \
+lvm lvchange -a n /dev/dracut/root && \
+cryptsetup luksClose /dev/mapper/dracut_crypt_test && \
+echo "dracut-root-block-created" >/dev/sda1
 poweroff -f
diff --git a/test/TEST-10-RAID/cryptroot-ask b/test/TEST-10-RAID/cryptroot-ask
new file mode 100755 (executable)
index 0000000..db27c5b
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+[ -b /dev/mapper/$2 ] && exit 0
+echo -n test >/keyfile
+/sbin/cryptsetup luksOpen $1 $2 </keyfile
+
diff --git a/test/TEST-10-RAID/hard-off.sh b/test/TEST-10-RAID/hard-off.sh
new file mode 100755 (executable)
index 0000000..92dd304
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+poweroff -f
\ No newline at end of file
index cc75ed3..8bbb6e5 100755 (executable)
@@ -4,8 +4,9 @@ TEST_DESCRIPTION="root filesystem on an encrypted LVM PV"
 test_run() {
     $testdir/run-qemu -hda root.ext2 -m 512M -nographic \
        -net none -kernel /boot/vmlinuz-$(uname -r) \
-       -append "root=/dev/dracut/root rw console=ttyS0,115200n81" \
+       -append "root=/dev/dracut/root rw quiet console=ttyS0,115200n81" \
        -initrd initramfs.testing
+    grep -m 1 -q dracut-root-block-success root.ext2 || return 1
 }
 
 test_setup() {
@@ -42,14 +43,21 @@ test_setup() {
        -m "dash crypt lvm mdraid udev-rules base rootfs-block" \
        -d "ata_piix ext2 sd_mod" \
        -f initramfs.makeroot || return 1
-
+    rm -rf overlay
     # Invoke KVM and/or QEMU to actually create the target filesystem.
     $testdir/run-qemu -hda root.ext2 -m 512M -nographic -net none \
        -kernel "/boot/vmlinuz-$kernel" \
        -append "root=/dev/dracut/root rw rootfstype=ext2 quiet console=ttyS0,115200n81" \
        -initrd initramfs.makeroot  || return 1
-
-    sudo $basedir/dracut -l \
+    grep -m 1 -q dracut-root-block-created root.ext2 || return 1
+    (
+       initdir=overlay
+       . $basedir/dracut-functions
+       dracut_install poweroff shutdown
+       inst_simple ./hard-off.sh /emergency/01hard-off.sh
+       inst ./cryptroot-ask /sbin/cryptroot-ask
+    )
+    sudo $basedir/dracut -l -i overlay / \
        -m "dash crypt lvm mdraid udev-rules base rootfs-block" \
        -d "ata_piix ext2 sd_mod" \
        -f initramfs.testing || return 1
index 0efd896..ccdc9a4 100755 (executable)
@@ -1,13 +1,10 @@
 #!/bin/sh
 exec >/dev/console 2>&1
+echo "dracut-root-block-success" >/dev/sda1
 export TERM=linux
 export PS1='initramfs-test:\w\$ '
 [ -f /etc/fstab ] || ln -s /proc/mounts /etc/fstab
 stty sane
-echo "made it to the rootfs!"
-echo 3 >/proc/sys/vm/drop_caches
-free
-[ -x /bin/plymouth ] && /bin/plymouth quit
-sh -i
+echo "made it to the rootfs! Powering down."
 mount -n -o remount,ro /
 poweroff -f