Blob Blame History Raw
From ea8e543bb86660dd6ccc3048ae9916358b58a6b3 Mon Sep 17 00:00:00 2001
From: Harald Hoyer <harald@redhat.com>
Date: Wed, 17 Aug 2011 13:42:16 +0200
Subject: [PATCH] add TEST-16-DMSQUASH

This is a test for Fedora LiveCDs created via livecd-tools
---
 test/TEST-16-DMSQUASH/99-idesymlinks.rules     |    8 +
 test/TEST-16-DMSQUASH/Makefile                 |   10 ++
 test/TEST-16-DMSQUASH/create.py                |  186 ++++++++++++++++++++++++
 test/TEST-16-DMSQUASH/cryptroot-ask            |    6 +
 test/TEST-16-DMSQUASH/hard-off.sh              |    3 +
 test/TEST-16-DMSQUASH/livecd-fedora-minimal.ks |   22 +++
 test/TEST-16-DMSQUASH/test-init                |   17 ++
 test/TEST-16-DMSQUASH/test.sh                  |   66 +++++++++
 8 files changed, 318 insertions(+), 0 deletions(-)
 create mode 100644 test/TEST-16-DMSQUASH/99-idesymlinks.rules
 create mode 100644 test/TEST-16-DMSQUASH/Makefile
 create mode 100644 test/TEST-16-DMSQUASH/create.py
 create mode 100755 test/TEST-16-DMSQUASH/cryptroot-ask
 create mode 100755 test/TEST-16-DMSQUASH/hard-off.sh
 create mode 100644 test/TEST-16-DMSQUASH/livecd-fedora-minimal.ks
 create mode 100755 test/TEST-16-DMSQUASH/test-init
 create mode 100755 test/TEST-16-DMSQUASH/test.sh

