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