]> git.ipfire.org Git - thirdparty/dracut.git/blame - test/TEST-50-MULTINIC/test.sh
test: use dd to write status to marker disk
[thirdparty/dracut.git] / test / TEST-50-MULTINIC / test.sh
CommitLineData
a71f1b49 1#!/bin/bash
a3f73298
HH
2
3if [[ $NM ]]; then
4 USE_NETWORK="network-manager"
5 OMIT_NETWORK="network-legacy"
6else
7 USE_NETWORK="network-legacy"
8 OMIT_NETWORK="network-manager"
9fi
10
11TEST_DESCRIPTION="root filesystem on NFS with multiple nics with $USE_NETWORK"
a71f1b49
PS
12
13KVERSION=${KVERSION-$(uname -r)}
14
15# Uncomment this to debug failures
06853123 16#DEBUGFAIL="rd.shell rd.break"
67ab4f77 17#SERIAL="tcp:127.0.0.1:9999"
a71f1b49
PS
18
19run_server() {
20 # Start server first
21 echo "MULTINIC TEST SETUP: Starting DHCP/NFS server"
22
b093aa2d 23 fsck -a "$TESTDIR"/server.ext3 || return 1
ca8f1c1b 24
9288d21b
HH
25 $testdir/run-qemu \
26 -drive format=raw,index=0,media=disk,file="$TESTDIR"/server.ext3 \
9288d21b
HH
27 -net socket,listen=127.0.0.1:12350 \
28 -net nic,macaddr=52:54:01:12:34:56,model=e1000 \
29 ${SERIAL:+-serial "$SERIAL"} \
30 ${SERIAL:--serial file:"$TESTDIR"/server.log} \
31 -watchdog i6300esb -watchdog-action poweroff \
7934c6f9 32 -append "panic=1 systemd.crash_reboot loglevel=7 root=/dev/sda rootfstype=ext3 rw console=ttyS0,115200n81 selinux=0" \
9288d21b
HH
33 -initrd "$TESTDIR"/initramfs.server \
34 -pidfile "$TESTDIR"/server.pid -daemonize || return 1
ca8f1c1b 35
4bd0ab61 36 chmod 644 -- "$TESTDIR"/server.pid || return 1
a71f1b49
PS
37
38 # Cleanup the terminal if we have one
39 tty -s && stty sane
40
3aae122c 41 if ! [[ $SERIAL ]]; then
3aae122c
HH
42 while : ; do
43 grep Serving "$TESTDIR"/server.log && break
a3f73298 44 echo "Waiting for the server to startup"
3aae122c
HH
45 sleep 1
46 done
47 else
48 echo Sleeping 10 seconds to give the server a head start
49 sleep 10
50 fi
a71f1b49
PS
51}
52
53client_test() {
54 local test_name="$1"
55 local mac1="$2"
56 local mac2="$3"
57 local mac3="$4"
58 local cmdline="$5"
59 local check="$6"
60
61 echo "CLIENT TEST START: $test_name"
62
63 # Need this so kvm-qemu will boot (needs non-/dev/zero local disk)
b093aa2d 64 if ! dd if=/dev/zero of="$TESTDIR"/client.img bs=1M count=1; then
d6862983
HH
65 echo "Unable to make client sda image" 1>&2
66 return 1
a71f1b49
PS
67 fi
68
a3f73298 69 $testdir/run-qemu -drive format=raw,index=0,media=disk,file="$TESTDIR"/client.img \
ca8f1c1b
HH
70 -net socket,connect=127.0.0.1:12350 \
71 -net nic,macaddr=52:54:00:12:34:$mac1,model=e1000 \
72 -net nic,macaddr=52:54:00:12:34:$mac2,model=e1000 \
73 -net nic,macaddr=52:54:00:12:34:$mac3,model=e1000 \
74 -netdev hubport,id=n1,hubid=1 \
75 -netdev hubport,id=n2,hubid=2 \
76 -device e1000,netdev=n1,mac=52:54:00:12:34:98 \
77 -device e1000,netdev=n2,mac=52:54:00:12:34:99 \
78 -watchdog i6300esb -watchdog-action poweroff \
a3f73298 79 -append "quiet rd.net.timeout.dhcp=3 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" \
ca8f1c1b 80 -initrd "$TESTDIR"/initramfs.testing
a71f1b49 81
84bc1929
HH
82 { read OK; read IFACES; } < "$TESTDIR"/client.img
83
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
109
110test_run() {
111 if ! run_server; then
d6862983
HH
112 echo "Failed to start server" 1>&2
113 return 1
a71f1b49 114 fi
24a78b26
HH
115 test_client
116 ret=$?
117 kill_server
118 return $ret
6c980807 119}
a71f1b49 120
6c980807 121test_client() {
a71f1b49
PS
122 # Mac Numbering Scheme
123 # ...:00-02 receive IP adresses all others don't
124 # ...:02 receives a dhcp root-path
125
126 # PXE Style BOOTIF=
e0641277 127 client_test "MULTINIC root=nfs BOOTIF=" \
ca8f1c1b
HH
128 00 01 02 \
129 "root=nfs:192.168.50.1:/nfs/client BOOTIF=52-54-00-12-34-00" \
a3f73298 130 "ens2" || return 1
a71f1b49 131
84bc1929 132 client_test "MULTINIC root=nfs BOOTIF= ip=ens4:dhcp" \
ca8f1c1b 133 00 01 02 \
a3f73298
HH
134 "root=nfs:192.168.50.1:/nfs/client BOOTIF=52-54-00-12-34-00 ip=ens3:dhcp" \
135 "ens2 ens3" || return 1
84bc1929 136
a71f1b49
PS
137 # PXE Style BOOTIF= with dhcp root-path
138 client_test "MULTINIC root=dhcp BOOTIF=" \
ca8f1c1b
HH
139 00 01 02 \
140 "root=dhcp BOOTIF=52-54-00-12-34-02" \
a3f73298 141 "ens4" || return 1
a71f1b49
PS
142
143 # Multinic case, where only one nic works
144 client_test "MULTINIC root=nfs ip=dhcp" \
ca8f1c1b
HH
145 FF 00 FE \
146 "root=nfs:192.168.50.1:/nfs/client ip=dhcp" \
a3f73298 147 "ens3" || return 1
a71f1b49
PS
148
149 # Require two interfaces
a3f73298 150 client_test "MULTINIC root=nfs ip=ens3:dhcp ip=ens4:dhcp bootdev=ens3" \
ca8f1c1b 151 00 01 02 \
a3f73298
HH
152 "root=nfs:192.168.50.1:/nfs/client ip=ens3:dhcp ip=ens4:dhcp bootdev=ens3" \
153 "ens3 ens4" || return 1
a71f1b49
PS
154
155 # Require three interfaces with dhcp root-path
a3f73298 156 client_test "MULTINIC root=dhcp ip=ens2:dhcp ip=ens3:dhcp ip=ens4:dhcp bootdev=ens4" \
ca8f1c1b 157 00 01 02 \
a3f73298
HH
158 "root=dhcp ip=ens2:dhcp ip=ens3:dhcp ip=ens4:dhcp bootdev=ens4" \
159 "ens2 ens3 ens4" || return 1
8f4c0660 160
24a78b26 161 client_test "MULTINIC bonding" \
ca8f1c1b 162 00 01 02 \
a3f73298 163 "root=nfs:192.168.50.1:/nfs/client ip=bond0:dhcp bond=bond0:ens2,ens3,ens4:mode=balance-rr" \
ca8f1c1b 164 "bond0" || return 1
24a78b26 165
a3f73298 166 # bridge, where only one interface is actually connected
24a78b26 167 client_test "MULTINIC bridging" \
ca8f1c1b 168 00 01 02 \
a3f73298 169 "root=nfs:192.168.50.1:/nfs/client ip=bridge0:dhcp bridge=bridge0:ens2,ens6,ens7" \
ca8f1c1b 170 "bridge0" || return 1
8f4c0660 171 return 0
a71f1b49
PS
172}
173
174test_setup() {
ca8f1c1b 175 # Make server root
66a3d405 176 dd if=/dev/null of="$TESTDIR"/server.ext3 bs=1M seek=120
b093aa2d
HH
177 mke2fs -j -F -- "$TESTDIR"/server.ext3
178 mkdir -- "$TESTDIR"/mnt
4bd0ab61 179 mount -o loop -- "$TESTDIR"/server.ext3 "$TESTDIR"/mnt
ca8f1c1b 180 kernel=$KVERSION
3eca0cc8 181 (
b093aa2d 182 export initdir="$TESTDIR"/mnt
777f2db0 183 . "$basedir"/dracut-init.sh
d6862983
HH
184
185 (
186 cd "$initdir";
06853123 187 mkdir -p -- dev sys proc run var/run etc tmp var/lib/{dhcpd,rpcbind}
b093aa2d
HH
188 mkdir -p -- var/lib/nfs/{v4recovery,rpc_pipefs}
189 chmod 777 -- var/lib/rpcbind var/lib/nfs
d6862983
HH
190 )
191
192 for _f in modules.builtin.bin modules.builtin; do
193 [[ $srcmods/$_f ]] && break
194 done || {
195 dfatal "No modules.builtin.bin and modules.builtin found!"
196 return 1
197 }
3eca0cc8
HH
198
199 for _f in modules.builtin.bin modules.builtin modules.order; do
d6862983
HH
200 [[ $srcmods/$_f ]] && inst_simple "$srcmods/$_f" "/lib/modules/$kernel/$_f"
201 done
3eca0cc8 202
af119460 203 inst_multiple sh ls shutdown poweroff stty cat ps ln ip \
ca8f1c1b
HH
204 dmesg mkdir cp ping exportfs \
205 modprobe rpc.nfsd rpc.mountd showmount tcpdump \
206 /etc/services sleep mount chmod
96d22bd7 207 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
b093aa2d 208 [ -f "${_terminfodir}"/l/linux ] && break
d6862983 209 done
af119460
HH
210 inst_multiple -o "${_terminfodir}"/l/linux
211 type -P portmap >/dev/null && inst_multiple portmap
212 type -P rpcbind >/dev/null && inst_multiple rpcbind
213 [ -f /etc/netconfig ] && inst_multiple /etc/netconfig
214 type -P dhcpd >/dev/null && inst_multiple dhcpd
d6862983 215 [ -x /usr/sbin/dhcpd3 ] && inst /usr/sbin/dhcpd3 /usr/sbin/dhcpd
ec897491 216 instmods nfsd sunrpc ipv6 lockd af_packet
021b2fdd 217 inst_simple /etc/os-release
d6862983
HH
218 inst ./server-init.sh /sbin/init
219 inst ./hosts /etc/hosts
220 inst ./exports /etc/exports
221 inst ./dhcpd.conf /etc/dhcpd.conf
af119460 222 inst_multiple /etc/nsswitch.conf /etc/rpc /etc/protocols
d6862983 223
af119460 224 inst_multiple rpc.idmapd /etc/idmapd.conf
d6862983
HH
225
226 inst_libdir_file 'libnfsidmap_nsswitch.so*'
227 inst_libdir_file 'libnfsidmap/*.so*'
228 inst_libdir_file 'libnfsidmap*.so*'
c5ef4b63 229
3eca0cc8 230 _nsslibs=$(sed -e '/^#/d' -e 's/^.*://' -e 's/\[NOTFOUND=return\]//' /etc/nsswitch.conf \
ca8f1c1b 231 | tr -s '[:space:]' '\n' | sort -u | tr -s '[:space:]' '|')
3eca0cc8
HH
232 _nsslibs=${_nsslibs#|}
233 _nsslibs=${_nsslibs%|}
c5ef4b63 234
167a320e 235 inst_libdir_file -n "$_nsslibs" 'libnss_*.so*'
c5ef4b63 236
d6862983
HH
237 inst /etc/nsswitch.conf /etc/nsswitch.conf
238 inst /etc/passwd /etc/passwd
239 inst /etc/group /etc/group
3eca0cc8 240
b093aa2d 241 cp -a -- /etc/ld.so.conf* "$initdir"/etc
7ecb36ae 242 ldconfig -r "$initdir"
67ab4f77 243 dracut_kernel_post
3eca0cc8 244 )
a71f1b49
PS
245
246 # Make client root inside server root
a71f1b49 247 (
b093aa2d 248 export initdir="$TESTDIR"/mnt/nfs/client
777f2db0 249 . "$basedir"/dracut-init.sh
06853123
HH
250 (
251 cd "$initdir"
252 mkdir -p dev sys proc etc run
253 mkdir -p var/lib/nfs/rpc_pipefs
254 mkdir -p root usr/bin usr/lib usr/lib64 usr/sbin
255 for i in bin sbin lib lib64; do
256 ln -sfnr usr/$i $i
257 done
258 )
af119460 259 inst_multiple sh shutdown poweroff stty cat ps ln ip \
9ca53063 260 mount dmesg mkdir cp ping grep ls dd
96d22bd7 261 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
b093aa2d 262 [[ -f ${_terminfodir}/l/linux ]] && break
d6862983 263 done
af119460 264 inst_multiple -o "${_terminfodir}"/l/linux
021b2fdd 265 inst_simple /etc/os-release
d6862983 266 inst ./client-init.sh /sbin/init
d6862983
HH
267 inst /etc/nsswitch.conf /etc/nsswitch.conf
268 inst /etc/passwd /etc/passwd
269 inst /etc/group /etc/group
270
af119460 271 inst_multiple rpc.idmapd /etc/idmapd.conf
d6862983
HH
272 inst_libdir_file 'libnfsidmap_nsswitch.so*'
273 inst_libdir_file 'libnfsidmap/*.so*'
274 inst_libdir_file 'libnfsidmap*.so*'
3eca0cc8 275
b093aa2d 276 _nsslibs=$(sed -e '/^#/d' -e 's/^.*://' -e 's/\[NOTFOUND=return\]//' -- /etc/nsswitch.conf \
ca8f1c1b 277 | tr -s '[:space:]' '\n' | sort -u | tr -s '[:space:]' '|')
3eca0cc8
HH
278 _nsslibs=${_nsslibs#|}
279 _nsslibs=${_nsslibs%|}
280
167a320e 281 inst_libdir_file -n "$_nsslibs" 'libnss_*.so*'
a71f1b49 282
b093aa2d 283 cp -a -- /etc/ld.so.conf* "$initdir"/etc
4bd0ab61 284 ldconfig -r "$initdir"
3eca0cc8
HH
285 )
286
4bd0ab61 287 umount "$TESTDIR"/mnt
b093aa2d 288 rm -fr -- "$TESTDIR"/mnt
a71f1b49
PS
289
290 # Make an overlay with needed tools for the test harness
291 (
b093aa2d 292 export initdir="$TESTDIR"/overlay
777f2db0 293 . "$basedir"/dracut-init.sh
af119460 294 inst_multiple poweroff shutdown
4e882b80 295 inst_hook shutdown-emergency 000 ./hard-off.sh
781f1971 296 inst_hook emergency 000 ./hard-off.sh
d6862983 297 inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
f3f081e5 298 inst_simple ./99-default.link /etc/systemd/network/99-default.link
a71f1b49
PS
299 )
300
301 # Make server's dracut image
ca8f1c1b
HH
302 $basedir/dracut.sh \
303 -l -i "$TESTDIR"/overlay / \
8996d3df 304 -m "dash udev-rules base rootfs-block fs-lib debug kernel-modules watchdog qemu" \
a8986425 305 -d "af_packet piix ide-gd_mod ata_piix ext3 sd_mod nfsv2 nfsv3 nfsv4 nfs_acl nfs_layout_nfsv41_files nfsd e1000 i6300esb ib700wdt" \
e3e1f406 306 --no-hostonly-cmdline -N \
b093aa2d 307 -f "$TESTDIR"/initramfs.server "$KVERSION" || return 1
a71f1b49
PS
308
309 # Make client's dracut image
ca8f1c1b
HH
310 $basedir/dracut.sh \
311 -l -i "$TESTDIR"/overlay / \
a3f73298
HH
312 -o "plymouth ${OMIT_NETWORK}" \
313 -a "debug ${USE_NETWORK}" \
a8986425 314 -d "af_packet piix sd_mod sr_mod ata_piix ide-gd_mod e1000 nfsv2 nfsv3 nfsv4 nfs_acl nfs_layout_nfsv41_files sunrpc i6300esb ib700wdt" \
e3e1f406 315 --no-hostonly-cmdline -N \
b093aa2d 316 -f "$TESTDIR"/initramfs.testing "$KVERSION" || return 1
a71f1b49
PS
317}
318
6c980807 319kill_server() {
b093aa2d 320 if [[ -s "$TESTDIR"/server.pid ]]; then
4bd0ab61 321 kill -TERM -- $(cat "$TESTDIR"/server.pid)
b093aa2d 322 rm -f -- "$TESTDIR"/server.pid
a71f1b49 323 fi
6c980807
HH
324}
325
326test_cleanup() {
0be1785a 327 kill_server
a71f1b49
PS
328}
329
b093aa2d 330. "$testdir"/test-functions