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