test.sh revision e8a66f4af296dc1dd4879a1401eb42bf7b7aeb01
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering# ex: ts=8 sw=4 sts=4 et filetype=sh
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart PoetteringTEST_DESCRIPTION="cryptsetup systemd setup"
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering# Uncomment this to debug failures
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering#DEBUGFAIL="systemd.unit=multi-user.target"
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart PoetteringDEBUGTOOLS="df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort"
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering # TODO: qemu wrapper script: http://www.spinics.net/lists/kvm/msg72389.html
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering -net none -kernel /boot/vmlinuz-$KERNEL_VER \
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering -append "root=/dev/sda1 systemd.log_level=debug raid=noautodetect loglevel=2 init=/usr/lib/systemd/systemd ro console=ttyS0,115200n81 selinux=0 $DEBUGFAIL" || return 1
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering cryptsetup luksOpen ${LOOPDEV}p2 varcrypt <$TESTDIR/keyfile
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering mount /dev/mapper/varcrypt $TESTDIR/root/var
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering cp -a $TESTDIR/root/var/log/journal $TESTDIR
b1d4f8e154bf61b5de1b27461ef8e9c8c5e838a1Lennart Poettering cryptsetup luksClose /dev/mapper/varcrypt
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering test -s $TESTDIR/failed && ret=$(($ret+1))
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering # Create the blank file to use as a root filesystem
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering dd if=/dev/null of=$TESTDIR/rootdisk.img bs=1M seek=200
7410616cd9dbbec97cf98d75324da5cda2b2f7a2Lennart Poettering LOOPDEV=$(losetup --show -P -f $TESTDIR/rootdisk.img)
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering [ -b $LOOPDEV ] || return 1
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering sfdisk -C 6400 -H 2 -S 32 -L $LOOPDEV <<EOF
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering cryptsetup -q luksFormat ${LOOPDEV}p2 $TESTDIR/keyfile
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering cryptsetup luksOpen ${LOOPDEV}p2 varcrypt <$TESTDIR/keyfile
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering mount /dev/mapper/varcrypt $TESTDIR/root/var
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering # Create what will eventually be our root filesystem onto an overlay
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering (cd ../..; make DESTDIR=$initdir install)
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering rm -fr $initdir/usr/share/{man,doc,gtk-doc}
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering for i in $initdir/{sbin,bin}/* $initdir/lib/systemd/*; do
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poettering echo systemd-testsuite > $initdir/etc/hostname
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poettering eval $(udevadm info --export --query=env --name=/dev/mapper/varcrypt)
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poettering$DM_NAME UUID=$ID_FS_UUID /etc/varkey
696fd1ef4f2f8574e349332a16987c6772641eddLennart PoetteringLABEL=systemd / ext3 rw 0 1
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poettering/dev/mapper/varcrypt /var ext3 defaults 0 1
696fd1ef4f2f8574e349332a16987c6772641eddLennart Poettering cat >$initdir/etc/systemd/system/testsuite.target <<EOF
696fd1ef4f2f8574e349332a16987c6772641eddLennart PoetteringDescription=Testsuite target
696fd1ef4f2f8574e349332a16987c6772641eddLennart PoetteringRequires=multi-user.target
115cbf7e209a86cf5317fa12d44566247b4af332Evgeny VereshchaginAfter=multi-user.target
115cbf7e209a86cf5317fa12d44566247b4af332Evgeny VereshchaginConflicts=rescue.target
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart PoetteringAllowIsolate=yes
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering cat >$initdir/etc/systemd/system/testsuite.service <<EOF
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart PoetteringDescription=Testsuite service
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart PoetteringAfter=multi-user.target
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart PoetteringExecStart=/bin/bash -c 'set -x; systemctl --failed --no-legend --no-pager > /failed ; echo OK > /testok; while : ;do systemd-cat echo "testsuite service waiting for /var/log/journal" ; echo "testsuite service waiting for journal to move to /var/log/journal" > /dev/console ; for i in /var/log/journal/*;do [ -d "\$i" ] && echo "\$i" && break 2; done; sleep 1; done; sleep 1; exit 0;'
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart PoetteringExecStopPost=/usr/bin/systemctl poweroff --no-block
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart Poettering mkdir -p $initdir/etc/systemd/system/testsuite.target.wants
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering ln -fs ../testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering ln -fs testsuite.target $initdir/etc/systemd/system/default.target
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering dracut_install sh bash setsid loadkeys setfont \
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering login sushell sulogin gzip sleep echo mount umount cryptsetup
7de80bfe2e61d5818601ccfddbadad3b7703ed70Karel Zak type -P dmeventd >/dev/null && dracut_install dmeventd
6569cae18ed640a4e9f52f73e2a3ec54b07d0406Lennart Poettering inst_libdir_file "libdevmapper-event.so*"
3ef63c317481c2b3f1fe39e1b0f130aac3544522Lennart Poettering inst_rules 10-dm.rules 13-dm-disk.rules 95-dm-notify.rules
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart Poettering | while read file; do
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart Poettering inst /usr/lib/systemd/system/dbus.service
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart Poettering /usr/lib/kbd/keymaps/i386/qwerty/us.*; do
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart Poettering [[ -f $i ]] || continue
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart Poettering for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart Poettering [ -f ${_terminfodir}/l/linux ] && break
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart Poettering dracut_install -o ${_terminfodir}/l/linux
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart Poettering ln -fs /proc/self/mounts $initdir/etc/mtab
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart Poettering # install any Exec's from the service files
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart Poettering egrep -ho '^Exec[^ ]*=[^ ]+' $initdir/lib/systemd/system/*.service \
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart Poettering | while read i; do
067d851d30386c553e3a84f59d81d003ff638b91Daniel Wallace # install plymouth, if found... else remove plymouth service files
067d851d30386c553e3a84f59d81d003ff638b91Daniel Wallace # if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then
7de80bfe2e61d5818601ccfddbadad3b7703ed70Karel Zak # PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$TEST_BASE_DIR/test-functions" \
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering # /usr/libexec/plymouth/plymouth-populate-initrd -t $initdir
19f6d710772305610b928bc2678b9d77fe11e770Lennart Poettering rm -f $initdir/{usr/lib,etc}/systemd/system/plymouth* $initdir/{usr/lib,etc}/systemd/system/*/plymouth*
3ef63c317481c2b3f1fe39e1b0f130aac3544522Lennart Poettering [[ $DEBUGTOOLS ]] && dracut_install $DEBUGTOOLS
6569cae18ed640a4e9f52f73e2a3ec54b07d0406Lennart Poettering find "$initdir" -perm +111 -type f | xargs strip --strip-unneeded | ddebug
3ef63c317481c2b3f1fe39e1b0f130aac3544522Lennart Poettering inst /lib/modules/$KERNEL_VER/modules.builtin
41f9172f427bdbb8221c64029f78364b8dd4e527Lennart Poettering if [[ -d $initdir/lib/modules/$KERNEL_VER ]] && \
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart Poettering ! depmod -a -b "$initdir" $KERNEL_VER; then
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart Poettering dfatal "\"depmod -a $KERNEL_VER\" failed."
15411c0cb1192799b37ec8f25d6f30e8d7292fc6David Herrmann ddebug "cp -ar $TESTDIR/root $TESTDIR/nspawn-root"
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart Poettering cp -ar $TESTDIR/root $TESTDIR/nspawn-root
2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2Lennart Poettering cryptsetup luksClose /dev/mapper/varcrypt