]> git.ipfire.org Git - thirdparty/dracut.git/blob - test/TEST-50-MULTINIC/test.sh
b8783802ef05b40fa93d7af9f49210a8fff51e82
[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 "$SERIAL"} \
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 || { kill_server; return 1; }
94 }
95
96 test_client() {
97 # Mac Numbering Scheme
98 # ...:00-02 receive IP adresses all others don't
99 # ...:02 receives a dhcp root-path
100
101 # PXE Style BOOTIF=
102 client_test "MULTINIC root=nfs BOOTIF=" \
103 00 01 02 \
104 "root=nfs:192.168.50.1:/nfs/client BOOTIF=52-54-00-12-34-00" \
105 "ens3" || return 1
106
107 client_test "MULTINIC root=nfs BOOTIF= ip=ens4:dhcp" \
108 00 01 02 \
109 "root=nfs:192.168.50.1:/nfs/client BOOTIF=52-54-00-12-34-00 ip=ens4:dhcp" \
110 "ens3 ens4" || return 1
111
112 # PXE Style BOOTIF= with dhcp root-path
113 client_test "MULTINIC root=dhcp BOOTIF=" \
114 00 01 02 \
115 "root=dhcp BOOTIF=52-54-00-12-34-02" \
116 "ens5" || return 1
117
118 # Multinic case, where only one nic works
119 client_test "MULTINIC root=nfs ip=dhcp" \
120 FF 00 FE \
121 "root=nfs:192.168.50.1:/nfs/client ip=dhcp" \
122 "ens4" || return 1
123
124 # Require two interfaces
125 client_test "MULTINIC root=nfs ip=ens4:dhcp ip=ens5:dhcp bootdev=ens4" \
126 00 01 02 \
127 "root=nfs:192.168.50.1:/nfs/client ip=ens4:dhcp ip=ens5:dhcp bootdev=ens4" \
128 "ens4 ens5" || return 1
129
130 # Require three interfaces with dhcp root-path
131 client_test "MULTINIC root=dhcp ip=ens3:dhcp ip=ens4:dhcp ip=ens5:dhcp bootdev=ens5" \
132 00 01 02 \
133 "root=dhcp ip=ens3:dhcp ip=ens4:dhcp ip=ens5:dhcp bootdev=ens5" \
134 "ens3 ens4 ens5" || return 1
135
136 kill_server
137 return 0
138 }
139
140 test_setup() {
141 # Make server root
142 dd if=/dev/null of="$TESTDIR"/server.ext3 bs=1M seek=60
143 mke2fs -j -F -- "$TESTDIR"/server.ext3
144 mkdir -- "$TESTDIR"/mnt
145 sudo mount -o loop -- "$TESTDIR"/server.ext3 "$TESTDIR"/mnt
146
147 (
148 export initdir="$TESTDIR"/mnt
149 . "$basedir"/dracut-init.sh
150
151 (
152 cd "$initdir";
153 mkdir -p -- dev sys proc run var/run etc tmp var/lib/{dhcpd,rpcbind}
154 mkdir -p -- var/lib/nfs/{v4recovery,rpc_pipefs}
155 chmod 777 -- var/lib/rpcbind var/lib/nfs
156 )
157
158 for _f in modules.builtin.bin modules.builtin; do
159 [[ $srcmods/$_f ]] && break
160 done || {
161 dfatal "No modules.builtin.bin and modules.builtin found!"
162 return 1
163 }
164
165 for _f in modules.builtin.bin modules.builtin modules.order; do
166 [[ $srcmods/$_f ]] && inst_simple "$srcmods/$_f" "/lib/modules/$kernel/$_f"
167 done
168
169 inst_multiple sh ls shutdown poweroff stty cat ps ln ip \
170 dmesg mkdir cp ping exportfs \
171 modprobe rpc.nfsd rpc.mountd showmount tcpdump \
172 /etc/services sleep mount chmod
173 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
174 [ -f "${_terminfodir}"/l/linux ] && break
175 done
176 inst_multiple -o "${_terminfodir}"/l/linux
177 type -P portmap >/dev/null && inst_multiple portmap
178 type -P rpcbind >/dev/null && inst_multiple rpcbind
179 [ -f /etc/netconfig ] && inst_multiple /etc/netconfig
180 type -P dhcpd >/dev/null && inst_multiple dhcpd
181 [ -x /usr/sbin/dhcpd3 ] && inst /usr/sbin/dhcpd3 /usr/sbin/dhcpd
182 instmods nfsd sunrpc ipv6 lockd af_packet
183 inst_simple /etc/os-release
184 inst ./server-init.sh /sbin/init
185 inst ./hosts /etc/hosts
186 inst ./exports /etc/exports
187 inst ./dhcpd.conf /etc/dhcpd.conf
188 inst_multiple /etc/nsswitch.conf /etc/rpc /etc/protocols
189
190 inst_multiple rpc.idmapd /etc/idmapd.conf
191
192 inst_libdir_file 'libnfsidmap_nsswitch.so*'
193 inst_libdir_file 'libnfsidmap/*.so*'
194 inst_libdir_file 'libnfsidmap*.so*'
195
196 _nsslibs=$(sed -e '/^#/d' -e 's/^.*://' -e 's/\[NOTFOUND=return\]//' /etc/nsswitch.conf \
197 | tr -s '[:space:]' '\n' | sort -u | tr -s '[:space:]' '|')
198 _nsslibs=${_nsslibs#|}
199 _nsslibs=${_nsslibs%|}
200
201 inst_libdir_file -n "$_nsslibs" 'libnss_*.so*'
202
203 inst /etc/nsswitch.conf /etc/nsswitch.conf
204 inst /etc/passwd /etc/passwd
205 inst /etc/group /etc/group
206
207 cp -a -- /etc/ld.so.conf* "$initdir"/etc
208 sudo ldconfig -r -- "$initdir"
209 dracut_kernel_post
210 )
211
212 # Make client root inside server root
213 (
214 export initdir="$TESTDIR"/mnt/nfs/client
215 . "$basedir"/dracut-init.sh
216 (
217 cd "$initdir"
218 mkdir -p dev sys proc etc run
219 mkdir -p var/lib/nfs/rpc_pipefs
220 mkdir -p root usr/bin usr/lib usr/lib64 usr/sbin
221 for i in bin sbin lib lib64; do
222 ln -sfnr usr/$i $i
223 done
224 )
225 inst_multiple sh shutdown poweroff stty cat ps ln ip \
226 mount dmesg mkdir cp ping grep ls
227 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
228 [[ -f ${_terminfodir}/l/linux ]] && break
229 done
230 inst_multiple -o "${_terminfodir}"/l/linux
231 inst_simple /etc/os-release
232 inst ./client-init.sh /sbin/init
233 inst /etc/nsswitch.conf /etc/nsswitch.conf
234 inst /etc/passwd /etc/passwd
235 inst /etc/group /etc/group
236
237 inst_multiple rpc.idmapd /etc/idmapd.conf
238 inst_libdir_file 'libnfsidmap_nsswitch.so*'
239 inst_libdir_file 'libnfsidmap/*.so*'
240 inst_libdir_file 'libnfsidmap*.so*'
241
242 _nsslibs=$(sed -e '/^#/d' -e 's/^.*://' -e 's/\[NOTFOUND=return\]//' -- /etc/nsswitch.conf \
243 | tr -s '[:space:]' '\n' | sort -u | tr -s '[:space:]' '|')
244 _nsslibs=${_nsslibs#|}
245 _nsslibs=${_nsslibs%|}
246
247 inst_libdir_file -n "$_nsslibs" 'libnss_*.so*'
248
249 cp -a -- /etc/ld.so.conf* "$initdir"/etc
250 sudo ldconfig -r "$initdir"
251 )
252
253 sudo umount "$TESTDIR"/mnt
254 rm -fr -- "$TESTDIR"/mnt
255
256 # Make an overlay with needed tools for the test harness
257 (
258 export initdir="$TESTDIR"/overlay
259 . "$basedir"/dracut-init.sh
260 inst_multiple poweroff shutdown
261 inst_hook emergency 000 ./hard-off.sh
262 inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
263 )
264
265 # Make server's dracut image
266 $basedir/dracut.sh -l -i "$TESTDIR"/overlay / \
267 -m "dash udev-rules base rootfs-block fs-lib debug kernel-modules watchdog" \
268 -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" \
269 --no-hostonly-cmdline -N \
270 -f "$TESTDIR"/initramfs.server "$KVERSION" || return 1
271
272 # Make client's dracut image
273 $basedir/dracut.sh -l -i "$TESTDIR"/overlay / \
274 -o "plymouth" \
275 -a "debug" \
276 -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" \
277 --no-hostonly-cmdline -N \
278 -f "$TESTDIR"/initramfs.testing "$KVERSION" || return 1
279 }
280
281 kill_server() {
282 if [[ -s "$TESTDIR"/server.pid ]]; then
283 sudo kill -TERM -- $(cat "$TESTDIR"/server.pid)
284 rm -f -- "$TESTDIR"/server.pid
285 fi
286 }
287
288 test_cleanup() {
289 kill_server
290 }
291
292 . "$testdir"/test-functions