]> git.ipfire.org Git - thirdparty/dracut.git/blame - test/TEST-20-NFS/test.sh
NBD test: add more option parsing tests
[thirdparty/dracut.git] / test / TEST-20-NFS / test.sh
CommitLineData
528277f3
DD
1#!/bin/bash
2TEST_DESCRIPTION="root filesystem on NFS"
3
4KVERSION=${KVERSION-$(uname -r)}
528277f3 5
ae227ca8
DD
6# Uncomment this to debug failures
7#DEBUGFAIL="rdinitdebug rdnetdebug"
8
cc75acdc 9run_server() {
528277f3 10 # Start server first
cc75acdc
DD
11 echo "NFS TEST SETUP: Starting DHCP/NFS server"
12
528277f3
DD
13 $testdir/run-qemu -hda server.ext2 -m 512M -nographic \
14 -net nic,macaddr=52:54:00:12:34:56,model=e1000 \
15 -net socket,mcast=230.0.0.1:1234 \
16 -serial udp:127.0.0.1:9999 \
17 -kernel /boot/vmlinuz-$KVERSION \
18 -append "root=/dev/sda rw quiet console=ttyS0,115200n81" \
cc75acdc
DD
19 -initrd initramfs.server -pidfile server.pid -daemonize || return 1
20 sudo chmod 644 server.pid || return 1
528277f3 21
d462f6dc
DD
22 # Cleanup the terminal if we have one
23 tty -s && stty sane
24
528277f3
DD
25 echo Sleeping 10 seconds to give the server a head start
26 sleep 10
cc75acdc
DD
27}
28
29client_test() {
30 local test_name="$1"
31 local mac=$2
32 local cmdline="$3"
574f2965 33 local server="$4"
9f25b834
DD
34 local check_opt="$5"
35 local nfsinfo opts found expected
cc75acdc
DD
36
37 echo "CLIENT TEST START: $test_name"
38
39 # Need this so kvm-qemu will boot (needs non-/dev/zero local disk)
40 if ! dd if=/dev/zero of=client.img bs=1M count=1; then
41 echo "Unable to make client sda image" 1>&2
42 return 1
43 fi
528277f3
DD
44
45 $testdir/run-qemu -hda client.img -m 512M -nographic \
cc75acdc 46 -net nic,macaddr=$mac,model=e1000 \
528277f3
DD
47 -net socket,mcast=230.0.0.1:1234 \
48 -kernel /boot/vmlinuz-$KVERSION \
ae227ca8 49 -append "$cmdline $DEBUGFAIL ro quiet console=ttyS0,115200n81" \
528277f3
DD
50 -initrd initramfs.testing
51
574f2965
DD
52 if [[ $? -ne 0 ]] || ! grep -m 1 -q nfs-OK client.img; then
53 echo "CLIENT TEST END: $test_name [FAILED - BAD EXIT]"
cc75acdc
DD
54 return 1
55 fi
574f2965
DD
56
57 # nfsinfo=( server:/path nfs{,4} options )
58 nfsinfo=($(awk '{print $2, $3, $4; exit}' client.img))
59
60 if [[ "${nfsinfo[0]%%:*}" != "$server" ]]; then
9f25b834
DD
61 echo "CLIENT TEST INFO: got server: ${nfsinfo[0]%%:*}"
62 echo "CLIENT TEST INFO: expected server: $server"
574f2965
DD
63 echo "CLIENT TEST END: $test_name [FAILED - WRONG SERVER]"
64 return 1
65 fi
66
9f25b834
DD
67 found=0
68 expected=1
69 if [[ ${check_opt:0:1} == '-' ]]; then
70 expected=0
71 check_opt=${check_opt:1}
72 fi
73
74 opts=${nfsinfo[2]},
75 while [[ $opts ]]; do
76 if [[ ${opts%%,*} == $check_opt ]]; then
77 found=1
78 break
79 fi
80 opts=${opts#*,}
81 done
82
83 if [[ $found -ne $expected ]]; then
84 echo "CLIENT TEST INFO: got options: ${nfsinfo[2]%%:*}"
85 if [[ $expected -eq 0 ]]; then
86 echo "CLIENT TEST INFO: did not expect: $check_opt"
87 echo "CLIENT TEST END: $test_name [FAILED - UNEXPECTED OPTION]"
88 else
89 echo "CLIENT TEST INFO: missing: $check_opt"
90 echo "CLIENT TEST END: $test_name [FAILED - MISSING OPTION]"
91 fi
92 return 1
93 fi
94
574f2965
DD
95 echo "CLIENT TEST END: $test_name [OK]"
96 return 0
cc75acdc
DD
97}
98
6b6805b8 99test_nfsv3() {
da2643fa
DD
100 # MAC numbering scheme:
101 # NFSv3: last octect starts at 0x00 and works up
102 # NFSv4: last octect starts at 0x80 and works up
103
ae227ca8 104 client_test "NFSv3 root=dhcp DHCP path only" 52:54:00:12:34:00 \
9f25b834 105 "root=dhcp" 192.168.50.1 -wsize=4096 || return 1
ae227ca8
DD
106
107 client_test "NFSv3 root=nfs DHCP path only" 52:54:00:12:34:00 \
9f25b834 108 "root=nfs" 192.168.50.1 -wsize=4096 || return 1
ae227ca8
DD
109
110 client_test "NFSv3 root=/dev/nfs DHCP path only" 52:54:00:12:34:00 \
9f25b834 111 "root=/dev/nfs" 192.168.50.1 -wsize=4096 || return 1
ae227ca8
DD
112
113 client_test "NFSv3 root=dhcp DHCP IP:path" 52:54:00:12:34:01 \
9f25b834 114 "root=dhcp" 192.168.50.2 -wsize=4096 || return 1
ae227ca8
DD
115
116 client_test "NFSv3 root=nfs DHCP IP:path" 52:54:00:12:34:01 \
9f25b834 117 "root=nfs" 192.168.50.2 -wsize=4096 || return 1
ae227ca8
DD
118
119 client_test "NFSv3 root=/dev/nfs DHCP IP:path" 52:54:00:12:34:01 \
9f25b834 120 "root=/dev/nfs" 192.168.50.2 -wsize=4096 || return 1
ae227ca8
DD
121
122 client_test "NFSv3 root=dhcp DHCP proto:IP:path" 52:54:00:12:34:02 \
9f25b834
DD
123 "root=dhcp" 192.168.50.3 -wsize=4096 || return 1
124
da2643fa 125 client_test "NFSv3 root=dhcp DHCP proto:IP:path:options" 52:54:00:12:34:03 \
9f25b834 126 "root=dhcp" 192.168.50.3 wsize=4096 || return 1
ae227ca8 127
bed87ed9
DD
128 client_test "NFSv3 root=nfs:..." 52:54:00:12:34:04 \
129 "root=nfs:192.168.50.1:/nfs/client" 192.168.50.1 -wsize=4096 || return 1
130
0000e181
DD
131 client_test "NFSv3 nfsroot=/nfs/client" 52:54:00:12:34:04 \
132 "nfsroot=/nfs/client" 192.168.50.1 -wsize=4096 || return 1
133
134 client_test "NFSv3 nfsroot=192.168.50.2:/nfs/client" 52:54:00:12:34:04 \
135 "nfsroot=192.168.50.2:/nfs/client" 192.168.50.2 -wsize=4096 || return 1
136
137 client_test "NFSv3 root=dhcp nfsroot=/nfs/client" 52:54:00:12:34:04 \
138 "root=dhcp nfsroot=/nfs/client" 192.168.50.1 -wsize=4096 || return 1
139
140 client_test "NFSv3 root=nfs nfsroot=/nfs/client" 52:54:00:12:34:04 \
141 "root=nfs nfsroot=/nfs/client" 192.168.50.1 -wsize=4096 || return 1
142
abe9ccc8
DD
143 client_test "NFSv3 root=nfs nfsroot=/nfs/%s" 52:54:00:12:34:04 \
144 "root=nfs nfsroot=/nfs/%s" 192.168.50.1 -wsize=4096 || return 1
145
146 client_test "NFSv3 root=nfs nfsroot=/nfs/ip/%s no host name (use IP)" \
147 52:54:00:12:34:7f \
148 "root=nfs nfsroot=/nfs/ip/%s \
149 ip=192.168.50.101:192.168.50.1::255.255.255.0::eth0:static" \
150 192.168.50.1 -wsize=4096 || return 1
151
0000e181
DD
152 client_test "NFSv3 root=nfs nfsroot=/nfs/client,wsize=4096" \
153 52:54:00:12:34:04 "root=nfs nfsroot=/nfs/client,wsize=4096" \
154 192.168.50.1 wsize=4096 || return 1
155
156 client_test "NFSv3 root=nfs DHCP path,options" \
157 52:54:00:12:34:05 "root=dhcp" 192.168.50.1 wsize=4096 || return 1
158
159 client_test "NFSv3 root=dhcp DHCP IP:path,options" \
160 52:54:00:12:34:06 "root=dhcp" 192.168.50.2 wsize=4096 || return 1
161
162 client_test "NFSv3 root=dhcp DHCP proto:IP:path,options" \
163 52:54:00:12:34:07 "root=dhcp" 192.168.50.3 wsize=4096 || return 1
6b6805b8 164}
0000e181 165
6b6805b8 166test_nfsv4() {
ae227ca8
DD
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
169 # switch_root
170
da2643fa 171 client_test "NFSv4 root=nfs4 DHCP path only" 52:54:00:12:34:80 \
9f25b834 172 "root=nfs4" 192.168.50.1 -wsize=4096 || return 1
ae227ca8 173
da2643fa 174 client_test "NFSv4 root=/dev/nfs4 DHCP path only" 52:54:00:12:34:80 \
9f25b834 175 "root=/dev/nfs4" 192.168.50.1 -wsize=4096 || return 1
ae227ca8 176
da2643fa 177 client_test "NFSv4 root=nfs4 DHCP IP:path" 52:54:00:12:34:81 \
9f25b834 178 "root=nfs4" 192.168.50.2 -wsize=4096 || return 1
ae227ca8 179
da2643fa 180 client_test "NFSv4 root=/dev/nfs4 DHCP IP:path" 52:54:00:12:34:81 \
9f25b834 181 "root=/dev/nfs4" 192.168.50.2 -wsize=4096 || return 1
ae227ca8 182
da2643fa 183 client_test "NFSv4 root=dhcp DHCP proto:IP:path" 52:54:00:12:34:82 \
9f25b834
DD
184 "root=dhcp" 192.168.50.3 -wsize=4096 || return 1
185
da2643fa 186 client_test "NFSv4 root=dhcp DHCP proto:IP:path:options" 52:54:00:12:34:83 \
9f25b834 187 "root=dhcp" 192.168.50.3 wsize=4096 || return 1
0000e181 188
bed87ed9
DD
189 client_test "NFSv4 root=nfs4:..." 52:54:00:12:34:84 \
190 "root=nfs4:192.168.50.1:/client" 192.168.50.1 \
191 -wsize=4096 || return 1
192
0000e181
DD
193 client_test "NFSv4 root=nfs4 nfsroot=/client" 52:54:00:12:34:84 \
194 "root=nfs4 nfsroot=/client" 192.168.50.1 -wsize=4096 || return 1
195
196 client_test "NFSv4 root=nfs4 nfsroot=192.168.50.2:/client" \
197 52:54:00:12:34:84 "root=nfs4 nfsroot=192.168.50.2:/client" \
198 192.168.50.2 -wsize=4096 || return 1
199
200 client_test "NFSv4 root=nfs4 nfsroot=path,opts" \
201 52:54:00:12:34:84 "root=nfs4 nfsroot=/client,wsize=4096" \
202 192.168.50.1 wsize=4096 || return 1
203
abe9ccc8
DD
204 # This one only works with NFSv4 in the test suite -- NFSv3 needs
205 # a /nfs prefix due to our server configuration
206 client_test "NFSv4 root=nfs4" 52:54:00:12:34:84 \
207 "root=nfs4" 192.168.50.1 -wsize=4096 || return 1
208
0000e181
DD
209 client_test "NFSv4 root=nfs4 DHCP path,options" \
210 52:54:00:12:34:85 "root=nfs4" 192.168.50.1 wsize=4096 || return 1
211
212 client_test "NFSv4 root=nfs4 DHCP IP:path,options" \
213 52:54:00:12:34:86 "root=nfs4" 192.168.50.2 wsize=4096 || return 1
214
215 client_test "NFSv4 root=dhcp DHCP proto:IP:path,options" \
216 52:54:00:12:34:87 "root=dhcp" 192.168.50.3 wsize=4096 || return 1
528277f3
DD
217}
218
6b6805b8
DD
219test_run() {
220 if ! run_server; then
221 echo "Failed to start server" 1>&2
222 return 1
223 fi
224
225 test_nfsv3 || return 1
226 test_nfsv4
227}
228
528277f3
DD
229test_setup() {
230 # Make server root
169363e8 231 dd if=/dev/zero of=server.ext2 bs=1M count=60
528277f3
DD
232 mke2fs -F server.ext2
233 mkdir mnt
234 sudo mount -o loop server.ext2 mnt
235
236 kernel=$KVERSION
237 (
238 initdir=mnt
239 . $basedir/dracut-functions
240 dracut_install sh ls shutdown poweroff stty cat ps ln ip \
241 /lib/terminfo/l/linux dmesg mkdir cp ping exportfs \
ba64a17f 242 rpcbind modprobe rpc.nfsd rpc.mountd dhcpd showmount tcpdump \
ae227ca8 243 /etc/netconfig /etc/services sleep mount
169363e8 244 instmods nfsd sunrpc ipv6
528277f3 245 inst ./server-init /sbin/init
ba64a17f
DD
246 inst ./hosts /etc/hosts
247 inst ./exports /etc/exports
248 inst ./dhcpd.conf /etc/dhcpd.conf
169363e8
HH
249 dracut_install /etc/nsswitch.conf /etc/rpc /etc/protocols
250 dracut_install rpc.idmapd /etc/idmapd.conf
251 if ldd $(which rpc.idmapd) |grep -q lib64; then
252 LIBDIR="/lib64"
253 else
254 LIBDIR="/lib"
255 fi
256
257 dracut_install $(ls {/usr,}$LIBDIR/libnfsidmap*.so* 2>/dev/null )
258 dracut_install $(ls {/usr,}$LIBDIR/libnss*.so 2>/dev/null)
528277f3
DD
259 (
260 cd "$initdir";
ae227ca8
DD
261 mkdir -p dev sys proc etc var/run tmp var/lib/{dhcpd,rpcbind}
262 mkdir -p var/lib/nfs/{v4recovery,rpc_pipefs}
528277f3 263 chmod 777 var/lib/rpcbind var/lib/nfs
528277f3
DD
264 )
265 inst /etc/nsswitch.conf /etc/nsswitch.conf
266 inst /etc/passwd /etc/passwd
267 inst /etc/group /etc/group
ae227ca8 268 for i in /lib*/libnss_files**;do
528277f3
DD
269 inst_library $i
270 done
271
272 /sbin/depmod -a -b "$initdir" $kernel
273 ldconfig -n -r "$initdir" /lib* /usr/lib*
274 )
275
276 # Make client root inside server root
35b70995
DD
277 initdir=mnt/nfs/client
278 mkdir -p $initdir
528277f3
DD
279
280 (
281 . $basedir/dracut-functions
282 dracut_install sh shutdown poweroff stty cat ps ln ip \
283 /lib/terminfo/l/linux mount dmesg mkdir \
284 cp ping grep
285 inst ./client-init /sbin/init
286 (
287 cd "$initdir"
288 mkdir -p dev sys proc etc
289 mkdir -p var/lib/nfs/rpc_pipefs
290 )
291 inst /etc/nsswitch.conf /etc/nsswitch.conf
292 inst /etc/passwd /etc/passwd
293 inst /etc/group /etc/group
294 for i in /lib*/libnss_files*;do
295 inst_library $i
296 done
297
298 ldconfig -n -r "$initdir" /lib* /usr/lib*
299 )
300
abe9ccc8
DD
301 mkdir -p mnt/nfs/nfs3-5
302 mkdir -p mnt/nfs/ip/192.168.50.101
303 mkdir -p mnt/nfs/tftpboot/nfs4-5
304
528277f3
DD
305 sudo umount mnt
306 rm -fr mnt
307
308 # Make an overlay with needed tools for the test harness
309 (
310 initdir=overlay
311 mkdir overlay
312 . $basedir/dracut-functions
313 dracut_install poweroff shutdown
314 inst_simple ./hard-off.sh /emergency/01hard-off.sh
315 )
316
317 # Make server's dracut image
318 $basedir/dracut -l -i overlay / \
cc75acdc 319 -m "dash udev-rules base rootfs-block debug" \
528277f3
DD
320 -d "ata_piix ext2 sd_mod e1000" \
321 -f initramfs.server $KVERSION || return 1
322
323 # Make client's dracut image
324 $basedir/dracut -l -i overlay / \
cc75acdc 325 -m "dash udev-rules base network nfs debug" \
528277f3
DD
326 -d "e1000 nfs sunrpc" \
327 -f initramfs.testing $KVERSION || return 1
528277f3
DD
328}
329
330test_cleanup() {
331 if [[ -s server.pid ]]; then
332 sudo kill -TERM $(cat server.pid)
333 rm -f server.pid
334 fi
335 rm -rf mnt overlay
336 rm -f server.ext2 client.img initramfs.server initramfs.testing
337}
338
339. $testdir/test-functions