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