]> git.ipfire.org Git - thirdparty/dracut.git/blame - test/TEST-40-NBD/test.sh
fix(zfcp_rules): correct shellcheck regression when parsing ccw args
[thirdparty/dracut.git] / test / TEST-40-NBD / test.sh
CommitLineData
9ecbe2e4 1#!/bin/bash
967cc19a 2
77854c6d 3# shellcheck disable=SC2034
77906443 4TEST_DESCRIPTION="root filesystem on NBD with $USE_NETWORK"
9ecbe2e4 5
9ecbe2e4 6# Uncomment this to debug failures
8b2afb08 7# DEBUGFAIL="rd.debug systemd.log_target=console loglevel=7"
66a3d405 8#DEBUGFAIL="rd.shell rd.break rd.debug systemd.log_target=console loglevel=7 systemd.log_level=debug"
b0d6254d 9#SERIAL="tcp:127.0.0.1:9999"
9ecbe2e4 10
d63a4e28 11test_check() {
8b2afb08 12 if ! type -p nbd-server &> /dev/null; then
eb8856a5
HH
13 echo "Test needs nbd-server... Skipping"
14 return 1
15 fi
16
77854c6d 17 if ! modinfo -k "$KVERSION" nbd &> /dev/null; then
eb8856a5
HH
18 echo "Kernel module nbd does not exist"
19 return 1
20 fi
21
22 return 0
d63a4e28
HH
23}
24
9ecbe2e4
DD
25run_server() {
26 # Start server first
b2c5f5dc 27 echo "NBD TEST SETUP: Starting DHCP/NBD server"
9ecbe2e4 28
b80ee080
HH
29 declare -a disk_args=()
30 # shellcheck disable=SC2034
31 declare -i disk_index=0
32 qemu_add_drive_args disk_index disk_args "$TESTDIR"/unencrypted.img unencrypted
33 qemu_add_drive_args disk_index disk_args "$TESTDIR"/encrypted.img encrypted
34 qemu_add_drive_args disk_index disk_args "$TESTDIR"/server.img serverroot
35
77854c6d 36 "$testdir"/run-qemu \
b80ee080
HH
37 "${disk_args[@]}" \
38 -serial "${SERIAL:-"file:$TESTDIR/server.log"}" \
83691c41
HH
39 -net nic,macaddr=52:54:00:12:34:56,model=e1000 \
40 -net socket,listen=127.0.0.1:12340 \
006890a2 41 -append "panic=1 oops=panic softlockup_panic=1 rd.luks=0 systemd.crash_reboot quiet root=/dev/disk/by-id/ata-disk_serverroot rootfstype=ext4 rw console=ttyS0,115200n81 selinux=0 $SERVER_DEBUG" \
b80ee080
HH
42 -initrd "$TESTDIR"/initramfs.server \
43 -pidfile "$TESTDIR"/server.pid -daemonize || return 1
77854c6d 44 chmod 644 "$TESTDIR"/server.pid || return 1
9ecbe2e4
DD
45
46 # Cleanup the terminal if we have one
47 tty -s && stty sane
48
3aae122c
HH
49 if ! [[ $SERIAL ]]; then
50 echo "Waiting for the server to startup"
9a52c3fd 51 while :; do
3aae122c 52 grep Serving "$TESTDIR"/server.log && break
0f62da04 53 tail "$TESTDIR"/server.log
3aae122c
HH
54 sleep 1
55 done
56 else
57 echo Sleeping 10 seconds to give the server a head start
58 sleep 10
59 fi
9ecbe2e4
DD
60}
61
62client_test() {
63 local test_name="$1"
64 local mac=$2
65 local cmdline="$3"
a29f15a5
DD
66 local fstype=$4
67 local fsopt=$5
68 local found opts nbdinfo
69
006890a2 70 [[ $fstype ]] || fstype=ext4
75e8f476 71 [[ $fsopt ]] || fsopt="ro"
9ecbe2e4
DD
72
73 echo "CLIENT TEST START: $test_name"
74
b80ee080
HH
75 declare -a disk_args=()
76 declare -i disk_index=0
77 qemu_add_drive_args disk_index disk_args "$TESTDIR"/marker.img marker
83691c41 78
f1346763 79 test_marker_reset
77854c6d 80 "$testdir"/run-qemu \
b80ee080 81 "${disk_args[@]}" \
77854c6d 82 -net nic,macaddr="$mac",model=e1000 \
83691c41 83 -net socket,connect=127.0.0.1:12340 \
b2cf61d9 84 -append "panic=1 oops=panic softlockup_panic=1 systemd.crash_reboot rd.shell=0 $cmdline $DEBUGFAIL rd.auto rd.info rd.retry=10 ro console=ttyS0,115200n81 selinux=0 " \
77854c6d 85 -initrd "$TESTDIR"/initramfs.testing
9ecbe2e4 86
77854c6d 87 # shellcheck disable=SC2181
f1346763 88 if [[ $? -ne 0 ]] || ! test_marker_check nbd-OK "$TESTDIR"/marker.img; then
83691c41
HH
89 echo "CLIENT TEST END: $test_name [FAILED - BAD EXIT]"
90 return 1
9ecbe2e4
DD
91 fi
92
a29f15a5 93 # nbdinfo=( fstype fsoptions )
b80ee080 94 read -r -a nbdinfo < <(awk '{print $2, $3; exit}' "$TESTDIR"/marker.img)
a29f15a5 95
75d758e8 96 if [[ ${nbdinfo[0]} != "$fstype" ]]; then
83691c41
HH
97 echo "CLIENT TEST END: $test_name [FAILED - WRONG FS TYPE] \"${nbdinfo[0]}\" != \"$fstype\""
98 return 1
a29f15a5
DD
99 fi
100
101 opts=${nbdinfo[1]},
102 while [[ $opts ]]; do
77854c6d 103 if [[ ${opts%%,*} == "$fsopt" ]]; then
83691c41
HH
104 found=1
105 break
106 fi
107 opts=${opts#*,}
a29f15a5
DD
108 done
109
110 if [[ ! $found ]]; then
83691c41
HH
111 echo "CLIENT TEST END: $test_name [FAILED - BAD FS OPTS] \"${nbdinfo[1]}\" != \"$fsopt\""
112 return 1
a29f15a5
DD
113 fi
114
9ecbe2e4
DD
115 echo "CLIENT TEST END: $test_name [OK]"
116}
117
118test_run() {
119 if ! run_server; then
83691c41
HH
120 echo "Failed to start server" 1>&2
121 return 1
9ecbe2e4 122 fi
57aa1e91
HH
123 client_run
124 kill_server
97add1b3
HH
125}
126
127client_run() {
006890a2 128 # The default is ext4,errors=continue so use that to determine
a29f15a5 129 # if our options were parsed and used
b070c1d3 130 client_test "NBD root=nbd:IP:port" 52:54:00:12:34:00 \
9a52c3fd 131 "root=nbd:192.168.50.1:raw rd.luks=0" || return 1
b070c1d3 132
83691c41 133 client_test "NBD root=nbd:IP:port::fsopts" 52:54:00:12:34:00 \
9a52c3fd 134 "root=nbd:192.168.50.1:raw::errors=panic rd.luks=0" \
006890a2 135 ext4 errors=panic || return 1
83691c41 136
bcf94bba 137 client_test "NBD root=nbd:IP:port:fstype" 52:54:00:12:34:00 \
006890a2 138 "root=nbd:192.168.50.1:raw:ext4 rd.luks=0" ext4 || return 1
a29f15a5 139
bcf94bba 140 client_test "NBD root=nbd:IP:port:fstype:fsopts" 52:54:00:12:34:00 \
006890a2
HG
141 "root=nbd:192.168.50.1:raw:ext4:errors=panic rd.luks=0" \
142 ext4 errors=panic || return 1
beb097d9 143
a29f15a5
DD
144 # DHCP root-path parsing
145
77906443
HH
146 client_test "NBD root=/dev/root netroot=dhcp DHCP root-path nbd:srv:port" 52:54:00:12:34:01 \
147 "root=/dev/root netroot=dhcp ip=dhcp rd.luks=0" || return 1
a29f15a5 148
77906443
HH
149 client_test "NBD root=/dev/root netroot=dhcp DHCP root-path nbd:srv:port:fstype" \
150 52:54:00:12:34:02 "root=/dev/root netroot=dhcp ip=dhcp rd.luks=0" ext2 || return 1
beb097d9 151
77906443 152 client_test "NBD root=/dev/root netroot=dhcp DHCP root-path nbd:srv:port::fsopts" \
006890a2 153 52:54:00:12:34:03 "root=/dev/root netroot=dhcp ip=dhcp rd.luks=0" ext4 errors=panic || return 1
a29f15a5 154
77906443
HH
155 client_test "NBD root=/dev/root netroot=dhcp DHCP root-path nbd:srv:port:fstype:fsopts" \
156 52:54:00:12:34:04 "root=/dev/root netroot=dhcp ip=dhcp rd.luks=0" ext2 errors=panic || return 1
aec48753
DD
157
158 # netroot handling
159
0f62da04 160 client_test "NBD netroot=nbd:IP:port" 52:54:00:12:34:00 \
77906443 161 "root=LABEL=dracut netroot=nbd:192.168.50.1:raw ip=dhcp rd.luks=0" || return 1
0f62da04 162
77906443
HH
163 client_test "NBD root=/dev/root netroot=dhcp DHCP root-path nbd:srv:port:fstype:fsopts" \
164 52:54:00:12:34:04 "root=/dev/root netroot=dhcp ip=dhcp rd.luks=0" ext2 errors=panic || return 1
8bd5873f
DD
165
166 # Encrypted root handling via LVM/LUKS over NBD
167
77854c6d
HH
168 # shellcheck disable=SC1090
169 . "$TESTDIR"/luks.uuid
0f62da04
HH
170
171 client_test "NBD root=LABEL=dracut netroot=nbd:IP:port" \
9a52c3fd 172 52:54:00:12:34:00 \
77906443 173 "root=LABEL=dracut rd.luks.uuid=$ID_FS_UUID rd.lv.vg=dracut ip=dhcp netroot=nbd:192.168.50.1:encrypted" || return 1
8bd5873f 174
006890a2 175 # XXX This should be ext4,errors=panic but that doesn't currently
8bd5873f
DD
176 # XXX work when you have a real root= line in addition to netroot=
177 # XXX How we should work here needs clarification
9a52c3fd
HH
178 # client_test "NBD root=LABEL=dracut netroot=dhcp (w/ fstype and opts)" \
179 # 52:54:00:12:34:05 \
180 # "root=LABEL=dracut rd.luks.uuid=$ID_FS_UUID rd.lv.vg=dracut netroot=dhcp" || return 1
9ca74ffe
HH
181
182 if [[ -s server.pid ]]; then
77854c6d
HH
183 kill -TERM "$(cat "$TESTDIR"/server.pid)"
184 rm -f -- "$TESTDIR"/server.pid
9ca74ffe
HH
185 fi
186
8bd5873f
DD
187}
188
189make_encrypted_root() {
0f62da04 190 rm -fr "$TESTDIR"/overlay
8bd5873f
DD
191 kernel=$KVERSION
192 # Create what will eventually be our root filesystem onto an overlay
193 (
77854c6d 194 # shellcheck disable=SC2030
83691c41 195 export initdir=$TESTDIR/overlay/source
77854c6d 196 # shellcheck disable=SC1090
c0321c90 197 . "$PKGLIBDIR"/dracut-init.sh
28f0b27f 198 mkdir -p "$initdir"
06853123 199 (
77854c6d 200 cd "$initdir" || exit
77906443 201 mkdir -p dev sys proc etc run var/run tmp
06853123 202 )
0f62da04 203
af119460 204 inst_multiple sh df free ls shutdown poweroff stty cat ps ln ip \
b80ee080 205 mount dmesg mkdir cp ping dd sync
96d22bd7 206 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
83691c41
HH
207 [ -f ${_terminfodir}/l/linux ] && break
208 done
af119460 209 inst_multiple -o ${_terminfodir}/l/linux
b80ee080 210
c0321c90
BD
211 inst_simple "${PKGLIBDIR}/modules.d/99base/dracut-lib.sh" "/lib/dracut-lib.sh"
212 inst_simple "${PKGLIBDIR}/modules.d/99base/dracut-dev-lib.sh" "/lib/dracut-dev-lib.sh"
213 inst_binary "${PKGLIBDIR}/dracut-util" "/usr/bin/dracut-util"
b80ee080
HH
214 ln -s dracut-util "${initdir}/usr/bin/dracut-getarg"
215 ln -s dracut-util "${initdir}/usr/bin/dracut-getargs"
216
83691c41 217 inst ./client-init.sh /sbin/init
021b2fdd 218 inst_simple /etc/os-release
9a52c3fd 219 find_binary plymouth > /dev/null && inst_multiple plymouth
77854c6d 220 cp -a /etc/ld.so.conf* "$initdir"/etc
4bd0ab61 221 ldconfig -r "$initdir"
8bd5873f
DD
222 )
223
224 # second, install the files needed to make the root filesystem
225 (
77854c6d
HH
226 # shellcheck disable=SC2030
227 # shellcheck disable=SC2031
83691c41 228 export initdir=$TESTDIR/overlay
77854c6d 229 # shellcheck disable=SC1090
c0321c90 230 . "$PKGLIBDIR"/dracut-init.sh
06853123 231 (
77854c6d 232 cd "$initdir" || exit
8b2afb08 233 mkdir -p dev sys proc etc tmp var run root
2f78bafa 234 ln -s ../run var/run
06853123 235 )
006890a2 236 inst_multiple mkfs.ext4 poweroff cp umount dd sync
4e882b80 237 inst_hook shutdown-emergency 000 ./hard-off.sh
781f1971 238 inst_hook emergency 000 ./hard-off.sh
0f62da04 239 inst_hook initqueue 01 ./create-encrypted-root.sh
356333b3 240 inst_hook initqueue/finished 01 ./finished-false.sh
8bd5873f
DD
241 )
242
243 # create an initramfs that will create the target root filesystem.
244 # We do it this way so that we do not risk trashing the host mdraid
245 # devices, volume groups, encrypted partitions, etc.
f9939d0e 246 "$DRACUT" -l -i "$TESTDIR"/overlay / \
1573bb81 247 -m "dash crypt lvm mdraid kernel-modules qemu" \
006890a2 248 -d "piix ide-gd_mod ata_piix ext4 sd_mod" \
9a52c3fd 249 --no-hostonly-cmdline -N \
77854c6d
HH
250 -f "$TESTDIR"/initramfs.makeroot "$KVERSION" || return 1
251 rm -rf -- "$TESTDIR"/overlay
8bd5873f 252
b80ee080
HH
253 declare -a disk_args=()
254 # shellcheck disable=SC2034
255 declare -i disk_index=0
f1346763
HG
256 qemu_add_drive_args disk_index disk_args "$TESTDIR"/marker.img marker 1
257 qemu_add_drive_args disk_index disk_args "$TESTDIR"/encrypted.img root 120
b80ee080 258
8bd5873f 259 # Invoke KVM and/or QEMU to actually create the target filesystem.
77854c6d 260 "$testdir"/run-qemu \
b80ee080 261 "${disk_args[@]}" \
bb278147 262 -append "root=/dev/fakeroot rw quiet console=ttyS0,115200n81 selinux=0" \
77854c6d 263 -initrd "$TESTDIR"/initramfs.makeroot || return 1
f1346763 264 test_marker_check dracut-root-block-created || return 1
b80ee080 265 grep -F -a -m 1 ID_FS_UUID "$TESTDIR"/marker.img > "$TESTDIR"/luks.uuid
9ecbe2e4
DD
266}
267
268make_client_root() {
0f62da04 269 rm -fr "$TESTDIR"/overlay
9ecbe2e4
DD
270 kernel=$KVERSION
271 (
77854c6d
HH
272 mkdir -p "$TESTDIR"/overlay/source
273 # shellcheck disable=SC2030
274 # shellcheck disable=SC2031
0f62da04 275 export initdir=$TESTDIR/overlay/source
77854c6d 276 # shellcheck disable=SC1090
c0321c90 277 . "$PKGLIBDIR"/dracut-init.sh
28f0b27f 278 mkdir -p "$initdir"
06853123 279 (
77854c6d 280 cd "$initdir" || exit
77906443 281 mkdir -p dev sys proc etc run var/run tmp
06853123 282 )
af119460 283 inst_multiple sh ls shutdown poweroff stty cat ps ln ip \
b80ee080 284 dmesg mkdir cp ping dd mount sync
96d22bd7 285 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
83691c41
HH
286 [ -f ${_terminfodir}/l/linux ] && break
287 done
af119460 288 inst_multiple -o ${_terminfodir}/l/linux
b80ee080 289
c0321c90
BD
290 inst_simple "${PKGLIBDIR}/modules.d/99base/dracut-lib.sh" "/lib/dracut-lib.sh"
291 inst_simple "${PKGLIBDIR}/modules.d/99base/dracut-dev-lib.sh" "/lib/dracut-dev-lib.sh"
292 inst_binary "${PKGLIBDIR}/dracut-util" "/usr/bin/dracut-util"
b80ee080
HH
293 ln -s dracut-util "${initdir}/usr/bin/dracut-getarg"
294 ln -s dracut-util "${initdir}/usr/bin/dracut-getargs"
295
83691c41 296 inst ./client-init.sh /sbin/init
021b2fdd 297 inst_simple /etc/os-release
8b2afb08 298 inst_multiple -o {,/usr}/etc/nsswitch.conf
83691c41
HH
299 inst /etc/passwd /etc/passwd
300 inst /etc/group /etc/group
9a52c3fd 301 for i in /usr/lib*/libnss_files* /lib*/libnss_files*; do
28f0b27f 302 [ -e "$i" ] || continue
77854c6d 303 inst "$i"
83691c41 304 done
77854c6d 305 cp -a /etc/ld.so.conf* "$initdir"/etc
4bd0ab61 306 ldconfig -r "$initdir"
9ecbe2e4
DD
307 )
308
0f62da04
HH
309 # second, install the files needed to make the root filesystem
310 (
77854c6d
HH
311 # shellcheck disable=SC2030
312 # shellcheck disable=SC2031
0f62da04 313 export initdir=$TESTDIR/overlay
77854c6d 314 # shellcheck disable=SC1090
c0321c90 315 . "$PKGLIBDIR"/dracut-init.sh
006890a2 316 inst_multiple sfdisk mkfs.ext4 poweroff cp umount sync dd
0f62da04
HH
317 inst_hook initqueue 01 ./create-client-root.sh
318 inst_hook initqueue/finished 01 ./finished-false.sh
0f62da04
HH
319 )
320
321 # create an initramfs that will create the target root filesystem.
322 # We do it this way so that we do not risk trashing the host mdraid
323 # devices, volume groups, encrypted partitions, etc.
f9939d0e 324 "$DRACUT" -l -i "$TESTDIR"/overlay / \
1573bb81 325 -m "dash rootfs-block kernel-modules qemu" \
006890a2 326 -d "piix ide-gd_mod ata_piix ext4 sd_mod" \
9a52c3fd
HH
327 --nomdadmconf \
328 --no-hostonly-cmdline -N \
77854c6d 329 -f "$TESTDIR"/initramfs.makeroot "$KVERSION" || return 1
0f62da04 330
b80ee080
HH
331 declare -a disk_args=()
332 # shellcheck disable=SC2034
333 declare -i disk_index=0
f1346763
HG
334 qemu_add_drive_args disk_index disk_args "$TESTDIR"/marker.img marker 1
335 qemu_add_drive_args disk_index disk_args "$TESTDIR"/unencrypted.img root 120
b80ee080 336
0f62da04 337 # Invoke KVM and/or QEMU to actually create the target filesystem.
77854c6d 338 "$testdir"/run-qemu \
b80ee080 339 "${disk_args[@]}" \
006890a2 340 -append "root=/dev/dracut/root rw rootfstype=ext4 quiet console=ttyS0,115200n81 selinux=0" \
77854c6d 341 -initrd "$TESTDIR"/initramfs.makeroot || return 1
f1346763 342 test_marker_check dracut-root-block-created || return 1
0f62da04 343 rm -fr "$TESTDIR"/overlay
9ecbe2e4
DD
344}
345
346make_server_root() {
77854c6d 347 rm -fr "$TESTDIR"/overlay
909961d0 348 # shellcheck disable=SC2031
77906443 349 export kernel=$KVERSION
9ecbe2e4 350 (
77854c6d
HH
351 mkdir -p "$TESTDIR"/overlay/source
352 # shellcheck disable=SC2030
353 # shellcheck disable=SC2031
0f62da04 354 export initdir=$TESTDIR/overlay/source
77854c6d 355 # shellcheck disable=SC1090
c0321c90 356 . "$PKGLIBDIR"/dracut-init.sh
28f0b27f 357 mkdir -p "$initdir"
83691c41 358 (
77854c6d 359 cd "$initdir" || exit
d63a4e28 360 mkdir -p run dev sys proc etc var var/lib/dhcpd tmp etc/nbd-server
2f78bafa 361 ln -s ../run var/run
83691c41 362 )
9a52c3fd 363 cat > "$initdir/etc/nbd-server/config" << EOF
b070c1d3
HH
364[generic]
365[raw]
b80ee080 366exportname = /dev/disk/by-id/ata-disk_unencrypted
b070c1d3 367port = 2000
eb8856a5 368bs = 4096
b070c1d3 369[encrypted]
b80ee080 370exportname = /dev/disk/by-id/ata-disk_encrypted
b070c1d3 371port = 2001
eb8856a5 372bs = 4096
b070c1d3 373EOF
af119460 374 inst_multiple sh ls shutdown poweroff stty cat ps ln ip \
9a52c3fd 375 dmesg mkdir cp ping grep \
8b2afb08 376 sleep nbd-server chmod modprobe vi pidof
96d22bd7 377 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
83691c41
HH
378 [ -f ${_terminfodir}/l/linux ] && break
379 done
af119460 380 inst_multiple -o ${_terminfodir}/l/linux
8b2afb08 381 instmods nfsd sunrpc ipv6 lockd af_packet 8021q ipvlan macvlan
9a52c3fd 382 type -P dhcpd > /dev/null && inst_multiple dhcpd
83691c41 383 inst ./server-init.sh /sbin/init
021b2fdd 384 inst_simple /etc/os-release
83691c41
HH
385 inst ./hosts /etc/hosts
386 inst ./dhcpd.conf /etc/dhcpd.conf
8b2afb08 387 inst_multiple -o {,/usr}/etc/nsswitch.conf
83691c41
HH
388 inst /etc/passwd /etc/passwd
389 inst /etc/group /etc/group
8b2afb08
HH
390 _nsslibs=$(
391 cat "$dracutsysrootdir"/{,usr/}etc/nsswitch.conf 2> /dev/null \
392 | sed -e '/^#/d' -e 's/^.*://' -e 's/\[NOTFOUND=return\]//' \
393 | tr -s '[:space:]' '\n' | sort -u | tr -s '[:space:]' '|'
394 )
395 _nsslibs=${_nsslibs#|}
396 _nsslibs=${_nsslibs%|}
397
398 inst_libdir_file -n "$_nsslibs" 'libnss_*.so*'
9ecbe2e4 399
77854c6d 400 cp -a /etc/ld.so.conf* "$initdir"/etc
4bd0ab61 401 ldconfig -r "$initdir"
8b2afb08 402 dracut_kernel_post
9ecbe2e4
DD
403 )
404
0f62da04
HH
405 # second, install the files needed to make the root filesystem
406 (
77854c6d
HH
407 # shellcheck disable=SC2030
408 # shellcheck disable=SC2031
0f62da04 409 export initdir=$TESTDIR/overlay
77854c6d 410 # shellcheck disable=SC1090
c0321c90 411 . "$PKGLIBDIR"/dracut-init.sh
006890a2 412 inst_multiple sfdisk mkfs.ext4 poweroff cp umount sync dd sync
0f62da04
HH
413 inst_hook initqueue 01 ./create-server-root.sh
414 inst_hook initqueue/finished 01 ./finished-false.sh
0f62da04
HH
415 )
416
417 # create an initramfs that will create the target root filesystem.
418 # We do it this way so that we do not risk trashing the host mdraid
419 # devices, volume groups, encrypted partitions, etc.
f9939d0e 420 "$DRACUT" -l -i "$TESTDIR"/overlay / \
1573bb81 421 -m "dash rootfs-block kernel-modules qemu" \
006890a2 422 -d "piix ide-gd_mod ata_piix ext4 sd_mod" \
9a52c3fd
HH
423 --nomdadmconf \
424 --no-hostonly-cmdline -N \
77854c6d 425 -f "$TESTDIR"/initramfs.makeroot "$KVERSION" || return 1
0f62da04 426
b80ee080
HH
427 declare -a disk_args=()
428 # shellcheck disable=SC2034
429 declare -i disk_index=0
f1346763
HG
430 qemu_add_drive_args disk_index disk_args "$TESTDIR"/marker.img marker 1
431 qemu_add_drive_args disk_index disk_args "$TESTDIR"/server.img root 120
b80ee080 432
0f62da04 433 # Invoke KVM and/or QEMU to actually create the target filesystem.
77854c6d 434 "$testdir"/run-qemu \
b80ee080 435 "${disk_args[@]}" \
006890a2 436 -append "root=/dev/dracut/root rw rootfstype=ext4 quiet console=ttyS0,115200n81 selinux=0" \
77854c6d 437 -initrd "$TESTDIR"/initramfs.makeroot || return 1
f1346763 438 test_marker_check dracut-root-block-created || return 1
0f62da04 439 rm -fr "$TESTDIR"/overlay
9ecbe2e4
DD
440}
441
442test_setup() {
8bd5873f 443 make_encrypted_root || return 1
9ecbe2e4
DD
444 make_client_root || return 1
445 make_server_root || return 1
446
77854c6d 447 rm -fr "$TESTDIR"/overlay
9ecbe2e4
DD
448 # Make the test image
449 (
77854c6d 450 # shellcheck disable=SC2031
8b2afb08 451 # shellcheck disable=SC2030
83691c41 452 export initdir=$TESTDIR/overlay
77854c6d 453 # shellcheck disable=SC1090
c0321c90 454 . "$PKGLIBDIR"/dracut-init.sh
9ca53063 455 inst_multiple poweroff shutdown dd
4e882b80 456 inst_hook shutdown-emergency 000 ./hard-off.sh
3f7e5358 457 inst ./cryptroot-ask.sh /sbin/cryptroot-ask
83691c41 458
d63a4e28
HH
459 # inst ./debug-shell.service /lib/systemd/system/debug-shell.service
460 # mkdir -p "${initdir}/lib/systemd/system/sysinit.target.wants"
461 # ln -fs ../debug-shell.service "${initdir}/lib/systemd/system/sysinit.target.wants/debug-shell.service"
83691c41 462
77854c6d
HH
463 # shellcheck disable=SC1090
464 . "$TESTDIR"/luks.uuid
465 mkdir -p "$initdir"/etc
466 echo "luks-$ID_FS_UUID /dev/nbd0 /etc/key" > "$initdir"/etc/crypttab
467 echo -n test > "$initdir"/etc/key
8b2afb08 468 inst_simple ./client.link /etc/systemd/network/01-client.link
9ecbe2e4
DD
469 )
470
f9939d0e 471 "$DRACUT" -l -i "$TESTDIR"/overlay / \
1586621b 472 -o "plymouth iscsi nfs" \
77906443 473 -a "debug watchdog ${USE_NETWORK}" \
9a52c3fd 474 --no-hostonly-cmdline -N \
77854c6d 475 -f "$TESTDIR"/initramfs.testing "$KVERSION" || return 1
8b2afb08
HH
476
477 (
478 # shellcheck disable=SC2031
479 export initdir="$TESTDIR"/overlay
480 # shellcheck disable=SC1090
c0321c90 481 . "$PKGLIBDIR"/dracut-init.sh
8b2afb08
HH
482 rm "$initdir"/etc/systemd/network/01-client.link
483 inst_simple ./server.link /etc/systemd/network/01-server.link
484 inst_hook pre-mount 99 ./wait-if-server.sh
485 )
f9939d0e 486 "$DRACUT" -l -i "$TESTDIR"/overlay / \
1573bb81 487 -a "rootfs-block debug kernel-modules network network-legacy" \
006890a2 488 -d "af_packet piix ide-gd_mod ata_piix ext4 sd_mod e1000 drbg" \
8b2afb08
HH
489 --no-hostonly-cmdline -N \
490 -f "$TESTDIR"/initramfs.server "$KVERSION" || return 1
491
492 rm -rf -- "$TESTDIR"/overlay
9ecbe2e4
DD
493}
494
97add1b3 495kill_server() {
0be1785a 496 if [[ -s $TESTDIR/server.pid ]]; then
77854c6d
HH
497 kill -TERM "$(cat "$TESTDIR"/server.pid)"
498 rm -f -- "$TESTDIR"/server.pid
9ecbe2e4 499 fi
97add1b3
HH
500}
501
502test_cleanup() {
503 kill_server
9ecbe2e4
DD
504}
505
77854c6d
HH
506# shellcheck disable=SC1090
507. "$testdir"/test-functions