3 # shellcheck disable=SC2034
4 TEST_DESCRIPTION
="root filesystem on NFS with multiple nics with $USE_NETWORK"
6 # Uncomment this to debug failures
7 #DEBUGFAIL="loglevel=7 rd.shell rd.break"
8 #SERIAL="tcp:127.0.0.1:9999"
12 echo "MULTINIC TEST SETUP: Starting DHCP/NFS server"
14 declare -a disk_args
=()
15 # shellcheck disable=SC2034
16 declare -i disk_index
=0
17 qemu_add_drive_args disk_index disk_args
"$TESTDIR"/server.img root
21 -net socket
,listen
=127.0.0.1:12350 \
22 -net nic
,macaddr
=52:54:01:12:34:56,model
=e1000 \
23 -serial "${SERIAL:-"file:$TESTDIR/server.log"}" \
24 -device i6300esb
-watchdog-action poweroff \
25 -append "panic=1 oops=panic softlockup_panic=1 systemd.crash_reboot root=LABEL=dracut rootfstype=ext4 rw console=ttyS0,115200n81 selinux=0" \
26 -initrd "$TESTDIR"/initramfs.server \
27 -pidfile "$TESTDIR"/server.pid
-daemonize ||
return 1
29 chmod 644 -- "$TESTDIR"/server.pid ||
return 1
31 # Cleanup the terminal if we have one
34 if ! [[ $SERIAL ]]; then
36 grep Serving
"$TESTDIR"/server.log
&& break
37 echo "Waiting for the server to startup"
38 tail "$TESTDIR"/server.log
42 echo Sleeping
10 seconds to give the server a
head start
55 echo "CLIENT TEST START: $test_name"
57 declare -a disk_args
=()
58 # shellcheck disable=SC2034
59 declare -i disk_index
=0
60 qemu_add_drive_args disk_index disk_args
"$TESTDIR"/marker.img marker
61 cmdline
="$cmdline rd.net.timeout.dhcp=30"
63 # Invoke KVM and/or QEMU to actually create the target filesystem.
67 -net socket
,connect
=127.0.0.1:12350 \
68 -net nic
,macaddr
=52:54:00:12:34:"$mac1",model
=e1000 \
69 -net nic
,macaddr
=52:54:00:12:34:"$mac2",model
=e1000 \
70 -net nic
,macaddr
=52:54:00:12:34:"$mac3",model
=e1000 \
71 -netdev hubport
,id
=n1
,hubid
=1 \
72 -netdev hubport
,id
=n2
,hubid
=2 \
73 -device e1000
,netdev
=n1
,mac
=52:54:00:12:34:98 \
74 -device e1000
,netdev
=n2
,mac
=52:54:00:12:34:99 \
75 -device i6300esb
-watchdog-action poweroff \
76 -append "quiet panic=1 oops=panic softlockup_panic=1 systemd.crash_reboot rd.shell=0 $cmdline $DEBUGFAIL rd.retry=5 ro console=ttyS0,115200n81 selinux=0 init=/sbin/init rd.debug systemd.log_target=console" \
77 -initrd "$TESTDIR"/initramfs.testing ||
return 1
82 } < "$TESTDIR"/marker.img
84 if [[ $OK != "OK" ]]; then
85 echo "CLIENT TEST END: $test_name [FAILED - BAD EXIT]"
90 if [[ " $IFACES " != *\
$i\
* ]]; then
91 echo "$i not in '$IFACES'"
92 echo "CLIENT TEST END: $test_name [FAILED - BAD IF]"
98 if [[ " $check " != *\
$i\
* ]]; then
99 echo "$i in '$IFACES', but should not be"
100 echo "CLIENT TEST END: $test_name [FAILED - BAD IF]"
105 echo "CLIENT TEST END: $test_name [OK]"
110 if ! run_server
; then
111 echo "Failed to start server" 1>&2
121 # Mac Numbering Scheme
122 # ...:00-02 receive IP adresses all others don't
123 # ...:02 receives a dhcp root-path
126 client_test
"MULTINIC root=nfs BOOTIF=" \
128 "root=nfs:192.168.50.1:/nfs/client BOOTIF=52-54-00-12-34-00" \
131 client_test
"MULTINIC root=nfs BOOTIF= ip=enp0s3:dhcp" \
133 "root=nfs:192.168.50.1:/nfs/client BOOTIF=52-54-00-12-34-00 ip=enp0s2:dhcp" \
134 "enp0s1 enp0s2" ||
return 1
136 # PXE Style BOOTIF= with dhcp root-path
137 client_test
"MULTINIC root=dhcp BOOTIF=" \
139 "root=dhcp BOOTIF=52-54-00-12-34-02" \
142 # Multinic case, where only one nic works
143 client_test
"MULTINIC root=nfs ip=dhcp" \
145 "root=nfs:192.168.50.1:/nfs/client ip=dhcp" \
148 # Require two interfaces
149 client_test
"MULTINIC root=nfs ip=enp0s2:dhcp ip=enp0s3:dhcp bootdev=enp0s2" \
151 "root=nfs:192.168.50.1:/nfs/client ip=enp0s2:dhcp ip=enp0s3:dhcp bootdev=enp0s2" \
152 "enp0s2 enp0s3" ||
return 1
154 # Require three interfaces with dhcp root-path
155 client_test
"MULTINIC root=dhcp ip=enp0s1:dhcp ip=enp0s2:dhcp ip=enp0s3:dhcp bootdev=enp0s3" \
157 "root=dhcp ip=enp0s1:dhcp ip=enp0s2:dhcp ip=enp0s3:dhcp bootdev=enp0s3" \
158 "enp0s1 enp0s2 enp0s3" ||
return 1
160 client_test
"MULTINIC bonding" \
162 "root=nfs:192.168.50.1:/nfs/client ip=bond0:dhcp bond=bond0:enp0s1,enp0s2,enp0s3:mode=balance-rr" \
165 # bridge, where only one interface is actually connected
166 client_test
"MULTINIC bridging" \
168 "root=nfs:192.168.50.1:/nfs/client ip=bridge0:dhcp::52:54:00:12:34:00 bridge=bridge0:enp0s1,enp0s5,enp0s6" \
169 "bridge0" ||
return 1
174 export kernel
=$KVERSION
175 export srcmods
="/lib/modules/$kernel/"
176 rm -rf -- "$TESTDIR"/overlay
178 mkdir
-p "$TESTDIR"/overlay
/source
179 # shellcheck disable=SC2030
180 export initdir
=$TESTDIR/overlay
/source
181 # shellcheck disable=SC1090
182 .
"$basedir"/dracut-init.sh
185 cd "$initdir" ||
exit
186 mkdir
-p dev sys proc run etc var
/run tmp var
/lib
/{dhcpd
,rpcbind
}
187 mkdir
-p var
/lib
/nfs
/{v4recovery
,rpc_pipefs
}
188 chmod 777 var
/lib
/rpcbind var
/lib
/nfs
191 inst_multiple sh
ls shutdown poweroff stty
cat ps
ln ip \
192 dmesg mkdir
cp ping exportfs \
193 modprobe rpc.nfsd rpc.mountd showmount tcpdump \
195 for _terminfodir
in /lib
/terminfo
/etc
/terminfo
/usr
/share
/terminfo
; do
196 if [ -f "${_terminfodir}"/l
/linux
]; then
197 inst_multiple
-o "${_terminfodir}"/l
/linux
201 type -P portmap
> /dev
/null
&& inst_multiple portmap
202 type -P rpcbind
> /dev
/null
&& inst_multiple rpcbind
203 [ -f /etc
/netconfig
] && inst_multiple
/etc
/netconfig
204 type -P dhcpd
> /dev
/null
&& inst_multiple dhcpd
205 instmods nfsd sunrpc ipv6 lockd af_packet
206 inst .
/server-init.sh
/sbin
/init
207 inst_simple
/etc
/os-release
208 inst .
/hosts
/etc
/hosts
209 inst .
/exports
/etc
/exports
210 inst .
/dhcpd.conf
/etc
/dhcpd.conf
211 inst_multiple
-o {,/usr
}/etc
/nsswitch.conf
{,/usr
}/etc
/rpc \
212 {,/usr
}/etc
/protocols
{,/usr
}/etc
/services
213 inst_multiple
-o rpc.idmapd
/etc
/idmapd.conf
215 inst_libdir_file
'libnfsidmap_nsswitch.so*'
216 inst_libdir_file
'libnfsidmap/*.so*'
217 inst_libdir_file
'libnfsidmap*.so*'
220 cat "$dracutsysrootdir"/{,usr
/}etc
/nsswitch.conf
2> /dev
/null \
221 |
sed -e '/^#/d' -e 's/^.*://' -e 's/\[NOTFOUND=return\]//' \
222 |
tr -s '[:space:]' '\n' |
sort -u |
tr -s '[:space:]' '|'
224 _nsslibs
=${_nsslibs#|}
225 _nsslibs
=${_nsslibs%|}
226 inst_libdir_file
-n "$_nsslibs" 'libnss_*.so*'
228 inst
/etc
/passwd
/etc
/passwd
229 inst
/etc
/group
/etc
/group
231 cp -a /etc
/ld.so.conf
* "$initdir"/etc
232 ldconfig
-r "$initdir"
236 # Make client root inside server root
238 # shellcheck disable=SC2030
239 # shellcheck disable=SC2031
240 export initdir
=$TESTDIR/overlay
/source
/nfs
/client
241 # shellcheck disable=SC1090
242 .
"$basedir"/dracut-init.sh
245 cd "$initdir" ||
exit
246 mkdir
-p dev sys proc etc run root usr var
/lib
/nfs
/rpc_pipefs
249 inst_multiple sh shutdown poweroff stty
cat ps
ln ip
dd \
250 mount dmesg mkdir
cp ping grep setsid
ls vi
less cat sync
251 for _terminfodir
in /lib
/terminfo
/etc
/terminfo
/usr
/share
/terminfo
; do
252 if [ -f "${_terminfodir}"/l
/linux
]; then
253 inst_multiple
-o "${_terminfodir}"/l
/linux
258 inst_simple
"${basedir}/modules.d/99base/dracut-lib.sh" "/lib/dracut-lib.sh"
259 inst_simple
"${basedir}/modules.d/99base/dracut-dev-lib.sh" "/lib/dracut-dev-lib.sh"
260 inst_binary
"${basedir}/dracut-util" "/usr/bin/dracut-util"
261 ln -s dracut-util
"${initdir}/usr/bin/dracut-getarg"
262 ln -s dracut-util
"${initdir}/usr/bin/dracut-getargs"
264 inst .
/client-init.sh
/sbin
/init
265 inst_simple
/etc
/os-release
266 inst_multiple
-o {,/usr
}/etc
/nsswitch.conf
267 inst
/etc
/passwd
/etc
/passwd
268 inst
/etc
/group
/etc
/group
270 inst_libdir_file
'libnfsidmap_nsswitch.so*'
271 inst_libdir_file
'libnfsidmap/*.so*'
272 inst_libdir_file
'libnfsidmap*.so*'
275 cat "$dracutsysrootdir"/{,usr
/}etc
/nsswitch.conf
2> /dev
/null \
276 |
sed -e '/^#/d' -e 's/^.*://' -e 's/\[NOTFOUND=return\]//' \
277 |
tr -s '[:space:]' '\n' |
sort -u |
tr -s '[:space:]' '|'
279 _nsslibs
=${_nsslibs#|}
280 _nsslibs
=${_nsslibs%|}
281 inst_libdir_file
-n "$_nsslibs" 'libnss_*.so*'
283 cp -a /etc
/ld.so.conf
* "$initdir"/etc
284 ldconfig
-r "$initdir"
287 # second, install the files needed to make the root filesystem
289 # shellcheck disable=SC2030
290 # shellcheck disable=SC2031
291 export initdir
=$TESTDIR/overlay
292 # shellcheck disable=SC1090
293 .
"$basedir"/dracut-init.sh
294 inst_multiple sfdisk mkfs.ext4 poweroff
cp umount sync
dd
295 inst_hook initqueue
01 .
/create-root.sh
296 inst_hook initqueue
/finished
01 .
/finished-false.sh
299 # create an initramfs that will create the target root filesystem.
300 # We do it this way so that we do not risk trashing the host mdraid
301 # devices, volume groups, encrypted partitions, etc.
302 "$DRACUT" -l -i "$TESTDIR"/overlay
/ \
303 -m "bash rootfs-block kernel-modules qemu" \
304 -d "piix ide-gd_mod ata_piix ext4 sd_mod" \
306 --no-hostonly-cmdline -N \
307 -f "$TESTDIR"/initramfs.makeroot
"$KVERSION" ||
return 1
308 rm -rf -- "$TESTDIR"/overlay
310 declare -a disk_args
=()
311 # shellcheck disable=SC2034
312 declare -i disk_index
=0
313 qemu_add_drive_args disk_index disk_args
"$TESTDIR"/marker.img marker
1
314 qemu_add_drive_args disk_index disk_args
"$TESTDIR"/server.img root
120
316 # Invoke KVM and/or QEMU to actually create the target filesystem.
317 "$testdir"/run-qemu \
319 -append "root=/dev/dracut/root rw rootfstype=ext4 quiet console=ttyS0,115200n81 selinux=0" \
320 -initrd "$TESTDIR"/initramfs.makeroot ||
return 1
321 test_marker_check dracut-root-block-created ||
return 1
323 # Make an overlay with needed tools for the test harness
325 # shellcheck disable=SC2031
326 # shellcheck disable=SC2030
327 export initdir
="$TESTDIR"/overlay
328 mkdir
-p "$TESTDIR"/overlay
329 # shellcheck disable=SC1090
330 .
"$basedir"/dracut-init.sh
331 inst_multiple poweroff shutdown
332 inst_hook shutdown-emergency
000 .
/hard-off.sh
333 inst_hook emergency
000 .
/hard-off.sh
334 inst_simple .
/client.link
/etc
/systemd
/network
/01-client.link
337 inst_hook pre-pivot
85 "$basedir/modules.d/45ifcfg/write-ifcfg.sh"
339 # Make client's dracut image
340 "$DRACUT" -l -i "$TESTDIR"/overlay
/ \
341 -o "ifcfg plymouth" \
342 -a "debug watchdog ${USE_NETWORK}" \
343 --no-hostonly-cmdline -N \
344 -f "$TESTDIR"/initramfs.testing
"$KVERSION" ||
return 1
347 # shellcheck disable=SC2031
348 export initdir
="$TESTDIR"/overlay
349 # shellcheck disable=SC1090
350 .
"$basedir"/dracut-init.sh
351 rm "$initdir"/etc
/systemd
/network
/01-client.link
352 inst_simple .
/server.link
/etc
/systemd
/network
/01-server.link
353 inst_hook pre-mount
99 .
/wait-if-server.sh
355 # Make server's dracut image
356 "$DRACUT" -l -i "$TESTDIR"/overlay
/ \
357 -m "dash rootfs-block debug kernel-modules watchdog qemu network network-legacy" \
358 -d "af_packet piix ide-gd_mod ata_piix ext4 sd_mod nfsv2 nfsv3 nfsv4 nfs_acl nfs_layout_nfsv41_files nfsd e1000 i6300esb ib700wdt" \
359 --no-hostonly-cmdline -N \
360 -f "$TESTDIR"/initramfs.server
"$KVERSION" ||
return 1
365 if [[ -s "$TESTDIR"/server.pid
]]; then
366 kill -TERM -- "$(cat "$TESTDIR"/server.pid)"
367 rm -f -- "$TESTDIR"/server.pid
375 # shellcheck disable=SC1090
376 .
"$testdir"/test-functions