diff --git a/test/TEST-16-DMSQUASH/99-idesymlinks.rules b/test/TEST-16-DMSQUASH/99-idesymlinks.rules
new file mode 100644
index 0000000..d557790
--- /dev/null
+++ b/test/TEST-16-DMSQUASH/99-idesymlinks.rules
@@ -0,0 +1,8 @@
+ACTION=="add|change", SUBSYSTEM=="block", ENV{DEVTYPE}=="disk", KERNEL=="hda", SYMLINK+="sda"
+ACTION=="add|change", SUBSYSTEM=="block", ENV{DEVTYPE}=="partition", KERNEL=="hda*", SYMLINK+="sda$env{MINOR}"
+ACTION=="add|change", SUBSYSTEM=="block", ENV{DEVTYPE}=="disk", KERNEL=="hdb", SYMLINK+="sdb"
+ACTION=="add|change", SUBSYSTEM=="block", ENV{DEVTYPE}=="partition", KERNEL=="hdb*", SYMLINK+="sdb$env{MINOR}"
+ACTION=="add|change", SUBSYSTEM=="block", ENV{DEVTYPE}=="disk", KERNEL=="hdc", SYMLINK+="sdc"
+ACTION=="add|change", SUBSYSTEM=="block", ENV{DEVTYPE}=="partition", KERNEL=="hdc*", SYMLINK+="sdc$env{MINOR}"
+ACTION=="add|change", SUBSYSTEM=="block", ENV{DEVTYPE}=="disk", KERNEL=="hdd", SYMLINK+="sdd"
+ACTION=="add|change", SUBSYSTEM=="block", ENV{DEVTYPE}=="partition", KERNEL=="hdd*", SYMLINK+="sdd$env{MINOR}"
diff --git a/test/TEST-16-DMSQUASH/Makefile b/test/TEST-16-DMSQUASH/Makefile
new file mode 100644
index 0000000..bc0ddb6
--- /dev/null
+++ b/test/TEST-16-DMSQUASH/Makefile
@@ -0,0 +1,10 @@
+all:
+	@make -s --no-print-directory -C ../.. all
+	@basedir=../.. testdir=../ ./test.sh --all
+setup:
+	@make --no-print-directory -C ../.. all
+	@basedir=../.. testdir=../ ./test.sh --setup
+clean:
+	@basedir=../.. testdir=../ ./test.sh --clean
+run:
+	@basedir=../.. testdir=../ ./test.sh --run
diff --git a/test/TEST-16-DMSQUASH/create.py b/test/TEST-16-DMSQUASH/create.py
new file mode 100644
index 0000000..15d29ff
--- /dev/null
+++ b/test/TEST-16-DMSQUASH/create.py
@@ -0,0 +1,186 @@
+#!/usr/bin/python -tt
+#
+# livecd-creator : Creates Live CD based for Fedora.
+#
+# Copyright 2007, Red Hat  Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Library General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+import os
+import os.path
+import sys
+import time
+import optparse
+import logging
+import shutil
+from distutils.dir_util import copy_tree
+
+import imgcreate
+from imgcreate.fs import makedirs
+
+class myLiveImageCreator(imgcreate.x86LiveImageCreator):
+    def install(self, repo_urls = {}):
+        copy_tree("root-source", self._instroot)
+
+    def configure(self):
+        self._create_bootconfig()
+
+    def _get_kernel_versions(self):
+        ret = {}
+        version=os.uname()
+        version=version[2]
+        ret["kernel-" + version] = [version]
+        return ret
+
+    def __sanity_check(self):
+        pass
+
+class Usage(Exception):
+    def __init__(self, msg = None, no_error = False):
+        Exception.__init__(self, msg, no_error)
+
+def parse_options(args):
+    parser = optparse.OptionParser()
+
+    imgopt = optparse.OptionGroup(parser, "Image options",
+                                  "These options define the created image.")
+    imgopt.add_option("-c", "--config", type="string", dest="kscfg",
+                      help="Path or url to kickstart config file")
+    imgopt.add_option("-b", "--base-on", type="string", dest="base_on",
+                      help="Add packages to an existing live CD iso9660 image.")
+    imgopt.add_option("-f", "--fslabel", type="string", dest="fslabel",
+                      help="File system label (default based on config name)")
+    # Provided for img-create compatibility
+    imgopt.add_option("-n", "--name", type="string", dest="fslabel",
+                      help=optparse.SUPPRESS_HELP)
+    imgopt.add_option("", "--image-type", type="string", dest="image_type",
+                      help=optparse.SUPPRESS_HELP)
+    imgopt.add_option("", "--compression-type", type="string", dest="compress_type",
+                      help="Compression type recognized by mksquashfs "
+                           "(default xz needs a 2.6.38+ kernel, gzip works "
+                           "with all kernels, lzo needs a 2.6.36+ kernel, lzma "
+                           "needs custom kernel.) Set to 'None' to force read "
+                           "from base_on.",
+                      default="xz")
+    imgopt.add_option("", "--releasever", type="string", dest="releasever",
+                      default=None,
+                      help="Value to substitute for $releasever in kickstart repo urls")
+    parser.add_option_group(imgopt)
+
+    # options related to the config of your system
+    sysopt = optparse.OptionGroup(parser, "System directory options",
+                                  "These options define directories used on your system for creating the live image")
+    sysopt.add_option("-t", "--tmpdir", type="string",
+                      dest="tmpdir", default="/var/tmp",
+                      help="Temporary directory to use (default: /var/tmp)")
+    sysopt.add_option("", "--cache", type="string",
+                      dest="cachedir", default=None,
+                      help="Cache directory to use (default: private cache")
+    parser.add_option_group(sysopt)
+
+    imgcreate.setup_logging(parser)
+
+    # debug options not recommended for "production" images
+    # Start a shell in the chroot for post-configuration.
+    parser.add_option("-l", "--shell", action="store_true", dest="give_shell",
+                      help=optparse.SUPPRESS_HELP)
+    # Don't compress the image.
+    parser.add_option("-s", "--skip-compression", action="store_true", dest="skip_compression",
+                      help=optparse.SUPPRESS_HELP)
+    parser.add_option("", "--skip-minimize", action="store_true", dest="skip_minimize",
+                      help=optparse.SUPPRESS_HELP)
+
+    (options, args) = parser.parse_args()
+
+    # Pretend to be a image-creator if called with that name
+    options.image_type = 'livecd'
+    if options.image_type not in ('livecd', 'image'):
+        raise Usage("'%s' is a recognized image type" % options.image_type)
+
+    # image-create compatibility: Last argument is kickstart file
+    if len(args) == 1:
+        options.kscfg = args.pop()
+    if len(args):
+        raise Usage("Extra arguments given")
+
+    if options.base_on and not os.path.isfile(options.base_on):
+        raise Usage("Image file '%s' does not exist" %(options.base_on,))
+    if options.image_type == 'livecd':
+        if options.fslabel and len(options.fslabel) > imgcreate.FSLABEL_MAXLEN:
+            raise Usage("CD labels are limited to 32 characters")
+        if options.fslabel and options.fslabel.find(" ") != -1:
+            raise Usage("CD labels cannot contain spaces.")
+
+    return options
+
+def main():
+    try:
+        options = parse_options(sys.argv[1:])
+    except Usage, (msg, no_error):
+        if no_error:
+            out = sys.stdout
+            ret = 0
+        else:
+            out = sys.stderr
+            ret = 2
+        if msg:
+            print >> out, msg
+        return ret
+
+    if os.geteuid () != 0:
+        print >> sys.stderr, "You must run %s as root" % sys.argv[0]
+        return 1
+
+    if options.fslabel:
+        fslabel = options.fslabel
+        name = fslabel
+    else:
+        name = "livecd"
+
+        fslabel = "LiveCD"
+        logging.info("Using label '%s' and name '%s'" % (fslabel, name))
+
+    ks = imgcreate.read_kickstart(options.kscfg)
+
+    creator = myLiveImageCreator(ks, name,
+                                 fslabel=fslabel,
+                                 releasever=options.releasever,
+                                 tmpdir=os.path.abspath(options.tmpdir))
+
+    creator.compress_type = options.compress_type
+    creator.skip_compression = options.skip_compression
+    creator.skip_minimize = options.skip_minimize
+    if options.cachedir:
+        options.cachedir = os.path.abspath(options.cachedir)
+
+    try:
+        creator.mount(options.base_on, options.cachedir)
+        creator.install()
+        creator.configure()
+        if options.give_shell:
+            print "Launching shell. Exit to continue."
+            print "----------------------------------"
+            creator.launch_shell()
+        creator.unmount()
+        creator.package()
+    except imgcreate.CreatorError, e:
+        logging.error(u"Error creating Live CD : %s" % e)
+        return 1
+    finally:
+        creator.cleanup()
+
+    return 0
+
+if __name__ == "__main__":
+    sys.exit(main())
diff --git a/test/TEST-16-DMSQUASH/cryptroot-ask b/test/TEST-16-DMSQUASH/cryptroot-ask
new file mode 100755
index 0000000..db27c5b
--- /dev/null
+++ b/test/TEST-16-DMSQUASH/cryptroot-ask
@@ -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-16-DMSQUASH/hard-off.sh b/test/TEST-16-DMSQUASH/hard-off.sh
new file mode 100755
index 0000000..12c3d5a
--- /dev/null
+++ b/test/TEST-16-DMSQUASH/hard-off.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+getarg rd.shell || poweroff -f
+getarg failme && poweroff -f
diff --git a/test/TEST-16-DMSQUASH/livecd-fedora-minimal.ks b/test/TEST-16-DMSQUASH/livecd-fedora-minimal.ks
new file mode 100644
index 0000000..88637ae
--- /dev/null
+++ b/test/TEST-16-DMSQUASH/livecd-fedora-minimal.ks
@@ -0,0 +1,22 @@
+lang en_US.UTF-8
+keyboard us
+timezone US/Eastern
+auth --useshadow --enablemd5
+selinux --enforcing
+firewall --disabled
+part / --size 1024
+
+repo --name=fedora --mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-16&arch=$basearch
+
+%packages
+@core
+anaconda-runtime
+bash
+kernel
+passwd
+policycoreutils
+chkconfig
+authconfig
+rootfiles
+
+%end
diff --git a/test/TEST-16-DMSQUASH/test-init b/test/TEST-16-DMSQUASH/test-init
new file mode 100755
index 0000000..616bf68
--- /dev/null
+++ b/test/TEST-16-DMSQUASH/test-init
@@ -0,0 +1,17 @@
+#!/bin/sh
+export PATH=/sbin:/bin:/usr/sbin:/usr/bin
+strstr() { [ "${1#*$2*}" != "$1" ]; }
+CMDLINE=$(while read line; do echo $line;done < /proc/cmdline)
+plymouth --quit
+exec >/dev/console 2>&1
+echo "dracut-root-block-success" >/dev/sda
+export TERM=linux
+export PS1='initramfs-test:\w\$ '
+[ -f /etc/mtab ] || ln -sfn /proc/mounts /etc/mtab
+[ -f /etc/fstab ] || ln -sfn /proc/mounts /etc/fstab
+stty sane
+echo "made it to the rootfs!"
+strstr "$CMDLINE" "rd.shell" && sh -i
+echo "Powering down."
+mount -n -o remount,ro /
+poweroff -f
diff --git a/test/TEST-16-DMSQUASH/test.sh b/test/TEST-16-DMSQUASH/test.sh
new file mode 100755
index 0000000..5d8075c
--- /dev/null
+++ b/test/TEST-16-DMSQUASH/test.sh
@@ -0,0 +1,66 @@
+#!/bin/bash
+TEST_DESCRIPTION="root filesystem on a LiveCD dmsquash filesystem"
+
+KVERSION=${KVERSION-$(uname -r)}
+
+# Uncomment this to debug failures
+#DEBUGFAIL="rd.shell rd.break"
+
+test_run() {
+    $testdir/run-qemu -boot order=d -cdrom livecd.iso -hda root.img -m 256M -nographic \
+	-net none -kernel /boot/vmlinuz-$KVERSION \
+	-append "root=live:CDLABEL=LiveCD live rw quiet rd.retry=3 rd.info console=ttyS0,115200n81 selinux=0 rd.debug $DEBUGFAIL" \
+	-initrd initramfs.testing
+    grep -m 1 -q dracut-root-block-success root.img || return 1
+}
+
+test_setup() {
+    mkdir -p overlay
+    (
+	initdir=overlay
+	. $basedir/dracut-functions
+	dracut_install poweroff shutdown
+	inst_hook emergency 000 ./hard-off.sh
+	inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
+    )
+
+    dd if=/dev/null of=root.img seek=100
+
+    sudo $basedir/dracut -l -i overlay / \
+	-a "debug" \
+	-d "piix ide-gd_mod ata_piix ext3 sd_mod" \
+	-f initramfs.testing $KVERSION || return 1
+
+    mkdir -p root-source
+    kernel=$KVERSION
+    # Create what will eventually be our root filesystem onto an overlay
+    (
+	initdir=root-source
+	. $basedir/dracut-functions
+	dracut_install sh df free ls shutdown poweroff stty cat ps ln ip route \
+	    /lib/terminfo/l/linux mount dmesg ifconfig dhclient mkdir cp ping dhclient \
+	    umount strace less
+	inst "$basedir/modules.d/40network/dhclient-script" "/sbin/dhclient-script"
+	inst "$basedir/modules.d/40network/ifup" "/sbin/ifup"
+	dracut_install grep syslinux isohybrid
+	for f in /usr/share/syslinux/*; do
+	    inst_simple "$f"
+	done
+	inst ./test-init /sbin/init
+	inst ./initramfs.testing "/boot/initramfs-$KVERSION.img"
+	inst /boot/vmlinuz-$KVERSION
+	find_binary plymouth >/dev/null && dracut_install plymouth
+	(cd "$initdir"; mkdir -p dev sys proc etc var/run tmp )
+	cp -a /etc/ld.so.conf* $initdir/etc
+	sudo ldconfig -r "$initdir"
+    )
+    python create.py -d -c livecd-fedora-minimal.ks
+    exit 0
+}
+
+test_cleanup() {
+    rm -fr overlay root-source
+    rm -f root.img initramfs.makeroot initramfs.testing livecd.iso
+}
+
+. $testdir/test-functions