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