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