]> git.ipfire.org Git - thirdparty/dracut.git/blob - test/TEST-50-MULTINIC/test.sh
14f6b6b76b2760b36c541484a7d09867cff00a6d
[thirdparty/dracut.git] / test / TEST-50-MULTINIC / test.sh
1 #!/bin/bash
2
3 if [[ $NM ]]; then
4 USE_NETWORK="network-manager"
5 OMIT_NETWORK="network-legacy"
6 else
7 USE_NETWORK="network-legacy"
8 OMIT_NETWORK="network-manager"
9 fi
10
11 TEST_DESCRIPTION="root filesystem on NFS with multiple nics with $USE_NETWORK"
12
13 KVERSION=${KVERSION-$(uname -r)}
14
15 # Uncomment this to debug failures
16 #DEBUGFAIL="rd.shell rd.break"
17 #SERIAL="tcp:127.0.0.1:9999"
18
19 run_server() {
20 # Start server first
21 echo "MULTINIC TEST SETUP: Starting DHCP/NFS server"
22
23 fsck -a "$TESTDIR"/server.ext3 || return 1
24
25 $testdir/run-qemu \
26 -drive format=raw,index=0,media=disk,file="$TESTDIR"/server.ext3 \
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 \
32 -append "panic=1 systemd.crash_reboot loglevel=7 root=/dev/sda rootfstype=ext3 rw console=ttyS0,115200n81 selinux=0" \
33 -initrd "$TESTDIR"/initramfs.server \
34 -pidfile "$TESTDIR"/server.pid -daemonize || return 1
35
36 chmod 644 -- "$TESTDIR"/server.pid || return 1
37
38 # Cleanup the terminal if we have one
39 tty -s && stty sane
40
41 if ! [[ $SERIAL ]]; then
42 while : ; do
43 grep Serving "$TESTDIR"/server.log && break
44 echo "Waiting for the server to startup"
45 sleep 1
46 done
47 else
48 echo Sleeping 10 seconds to give the server a head start
49 sleep 10
50 fi
51 }
52
53 client_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)
64 if ! dd if=/dev/zero of="$TESTDIR"/client.img bs=1M count=1; then
65 echo "Unable to make client sda image" 1>&2
66 return 1
67 fi
68
69 $testdir/run-qemu -drive format=raw,index=0,media=disk,file="$TESTDIR"/client.img \
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 \
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" \
80 -initrd "$TESTDIR"/initramfs.testing
81
82 { read OK; read IFACES; } < "$TESTDIR"/client.img
83
84 if [[ "$OK" != "OK" ]]; then
85 echo "CLIENT TEST END: $test_name [FAILED - BAD EXIT]"
86 return 1
87 fi
88
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
96
97 for i in $IFACES; do
98 if [[ " $check " != *\ $i\ * ]]; then
99 echo "$i in '$IFACES', but should not be"
100 echo "CLIENT TEST END: $test_name [FAILED - BAD IF]"
101 return 1
102 fi
103 done
104
105 echo "CLIENT TEST END: $test_name [OK]"
106 return 0
107 }
108
109
110 test_run() {
111 if ! run_server; then
112 echo "Failed to start server" 1>&2
113 return 1
114 fi
115 test_client
116 ret=$?
117 kill_server
118 return $ret
119 }
120
121 test_client() {
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=
127 client_test "MULTINIC root=nfs BOOTIF=" \
128 00 01 02 \
129 "root=nfs:192.168.50.1:/nfs/client BOOTIF=52-54-00-12-34-00" \
130 "ens2" || return 1
131
132 client_test "MULTINIC root=nfs BOOTIF= ip=ens4:dhcp" \
133 00 01 02 \
134 "root=nfs:192.168.50.1:/nfs/client BOOTIF=52-54-00-12-34-00 ip=ens3:dhcp" \
135 "ens2 ens3" || return 1
136
137 # PXE Style BOOTIF= with dhcp root-path
138 client_test "MULTINIC root=dhcp BOOTIF=" \
139 00 01 02 \
140 "root=dhcp BOOTIF=52-54-00-12-34-02" \
141 "ens4" || return 1
142
143 # Multinic case, where only one nic works
144 client_test "MULTINIC root=nfs ip=dhcp" \
145 FF 00 FE \
146 "root=nfs:192.168.50.1:/nfs/client ip=dhcp" \
147 "ens3" || return 1
148
149 # Require two interfaces
150 client_test "MULTINIC root=nfs ip=ens3:dhcp ip=ens4:dhcp bootdev=ens3" \
151 00 01 02 \
152 "root=nfs:192.168.50.1:/nfs/client ip=ens3:dhcp ip=ens4:dhcp bootdev=ens3" \
153 "ens3 ens4" || return 1
154
155 # Require three interfaces with dhcp root-path
156 client_test "MULTINIC root=dhcp ip=ens2:dhcp ip=ens3:dhcp ip=ens4:dhcp bootdev=ens4" \
157 00 01 02 \
158 "root=dhcp ip=ens2:dhcp ip=ens3:dhcp ip=ens4:dhcp bootdev=ens4" \
159 "ens2 ens3 ens4" || return 1
160
161 client_test "MULTINIC bonding" \
162 00 01 02 \
163 "root=nfs:192.168.50.1:/nfs/client ip=bond0:dhcp bond=bond0:ens2,ens3,ens4:mode=balance-rr" \
164 "bond0" || return 1
165
166 # bridge, where only one interface is actually connected
167 client_test "MULTINIC bridging" \
168 00 01 02 \
169 "root=nfs:192.168.50.1:/nfs/client ip=bridge0:dhcp bridge=bridge0:ens2,ens6,ens7" \
170 "bridge0" || return 1
171 return 0
172 }
173
174 test_setup() {
175 # Make server root
176 dd if=/dev/null of="$TESTDIR"/server.ext3 bs=1M seek=120
177 mke2fs -j -F -- "$TESTDIR"/server.ext3
178 mkdir -- "$TESTDIR"/mnt
179 mount -o loop -- "$TESTDIR"/server.ext3 "$TESTDIR"/mnt
180 kernel=$KVERSION
181 (
182 export initdir="$TESTDIR"/mnt
183 . "$basedir"/dracut-init.sh
184
185 (
186 cd "$initdir";
187 mkdir -p -- dev sys proc run var/run etc tmp var/lib/{dhcpd,rpcbind}
188 mkdir -p -- var/lib/nfs/{v4recovery,rpc_pipefs}
189 chmod 777 -- var/lib/rpcbind var/lib/nfs
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 }
198
199 for _f in modules.builtin.bin modules.builtin modules.order; do
200 [[ $srcmods/$_f ]] && inst_simple "$srcmods/$_f" "/lib/modules/$kernel/$_f"
201 done
202
203 inst_multiple sh ls shutdown poweroff stty cat ps ln ip \
204 dmesg mkdir cp ping exportfs \
205 modprobe rpc.nfsd rpc.mountd showmount tcpdump \
206 /etc/services sleep mount chmod
207 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
208 [ -f "${_terminfodir}"/l/linux ] && break
209 done
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
215 [ -x /usr/sbin/dhcpd3 ] && inst /usr/sbin/dhcpd3 /usr/sbin/dhcpd
216 instmods nfsd sunrpc ipv6 lockd af_packet
217 inst_simple /etc/os-release
218 inst ./server-init.sh /sbin/init
219 inst ./hosts /etc/hosts
220 inst ./exports /etc/exports
221 inst ./dhcpd.conf /etc/dhcpd.conf
222 inst_multiple /etc/nsswitch.conf /etc/rpc /etc/protocols
223
224 inst_multiple rpc.idmapd /etc/idmapd.conf
225
226 inst_libdir_file 'libnfsidmap_nsswitch.so*'
227 inst_libdir_file 'libnfsidmap/*.so*'
228 inst_libdir_file 'libnfsidmap*.so*'
229
230 _nsslibs=$(sed -e '/^#/d' -e 's/^.*://' -e 's/\[NOTFOUND=return\]//' /etc/nsswitch.conf \
231 | tr -s '[:space:]' '\n' | sort -u | tr -s '[:space:]' '|')
232 _nsslibs=${_nsslibs#|}
233 _nsslibs=${_nsslibs%|}
234
235 inst_libdir_file -n "$_nsslibs" 'libnss_*.so*'
236
237 inst /etc/nsswitch.conf /etc/nsswitch.conf
238 inst /etc/passwd /etc/passwd
239 inst /etc/group /etc/group
240
241 cp -a -- /etc/ld.so.conf* "$initdir"/etc
242 ldconfig -r "$initdir"
243 dracut_kernel_post
244 )
245
246 # Make client root inside server root
247 (
248 export initdir="$TESTDIR"/mnt/nfs/client
249 . "$basedir"/dracut-init.sh
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 )
259 inst_multiple sh shutdown poweroff stty cat ps ln ip \
260 mount dmesg mkdir cp ping grep ls
261 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
262 [[ -f ${_terminfodir}/l/linux ]] && break
263 done
264 inst_multiple -o "${_terminfodir}"/l/linux
265 inst_simple /etc/os-release
266 inst ./client-init.sh /sbin/init
267 inst /etc/nsswitch.conf /etc/nsswitch.conf
268 inst /etc/passwd /etc/passwd
269 inst /etc/group /etc/group
270
271 inst_multiple rpc.idmapd /etc/idmapd.conf
272 inst_libdir_file 'libnfsidmap_nsswitch.so*'
273 inst_libdir_file 'libnfsidmap/*.so*'
274 inst_libdir_file 'libnfsidmap*.so*'
275
276 _nsslibs=$(sed -e '/^#/d' -e 's/^.*://' -e 's/\[NOTFOUND=return\]//' -- /etc/nsswitch.conf \
277 | tr -s '[:space:]' '\n' | sort -u | tr -s '[:space:]' '|')
278 _nsslibs=${_nsslibs#|}
279 _nsslibs=${_nsslibs%|}
280
281 inst_libdir_file -n "$_nsslibs" 'libnss_*.so*'
282
283 cp -a -- /etc/ld.so.conf* "$initdir"/etc
284 ldconfig -r "$initdir"
285 )
286
287 umount "$TESTDIR"/mnt
288 rm -fr -- "$TESTDIR"/mnt
289
290 # Make an overlay with needed tools for the test harness
291 (
292 export initdir="$TESTDIR"/overlay
293 . "$basedir"/dracut-init.sh
294 inst_multiple poweroff shutdown
295 inst_hook shutdown-emergency 000 ./hard-off.sh
296 inst_hook emergency 000 ./hard-off.sh
297 inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
298 inst_simple ./99-default.link /etc/systemd/network/99-default.link
299 )
300
301 # Make server's dracut image
302 $basedir/dracut.sh \
303 -l -i "$TESTDIR"/overlay / \
304 -m "dash udev-rules base rootfs-block fs-lib debug kernel-modules watchdog qemu" \
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" \
306 --no-hostonly-cmdline -N \
307 -f "$TESTDIR"/initramfs.server "$KVERSION" || return 1
308
309 # Make client's dracut image
310 $basedir/dracut.sh \
311 -l -i "$TESTDIR"/overlay / \
312 -o "plymouth ${OMIT_NETWORK}" \
313 -a "debug ${USE_NETWORK}" \
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" \
315 --no-hostonly-cmdline -N \
316 -f "$TESTDIR"/initramfs.testing "$KVERSION" || return 1
317 }
318
319 kill_server() {
320 if [[ -s "$TESTDIR"/server.pid ]]; then
321 kill -TERM -- $(cat "$TESTDIR"/server.pid)
322 rm -f -- "$TESTDIR"/server.pid
323 fi
324 }
325
326 test_cleanup() {
327 kill_server
328 }
329
330 . "$testdir"/test-functions