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