Blame SOURCES/0063-test-TEST-17-LVM-THIN-add-test-case-for-lvm-thin-poo.patch

712866
From a34d3dcaa8947c8df6a3b809e42e6868d08ba649 Mon Sep 17 00:00:00 2001
712866
From: Harald Hoyer <harald@redhat.com>
712866
Date: Mon, 16 Dec 2013 13:15:48 +0100
712866
Subject: [PATCH] test/TEST-17-LVM-THIN: add test case for lvm thin pools
712866
712866
---
712866
 test/TEST-17-LVM-THIN/.testdir             |  1 +
712866
 test/TEST-17-LVM-THIN/99-idesymlinks.rules |  8 +++
712866
 test/TEST-17-LVM-THIN/Makefile             | 10 ++++
712866
 test/TEST-17-LVM-THIN/create-root.sh       | 31 +++++++++++
712866
 test/TEST-17-LVM-THIN/finished-false.sh    |  2 +
712866
 test/TEST-17-LVM-THIN/hard-off.sh          |  3 +
712866
 test/TEST-17-LVM-THIN/test-init.sh         | 17 ++++++
712866
 test/TEST-17-LVM-THIN/test.sh              | 88 ++++++++++++++++++++++++++++++
712866
 8 files changed, 160 insertions(+)
712866
 create mode 100644 test/TEST-17-LVM-THIN/.testdir
712866
 create mode 100644 test/TEST-17-LVM-THIN/99-idesymlinks.rules
712866
 create mode 100644 test/TEST-17-LVM-THIN/Makefile
712866
 create mode 100755 test/TEST-17-LVM-THIN/create-root.sh
712866
 create mode 100755 test/TEST-17-LVM-THIN/finished-false.sh
712866
 create mode 100755 test/TEST-17-LVM-THIN/hard-off.sh
712866
 create mode 100755 test/TEST-17-LVM-THIN/test-init.sh
712866
 create mode 100755 test/TEST-17-LVM-THIN/test.sh
