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