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 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 echo Sleeping
10 seconds to give the server a
head start
43 local nfsinfo opts found expected
45 echo "CLIENT TEST START: $test_name"
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
54 -drive format
=raw
,index
=0,media
=disk
,file=$TESTDIR/client.img \
55 -m 512M
-smp 2 -nographic \
56 -net nic
,macaddr
=$mac,model
=e1000 \
57 -net socket
,connect
=127.0.0.1:12320 \
58 -watchdog i6300esb
-watchdog-action poweroff \
60 -append "panic=1 rd.shell=0 $cmdline $DEBUGFAIL rd.debug rd.retry=10 rd.info quiet ro console=ttyS0,115200n81 selinux=0" \
61 -initrd $TESTDIR/initramfs.testing
63 if [[ $?
-ne 0 ]] ||
! grep -F -m 1 -q nfs-OK
$TESTDIR/client.img
; then
64 echo "CLIENT TEST END: $test_name [FAILED - BAD EXIT]"
68 # nfsinfo=( server:/path nfs{,4} options )
69 nfsinfo
=($
(awk '{print $2, $3, $4; exit}' $TESTDIR/client.img
))
71 if [[ "${nfsinfo[0]%%:*}" != "$server" ]]; then
72 echo "CLIENT TEST INFO: got server: ${nfsinfo[0]%%:*}"
73 echo "CLIENT TEST INFO: expected server: $server"
74 echo "CLIENT TEST END: $test_name [FAILED - WRONG SERVER]"
80 if [[ ${check_opt:0:1} = '-' ]]; then
82 check_opt
=${check_opt:1}
87 if [[ ${opts%%,*} = $check_opt ]]; then
94 if [[ $found -ne $expected ]]; then
95 echo "CLIENT TEST INFO: got options: ${nfsinfo[2]%%:*}"
96 if [[ $expected -eq 0 ]]; then
97 echo "CLIENT TEST INFO: did not expect: $check_opt"
98 echo "CLIENT TEST END: $test_name [FAILED - UNEXPECTED OPTION]"
100 echo "CLIENT TEST INFO: missing: $check_opt"
101 echo "CLIENT TEST END: $test_name [FAILED - MISSING OPTION]"
106 echo "CLIENT TEST END: $test_name [OK]"
111 # MAC numbering scheme:
112 # NFSv3: last octect starts at 0x00 and works up
113 # NFSv4: last octect starts at 0x80 and works up
115 client_test
"NFSv3 root=dhcp DHCP path only" 52:54:00:12:34:00 \
116 "root=dhcp" 192.168.50.1 -wsize=4096 ||
return 1
118 if [[ "$(systemctl --version)" != *"systemd 230"* ]] 2>/dev
/null
; then
119 client_test
"NFSv3 Legacy root=/dev/nfs nfsroot=IP:path" 52:54:00:12:34:01 \
120 "root=/dev/nfs nfsroot=192.168.50.1:/nfs/client" 192.168.50.1 -wsize=4096 ||
return 1
122 client_test
"NFSv3 Legacy root=/dev/nfs DHCP path only" 52:54:00:12:34:00 \
123 "root=/dev/nfs" 192.168.50.1 -wsize=4096 ||
return 1
125 client_test
"NFSv3 Legacy root=/dev/nfs DHCP IP:path" 52:54:00:12:34:01 \
126 "root=/dev/nfs" 192.168.50.2 -wsize=4096 ||
return 1
129 client_test
"NFSv3 root=dhcp DHCP IP:path" 52:54:00:12:34:01 \
130 "root=dhcp" 192.168.50.2 -wsize=4096 ||
return 1
132 client_test
"NFSv3 root=dhcp DHCP proto:IP:path" 52:54:00:12:34:02 \
133 "root=dhcp" 192.168.50.3 -wsize=4096 ||
return 1
135 client_test
"NFSv3 root=dhcp DHCP proto:IP:path:options" 52:54:00:12:34:03 \
136 "root=dhcp" 192.168.50.3 wsize
=4096 ||
return 1
138 client_test
"NFSv3 root=nfs:..." 52:54:00:12:34:04 \
139 "root=nfs:192.168.50.1:/nfs/client" 192.168.50.1 -wsize=4096 ||
return 1
141 client_test
"NFSv3 Bridge root=nfs:..." 52:54:00:12:34:04 \
142 "root=nfs:192.168.50.1:/nfs/client bridge net.ifnames=0" 192.168.50.1 -wsize=4096 ||
return 1
144 client_test
"NFSv3 Legacy root=IP:path" 52:54:00:12:34:04 \
145 "root=192.168.50.1:/nfs/client" 192.168.50.1 -wsize=4096 ||
return 1
147 # This test must fail: nfsroot= requires root=/dev/nfs
148 client_test
"NFSv3 Invalid root=dhcp nfsroot=/nfs/client" 52:54:00:12:34:04 \
149 "root=dhcp nfsroot=/nfs/client failme rd.debug" 192.168.50.1 -wsize=4096 && return 1
151 client_test
"NFSv3 root=dhcp DHCP path,options" \
152 52:54:00:12:34:05 "root=dhcp" 192.168.50.1 wsize
=4096 ||
return 1
154 client_test
"NFSv3 Bridge Customized root=dhcp DHCP path,options" \
155 52:54:00:12:34:05 "root=dhcp bridge=foobr0:ens3" 192.168.50.1 wsize
=4096 ||
return 1
157 client_test
"NFSv3 root=dhcp DHCP IP:path,options" \
158 52:54:00:12:34:06 "root=dhcp" 192.168.50.2 wsize
=4096 ||
return 1
160 client_test
"NFSv3 root=dhcp DHCP proto:IP:path,options" \
161 52:54:00:12:34:07 "root=dhcp" 192.168.50.3 wsize
=4096 ||
return 1
167 # There is a mandatory 90 second recovery when starting the NFSv4
168 # server, so put these later in the list to avoid a pause when doing
171 client_test
"NFSv4 root=dhcp DHCP proto:IP:path" 52:54:00:12:34:82 \
172 "root=dhcp" 192.168.50.3 -wsize=4096 ||
return 1
174 client_test
"NFSv4 root=dhcp DHCP proto:IP:path:options" 52:54:00:12:34:83 \
175 "root=dhcp" 192.168.50.3 wsize
=4096 ||
return 1
177 client_test
"NFSv4 root=nfs4:..." 52:54:00:12:34:84 \
178 "root=nfs4:192.168.50.1:/client" 192.168.50.1 \
179 -wsize=4096 ||
return 1
181 client_test
"NFSv4 root=dhcp DHCP proto:IP:path,options" \
182 52:54:00:12:34:87 "root=dhcp" 192.168.50.3 wsize
=4096 ||
return 1
188 if [[ -s server.pid
]]; then
189 sudo
kill -TERM $
(cat $TESTDIR/server.pid
)
190 rm -f -- $TESTDIR/server.pid
193 if ! run_server
; then
194 echo "Failed to start server" 1>&2
203 if [[ -s $TESTDIR/server.pid
]]; then
204 sudo
kill -TERM $
(cat $TESTDIR/server.pid
)
205 rm -f -- $TESTDIR/server.pid
213 dd if=/dev
/null of
=$TESTDIR/server.ext3 bs
=1M seek
=120
214 mke2fs
-j -F $TESTDIR/server.ext3
216 sudo mount
-o loop
$TESTDIR/server.ext3
$TESTDIR/mnt
219 export kernel
=$KVERSION
220 export srcmods
="/lib/modules/$kernel/"
224 export initdir
=$TESTDIR/mnt
225 .
$basedir/dracut-init.sh
227 for _f
in modules.
builtin.bin modules.
builtin; do
228 [[ $srcmods/$_f ]] && break
230 dfatal
"No modules.builtin.bin and modules.builtin found!"
234 for _f
in modules.
builtin.bin modules.
builtin modules.order
; do
235 [[ $srcmods/$_f ]] && inst_simple
"$srcmods/$_f" "/lib/modules/$kernel/$_f"
238 inst_multiple sh
ls shutdown poweroff stty
cat ps
ln ip \
239 dmesg mkdir
cp ping exportfs \
240 modprobe rpc.nfsd rpc.mountd showmount tcpdump \
241 /etc
/services
sleep mount
chmod rm
242 for _terminfodir
in /lib
/terminfo
/etc
/terminfo
/usr
/share
/terminfo
; do
243 [ -f ${_terminfodir}/l
/linux
] && break
245 inst_multiple
-o ${_terminfodir}/l
/linux
246 type -P portmap
>/dev
/null
&& inst_multiple portmap
247 type -P rpcbind
>/dev
/null
&& inst_multiple rpcbind
248 [ -f /etc
/netconfig
] && inst_multiple
/etc
/netconfig
249 type -P dhcpd
>/dev
/null
&& inst_multiple dhcpd
250 [ -x /usr
/sbin
/dhcpd3
] && inst
/usr
/sbin
/dhcpd3
/usr
/sbin
/dhcpd
251 instmods nfsd sunrpc ipv6 lockd af_packet
252 inst .
/server-init.sh
/sbin
/init
253 inst_simple
/etc
/os-release
254 inst .
/hosts
/etc
/hosts
255 inst .
/exports
/etc
/exports
256 inst .
/dhcpd.conf
/etc
/dhcpd.conf
257 inst_multiple
/etc
/nsswitch.conf
/etc
/rpc
/etc
/protocols
258 inst_multiple rpc.idmapd
/etc
/idmapd.conf
260 inst_libdir_file
'libnfsidmap_nsswitch.so*'
261 inst_libdir_file
'libnfsidmap/*.so*'
262 inst_libdir_file
'libnfsidmap*.so*'
264 _nsslibs
=$
(sed -e '/^#/d' -e 's/^.*://' -e 's/\[NOTFOUND=return\]//' /etc
/nsswitch.conf \
265 |
tr -s '[:space:]' '\n' |
sort -u |
tr -s '[:space:]' '|')
266 _nsslibs
=${_nsslibs#|}
267 _nsslibs
=${_nsslibs%|}
269 inst_libdir_file
-n "$_nsslibs" 'libnss_*.so*'
273 mkdir
-p dev sys proc run etc var
/run tmp var
/lib
/{dhcpd
,rpcbind
}
274 mkdir
-p var
/lib
/nfs
/{v4recovery
,rpc_pipefs
}
275 chmod 777 var
/lib
/rpcbind var
/lib
/nfs
277 inst
/etc
/nsswitch.conf
/etc
/nsswitch.conf
279 inst
/etc
/passwd
/etc
/passwd
280 inst
/etc
/group
/etc
/group
282 cp -a /etc
/ld.so.conf
* $initdir/etc
283 sudo ldconfig
-r "$initdir"
288 # Make client root inside server root
290 export initdir
=$TESTDIR/mnt
/nfs
/client
291 .
$basedir/dracut-init.sh
293 inst_multiple sh shutdown poweroff stty
cat ps
ln ip \
294 mount dmesg mkdir
cp ping grep setsid
ls vi
/etc
/virc
less cat
295 for _terminfodir
in /lib
/terminfo
/etc
/terminfo
/usr
/share
/terminfo
; do
296 [ -f ${_terminfodir}/l
/linux
] && break
298 inst_multiple
-o ${_terminfodir}/l
/linux
299 inst .
/client-init.sh
/sbin
/init
300 inst_simple
/etc
/os-release
303 mkdir
-p dev sys proc etc run
304 mkdir
-p var
/lib
/nfs
/rpc_pipefs
305 mkdir
-p root usr
/bin usr
/lib usr
/lib64 usr
/sbin
306 for i
in bin sbin lib lib64
; do
310 inst
/etc
/nsswitch.conf
/etc
/nsswitch.conf
311 inst
/etc
/passwd
/etc
/passwd
312 inst
/etc
/group
/etc
/group
314 inst_libdir_file
'libnfsidmap_nsswitch.so*'
315 inst_libdir_file
'libnfsidmap/*.so*'
316 inst_libdir_file
'libnfsidmap*.so*'
318 _nsslibs
=$
(sed -e '/^#/d' -e 's/^.*://' -e 's/\[NOTFOUND=return\]//' /etc
/nsswitch.conf \
319 |
tr -s '[:space:]' '\n' |
sort -u |
tr -s '[:space:]' '|')
320 _nsslibs
=${_nsslibs#|}
321 _nsslibs
=${_nsslibs%|}
323 inst_libdir_file
-n "$_nsslibs" 'libnss_*.so*'
325 cp -a /etc
/ld.so.conf
* $initdir/etc
326 sudo ldconfig
-r "$initdir"
329 mkdir
-p $TESTDIR/mnt
/nfs
/nfs3-5
330 mkdir
-p $TESTDIR/mnt
/nfs
/ip
/192.168.50.101
331 mkdir
-p $TESTDIR/mnt
/nfs
/tftpboot
/nfs4-5
333 sudo umount
$TESTDIR/mnt
334 rm -fr -- $TESTDIR/mnt
336 # Make an overlay with needed tools for the test harness
338 export initdir
=$TESTDIR/overlay
339 .
$basedir/dracut-init.sh
340 mkdir
$TESTDIR/overlay
341 inst_multiple poweroff shutdown
342 inst_hook shutdown-emergency
000 .
/hard-off.sh
343 inst_hook emergency
000 .
/hard-off.sh
344 inst_simple .
/99-idesymlinks.rules
/etc
/udev
/rules.d
/99-idesymlinks.rules
347 # Make server's dracut image
348 $basedir/dracut.sh
-l -i $TESTDIR/overlay
/ \
349 -m "dash udev-rules base rootfs-block fs-lib debug kernel-modules watchdog" \
350 -d "af_packet piix ide-gd_mod ata_piix ext3 sd_mod e1000 i6300esb" \
351 --no-hostonly-cmdline -N \
352 -f $TESTDIR/initramfs.server
$KVERSION ||
return 1
354 # Make client's dracut image
355 $basedir/dracut.sh
-l -i $TESTDIR/overlay
/ \
357 -a "debug watchdog" \
358 -d "af_packet piix ide-gd_mod ata_piix sd_mod e1000 nfs sunrpc i6300esb" \
359 --no-hostonly-cmdline -N \
360 -f $TESTDIR/initramfs.testing
$KVERSION ||
return 1
364 if [[ -s $TESTDIR/server.pid
]]; then
365 sudo
kill -TERM $
(cat $TESTDIR/server.pid
)
366 rm -f -- $TESTDIR/server.pid
370 .
$testdir/test-functions