712866
712866
diff --git a/test/TEST-17-LVM-THIN/.testdir b/test/TEST-17-LVM-THIN/.testdir
712866
new file mode 100644
712866
index 0000000..9af2638
712866
--- /dev/null
712866
+++ b/test/TEST-17-LVM-THIN/.testdir
712866
@@ -0,0 +1 @@
712866
+TESTDIR="/var/tmp/dracut-test.uElZSK"
712866
diff --git a/test/TEST-17-LVM-THIN/99-idesymlinks.rules b/test/TEST-17-LVM-THIN/99-idesymlinks.rules
712866
new file mode 100644
712866
index 0000000..d557790
712866
--- /dev/null
712866
+++ b/test/TEST-17-LVM-THIN/99-idesymlinks.rules
712866
@@ -0,0 +1,8 @@
712866
+ACTION=="add|change", SUBSYSTEM=="block", ENV{DEVTYPE}=="disk", KERNEL=="hda", SYMLINK+="sda"
712866
+ACTION=="add|change", SUBSYSTEM=="block", ENV{DEVTYPE}=="partition", KERNEL=="hda*", SYMLINK+="sda$env{MINOR}"
712866
+ACTION=="add|change", SUBSYSTEM=="block", ENV{DEVTYPE}=="disk", KERNEL=="hdb", SYMLINK+="sdb"
712866
+ACTION=="add|change", SUBSYSTEM=="block", ENV{DEVTYPE}=="partition", KERNEL=="hdb*", SYMLINK+="sdb$env{MINOR}"
712866
+ACTION=="add|change", SUBSYSTEM=="block", ENV{DEVTYPE}=="disk", KERNEL=="hdc", SYMLINK+="sdc"
712866
+ACTION=="add|change", SUBSYSTEM=="block", ENV{DEVTYPE}=="partition", KERNEL=="hdc*", SYMLINK+="sdc$env{MINOR}"
712866
+ACTION=="add|change", SUBSYSTEM=="block", ENV{DEVTYPE}=="disk", KERNEL=="hdd", SYMLINK+="sdd"
712866
+ACTION=="add|change", SUBSYSTEM=="block", ENV{DEVTYPE}=="partition", KERNEL=="hdd*", SYMLINK+="sdd$env{MINOR}"
712866
diff --git a/test/TEST-17-LVM-THIN/Makefile b/test/TEST-17-LVM-THIN/Makefile
712866
new file mode 100644
712866
index 0000000..aad2705
712866
--- /dev/null
712866
+++ b/test/TEST-17-LVM-THIN/Makefile
712866
@@ -0,0 +1,10 @@
712866
+all:
712866
+	@$(MAKE) -s --no-print-directory -C ../.. all
712866
+	@V=$(V) basedir=../.. testdir=../ ./test.sh --all
712866
+setup:
712866
+	@$(MAKE) --no-print-directory -C ../.. all
712866
+	@basedir=../.. testdir=../ ./test.sh --setup
712866
+clean:
712866
+	@basedir=../.. testdir=../ ./test.sh --clean
712866
+run:
712866
+	@basedir=../.. testdir=../ ./test.sh --run
712866
diff --git a/test/TEST-17-LVM-THIN/create-root.sh b/test/TEST-17-LVM-THIN/create-root.sh
712866
new file mode 100755
712866
index 0000000..740704f
712866
--- /dev/null
712866
+++ b/test/TEST-17-LVM-THIN/create-root.sh
712866
@@ -0,0 +1,31 @@
712866
+#!/bin/sh
712866
+# don't let udev and this script step on eachother's toes
712866
+for x in 64-lvm.rules 70-mdadm.rules 99-mount-rules; do
712866
+    > "/etc/udev/rules.d/$x"
712866
+done
712866
+rm -f -- /etc/lvm/lvm.conf
712866
+udevadm control --reload
712866
+# save a partition at the beginning for future flagging purposes
712866
+sfdisk -C 2560 -H 2 -S 32 -L /dev/sda <
712866
+,1
712866
+,800
712866
+,800
712866
+,800
712866
+EOF
712866
+for i in sda2 sda3 sda4; do
712866
+lvm pvcreate -ff  -y /dev/$i ;
712866
+done && \
712866
+lvm vgcreate dracut /dev/sda[234] && \
712866
+lvm lvcreate -l 16  -T dracut/mythinpool && \
712866
+lvm lvcreate -V1G -T dracut/mythinpool -n root && \
712866
+lvm vgchange -ay && \
712866
+mke2fs /dev/dracut/root && \
712866
+mkdir -p /sysroot && \
712866
+mount /dev/dracut/root /sysroot && \
712866
+cp -a -t /sysroot /source/* && \
712866
+umount /sysroot && \
712866
+sleep 1 && \
712866
+lvm lvchange -a n /dev/dracut/root && \
712866
+sleep 1 && \
712866
+echo "dracut-root-block-created" >/dev/sda1
712866
+poweroff -f
712866
diff --git a/test/TEST-17-LVM-THIN/finished-false.sh b/test/TEST-17-LVM-THIN/finished-false.sh
712866
new file mode 100755
712866
index 0000000..ecdbef9
712866
--- /dev/null
712866
+++ b/test/TEST-17-LVM-THIN/finished-false.sh
712866
@@ -0,0 +1,2 @@
712866
+#!/bin/sh
712866
+exit 1
712866
diff --git a/test/TEST-17-LVM-THIN/hard-off.sh b/test/TEST-17-LVM-THIN/hard-off.sh
712866
new file mode 100755
712866
index 0000000..12c3d5a
712866
--- /dev/null
712866
+++ b/test/TEST-17-LVM-THIN/hard-off.sh
712866
@@ -0,0 +1,3 @@
712866
+#!/bin/sh
712866
+getarg rd.shell || poweroff -f
712866
+getarg failme && poweroff -f
712866
diff --git a/test/TEST-17-LVM-THIN/test-init.sh b/test/TEST-17-LVM-THIN/test-init.sh
712866
new file mode 100755
712866
index 0000000..fd03aa5
712866
--- /dev/null
712866
+++ b/test/TEST-17-LVM-THIN/test-init.sh
712866
@@ -0,0 +1,17 @@
712866
+#!/bin/sh
712866
+export PATH=/sbin:/bin:/usr/sbin:/usr/bin
712866
+strstr() { [ "${1#*$2*}" != "$1" ]; }
712866
+CMDLINE=$(while read line; do echo $line;done < /proc/cmdline)
712866
+plymouth --quit
712866
+exec >/dev/console 2>&1
712866
+echo "dracut-root-block-success" >/dev/sda1
712866
+export TERM=linux
712866
+export PS1='initramfs-test:\w\$ '
712866
+[ -f /etc/mtab ] || ln -sfn /proc/mounts /etc/mtab
712866
+[ -f /etc/fstab ] || ln -sfn /proc/mounts /etc/fstab
712866
+stty sane
712866
+echo "made it to the rootfs!"
712866
+strstr "$CMDLINE" "rd.shell" && sh -i
712866
+echo "Powering down."
712866
+mount -n -o remount,ro /
712866
+poweroff -f
712866
diff --git a/test/TEST-17-LVM-THIN/test.sh b/test/TEST-17-LVM-THIN/test.sh
712866
new file mode 100755
712866
index 0000000..0cfce19
712866
--- /dev/null
712866
+++ b/test/TEST-17-LVM-THIN/test.sh
712866
@@ -0,0 +1,88 @@
712866
+#!/bin/bash
712866
+TEST_DESCRIPTION="root filesystem on LVM PV with thin pool"
712866
+
712866
+KVERSION=${KVERSION-$(uname -r)}
712866
+
712866
+# Uncomment this to debug failures
712866
+#DEBUGFAIL="rd.break rd.shell"
712866
+
712866
+test_run() {
712866
+    $testdir/run-qemu \
712866
+	-hda $TESTDIR/root.ext2 \
712866
+	-m 256M -smp 2 -nographic \
712866
+	-net none -kernel /boot/vmlinuz-$KVERSION \
712866
+	-append "root=/dev/dracut/root rw rd.auto=1 quiet rd.retry=3 rd.info console=ttyS0,115200n81 selinux=0 rd.debug  $DEBUGFAIL" \
712866
+	-initrd $TESTDIR/initramfs.testing
712866
+    grep -F -m 1 -q dracut-root-block-success $TESTDIR/root.ext2 || return 1
712866
+}
712866
+
712866
+test_setup() {
712866
+    # Create the blank file to use as a root filesystem
712866
+    dd if=/dev/null of=$TESTDIR/root.ext2 bs=1M seek=80
712866
+
712866
+    kernel=$KVERSION
712866
+    # Create what will eventually be our root filesystem onto an overlay
712866
+    (
712866
+	export initdir=$TESTDIR/overlay/source
712866
+	. $basedir/dracut-functions.sh
712866
+	inst_multiple sh df free ls shutdown poweroff stty cat ps ln ip route \
712866
+	    mount dmesg ifconfig dhclient mkdir cp ping dhclient
712866
+        for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
712866
+	    [ -f ${_terminfodir}/l/linux ] && break
712866
+	done
712866
+	inst_multiple -o ${_terminfodir}/l/linux
712866
+	inst "$basedir/modules.d/40network/dhclient-script.sh" "/sbin/dhclient-script"
712866
+	inst "$basedir/modules.d/40network/ifup.sh" "/sbin/ifup"
712866
+	inst_multiple grep
712866
+        inst_simple /etc/os-release
712866
+	inst ./test-init.sh /sbin/init
712866
+	find_binary plymouth >/dev/null && inst_multiple plymouth
712866
+	(cd "$initdir"; mkdir -p dev sys proc etc var/run tmp )
712866
+	cp -a /etc/ld.so.conf* $initdir/etc
712866
+	mkdir $initdir/run
712866
+	sudo ldconfig -r "$initdir"
712866
+    )
712866
+
712866
+    # second, install the files needed to make the root filesystem
712866
+    (
712866
+	export initdir=$TESTDIR/overlay
712866
+	. $basedir/dracut-functions.sh
712866
+	inst_multiple sfdisk mke2fs poweroff cp umount
712866
+	inst_hook initqueue 01 ./create-root.sh
712866
+        inst_hook initqueue/finished 01 ./finished-false.sh
712866
+	inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
712866
+    )
712866
+
712866
+    # create an initramfs that will create the target root filesystem.
712866
+    # We do it this way so that we do not risk trashing the host mdraid
712866
+    # devices, volume groups, encrypted partitions, etc.
712866
+    $basedir/dracut.sh -l -i $TESTDIR/overlay / \
712866
+	-m "dash lvm mdraid udev-rules base rootfs-block kernel-modules" \
712866
+	-d "piix ide-gd_mod ata_piix ext2 sd_mod" \
712866
+	-f $TESTDIR/initramfs.makeroot $KVERSION || return 1
712866
+    rm -rf -- $TESTDIR/overlay
712866
+    # Invoke KVM and/or QEMU to actually create the target filesystem.
712866
+    $testdir/run-qemu -hda $TESTDIR/root.ext2 -m 256M -smp 2 -nographic -net none \
712866
+	-kernel "/boot/vmlinuz-$kernel" \
712866
+	-append "root=/dev/fakeroot rw rootfstype=ext2 quiet console=ttyS0,115200n81 selinux=0" \
712866
+	-initrd $TESTDIR/initramfs.makeroot  || return 1
712866
+    grep -F -m 1 -q dracut-root-block-created $TESTDIR/root.ext2 || return 1
712866
+    (
712866
+	export initdir=$TESTDIR/overlay
712866
+	. $basedir/dracut-functions.sh
712866
+	inst_multiple poweroff shutdown
712866
+	inst_hook emergency 000 ./hard-off.sh
712866
+	inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
712866
+    )
712866
+    sudo $basedir/dracut.sh -l -i $TESTDIR/overlay / \
712866
+	-o "plymouth network" \
712866
+	-a "debug" -I lvs \
712866
+	-d "piix ide-gd_mod ata_piix ext2 sd_mod" \
712866
+	-f $TESTDIR/initramfs.testing $KVERSION || return 1
712866
+}
712866
+
712866
+test_cleanup() {
712866
+    return 0
712866
+}
712866
+
712866
+. $testdir/test-functions