]>
Commit | Line | Data |
---|---|---|
898720b7 HH |
1 | #!/bin/bash |
2 | # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- | |
3 | # ex: ts=8 sw=4 sts=4 et filetype=sh | |
4 | TEST_DESCRIPTION="Basic systemd setup" | |
5 | ||
6 | KVERSION=${KVERSION-$(uname -r)} | |
0d6e798a | 7 | KERNEL_VER=$(uname -r) |
898720b7 HH |
8 | |
9 | # Uncomment this to debug failures | |
10 | #DEBUGFAIL="systemd.unit=multi-user.target" | |
f7c05f7d HH |
11 | DEBUGTOOLS="df free ls stty cat ps ln ip route dmesg dhclient mkdir cp ping dhclient strace less grep id tty touch du sort" |
12 | ||
d9890f4e | 13 | run_qemu() { |
0d6e798a | 14 | # TODO: qemu wrapper script: http://www.spinics.net/lists/kvm/msg72389.html |
898720b7 | 15 | qemu-kvm \ |
7c1856aa | 16 | -hda $TESTDIR/rootdisk.img \ |
0d6e798a HH |
17 | -m 512M -nographic \ |
18 | -net none -kernel /boot/vmlinuz-$KERNEL_VER \ | |
19 | -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 | |
6ea4364c | 20 | |
898720b7 HH |
21 | ret=1 |
22 | mkdir -p $TESTDIR/root | |
23 | mount ${LOOPDEV}p1 $TESTDIR/root | |
24 | [[ -e $TESTDIR/root/testok ]] && ret=0 | |
32d96585 | 25 | cp -a $TESTDIR/root/failed $TESTDIR |
0d6e798a HH |
26 | cryptsetup luksOpen ${LOOPDEV}p2 varcrypt <$TESTDIR/keyfile |
27 | mount /dev/mapper/varcrypt $TESTDIR/root/var | |
28 | cp -a $TESTDIR/root/var/log/journal $TESTDIR | |
29 | umount $TESTDIR/root/var | |
898720b7 | 30 | umount $TESTDIR/root |
0d6e798a | 31 | cryptsetup luksClose /dev/mapper/varcrypt |
32d96585 | 32 | cat $TESTDIR/failed |
898720b7 | 33 | ls -l $TESTDIR/journal/*/*.journal |
32d96585 | 34 | test -s $TESTDIR/failed && ret=$(($ret+1)) |
898720b7 HH |
35 | return $ret |
36 | } | |
37 | ||
d9890f4e HH |
38 | |
39 | run_nspawn() { | |
5076f0cc | 40 | systemd-nspawn -b -D $TESTDIR/nspawn-root --capability=CAP_AUDIT_CONTROL,CAP_AUDIT_WRITE /usr/lib/systemd/systemd |
d9890f4e HH |
41 | ret=1 |
42 | [[ -e $TESTDIR/nspawn-root/testok ]] && ret=0 | |
43 | cp -a $TESTDIR/nspawn-root/var/log/journal $TESTDIR | |
44 | cp -a $TESTDIR/nspawn-root/failed $TESTDIR | |
45 | cat $TESTDIR/failed | |
46 | ls -l $TESTDIR/journal/*/*.journal | |
47 | test -s $TESTDIR/failed && ret=$(($ret+1)) | |
48 | return $ret | |
49 | } | |
50 | ||
51 | ||
52 | test_run() { | |
0d6e798a HH |
53 | if check_qemu ; then |
54 | run_qemu || return 1 | |
55 | else | |
56 | dwarn "can't run qemu-kvm, skipping" | |
57 | fi | |
58 | if check_nspawn; then | |
5fa594df | 59 | run_nspawn || return 1 |
0d6e798a HH |
60 | else |
61 | dwarn "can't run systemd-nspawn, skipping" | |
7b17d413 | 62 | fi |
d9890f4e HH |
63 | return 0 |
64 | } | |
65 | ||
898720b7 HH |
66 | test_setup() { |
67 | rm -f $TESTDIR/rootdisk.img | |
68 | # Create the blank file to use as a root filesystem | |
0d6e798a | 69 | dd if=/dev/null of=$TESTDIR/rootdisk.img bs=1M seek=200 |
898720b7 HH |
70 | LOOPDEV=$(losetup --show -P -f $TESTDIR/rootdisk.img) |
71 | [ -b $LOOPDEV ] || return 1 | |
72 | echo "LOOPDEV=$LOOPDEV" >> $STATEFILE | |
0d6e798a HH |
73 | sfdisk -C 6400 -H 2 -S 32 -L $LOOPDEV <<EOF |
74 | ,3200 | |
898720b7 HH |
75 | , |
76 | EOF | |
77 | ||
78 | mkfs.ext3 -L systemd ${LOOPDEV}p1 | |
0d6e798a HH |
79 | echo -n test >$TESTDIR/keyfile |
80 | cryptsetup -q luksFormat ${LOOPDEV}p2 $TESTDIR/keyfile | |
81 | cryptsetup luksOpen ${LOOPDEV}p2 varcrypt <$TESTDIR/keyfile | |
82 | mkfs.ext3 -L var /dev/mapper/varcrypt | |
898720b7 HH |
83 | mkdir -p $TESTDIR/root |
84 | mount ${LOOPDEV}p1 $TESTDIR/root | |
85 | mkdir -p $TESTDIR/root/run | |
0d6e798a HH |
86 | mkdir -p $TESTDIR/root/var |
87 | mount /dev/mapper/varcrypt $TESTDIR/root/var | |
898720b7 | 88 | |
898720b7 HH |
89 | # Create what will eventually be our root filesystem onto an overlay |
90 | ( | |
91 | LOG_LEVEL=5 | |
7c1856aa | 92 | initdir=$TESTDIR/root |
898720b7 HH |
93 | |
94 | # create the basic filesystem layout | |
95 | setup_basic_dirs | |
96 | ||
97 | # install compiled files | |
98 | (cd ../..; make DESTDIR=$initdir install) | |
99 | ||
0d6e798a HH |
100 | # remove unneeded documentation |
101 | rm -fr $initdir/usr/share/{man,doc,gtk-doc} | |
102 | ||
898720b7 | 103 | # install possible missing libraries |
6b197f2a | 104 | for i in $initdir/{sbin,bin}/* $initdir/lib/systemd/*; do |
898720b7 HH |
105 | inst_libs $i |
106 | done | |
107 | ||
108 | # activate kmsg import | |
6b197f2a | 109 | echo 'ImportKernel=yes' >> $initdir/etc/systemd/journald.conf |
898720b7 HH |
110 | |
111 | # make a journal directory | |
6b197f2a | 112 | mkdir -p $initdir/var/log/journal |
898720b7 HH |
113 | |
114 | # install some basic config files | |
6b197f2a HH |
115 | inst /etc/sysconfig/init |
116 | inst /etc/passwd | |
117 | inst /etc/shadow | |
118 | inst /etc/group | |
119 | inst /etc/shells | |
120 | inst /etc/nsswitch.conf | |
121 | inst /etc/pam.conf | |
122 | inst /etc/securetty | |
123 | inst /etc/os-release | |
7c1856aa | 124 | inst /etc/localtime |
898720b7 | 125 | # we want an empty environment |
6b197f2a | 126 | > $initdir/etc/environment |
0d6e798a | 127 | > $initdir/etc/machine-id |
898720b7 HH |
128 | |
129 | # set the hostname | |
6b197f2a | 130 | echo systemd-testsuite > $initdir/etc/hostname |
898720b7 | 131 | |
0d6e798a HH |
132 | eval $(udevadm info --export --query=env --name=/dev/mapper/varcrypt) |
133 | eval $(udevadm info --export --query=env --name=${LOOPDEV}p2) | |
134 | ||
135 | cat >$initdir/etc/crypttab <<EOF | |
136 | $DM_NAME UUID=$ID_FS_UUID /etc/varkey | |
137 | EOF | |
138 | echo -n test > $initdir/etc/varkey | |
139 | cat $initdir/etc/crypttab | ddebug | |
140 | ||
141 | cat >$initdir/etc/fstab <<EOF | |
142 | LABEL=systemd / ext3 rw 0 1 | |
143 | /dev/mapper/varcrypt /var ext3 defaults 0 1 | |
144 | EOF | |
145 | ||
898720b7 | 146 | # setup the testsuite target |
6b197f2a | 147 | cat >$initdir/etc/systemd/system/testsuite.target <<EOF |
898720b7 HH |
148 | [Unit] |
149 | Description=Testsuite target | |
150 | Requires=multi-user.target | |
151 | After=multi-user.target | |
152 | Conflicts=rescue.target | |
153 | AllowIsolate=yes | |
154 | EOF | |
155 | ||
156 | # setup the testsuite service | |
6b197f2a | 157 | cat >$initdir/etc/systemd/system/testsuite.service <<EOF |
898720b7 HH |
158 | [Unit] |
159 | Description=Testsuite service | |
160 | After=multi-user.target | |
161 | ||
162 | [Service] | |
0d6e798a HH |
163 | 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;' |
164 | ExecStopPost=/usr/bin/systemctl poweroff | |
898720b7 | 165 | Type=oneshot |
898720b7 | 166 | EOF |
6b197f2a HH |
167 | mkdir -p $initdir/etc/systemd/system/testsuite.target.wants |
168 | ln -fs ../testsuite.service $initdir/etc/systemd/system/testsuite.target.wants/testsuite.service | |
898720b7 HH |
169 | |
170 | # make the testsuite the default target | |
6b197f2a | 171 | ln -fs testsuite.target $initdir/etc/systemd/system/default.target |
3d3035e8 HH |
172 | mkdir -p $initdir/etc/rc.d |
173 | cat >$initdir/etc/rc.d/rc.local <<EOF | |
174 | #!/bin/bash | |
175 | exit 0 | |
176 | EOF | |
177 | chmod 0755 $initdir/etc/rc.d/rc.local | |
898720b7 HH |
178 | # install basic tools needed |
179 | dracut_install sh bash setsid loadkeys setfont \ | |
0d6e798a HH |
180 | login sushell sulogin gzip sleep echo mount umount cryptsetup |
181 | dracut_install dmsetup modprobe | |
182 | ||
183 | instmods dm_crypt =crypto | |
184 | ||
185 | type -P dmeventd >/dev/null && dracut_install dmeventd | |
186 | ||
187 | inst_libdir_file "libdevmapper-event.so*" | |
188 | ||
189 | inst_rules 10-dm.rules 13-dm-disk.rules 95-dm-notify.rules | |
898720b7 HH |
190 | |
191 | # install libnss_files for login | |
192 | inst_libdir_file "libnss_files*" | |
193 | ||
194 | # install dbus and pam | |
6b197f2a | 195 | find \ |
898720b7 HH |
196 | /etc/dbus-1 \ |
197 | /etc/pam.d \ | |
198 | /etc/security \ | |
199 | /lib64/security \ | |
200 | /lib/security -xtype f \ | |
201 | | while read file; do | |
202 | inst $file | |
203 | done | |
204 | ||
205 | # install dbus socket and service file | |
6b197f2a HH |
206 | inst /usr/lib/systemd/system/dbus.socket |
207 | inst /usr/lib/systemd/system/dbus.service | |
898720b7 HH |
208 | |
209 | # install basic keyboard maps and fonts | |
6b197f2a | 210 | for i in \ |
898720b7 HH |
211 | /usr/lib/kbd/consolefonts/latarcyrheb-sun16* \ |
212 | /usr/lib/kbd/keymaps/include/* \ | |
213 | /usr/lib/kbd/keymaps/i386/include/* \ | |
214 | /usr/lib/kbd/keymaps/i386/qwerty/us.*; do | |
6b197f2a HH |
215 | [[ -f $i ]] || continue |
216 | inst $i | |
217 | done | |
898720b7 HH |
218 | |
219 | # some basic terminfo files | |
6b197f2a | 220 | for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do |
898720b7 | 221 | [ -f ${_terminfodir}/l/linux ] && break |
6b197f2a HH |
222 | done |
223 | dracut_install -o ${_terminfodir}/l/linux | |
898720b7 HH |
224 | |
225 | # softlink mtab | |
6b197f2a | 226 | ln -fs /proc/self/mounts $initdir/etc/mtab |
898720b7 HH |
227 | |
228 | # install any Exec's from the service files | |
229 | egrep -ho '^Exec[^ ]*=[^ ]+' $initdir/lib/systemd/system/*.service \ | |
230 | | while read i; do | |
231 | i=${i##Exec*=}; i=${i##-} | |
232 | inst $i | |
233 | done | |
234 | ||
235 | # install plymouth, if found... else remove plymouth service files | |
0d6e798a HH |
236 | # if [ -x /usr/libexec/plymouth/plymouth-populate-initrd ]; then |
237 | # PLYMOUTH_POPULATE_SOURCE_FUNCTIONS="$TEST_BASE_DIR/test-functions" \ | |
238 | # /usr/libexec/plymouth/plymouth-populate-initrd -t $initdir | |
239 | # dracut_install plymouth plymouthd | |
240 | # else | |
241 | rm -f $initdir/{usr/lib,etc}/systemd/system/plymouth* $initdir/{usr/lib,etc}/systemd/system/*/plymouth* | |
242 | # fi | |
898720b7 HH |
243 | |
244 | # some helper tools for debugging | |
f7c05f7d | 245 | [[ $DEBUGTOOLS ]] && dracut_install $DEBUGTOOLS |
898720b7 HH |
246 | |
247 | # install ld.so.conf* and run ldconfig | |
6b197f2a HH |
248 | cp -a /etc/ld.so.conf* $initdir/etc |
249 | ldconfig -r "$initdir" | |
0d6e798a HH |
250 | ddebug "Strip binaeries" |
251 | find "$initdir" -perm +111 -type f | xargs strip --strip-unneeded | ddebug | |
252 | ||
253 | # copy depmod files | |
254 | inst /lib/modules/$KERNEL_VER/modules.order | |
255 | inst /lib/modules/$KERNEL_VER/modules.builtin | |
256 | # generate module dependencies | |
257 | if [[ -d $initdir/lib/modules/$KERNEL_VER ]] && \ | |
258 | ! depmod -a -b "$initdir" $KERNEL_VER; then | |
259 | dfatal "\"depmod -a $KERNEL_VER\" failed." | |
260 | exit 1 | |
261 | fi | |
898720b7 | 262 | ) |
d9890f4e | 263 | rm -fr $TESTDIR/nspawn-root |
0d6e798a HH |
264 | ddebug "cp -ar $TESTDIR/root $TESTDIR/nspawn-root" |
265 | cp -ar $TESTDIR/root $TESTDIR/nspawn-root | |
266 | # we don't mount in the nspawn root | |
267 | rm -fr $TESTDIR/nspawn-root/etc/fstab | |
268 | ||
269 | ddebug "umount $TESTDIR/root/var" | |
270 | umount $TESTDIR/root/var | |
271 | cryptsetup luksClose /dev/mapper/varcrypt | |
272 | ddebug "umount $TESTDIR/root" | |
d9890f4e | 273 | umount $TESTDIR/root |
898720b7 HH |
274 | } |
275 | ||
276 | test_cleanup() { | |
0d6e798a HH |
277 | umount $TESTDIR/root/var 2>/dev/null |
278 | [[ -b /dev/mapper/varcrypt ]] && cryptsetup luksClose /dev/mapper/varcrypt | |
898720b7 HH |
279 | umount $TESTDIR/root 2>/dev/null |
280 | [[ $LOOPDEV ]] && losetup -d $LOOPDEV | |
281 | return 0 | |
282 | } | |
283 | ||
284 | . $TEST_BASE_DIR/test-functions | |
285 | do_test "$@" |