2 TEST_DESCRIPTION
="root filesystem on NFS"
4 KVERSION
=${KVERSION-$(uname -r)}
6 # Uncomment this to debug failures
8 #SERIAL="tcp:127.0.0.1:9999"
12 echo "NFS TEST SETUP: Starting DHCP/NFS server"
14 fsck
-a $TESTDIR/server.ext3 ||
return 1
16 -drive format
=raw
,index
=0,media
=disk
,file=$TESTDIR/server.ext3 \
19 -net socket
,listen
=127.0.0.1:12320 \
20 -net nic
,macaddr
=52:54:00:12:34:56,model
=e1000 \
21 ${SERIAL:+-serial "$SERIAL"} \
22 ${SERIAL:--serial file:"$TESTDIR"/server.log} \
23 -watchdog i6300esb
-watchdog-action poweroff \
25 -append "panic=1 systemd.crash_reboot rd.debug loglevel=77 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
30 # Cleanup the terminal if we have one
33 if ! [[ $SERIAL ]]; then
34 echo "Waiting for the server to startup"
36 grep Serving
"$TESTDIR"/server.log
&& break
40 echo Sleeping
10 seconds to give the server a
head start
51 local nfsinfo opts found expected
53 echo "CLIENT TEST START: $test_name"
55 # Need this so kvm-qemu will boot (needs non-/dev/zero local disk)
56 if ! dd if=/dev
/zero of
=$TESTDIR/client.img bs
=1M count
=1; then
57 echo "Unable to make client sda image" 1>&2
62 -drive format
=raw
,index
=0,media
=disk
,file=$TESTDIR/client.img \
63 -m 512M
-smp 2 -nographic \
64 -net nic
,macaddr
=$mac,model
=e1000 \
65 -net socket
,connect
=127.0.0.1:12320 \
66 -watchdog i6300esb
-watchdog-action poweroff \
68 -append "panic=1 systemd.crash_reboot rd.shell=0 $cmdline $DEBUGFAIL rd.debug rd.retry=10 rd.info quiet ro console=ttyS0,115200n81 selinux=0" \
69 -initrd $TESTDIR/initramfs.testing
71 if [[ $?
-ne 0 ]] ||
! grep -F -m 1 -q nfs-OK
$TESTDIR/client.img
; then
72 echo "CLIENT TEST END: $test_name [FAILED - BAD EXIT]"
76 # nfsinfo=( server:/path nfs{,4} options )
77 nfsinfo
=($
(awk '{print $2, $3, $4; exit}' $TESTDIR/client.img
))
79 if [[ "${nfsinfo[0]%%:*}" != "$server" ]]; then
80 echo "CLIENT TEST INFO: got server: ${nfsinfo[0]%%:*}"
81 echo "CLIENT TEST INFO: expected server: $server"
82 echo "CLIENT TEST END: $test_name [FAILED - WRONG SERVER]"
88 if [[ ${check_opt:0:1} = '-' ]]; then
90 check_opt
=${check_opt:1}
95 if [[ ${opts%%,*} = $check_opt ]]; then
102 if [[ $found -ne $expected ]]; then
103 echo "CLIENT TEST INFO: got options: ${nfsinfo[2]%%:*}"
104 if [[ $expected -eq 0 ]]; then
105 echo "CLIENT TEST INFO: did not expect: $check_opt"
106 echo "CLIENT TEST END: $test_name [FAILED - UNEXPECTED OPTION]"
108 echo "CLIENT TEST INFO: missing: $check_opt"
109 echo "CLIENT TEST END: $test_name [FAILED - MISSING OPTION]"
114 echo "CLIENT TEST END: $test_name [OK]"
119 # MAC numbering scheme:
120 # NFSv3: last octect starts at 0x00 and works up
121 # NFSv4: last octect starts at 0x80 and works up
123 client_test
"NFSv3 root=dhcp DHCP path only" 52:54:00:12:34:00 \
124 "root=dhcp" 192.168.50.1 -wsize=4096 ||
return 1
126 if [[ "$(systemctl --version)" != *"systemd 230"* ]] 2>/dev
/null
; then
127 client_test
"NFSv3 Legacy root=/dev/nfs nfsroot=IP:path" 52:54:00:12:34:01 \
128 "root=/dev/nfs nfsroot=192.168.50.1:/nfs/client" 192.168.50.1 -wsize=4096 ||
return 1
130 client_test
"NFSv3 Legacy root=/dev/nfs DHCP path only" 52:54:00:12:34:00 \
131 "root=/dev/nfs" 192.168.50.1 -wsize=4096 ||
return 1
133 client_test
"NFSv3 Legacy root=/dev/nfs DHCP IP:path" 52:54:00:12:34:01 \
134 "root=/dev/nfs" 192.168.50.2 -wsize=4096 ||
return 1
137 client_test
"NFSv3 root=dhcp DHCP IP:path" 52:54:00:12:34:01 \
138 "root=dhcp" 192.168.50.2 -wsize=4096 ||
return 1
140 client_test
"NFSv3 root=dhcp DHCP proto:IP:path" 52:54:00:12:34:02 \
141 "root=dhcp" 192.168.50.3 -wsize=4096 ||
return 1
143 client_test
"NFSv3 root=dhcp DHCP proto:IP:path:options" 52:54:00:12:34:03 \
144 "root=dhcp" 192.168.50.3 wsize
=4096 ||
return 1
146 client_test
"NFSv3 root=nfs:..." 52:54:00:12:34:04 \
147 "root=nfs:192.168.50.1:/nfs/client" 192.168.50.1 -wsize=4096 ||
return 1
149 client_test
"NFSv3 Bridge root=nfs:..." 52:54:00:12:34:04 \
150 "root=nfs:192.168.50.1:/nfs/client bridge net.ifnames=0" 192.168.50.1 -wsize=4096 ||
return 1
152 client_test
"NFSv3 Legacy root=IP:path" 52:54:00:12:34:04 \
153 "root=192.168.50.1:/nfs/client" 192.168.50.1 -wsize=4096 ||
return 1
155 # This test must fail: nfsroot= requires root=/dev/nfs
156 client_test
"NFSv3 Invalid root=dhcp nfsroot=/nfs/client" 52:54:00:12:34:04 \
157 "root=dhcp nfsroot=/nfs/client failme rd.debug" 192.168.50.1 -wsize=4096 && return 1
159 client_test
"NFSv3 root=dhcp DHCP path,options" \
160 52:54:00:12:34:05 "root=dhcp" 192.168.50.1 wsize
=4096 ||
return 1
162 client_test
"NFSv3 Bridge Customized root=dhcp DHCP path,options" \
163 52:54:00:12:34:05 "root=dhcp bridge=foobr0:ens3" 192.168.50.1 wsize
=4096 ||
return 1
165 client_test
"NFSv3 root=dhcp DHCP IP:path,options" \
166 52:54:00:12:34:06 "root=dhcp" 192.168.50.2 wsize
=4096 ||
return 1
168 client_test
"NFSv3 root=dhcp DHCP proto:IP:path,options" \
169 52:54:00:12:34:07 "root=dhcp" 192.168.50.3 wsize
=4096 ||
return 1
175 # There is a mandatory 90 second recovery when starting the NFSv4
176 # server, so put these later in the list to avoid a pause when doing
179 client_test
"NFSv4 root=dhcp DHCP proto:IP:path" 52:54:00:12:34:82 \
180 "root=dhcp" 192.168.50.3 -wsize=4096 ||
return 1
182 client_test
"NFSv4 root=dhcp DHCP proto:IP:path:options" 52:54:00:12:34:83 \
183 "root=dhcp" 192.168.50.3 wsize
=4096 ||
return 1
185 client_test
"NFSv4 root=nfs4:..." 52:54:00:12:34:84 \
186 "root=nfs4:192.168.50.1:/client" 192.168.50.1 \
187 -wsize=4096 ||
return 1
189 client_test
"NFSv4 root=dhcp DHCP proto:IP:path,options" \
190 52:54:00:12:34:87 "root=dhcp" 192.168.50.3 wsize
=4096 ||
return 1
196 if [[ -s server.pid
]]; then
197 sudo
kill -TERM $
(cat $TESTDIR/server.pid
)
198 rm -f -- $TESTDIR/server.pid
201 if ! run_server
; then
202 echo "Failed to start server" 1>&2
211 if [[ -s $TESTDIR/server.pid
]]; then
212 sudo
kill -TERM $
(cat $TESTDIR/server.pid
)
213 rm -f -- $TESTDIR/server.pid
221 dd if=/dev
/null of
=$TESTDIR/server.ext3 bs
=1M seek
=120
222 mke2fs
-j -F $TESTDIR/server.ext3
224 sudo mount
-o loop
$TESTDIR/server.ext3
$TESTDIR/mnt
227 export kernel
=$KVERSION
228 export srcmods
="/lib/modules/$kernel/"
232 export initdir
=$TESTDIR/mnt
233 .
$basedir/dracut-init.sh
235 for _f
in modules.
builtin.bin modules.
builtin; do
236 [[ $srcmods/$_f ]] && break
238 dfatal
"No modules.builtin.bin and modules.builtin found!"
242 for _f
in modules.
builtin.bin modules.
builtin modules.order
; do
243 [[ $srcmods/$_f ]] && inst_simple
"$srcmods/$_f" "/lib/modules/$kernel/$_f"
246 inst_multiple sh
ls shutdown poweroff stty
cat ps
ln ip \
247 dmesg mkdir
cp ping exportfs \
248 modprobe rpc.nfsd rpc.mountd showmount tcpdump \
249 /etc
/services
sleep mount
chmod rm
250 for _terminfodir
in /lib
/terminfo
/etc
/terminfo
/usr
/share
/terminfo
; do
251 [ -f ${_terminfodir}/l
/linux
] && break
253 inst_multiple
-o ${_terminfodir}/l
/linux
254 type -P portmap
>/dev
/null
&& inst_multiple portmap
255 type -P rpcbind
>/dev
/null
&& inst_multiple rpcbind
256 [ -f /etc
/netconfig
] && inst_multiple
/etc
/netconfig
257 type -P dhcpd
>/dev
/null
&& inst_multiple dhcpd
258 [ -x /usr
/sbin
/dhcpd3
] && inst
/usr
/sbin
/dhcpd3
/usr
/sbin
/dhcpd
259 instmods nfsd sunrpc ipv6 lockd af_packet
260 inst .
/server-init.sh
/sbin
/init
261 inst_simple
/etc
/os-release
262 inst .
/hosts
/etc
/hosts
263 inst .
/exports
/etc
/exports
264 inst .
/dhcpd.conf
/etc
/dhcpd.conf
265 inst_multiple
/etc
/nsswitch.conf
/etc
/rpc
/etc
/protocols
266 inst_multiple rpc.idmapd
/etc
/idmapd.conf
268 inst_libdir_file
'libnfsidmap_nsswitch.so*'
269 inst_libdir_file
'libnfsidmap/*.so*'
270 inst_libdir_file
'libnfsidmap*.so*'
272 _nsslibs
=$
(sed -e '/^#/d' -e 's/^.*://' -e 's/\[NOTFOUND=return\]//' /etc
/nsswitch.conf \
273 |
tr -s '[:space:]' '\n' |
sort -u |
tr -s '[:space:]' '|')
274 _nsslibs
=${_nsslibs#|}
275 _nsslibs
=${_nsslibs%|}
277 inst_libdir_file
-n "$_nsslibs" 'libnss_*.so*'
281 mkdir
-p dev sys proc run etc var
/run tmp var
/lib
/{dhcpd
,rpcbind
}
282 mkdir
-p var
/lib
/nfs
/{v4recovery
,rpc_pipefs
}
283 chmod 777 var
/lib
/rpcbind var
/lib
/nfs
285 inst
/etc
/nsswitch.conf
/etc
/nsswitch.conf
287 inst
/etc
/passwd
/etc
/passwd
288 inst
/etc
/group
/etc
/group
290 cp -a /etc
/ld.so.conf
* $initdir/etc
291 sudo ldconfig
-r "$initdir"
296 # Make client root inside server root
298 export initdir
=$TESTDIR/mnt
/nfs
/client
299 .
$basedir/dracut-init.sh
301 inst_multiple sh shutdown poweroff stty
cat ps
ln ip \
302 mount dmesg mkdir
cp ping grep setsid
ls vi
/etc
/virc
less cat
303 for _terminfodir
in /lib
/terminfo
/etc
/terminfo
/usr
/share
/terminfo
; do
304 [ -f ${_terminfodir}/l
/linux
] && break
306 inst_multiple
-o ${_terminfodir}/l
/linux
307 inst .
/client-init.sh
/sbin
/init
308 inst_simple
/etc
/os-release
311 mkdir
-p dev sys proc etc run
312 mkdir
-p var
/lib
/nfs
/rpc_pipefs
313 mkdir
-p root usr
/bin usr
/lib usr
/lib64 usr
/sbin
314 for i
in bin sbin lib lib64
; do
318 inst
/etc
/nsswitch.conf
/etc
/nsswitch.conf
319 inst
/etc
/passwd
/etc
/passwd
320 inst
/etc
/group
/etc
/group
322 inst_libdir_file
'libnfsidmap_nsswitch.so*'
323 inst_libdir_file
'libnfsidmap/*.so*'
324 inst_libdir_file
'libnfsidmap*.so*'
326 _nsslibs
=$
(sed -e '/^#/d' -e 's/^.*://' -e 's/\[NOTFOUND=return\]//' /etc
/nsswitch.conf \
327 |
tr -s '[:space:]' '\n' |
sort -u |
tr -s '[:space:]' '|')
328 _nsslibs
=${_nsslibs#|}
329 _nsslibs
=${_nsslibs%|}
331 inst_libdir_file
-n "$_nsslibs" 'libnss_*.so*'
333 cp -a /etc
/ld.so.conf
* $initdir/etc
334 sudo ldconfig
-r "$initdir"
337 mkdir
-p $TESTDIR/mnt
/nfs
/nfs3-5
338 mkdir
-p $TESTDIR/mnt
/nfs
/ip
/192.168.50.101
339 mkdir
-p $TESTDIR/mnt
/nfs
/tftpboot
/nfs4-5
341 sudo umount
$TESTDIR/mnt
342 rm -fr -- $TESTDIR/mnt
344 # Make an overlay with needed tools for the test harness
346 export initdir
=$TESTDIR/overlay
347 .
$basedir/dracut-init.sh
348 mkdir
$TESTDIR/overlay
349 inst_multiple poweroff shutdown
350 inst_hook shutdown-emergency
000 .
/hard-off.sh
351 inst_hook emergency
000 .
/hard-off.sh
352 inst_simple .
/99-idesymlinks.rules
/etc
/udev
/rules.d
/99-idesymlinks.rules
353 inst_simple .
/99-default.link
/etc
/systemd
/network
/99-default.link
356 # Make server's dracut image
357 $basedir/dracut.sh
-l -i $TESTDIR/overlay
/ \
358 -m "dash udev-rules base rootfs-block fs-lib debug kernel-modules watchdog qemu" \
359 -d "af_packet piix ide-gd_mod ata_piix ext3 sd_mod e1000 i6300esb" \
360 --no-hostonly-cmdline -N \
361 -f $TESTDIR/initramfs.server
$KVERSION ||
return 1
363 # Make client's dracut image
364 $basedir/dracut.sh
-l -i $TESTDIR/overlay
/ \
366 -a "debug watchdog" \
367 -d "af_packet piix ide-gd_mod ata_piix sd_mod e1000 nfs sunrpc i6300esb" \
368 --no-hostonly-cmdline -N \
369 -f $TESTDIR/initramfs.testing
$KVERSION ||
return 1
373 if [[ -s $TESTDIR/server.pid
]]; then
374 sudo
kill -TERM $
(cat $TESTDIR/server.pid
)
375 rm -f -- $TESTDIR/server.pid
379 .
$testdir/test-functions