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

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