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