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