]> git.ipfire.org Git - thirdparty/dracut.git/blame - test/TEST-50-MULTINIC/test.sh
fix(test): use bash for jobs -r parameter
[thirdparty/dracut.git] / test / TEST-50-MULTINIC / test.sh
CommitLineData
a71f1b49 1#!/bin/bash
a3f73298 2
c864f893 3# shellcheck disable=SC2034
a3f73298 4TEST_DESCRIPTION="root filesystem on NFS with multiple nics with $USE_NETWORK"
a71f1b49 5
a71f1b49 6# Uncomment this to debug failures
8b2afb08 7#DEBUGFAIL="loglevel=7 rd.shell rd.break"
67ab4f77 8#SERIAL="tcp:127.0.0.1:9999"
a71f1b49
PS
9
10run_server() {
11 # Start server first
12 echo "MULTINIC TEST SETUP: Starting DHCP/NFS server"
13
b80ee080
HH
14 declare -a disk_args=()
15 # shellcheck disable=SC2034
16 declare -i disk_index=0
17 qemu_add_drive_args disk_index disk_args "$TESTDIR"/server.img root
18
c864f893 19 "$testdir"/run-qemu \
b80ee080 20 "${disk_args[@]}" \
9288d21b
HH
21 -net socket,listen=127.0.0.1:12350 \
22 -net nic,macaddr=52:54:01:12:34:56,model=e1000 \
c864f893 23 -serial "${SERIAL:-"file:$TESTDIR/server.log"}" \
9f6b4e53 24 -device i6300esb -watchdog-action poweroff \
006890a2 25 -append "panic=1 oops=panic softlockup_panic=1 systemd.crash_reboot root=LABEL=dracut rootfstype=ext4 rw console=ttyS0,115200n81 selinux=0" \
9288d21b
HH
26 -initrd "$TESTDIR"/initramfs.server \
27 -pidfile "$TESTDIR"/server.pid -daemonize || return 1
ca8f1c1b 28
4bd0ab61 29 chmod 644 -- "$TESTDIR"/server.pid || return 1
a71f1b49
PS
30
31 # Cleanup the terminal if we have one
32 tty -s && stty sane
33
3aae122c 34 if ! [[ $SERIAL ]]; then
9a52c3fd 35 while :; do
3aae122c 36 grep Serving "$TESTDIR"/server.log && break
a3f73298 37 echo "Waiting for the server to startup"
0f62da04 38 tail "$TESTDIR"/server.log
3aae122c
HH
39 sleep 1
40 done
41 else
42 echo Sleeping 10 seconds to give the server a head start
43 sleep 10
44 fi
a71f1b49
PS
45}
46
47client_test() {
48 local test_name="$1"
49 local mac1="$2"
50 local mac2="$3"
51 local mac3="$4"
52 local cmdline="$5"
53 local check="$6"
54
55 echo "CLIENT TEST START: $test_name"
56
b80ee080
HH
57 declare -a disk_args=()
58 # shellcheck disable=SC2034
59 declare -i disk_index=0
60 qemu_add_drive_args disk_index disk_args "$TESTDIR"/marker.img marker
462d9b92 61 cmdline="$cmdline rd.net.timeout.dhcp=30"
8b2afb08 62
b80ee080 63 # Invoke KVM and/or QEMU to actually create the target filesystem.
f1346763 64 test_marker_reset
b80ee080
HH
65 "$testdir"/run-qemu \
66 "${disk_args[@]}" \
9a52c3fd 67 -net socket,connect=127.0.0.1:12350 \
c864f893
HH
68 -net nic,macaddr=52:54:00:12:34:"$mac1",model=e1000 \
69 -net nic,macaddr=52:54:00:12:34:"$mac2",model=e1000 \
70 -net nic,macaddr=52:54:00:12:34:"$mac3",model=e1000 \
9a52c3fd
HH
71 -netdev hubport,id=n1,hubid=1 \
72 -netdev hubport,id=n2,hubid=2 \
73 -device e1000,netdev=n1,mac=52:54:00:12:34:98 \
74 -device e1000,netdev=n2,mac=52:54:00:12:34:99 \
9f6b4e53 75 -device i6300esb -watchdog-action poweroff \
b2cf61d9 76 -append "quiet panic=1 oops=panic softlockup_panic=1 systemd.crash_reboot rd.shell=0 $cmdline $DEBUGFAIL rd.retry=5 ro console=ttyS0,115200n81 selinux=0 init=/sbin/init rd.debug systemd.log_target=console" \
b80ee080 77 -initrd "$TESTDIR"/initramfs.testing || return 1
9a52c3fd
HH
78
79 {
c864f893
HH
80 read -r OK
81 read -r IFACES
b80ee080 82 } < "$TESTDIR"/marker.img
84bc1929 83
75d758e8 84 if [[ $OK != "OK" ]]; then
d6862983
HH
85 echo "CLIENT TEST END: $test_name [FAILED - BAD EXIT]"
86 return 1
a71f1b49
PS
87 fi
88
84bc1929
HH
89 for i in $check; do
90 if [[ " $IFACES " != *\ $i\ * ]]; then
91 echo "$i not in '$IFACES'"
92 echo "CLIENT TEST END: $test_name [FAILED - BAD IF]"
93 return 1
94 fi
95 done
a71f1b49 96
84bc1929
HH
97 for i in $IFACES; do
98 if [[ " $check " != *\ $i\ * ]]; then
99 echo "$i in '$IFACES', but should not be"
d6862983
HH
100 echo "CLIENT TEST END: $test_name [FAILED - BAD IF]"
101 return 1
102 fi
a71f1b49
PS
103 done
104
105 echo "CLIENT TEST END: $test_name [OK]"
106 return 0
107}
108
a71f1b49
PS
109test_run() {
110 if ! run_server; then
d6862983
HH
111 echo "Failed to start server" 1>&2
112 return 1
a71f1b49 113 fi
24a78b26
HH
114 test_client
115 ret=$?
116 kill_server
117 return $ret
6c980807 118}
a71f1b49 119
6c980807 120test_client() {
a71f1b49 121 # Mac Numbering Scheme
ddf63231 122 # ...:00-02 receive IP addresses all others don't
a71f1b49
PS
123 # ...:02 receives a dhcp root-path
124
125 # PXE Style BOOTIF=
e0641277 126 client_test "MULTINIC root=nfs BOOTIF=" \
9a52c3fd
HH
127 00 01 02 \
128 "root=nfs:192.168.50.1:/nfs/client BOOTIF=52-54-00-12-34-00" \
b80ee080 129 "enp0s1" || return 1
a71f1b49 130
b80ee080 131 client_test "MULTINIC root=nfs BOOTIF= ip=enp0s3:dhcp" \
9a52c3fd 132 00 01 02 \
b80ee080
HH
133 "root=nfs:192.168.50.1:/nfs/client BOOTIF=52-54-00-12-34-00 ip=enp0s2:dhcp" \
134 "enp0s1 enp0s2" || return 1
84bc1929 135
a71f1b49
PS
136 # PXE Style BOOTIF= with dhcp root-path
137 client_test "MULTINIC root=dhcp BOOTIF=" \
9a52c3fd
HH
138 00 01 02 \
139 "root=dhcp BOOTIF=52-54-00-12-34-02" \
b80ee080 140 "enp0s3" || return 1
a71f1b49
PS
141
142 # Multinic case, where only one nic works
143 client_test "MULTINIC root=nfs ip=dhcp" \
9a52c3fd
HH
144 FF 00 FE \
145 "root=nfs:192.168.50.1:/nfs/client ip=dhcp" \
b80ee080 146 "enp0s2" || return 1
a71f1b49
PS
147
148 # Require two interfaces
b80ee080 149 client_test "MULTINIC root=nfs ip=enp0s2:dhcp ip=enp0s3:dhcp bootdev=enp0s2" \
9a52c3fd 150 00 01 02 \
b80ee080
HH
151 "root=nfs:192.168.50.1:/nfs/client ip=enp0s2:dhcp ip=enp0s3:dhcp bootdev=enp0s2" \
152 "enp0s2 enp0s3" || return 1
a71f1b49
PS
153
154 # Require three interfaces with dhcp root-path
b80ee080 155 client_test "MULTINIC root=dhcp ip=enp0s1:dhcp ip=enp0s2:dhcp ip=enp0s3:dhcp bootdev=enp0s3" \
9a52c3fd 156 00 01 02 \
b80ee080
HH
157 "root=dhcp ip=enp0s1:dhcp ip=enp0s2:dhcp ip=enp0s3:dhcp bootdev=enp0s3" \
158 "enp0s1 enp0s2 enp0s3" || return 1
8f4c0660 159
24a78b26 160 client_test "MULTINIC bonding" \
9a52c3fd 161 00 01 02 \
b80ee080 162 "root=nfs:192.168.50.1:/nfs/client ip=bond0:dhcp bond=bond0:enp0s1,enp0s2,enp0s3:mode=balance-rr" \
9a52c3fd 163 "bond0" || return 1
24a78b26 164
a3f73298 165 # bridge, where only one interface is actually connected
24a78b26 166 client_test "MULTINIC bridging" \
9a52c3fd 167 00 01 02 \
9fb64d96 168 "root=nfs:192.168.50.1:/nfs/client ip=bridge0:dhcp::52:54:00:12:34:00 bridge=bridge0:enp0s1,enp0s5,enp0s6" \
9a52c3fd 169 "bridge0" || return 1
8f4c0660 170 return 0
a71f1b49
PS
171}
172
173test_setup() {
8b2afb08
HH
174 export kernel=$KVERSION
175 export srcmods="/lib/modules/$kernel/"
176 rm -rf -- "$TESTDIR"/overlay
3eca0cc8 177 (
c864f893
HH
178 mkdir -p "$TESTDIR"/overlay/source
179 # shellcheck disable=SC2030
0f62da04 180 export initdir=$TESTDIR/overlay/source
c864f893 181 # shellcheck disable=SC1090
c0321c90 182 . "$PKGLIBDIR"/dracut-init.sh
0f62da04 183
d6862983 184 (
c864f893 185 cd "$initdir" || exit
8b2afb08
HH
186 mkdir -p dev sys proc run etc var/run tmp var/lib/{dhcpd,rpcbind}
187 mkdir -p var/lib/nfs/{v4recovery,rpc_pipefs}
188 chmod 777 var/lib/rpcbind var/lib/nfs
d6862983
HH
189 )
190
af119460 191 inst_multiple sh ls shutdown poweroff stty cat ps ln ip \
9a52c3fd
HH
192 dmesg mkdir cp ping exportfs \
193 modprobe rpc.nfsd rpc.mountd showmount tcpdump \
8b2afb08 194 sleep mount chmod rm
96d22bd7 195 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
8b2afb08
HH
196 if [ -f "${_terminfodir}"/l/linux ]; then
197 inst_multiple -o "${_terminfodir}"/l/linux
198 break
199 fi
d6862983 200 done
9a52c3fd
HH
201 type -P portmap > /dev/null && inst_multiple portmap
202 type -P rpcbind > /dev/null && inst_multiple rpcbind
af119460 203 [ -f /etc/netconfig ] && inst_multiple /etc/netconfig
9a52c3fd 204 type -P dhcpd > /dev/null && inst_multiple dhcpd
ec897491 205 instmods nfsd sunrpc ipv6 lockd af_packet
d6862983 206 inst ./server-init.sh /sbin/init
8b2afb08 207 inst_simple /etc/os-release
d6862983
HH
208 inst ./hosts /etc/hosts
209 inst ./exports /etc/exports
210 inst ./dhcpd.conf /etc/dhcpd.conf
8b2afb08
HH
211 inst_multiple -o {,/usr}/etc/nsswitch.conf {,/usr}/etc/rpc \
212 {,/usr}/etc/protocols {,/usr}/etc/services
7299c14e 213 inst_multiple -o rpc.idmapd /etc/idmapd.conf
d6862983
HH
214
215 inst_libdir_file 'libnfsidmap_nsswitch.so*'
216 inst_libdir_file 'libnfsidmap/*.so*'
217 inst_libdir_file 'libnfsidmap*.so*'
c5ef4b63 218
8b2afb08
HH
219 _nsslibs=$(
220 cat "$dracutsysrootdir"/{,usr/}etc/nsswitch.conf 2> /dev/null \
221 | sed -e '/^#/d' -e 's/^.*://' -e 's/\[NOTFOUND=return\]//' \
222 | tr -s '[:space:]' '\n' | sort -u | tr -s '[:space:]' '|'
223 )
3eca0cc8
HH
224 _nsslibs=${_nsslibs#|}
225 _nsslibs=${_nsslibs%|}
167a320e 226 inst_libdir_file -n "$_nsslibs" 'libnss_*.so*'
c5ef4b63 227
d6862983
HH
228 inst /etc/passwd /etc/passwd
229 inst /etc/group /etc/group
3eca0cc8 230
8b2afb08 231 cp -a /etc/ld.so.conf* "$initdir"/etc
7ecb36ae 232 ldconfig -r "$initdir"
67ab4f77 233 dracut_kernel_post
3eca0cc8 234 )
a71f1b49
PS
235
236 # Make client root inside server root
a71f1b49 237 (
c864f893
HH
238 # shellcheck disable=SC2030
239 # shellcheck disable=SC2031
0f62da04 240 export initdir=$TESTDIR/overlay/source/nfs/client
c864f893 241 # shellcheck disable=SC1090
c0321c90 242 . "$PKGLIBDIR"/dracut-init.sh
8b2afb08 243
06853123 244 (
c864f893 245 cd "$initdir" || exit
8b2afb08 246 mkdir -p dev sys proc etc run root usr var/lib/nfs/rpc_pipefs
06853123 247 )
8b2afb08
HH
248
249 inst_multiple sh shutdown poweroff stty cat ps ln ip dd \
250 mount dmesg mkdir cp ping grep setsid ls vi less cat sync
96d22bd7 251 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
8b2afb08
HH
252 if [ -f "${_terminfodir}"/l/linux ]; then
253 inst_multiple -o "${_terminfodir}"/l/linux
254 break
255 fi
d6862983 256 done
c864f893 257
c0321c90
BD
258 inst_simple "${PKGLIBDIR}/modules.d/99base/dracut-lib.sh" "/lib/dracut-lib.sh"
259 inst_simple "${PKGLIBDIR}/modules.d/99base/dracut-dev-lib.sh" "/lib/dracut-dev-lib.sh"
260 inst_binary "${PKGLIBDIR}/dracut-util" "/usr/bin/dracut-util"
c864f893
HH
261 ln -s dracut-util "${initdir}/usr/bin/dracut-getarg"
262 ln -s dracut-util "${initdir}/usr/bin/dracut-getargs"
263
d6862983 264 inst ./client-init.sh /sbin/init
8b2afb08
HH
265 inst_simple /etc/os-release
266 inst_multiple -o {,/usr}/etc/nsswitch.conf
d6862983
HH
267 inst /etc/passwd /etc/passwd
268 inst /etc/group /etc/group
269
d6862983
HH
270 inst_libdir_file 'libnfsidmap_nsswitch.so*'
271 inst_libdir_file 'libnfsidmap/*.so*'
272 inst_libdir_file 'libnfsidmap*.so*'
3eca0cc8 273
8b2afb08
HH
274 _nsslibs=$(
275 cat "$dracutsysrootdir"/{,usr/}etc/nsswitch.conf 2> /dev/null \
276 | sed -e '/^#/d' -e 's/^.*://' -e 's/\[NOTFOUND=return\]//' \
277 | tr -s '[:space:]' '\n' | sort -u | tr -s '[:space:]' '|'
278 )
3eca0cc8
HH
279 _nsslibs=${_nsslibs#|}
280 _nsslibs=${_nsslibs%|}
167a320e 281 inst_libdir_file -n "$_nsslibs" 'libnss_*.so*'
a71f1b49 282
8b2afb08 283 cp -a /etc/ld.so.conf* "$initdir"/etc
4bd0ab61 284 ldconfig -r "$initdir"
3eca0cc8
HH
285 )
286
0f62da04
HH
287 # second, install the files needed to make the root filesystem
288 (
c864f893
HH
289 # shellcheck disable=SC2030
290 # shellcheck disable=SC2031
0f62da04 291 export initdir=$TESTDIR/overlay
c864f893 292 # shellcheck disable=SC1090
c0321c90 293 . "$PKGLIBDIR"/dracut-init.sh
006890a2 294 inst_multiple sfdisk mkfs.ext4 poweroff cp umount sync dd
0f62da04
HH
295 inst_hook initqueue 01 ./create-root.sh
296 inst_hook initqueue/finished 01 ./finished-false.sh
0f62da04
HH
297 )
298
299 # create an initramfs that will create the target root filesystem.
300 # We do it this way so that we do not risk trashing the host mdraid
301 # devices, volume groups, encrypted partitions, etc.
f9939d0e 302 "$DRACUT" -l -i "$TESTDIR"/overlay / \
1573bb81 303 -m "bash rootfs-block kernel-modules qemu" \
006890a2 304 -d "piix ide-gd_mod ata_piix ext4 sd_mod" \
9a52c3fd
HH
305 --nomdadmconf \
306 --no-hostonly-cmdline -N \
c864f893 307 -f "$TESTDIR"/initramfs.makeroot "$KVERSION" || return 1
8b2afb08 308 rm -rf -- "$TESTDIR"/overlay
b80ee080 309
b80ee080
HH
310 declare -a disk_args=()
311 # shellcheck disable=SC2034
312 declare -i disk_index=0
f1346763
HG
313 qemu_add_drive_args disk_index disk_args "$TESTDIR"/marker.img marker 1
314 qemu_add_drive_args disk_index disk_args "$TESTDIR"/server.img root 120
0f62da04
HH
315
316 # Invoke KVM and/or QEMU to actually create the target filesystem.
c864f893 317 "$testdir"/run-qemu \
b80ee080 318 "${disk_args[@]}" \
006890a2 319 -append "root=/dev/dracut/root rw rootfstype=ext4 quiet console=ttyS0,115200n81 selinux=0" \
c864f893 320 -initrd "$TESTDIR"/initramfs.makeroot || return 1
f1346763 321 test_marker_check dracut-root-block-created || return 1
a71f1b49
PS
322
323 # Make an overlay with needed tools for the test harness
324 (
c864f893 325 # shellcheck disable=SC2031
8b2afb08 326 # shellcheck disable=SC2030
b093aa2d 327 export initdir="$TESTDIR"/overlay
8b2afb08 328 mkdir -p "$TESTDIR"/overlay
c864f893 329 # shellcheck disable=SC1090
c0321c90 330 . "$PKGLIBDIR"/dracut-init.sh
af119460 331 inst_multiple poweroff shutdown
4e882b80 332 inst_hook shutdown-emergency 000 ./hard-off.sh
781f1971 333 inst_hook emergency 000 ./hard-off.sh
8b2afb08
HH
334 inst_simple ./client.link /etc/systemd/network/01-client.link
335
336 inst_binary awk
c0321c90 337 inst_hook pre-pivot 85 "$PKGLIBDIR/modules.d/45ifcfg/write-ifcfg.sh"
a71f1b49 338 )
8b2afb08 339 # Make client's dracut image
f9939d0e 340 "$DRACUT" -l -i "$TESTDIR"/overlay / \
1586621b 341 -o "ifcfg plymouth" \
8b2afb08
HH
342 -a "debug watchdog ${USE_NETWORK}" \
343 --no-hostonly-cmdline -N \
344 -f "$TESTDIR"/initramfs.testing "$KVERSION" || return 1
a71f1b49 345
8b2afb08
HH
346 (
347 # shellcheck disable=SC2031
348 export initdir="$TESTDIR"/overlay
349 # shellcheck disable=SC1090
c0321c90 350 . "$PKGLIBDIR"/dracut-init.sh
8b2afb08
HH
351 rm "$initdir"/etc/systemd/network/01-client.link
352 inst_simple ./server.link /etc/systemd/network/01-server.link
353 inst_hook pre-mount 99 ./wait-if-server.sh
354 )
a71f1b49 355 # Make server's dracut image
f9939d0e 356 "$DRACUT" -l -i "$TESTDIR"/overlay / \
9a18f133 357 -m "bash rootfs-block debug kernel-modules watchdog qemu network network-legacy" \
006890a2 358 -d "af_packet piix ide-gd_mod ata_piix ext4 sd_mod nfsv2 nfsv3 nfsv4 nfs_acl nfs_layout_nfsv41_files nfsd e1000 i6300esb ib700wdt" \
e3e1f406 359 --no-hostonly-cmdline -N \
b093aa2d 360 -f "$TESTDIR"/initramfs.server "$KVERSION" || return 1
a71f1b49 361
a71f1b49
PS
362}
363
6c980807 364kill_server() {
b093aa2d 365 if [[ -s "$TESTDIR"/server.pid ]]; then
c864f893 366 kill -TERM -- "$(cat "$TESTDIR"/server.pid)"
b093aa2d 367 rm -f -- "$TESTDIR"/server.pid
a71f1b49 368 fi
6c980807
HH
369}
370
371test_cleanup() {
0be1785a 372 kill_server
a71f1b49
PS
373}
374
c864f893 375# shellcheck disable=SC1090
b093aa2d 376. "$testdir"/test-functions