2012-05-21 20:55:48 +04:00
#!/bin/bash
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
TEST_DESCRIPTION = "Basic systemd setup"
KVERSION = ${ KVERSION - $( uname -r) }
2012-05-25 20:32:55 +04:00
KERNEL_VER = $( uname -r)
2012-05-21 20:55:48 +04:00
# Uncomment this to debug failures
#DEBUGFAIL="systemd.unit=multi-user.target"
2012-05-25 16:54:38 +04:00
DEBUGTOOLS = "df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort"
2012-05-24 17:51:10 +04:00
run_qemu( ) {
2012-05-25 20:32:55 +04:00
# TODO: qemu wrapper script: http://www.spinics.net/lists/kvm/msg72389.html
2012-05-21 20:55:48 +04:00
qemu-kvm \
2012-05-24 17:26:09 +04:00
-hda $TESTDIR /rootdisk.img \
2012-05-25 20:32:55 +04:00
-m 512M -nographic \
-net none -kernel /boot/vmlinuz-$KERNEL_VER \
-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
2012-05-25 16:55:26 +04:00
2012-05-21 20:55:48 +04:00
ret = 1
mkdir -p $TESTDIR /root
mount ${ LOOPDEV } p1 $TESTDIR /root
[ [ -e $TESTDIR /root/testok ] ] && ret = 0
2012-05-24 16:32:48 +04:00
cp -a $TESTDIR /root/failed $TESTDIR
2012-05-25 20:32:55 +04:00
cryptsetup luksOpen ${ LOOPDEV } p2 varcrypt <$TESTDIR /keyfile
mount /dev/mapper/varcrypt $TESTDIR /root/var
cp -a $TESTDIR /root/var/log/journal $TESTDIR
umount $TESTDIR /root/var
2012-05-21 20:55:48 +04:00
umount $TESTDIR /root
2012-05-25 20:32:55 +04:00
cryptsetup luksClose /dev/mapper/varcrypt
2012-05-24 16:32:48 +04:00
cat $TESTDIR /failed
2012-05-21 20:55:48 +04:00
ls -l $TESTDIR /journal/*/*.journal
2012-05-24 16:32:48 +04:00
test -s $TESTDIR /failed && ret = $(( $ret + 1 ))
2012-05-21 20:55:48 +04:00
return $ret
}
2012-05-24 17:51:10 +04:00
run_nspawn( ) {
systemd-nspawn -b -D $TESTDIR /nspawn-root /usr/lib/systemd/systemd
ret = 1
[ [ -e $TESTDIR /nspawn-root/testok ] ] && ret = 0
cp -a $TESTDIR /nspawn-root/var/log/journal $TESTDIR
cp -a $TESTDIR /nspawn-root/failed $TESTDIR
cat $TESTDIR /failed
ls -l $TESTDIR /journal/*/*.journal
test -s $TESTDIR /failed && ret = $(( $ret + 1 ))
return $ret
}
test_run( ) {
2012-05-25 20:32:55 +04:00
if check_qemu ; then
run_qemu || return 1
else
dwarn "can't run qemu-kvm, skipping"
fi
if check_nspawn; then
#run_nspawn || return 1
:
else
dwarn "can't run systemd-nspawn, skipping"
2012-05-24 18:00:33 +04:00
fi
2012-05-24 17:51:10 +04:00
return 0
}
2012-05-21 20:55:48 +04:00
test_setup( ) {
rm -f $TESTDIR /rootdisk.img
# Create the blank file to use as a root filesystem
2012-05-25 20:32:55 +04:00
dd if = /dev/null of = $TESTDIR /rootdisk.img bs = 1M seek = 200
2012-05-21 20:55:48 +04:00
LOOPDEV = $( losetup --show -P -f $TESTDIR /rootdisk.img)
[ -b $LOOPDEV ] || return 1
echo " LOOPDEV= $LOOPDEV " >> $STATEFILE
2012-05-25 20:32:55 +04:00
sfdisk -C 6400 -H 2 -S 32 -L $LOOPDEV <<EOF
,3200
2012-05-21 20:55:48 +04:00
,
EOF
mkfs.ext3 -L systemd ${ LOOPDEV } p1
2012-05-25 20:32:55 +04:00
echo -n test >$TESTDIR /keyfile
cryptsetup -q luksFormat ${ LOOPDEV } p2 $TESTDIR /keyfile
cryptsetup luksOpen ${ LOOPDEV } p2 varcrypt <$TESTDIR /keyfile
mkfs.ext3 -L var /dev/mapper/varcrypt
2012-05-21 20:55:48 +04:00
mkdir -p $TESTDIR /root
mount ${ LOOPDEV } p1 $TESTDIR /root
mkdir -p $TESTDIR /root/run
2012-05-25 20:32:55 +04:00
mkdir -p $TESTDIR /root/var
mount /dev/mapper/varcrypt $TESTDIR /root/var
2012-05-21 20:55:48 +04:00
# Create what will eventually be our root filesystem onto an overlay
(
LOG_LEVEL = 5
2012-05-24 17:26:09 +04:00
initdir = $TESTDIR /root
2012-05-21 20:55:48 +04:00
# create the basic filesystem layout
setup_basic_dirs
# install compiled files
( cd ../..; make DESTDIR = $initdir install)
2012-05-25 20:32:55 +04:00
# remove unneeded documentation
rm -fr $initdir /usr/share/{ man,doc,gtk-doc}
2012-05-21 20:55:48 +04:00
# install possible missing libraries
2012-05-24 17:27:53 +04:00
for i in $initdir /{ sbin,bin} /* $initdir /lib/systemd/*; do
2012-05-21 20:55:48 +04:00
inst_libs $i
done
# activate kmsg import
2012-05-24 17:27:53 +04:00
echo 'ImportKernel=yes' >> $initdir /etc/systemd/journald.conf
2012-05-21 20:55:48 +04:00
# make a journal directory
2012-05-24 17:27:53 +04:00
mkdir -p $initdir /var/log/journal
2012-05-21 20:55:48 +04:00
# install some basic config files
2012-05-24 17:27:53 +04:00
inst /etc/sysconfig/init
inst /etc/passwd
inst /etc/shadow
inst /etc/group
inst /etc/shells
inst /etc/nsswitch.conf
inst /etc/pam.conf
inst /etc/securetty
inst /etc/os-release
2012-05-24 17:26:09 +04:00
inst /etc/localtime
2012-05-21 20:55:48 +04:00
# we want an empty environment
2012-05-24 17:27:53 +04:00
> $initdir /etc/environment
2012-05-25 20:32:55 +04:00
> $initdir /etc/machine-id
2012-05-21 20:55:48 +04:00
# set the hostname
2012-05-24 17:27:53 +04:00
echo systemd-testsuite > $initdir /etc/hostname
2012-05-21 20:55:48 +04:00
2012-05-25 20:32:55 +04:00
eval $( udevadm info --export --query= env --name= /dev/mapper/varcrypt)
eval $( udevadm info --export --query= env --name= ${ LOOPDEV } p2)
cat >$initdir /etc/crypttab <<EOF
$DM_NAME UUID = $ID_FS_UUID /etc/varkey
EOF
echo -n test > $initdir /etc/varkey
cat $initdir /etc/crypttab | ddebug
cat >$initdir /etc/fstab <<EOF
LABEL = systemd / ext3 rw 0 1
/dev/mapper/varcrypt /var ext3 defaults 0 1
EOF
2012-05-21 20:55:48 +04:00
# setup the testsuite target
2012-05-24 17:27:53 +04:00
cat >$initdir /etc/systemd/system/testsuite.target <<EOF
2012-05-21 20:55:48 +04:00
[ Unit]
Description = Testsuite target
Requires = multi-user.target
After = multi-user.target
Conflicts = rescue.target
AllowIsolate = yes
EOF
# setup the testsuite service
2012-05-24 17:27:53 +04:00
cat >$initdir /etc/systemd/system/testsuite.service <<EOF
2012-05-21 20:55:48 +04:00
[ Unit]
Description = Testsuite service
After = multi-user.target
[ Service]
2012-05-25 20:32:55 +04:00
ExecStart = /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;'
ExecStopPost = /usr/bin/systemctl poweroff
2012-05-21 20:55:48 +04:00
Type = oneshot
EOF
2012-05-24 17:27:53 +04:00
mkdir -p $initdir /etc/systemd/system/testsuite.target.wants
ln -fs ../testsuite.service $initdir /etc/systemd/system/testsuite.target.wants/testsuite.service
2012-05-21 20:55:48 +04:00
# make the testsuite the default target
2012-05-24 17:27:53 +04:00
ln -fs testsuite.target $initdir /etc/systemd/system/default.target
2012-05-24 17:27:13 +04:00
mkdir -p $initdir /etc/rc.d
cat >$initdir /etc/rc.d/rc.local <<EOF
#!/bin/bash
exit 0
EOF
chmod 0755 $initdir /etc/rc.d/rc.local
2012-05-21 20:55:48 +04:00
# install basic tools needed
dracut_install sh bash setsid loadkeys setfont \
2012-05-25 20:32:55 +04:00
login sushell sulogin gzip sleep echo mount umount cryptsetup
dracut_install dmsetup modprobe
instmods dm_crypt = crypto
type -P dmeventd >/dev/null && dracut_install dmeventd
inst_libdir_file "libdevmapper-event.so*"
inst_rules 10-dm.rules 13-dm-disk.rules 95-dm-notify.rules
2012-05-21 20:55:48 +04:00
# install libnss_files for login
inst_libdir_file "libnss_files*"
# install dbus and pam
2012-05-24 17:27:53 +04:00
find \
2012-05-21 20:55:48 +04:00
/etc/dbus-1 \
/etc/pam.d \
/etc/security \
/lib64/security \
/lib/security -xtype f \
| while read file; do
inst $file
done
# install dbus socket and service file
2012-05-24 17:27:53 +04:00
inst /usr/lib/systemd/system/dbus.socket
inst /usr/lib/systemd/system/dbus.service
2012-05-21 20:55:48 +04:00
# install basic keyboard maps and fonts
2012-05-24 17:27:53 +04:00
for i in \
2012-05-21 20:55:48 +04:00
/usr/lib/kbd/consolefonts/latarcyrheb-sun16* \
/usr/lib/kbd/keymaps/include/* \
/usr/lib/kbd/keymaps/i386/include/* \
/usr/lib/kbd/keymaps/i386/qwerty/us.*; do
2012-05-24 17:27:53 +04:00
[ [ -f $i ] ] || continue
inst $i
done
2012-05-21 20:55:48 +04:00
# some basic terminfo files
2012-05-24 17:27:53 +04:00
for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
2012-05-21 20:55:48 +04:00
[ -f ${ _terminfodir } /l/linux ] && break
2012-05-24 17:27:53 +04:00
done
dracut_install -o ${ _terminfodir } /l/linux
2012-05-21 20:55:48 +04:00
# softlink mtab
2012-05-24 17:27:53 +04:00
ln -fs /proc/self/mounts $initdir /etc/mtab
2012-05-21 20:55:48 +04:00
# install any Exec's from the service files
egrep -ho '^Exec[^ ]*=[^ ]+' $initdir /lib/systemd/system/*.service \
| while read i; do
i = ${ i ##Exec*= } ; i = ${ i ##- }
inst $i
done
# install plymouth, if found... else remove plymouth service files
2012-05-25 20:32:55 +04:00
# if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then
# PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$TEST_BASE_DIR/test-functions" \
# /usr/libexec/plymouth/plymouth-populate-initrd -t $initdir
# dracut_install plymouth plymouthd
# else
rm -f $initdir /{ usr/lib,etc} /systemd/system/plymouth* $initdir /{ usr/lib,etc} /systemd/system/*/plymouth*
# fi
2012-05-21 20:55:48 +04:00
# some helper tools for debugging
2012-05-25 16:54:38 +04:00
[ [ $DEBUGTOOLS ] ] && dracut_install $DEBUGTOOLS
2012-05-21 20:55:48 +04:00
# install ld.so.conf* and run ldconfig
2012-05-24 17:27:53 +04:00
cp -a /etc/ld.so.conf* $initdir /etc
ldconfig -r " $initdir "
2012-05-25 20:32:55 +04:00
ddebug "Strip binaeries"
find " $initdir " -perm +111 -type f | xargs strip --strip-unneeded | ddebug
# copy depmod files
inst /lib/modules/$KERNEL_VER /modules.order
inst /lib/modules/$KERNEL_VER /modules.builtin
# generate module dependencies
if [ [ -d $initdir /lib/modules/$KERNEL_VER ] ] && \
! depmod -a -b " $initdir " $KERNEL_VER ; then
dfatal " \"depmod -a $KERNEL_VER \" failed. "
exit 1
fi
2012-05-21 20:55:48 +04:00
)
2012-05-24 17:51:10 +04:00
rm -fr $TESTDIR /nspawn-root
2012-05-25 20:32:55 +04:00
ddebug " cp -ar $TESTDIR /root $TESTDIR /nspawn-root "
cp -ar $TESTDIR /root $TESTDIR /nspawn-root
# we don't mount in the nspawn root
rm -fr $TESTDIR /nspawn-root/etc/fstab
ddebug " umount $TESTDIR /root/var "
umount $TESTDIR /root/var
cryptsetup luksClose /dev/mapper/varcrypt
ddebug " umount $TESTDIR /root "
2012-05-24 17:51:10 +04:00
umount $TESTDIR /root
2012-05-21 20:55:48 +04:00
}
test_cleanup( ) {
2012-05-25 20:32:55 +04:00
umount $TESTDIR /root/var 2>/dev/null
[ [ -b /dev/mapper/varcrypt ] ] && cryptsetup luksClose /dev/mapper/varcrypt
2012-05-21 20:55:48 +04:00
umount $TESTDIR /root 2>/dev/null
[ [ $LOOPDEV ] ] && losetup -d $LOOPDEV
return 0
}
. $TEST_BASE_DIR /test-functions
do_test " $@ "