]>
Commit | Line | Data |
---|---|---|
528277f3 DD |
1 | #!/bin/bash |
2 | TEST_DESCRIPTION="root filesystem on NFS" | |
3 | ||
4 | KVERSION=${KVERSION-$(uname -r)} | |
528277f3 | 5 | |
ae227ca8 | 6 | # Uncomment this to debug failures |
fa7ada31 | 7 | #DEBUGFAIL="rd.shell" |
67ab4f77 | 8 | #SERIAL="tcp:127.0.0.1:9999" |
ae227ca8 | 9 | |
cc75acdc | 10 | run_server() { |
528277f3 | 11 | # Start server first |
cc75acdc DD |
12 | echo "NFS TEST SETUP: Starting DHCP/NFS server" |
13 | ||
0635530d | 14 | fsck -a $TESTDIR/server.ext3 || return 1 |
0be1785a | 15 | $testdir/run-qemu \ |
4358ace4 | 16 | -drive format=raw,index=0,media=disk,file=$TESTDIR/server.ext3 \ |
dfb3db3d | 17 | -m 256M -cpu host -smp 2 \ |
44f870be | 18 | -display none \ |
14be3b16 | 19 | -net socket,listen=127.0.0.1:12320 \ |
24a78b26 | 20 | -net nic,macaddr=52:54:00:12:34:56,model=e1000 \ |
67b4a9ea | 21 | -serial ${SERIAL:-null} \ |
23d6dcd1 | 22 | -watchdog i6300esb -watchdog-action poweroff \ |
36867f1a HH |
23 | -no-reboot \ |
24 | -append "panic=1 rd.debug loglevel=77 root=/dev/sda rootfstype=ext3 rw console=ttyS0,115200n81 selinux=0" \ | |
14be3b16 HH |
25 | -initrd $TESTDIR/initramfs.server \ |
26 | -pidfile $TESTDIR/server.pid -daemonize || return 1 | |
0be1785a | 27 | sudo chmod 644 $TESTDIR/server.pid || return 1 |
528277f3 | 28 | |
d462f6dc DD |
29 | # Cleanup the terminal if we have one |
30 | tty -s && stty sane | |
31 | ||
528277f3 DD |
32 | echo Sleeping 10 seconds to give the server a head start |
33 | sleep 10 | |
cc75acdc DD |
34 | } |
35 | ||
36 | client_test() { | |
37 | local test_name="$1" | |
38 | local mac=$2 | |
39 | local cmdline="$3" | |
574f2965 | 40 | local server="$4" |
9f25b834 DD |
41 | local check_opt="$5" |
42 | local nfsinfo opts found expected | |
cc75acdc DD |
43 | |
44 | echo "CLIENT TEST START: $test_name" | |
45 | ||
46 | # Need this so kvm-qemu will boot (needs non-/dev/zero local disk) | |
0be1785a | 47 | if ! dd if=/dev/zero of=$TESTDIR/client.img bs=1M count=1; then |
14be3b16 HH |
48 | echo "Unable to make client sda image" 1>&2 |
49 | return 1 | |
cc75acdc | 50 | fi |
528277f3 | 51 | |
0be1785a | 52 | $testdir/run-qemu \ |
4358ace4 | 53 | -drive format=raw,index=0,media=disk,file=$TESTDIR/client.img \ |
dfb3db3d | 54 | -m 256M -cpu host -smp 2 -nographic \ |
14be3b16 HH |
55 | -net nic,macaddr=$mac,model=e1000 \ |
56 | -net socket,connect=127.0.0.1:12320 \ | |
23d6dcd1 | 57 | -watchdog i6300esb -watchdog-action poweroff \ |
36867f1a HH |
58 | -no-reboot \ |
59 | -append "panic=1 rd.shell=0 $cmdline $DEBUGFAIL rd.debug rd.retry=10 rd.info quiet ro console=ttyS0,115200n81 selinux=0" \ | |
14be3b16 | 60 | -initrd $TESTDIR/initramfs.testing |
528277f3 | 61 | |
021b2fdd | 62 | if [[ $? -ne 0 ]] || ! grep -F -m 1 -q nfs-OK $TESTDIR/client.img; then |
14be3b16 HH |
63 | echo "CLIENT TEST END: $test_name [FAILED - BAD EXIT]" |
64 | return 1 | |
cc75acdc | 65 | fi |
574f2965 DD |
66 | |
67 | # nfsinfo=( server:/path nfs{,4} options ) | |
0be1785a | 68 | nfsinfo=($(awk '{print $2, $3, $4; exit}' $TESTDIR/client.img)) |
574f2965 DD |
69 | |
70 | if [[ "${nfsinfo[0]%%:*}" != "$server" ]]; then | |
14be3b16 HH |
71 | echo "CLIENT TEST INFO: got server: ${nfsinfo[0]%%:*}" |
72 | echo "CLIENT TEST INFO: expected server: $server" | |
73 | echo "CLIENT TEST END: $test_name [FAILED - WRONG SERVER]" | |
74 | return 1 | |
574f2965 DD |
75 | fi |
76 | ||
9f25b834 DD |
77 | found=0 |
78 | expected=1 | |
9f786a9d | 79 | if [[ ${check_opt:0:1} = '-' ]]; then |
14be3b16 HH |
80 | expected=0 |
81 | check_opt=${check_opt:1} | |
9f25b834 | 82 | fi |
0be1785a | 83 | |
9f25b834 DD |
84 | opts=${nfsinfo[2]}, |
85 | while [[ $opts ]]; do | |
14be3b16 HH |
86 | if [[ ${opts%%,*} = $check_opt ]]; then |
87 | found=1 | |
88 | break | |
89 | fi | |
90 | opts=${opts#*,} | |
9f25b834 DD |
91 | done |
92 | ||
93 | if [[ $found -ne $expected ]]; then | |
14be3b16 HH |
94 | echo "CLIENT TEST INFO: got options: ${nfsinfo[2]%%:*}" |
95 | if [[ $expected -eq 0 ]]; then | |
96 | echo "CLIENT TEST INFO: did not expect: $check_opt" | |
97 | echo "CLIENT TEST END: $test_name [FAILED - UNEXPECTED OPTION]" | |
98 | else | |
99 | echo "CLIENT TEST INFO: missing: $check_opt" | |
100 | echo "CLIENT TEST END: $test_name [FAILED - MISSING OPTION]" | |
101 | fi | |
102 | return 1 | |
9f25b834 DD |
103 | fi |
104 | ||
574f2965 DD |
105 | echo "CLIENT TEST END: $test_name [OK]" |
106 | return 0 | |
cc75acdc DD |
107 | } |
108 | ||
6b6805b8 | 109 | test_nfsv3() { |
da2643fa DD |
110 | # MAC numbering scheme: |
111 | # NFSv3: last octect starts at 0x00 and works up | |
112 | # NFSv4: last octect starts at 0x80 and works up | |
aec48753 | 113 | |
ae227ca8 | 114 | client_test "NFSv3 root=dhcp DHCP path only" 52:54:00:12:34:00 \ |
14be3b16 | 115 | "root=dhcp" 192.168.50.1 -wsize=4096 || return 1 |
1e885ccd | 116 | |
f6fa9ef1 HH |
117 | if [[ "$(systemctl --version)" != *"systemd 230"* ]] 2>/dev/null; then |
118 | client_test "NFSv3 Legacy root=/dev/nfs nfsroot=IP:path" 52:54:00:12:34:01 \ | |
119 | "root=/dev/nfs nfsroot=192.168.50.1:/nfs/client" 192.168.50.1 -wsize=4096 || return 1 | |
9d4c1799 | 120 | |
f6fa9ef1 HH |
121 | client_test "NFSv3 Legacy root=/dev/nfs DHCP path only" 52:54:00:12:34:00 \ |
122 | "root=/dev/nfs" 192.168.50.1 -wsize=4096 || return 1 | |
950086e9 | 123 | |
f6fa9ef1 HH |
124 | client_test "NFSv3 Legacy root=/dev/nfs DHCP IP:path" 52:54:00:12:34:01 \ |
125 | "root=/dev/nfs" 192.168.50.2 -wsize=4096 || return 1 | |
126 | fi | |
ae227ca8 DD |
127 | |
128 | client_test "NFSv3 root=dhcp DHCP IP:path" 52:54:00:12:34:01 \ | |
14be3b16 | 129 | "root=dhcp" 192.168.50.2 -wsize=4096 || return 1 |
ae227ca8 | 130 | |
ae227ca8 | 131 | client_test "NFSv3 root=dhcp DHCP proto:IP:path" 52:54:00:12:34:02 \ |
14be3b16 | 132 | "root=dhcp" 192.168.50.3 -wsize=4096 || return 1 |
9f25b834 | 133 | |
da2643fa | 134 | client_test "NFSv3 root=dhcp DHCP proto:IP:path:options" 52:54:00:12:34:03 \ |
14be3b16 | 135 | "root=dhcp" 192.168.50.3 wsize=4096 || return 1 |
ae227ca8 | 136 | |
bed87ed9 | 137 | client_test "NFSv3 root=nfs:..." 52:54:00:12:34:04 \ |
14be3b16 | 138 | "root=nfs:192.168.50.1:/nfs/client" 192.168.50.1 -wsize=4096 || return 1 |
bed87ed9 | 139 | |
beb097d9 | 140 | client_test "NFSv3 Bridge root=nfs:..." 52:54:00:12:34:04 \ |
24a78b26 | 141 | "root=nfs:192.168.50.1:/nfs/client bridge net.ifnames=0" 192.168.50.1 -wsize=4096 || return 1 |
beb097d9 | 142 | |
798d9506 | 143 | client_test "NFSv3 Legacy root=IP:path" 52:54:00:12:34:04 \ |
14be3b16 | 144 | "root=192.168.50.1:/nfs/client" 192.168.50.1 -wsize=4096 || return 1 |
798d9506 | 145 | |
297cb80b WT |
146 | # This test must fail: nfsroot= requires root=/dev/nfs |
147 | client_test "NFSv3 Invalid root=dhcp nfsroot=/nfs/client" 52:54:00:12:34:04 \ | |
4e882b80 | 148 | "root=dhcp nfsroot=/nfs/client failme rd.debug" 192.168.50.1 -wsize=4096 && return 1 |
0000e181 | 149 | |
50e7ff76 | 150 | client_test "NFSv3 root=dhcp DHCP path,options" \ |
14be3b16 | 151 | 52:54:00:12:34:05 "root=dhcp" 192.168.50.1 wsize=4096 || return 1 |
0000e181 | 152 | |
beb097d9 | 153 | client_test "NFSv3 Bridge Customized root=dhcp DHCP path,options" \ |
67b4a9ea | 154 | 52:54:00:12:34:05 "root=dhcp bridge=foobr0:ens3" 192.168.50.1 wsize=4096 || return 1 |
beb097d9 | 155 | |
0000e181 | 156 | client_test "NFSv3 root=dhcp DHCP IP:path,options" \ |
14be3b16 | 157 | 52:54:00:12:34:06 "root=dhcp" 192.168.50.2 wsize=4096 || return 1 |
0000e181 DD |
158 | |
159 | client_test "NFSv3 root=dhcp DHCP proto:IP:path,options" \ | |
14be3b16 | 160 | 52:54:00:12:34:07 "root=dhcp" 192.168.50.3 wsize=4096 || return 1 |
0be1785a HH |
161 | |
162 | return 0 | |
6b6805b8 | 163 | } |
0000e181 | 164 | |
6b6805b8 | 165 | test_nfsv4() { |
ae227ca8 DD |
166 | # There is a mandatory 90 second recovery when starting the NFSv4 |
167 | # server, so put these later in the list to avoid a pause when doing | |
168 | # switch_root | |
169 | ||
da2643fa | 170 | client_test "NFSv4 root=dhcp DHCP proto:IP:path" 52:54:00:12:34:82 \ |
14be3b16 | 171 | "root=dhcp" 192.168.50.3 -wsize=4096 || return 1 |
9f25b834 | 172 | |
da2643fa | 173 | client_test "NFSv4 root=dhcp DHCP proto:IP:path:options" 52:54:00:12:34:83 \ |
14be3b16 | 174 | "root=dhcp" 192.168.50.3 wsize=4096 || return 1 |
0000e181 | 175 | |
bed87ed9 | 176 | client_test "NFSv4 root=nfs4:..." 52:54:00:12:34:84 \ |
14be3b16 HH |
177 | "root=nfs4:192.168.50.1:/client" 192.168.50.1 \ |
178 | -wsize=4096 || return 1 | |
bed87ed9 | 179 | |
0000e181 | 180 | client_test "NFSv4 root=dhcp DHCP proto:IP:path,options" \ |
14be3b16 | 181 | 52:54:00:12:34:87 "root=dhcp" 192.168.50.3 wsize=4096 || return 1 |
0be1785a HH |
182 | |
183 | return 0 | |
528277f3 DD |
184 | } |
185 | ||
6b6805b8 | 186 | test_run() { |
2cc8cbea | 187 | if [[ -s server.pid ]]; then |
14be3b16 | 188 | sudo kill -TERM $(cat $TESTDIR/server.pid) |
32bd2fbb | 189 | rm -f -- $TESTDIR/server.pid |
2cc8cbea HH |
190 | fi |
191 | ||
6b6805b8 | 192 | if ! run_server; then |
14be3b16 HH |
193 | echo "Failed to start server" 1>&2 |
194 | return 1 | |
6b6805b8 DD |
195 | fi |
196 | ||
3de984ba | 197 | test_nfsv3 && \ |
14be3b16 | 198 | test_nfsv4 |
3de984ba HH |
199 | |
200 | ret=$? | |
201 | ||
0be1785a | 202 | if [[ -s $TESTDIR/server.pid ]]; then |
14be3b16 | 203 | sudo kill -TERM $(cat $TESTDIR/server.pid) |
32bd2fbb | 204 | rm -f -- $TESTDIR/server.pid |
9ca74ffe | 205 | fi |
3de984ba HH |
206 | |
207 | return $ret | |
6b6805b8 DD |
208 | } |
209 | ||
528277f3 DD |
210 | test_setup() { |
211 | # Make server root | |
b8a9dc2d HH |
212 | dd if=/dev/null of=$TESTDIR/server.ext3 bs=1M seek=60 |
213 | mke2fs -j -F $TESTDIR/server.ext3 | |
0be1785a | 214 | mkdir $TESTDIR/mnt |
b8a9dc2d | 215 | sudo mount -o loop $TESTDIR/server.ext3 $TESTDIR/mnt |
528277f3 | 216 | |
9f88b037 HH |
217 | |
218 | export kernel=$KVERSION | |
219 | export srcmods="/lib/modules/$kernel/" | |
220 | # Detect lib paths | |
221 | ||
14be3b16 HH |
222 | ( |
223 | export initdir=$TESTDIR/mnt | |
777f2db0 | 224 | . $basedir/dracut-init.sh |
9f88b037 | 225 | |
14be3b16 HH |
226 | for _f in modules.builtin.bin modules.builtin; do |
227 | [[ $srcmods/$_f ]] && break | |
228 | done || { | |
229 | dfatal "No modules.builtin.bin and modules.builtin found!" | |
230 | return 1 | |
231 | } | |
9f88b037 HH |
232 | |
233 | for _f in modules.builtin.bin modules.builtin modules.order; do | |
14be3b16 HH |
234 | [[ $srcmods/$_f ]] && inst_simple "$srcmods/$_f" "/lib/modules/$kernel/$_f" |
235 | done | |
9f88b037 | 236 | |
af119460 | 237 | inst_multiple sh ls shutdown poweroff stty cat ps ln ip \ |
14be3b16 HH |
238 | dmesg mkdir cp ping exportfs \ |
239 | modprobe rpc.nfsd rpc.mountd showmount tcpdump \ | |
1de836c7 | 240 | /etc/services sleep mount chmod rm |
96d22bd7 | 241 | for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do |
14be3b16 HH |
242 | [ -f ${_terminfodir}/l/linux ] && break |
243 | done | |
af119460 HH |
244 | inst_multiple -o ${_terminfodir}/l/linux |
245 | type -P portmap >/dev/null && inst_multiple portmap | |
246 | type -P rpcbind >/dev/null && inst_multiple rpcbind | |
247 | [ -f /etc/netconfig ] && inst_multiple /etc/netconfig | |
248 | type -P dhcpd >/dev/null && inst_multiple dhcpd | |
14be3b16 HH |
249 | [ -x /usr/sbin/dhcpd3 ] && inst /usr/sbin/dhcpd3 /usr/sbin/dhcpd |
250 | instmods nfsd sunrpc ipv6 lockd af_packet | |
251 | inst ./server-init.sh /sbin/init | |
021b2fdd | 252 | inst_simple /etc/os-release |
14be3b16 HH |
253 | inst ./hosts /etc/hosts |
254 | inst ./exports /etc/exports | |
255 | inst ./dhcpd.conf /etc/dhcpd.conf | |
af119460 HH |
256 | inst_multiple /etc/nsswitch.conf /etc/rpc /etc/protocols |
257 | inst_multiple rpc.idmapd /etc/idmapd.conf | |
14be3b16 HH |
258 | |
259 | inst_libdir_file 'libnfsidmap_nsswitch.so*' | |
260 | inst_libdir_file 'libnfsidmap/*.so*' | |
261 | inst_libdir_file 'libnfsidmap*.so*' | |
9f88b037 HH |
262 | |
263 | _nsslibs=$(sed -e '/^#/d' -e 's/^.*://' -e 's/\[NOTFOUND=return\]//' /etc/nsswitch.conf \ | |
14be3b16 | 264 | | tr -s '[:space:]' '\n' | sort -u | tr -s '[:space:]' '|') |
9f88b037 HH |
265 | _nsslibs=${_nsslibs#|} |
266 | _nsslibs=${_nsslibs%|} | |
267 | ||
14be3b16 | 268 | inst_libdir_file -n "$_nsslibs" 'libnss_*.so*' |
9f88b037 | 269 | |
14be3b16 HH |
270 | ( |
271 | cd "$initdir"; | |
272 | mkdir -p dev sys proc run etc var/run tmp var/lib/{dhcpd,rpcbind} | |
273 | mkdir -p var/lib/nfs/{v4recovery,rpc_pipefs} | |
274 | chmod 777 var/lib/rpcbind var/lib/nfs | |
275 | ) | |
276 | inst /etc/nsswitch.conf /etc/nsswitch.conf | |
9f88b037 | 277 | |
14be3b16 HH |
278 | inst /etc/passwd /etc/passwd |
279 | inst /etc/group /etc/group | |
528277f3 | 280 | |
14be3b16 HH |
281 | cp -a /etc/ld.so.conf* $initdir/etc |
282 | sudo ldconfig -r "$initdir" | |
283 | dracut_kernel_post | |
528277f3 DD |
284 | ) |
285 | ||
528277f3 | 286 | |
67ab4f77 | 287 | # Make client root inside server root |
528277f3 | 288 | ( |
14be3b16 | 289 | export initdir=$TESTDIR/mnt/nfs/client |
777f2db0 | 290 | . $basedir/dracut-init.sh |
67ab4f77 | 291 | |
af119460 | 292 | inst_multiple sh shutdown poweroff stty cat ps ln ip \ |
4e1f8d0c | 293 | mount dmesg mkdir cp ping grep setsid ls vi /etc/virc less cat |
96d22bd7 | 294 | for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do |
14be3b16 HH |
295 | [ -f ${_terminfodir}/l/linux ] && break |
296 | done | |
af119460 | 297 | inst_multiple -o ${_terminfodir}/l/linux |
14be3b16 | 298 | inst ./client-init.sh /sbin/init |
021b2fdd | 299 | inst_simple /etc/os-release |
14be3b16 HH |
300 | ( |
301 | cd "$initdir" | |
302 | mkdir -p dev sys proc etc run | |
303 | mkdir -p var/lib/nfs/rpc_pipefs | |
4e1f8d0c HH |
304 | mkdir -p root usr/bin usr/lib usr/lib64 usr/sbin |
305 | for i in bin sbin lib lib64; do | |
306 | ln -sfnr usr/$i $i | |
307 | done | |
14be3b16 HH |
308 | ) |
309 | inst /etc/nsswitch.conf /etc/nsswitch.conf | |
310 | inst /etc/passwd /etc/passwd | |
311 | inst /etc/group /etc/group | |
312 | ||
313 | inst_libdir_file 'libnfsidmap_nsswitch.so*' | |
314 | inst_libdir_file 'libnfsidmap/*.so*' | |
315 | inst_libdir_file 'libnfsidmap*.so*' | |
9f88b037 HH |
316 | |
317 | _nsslibs=$(sed -e '/^#/d' -e 's/^.*://' -e 's/\[NOTFOUND=return\]//' /etc/nsswitch.conf \ | |
14be3b16 | 318 | | tr -s '[:space:]' '\n' | sort -u | tr -s '[:space:]' '|') |
9f88b037 HH |
319 | _nsslibs=${_nsslibs#|} |
320 | _nsslibs=${_nsslibs%|} | |
321 | ||
14be3b16 | 322 | inst_libdir_file -n "$_nsslibs" 'libnss_*.so*' |
528277f3 | 323 | |
14be3b16 HH |
324 | cp -a /etc/ld.so.conf* $initdir/etc |
325 | sudo ldconfig -r "$initdir" | |
528277f3 DD |
326 | ) |
327 | ||
0be1785a HH |
328 | mkdir -p $TESTDIR/mnt/nfs/nfs3-5 |
329 | mkdir -p $TESTDIR/mnt/nfs/ip/192.168.50.101 | |
330 | mkdir -p $TESTDIR/mnt/nfs/tftpboot/nfs4-5 | |
abe9ccc8 | 331 | |
0be1785a | 332 | sudo umount $TESTDIR/mnt |
32bd2fbb | 333 | rm -fr -- $TESTDIR/mnt |
528277f3 DD |
334 | |
335 | # Make an overlay with needed tools for the test harness | |
336 | ( | |
14be3b16 | 337 | export initdir=$TESTDIR/overlay |
777f2db0 | 338 | . $basedir/dracut-init.sh |
14be3b16 | 339 | mkdir $TESTDIR/overlay |
af119460 | 340 | inst_multiple poweroff shutdown |
4e882b80 | 341 | inst_hook shutdown-emergency 000 ./hard-off.sh |
781f1971 | 342 | inst_hook emergency 000 ./hard-off.sh |
14be3b16 | 343 | inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules |
528277f3 DD |
344 | ) |
345 | ||
346 | # Make server's dracut image | |
552ecca6 | 347 | $basedir/dracut.sh -l -i $TESTDIR/overlay / \ |
eda73c0a | 348 | -m "dash udev-rules base rootfs-block fs-lib debug kernel-modules watchdog" \ |
14be3b16 | 349 | -d "af_packet piix ide-gd_mod ata_piix ext3 sd_mod e1000 i6300esb" \ |
e3e1f406 | 350 | --no-hostonly-cmdline -N \ |
14be3b16 | 351 | -f $TESTDIR/initramfs.server $KVERSION || return 1 |
528277f3 DD |
352 | |
353 | # Make client's dracut image | |
552ecca6 | 354 | $basedir/dracut.sh -l -i $TESTDIR/overlay / \ |
14be3b16 HH |
355 | -o "plymouth dash" \ |
356 | -a "debug watchdog" \ | |
357 | -d "af_packet piix ide-gd_mod ata_piix sd_mod e1000 nfs sunrpc i6300esb" \ | |
e3e1f406 | 358 | --no-hostonly-cmdline -N \ |
14be3b16 | 359 | -f $TESTDIR/initramfs.testing $KVERSION || return 1 |
528277f3 DD |
360 | } |
361 | ||
362 | test_cleanup() { | |
0be1785a | 363 | if [[ -s $TESTDIR/server.pid ]]; then |
14be3b16 | 364 | sudo kill -TERM $(cat $TESTDIR/server.pid) |
32bd2fbb | 365 | rm -f -- $TESTDIR/server.pid |
528277f3 | 366 | fi |
528277f3 DD |
367 | } |
368 | ||
369 | . $testdir/test-functions |