]>
Commit | Line | Data |
---|---|---|
528277f3 DD |
1 | #!/bin/bash |
2 | TEST_DESCRIPTION="root filesystem on NFS" | |
3 | ||
4 | KVERSION=${KVERSION-$(uname -r)} | |
528277f3 | 5 | |
ae227ca8 DD |
6 | # Uncomment this to debug failures |
7 | #DEBUGFAIL="rdinitdebug rdnetdebug" | |
8 | ||
cc75acdc | 9 | run_server() { |
528277f3 | 10 | # Start server first |
cc75acdc DD |
11 | echo "NFS TEST SETUP: Starting DHCP/NFS server" |
12 | ||
5831685c | 13 | $testdir/run-qemu -hda server.ext2 -m 256M -nographic \ |
528277f3 DD |
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 | ||
29 | client_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 | 44 | |
5831685c | 45 | $testdir/run-qemu -hda client.img -m 256M -nographic \ |
50e7ff76 PS |
46 | -net nic,macaddr=$mac,model=e1000 \ |
47 | -net socket,mcast=230.0.0.1:1234 \ | |
48 | -kernel /boot/vmlinuz-$KVERSION \ | |
a3a3448d | 49 | -append "$cmdline $DEBUGFAIL rdshell ro quiet console=ttyS0,115200n81" \ |
50e7ff76 | 50 | -initrd initramfs.testing |
528277f3 | 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 | |
9f786a9d | 69 | if [[ ${check_opt:0:1} = '-' ]]; then |
9f25b834 DD |
70 | expected=0 |
71 | check_opt=${check_opt:1} | |
72 | fi | |
73 | ||
74 | opts=${nfsinfo[2]}, | |
75 | while [[ $opts ]]; do | |
9f786a9d | 76 | if [[ ${opts%%,*} = $check_opt ]]; then |
9f25b834 DD |
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 | 99 | test_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 | |
aec48753 | 103 | |
ae227ca8 | 104 | client_test "NFSv3 root=dhcp DHCP path only" 52:54:00:12:34:00 \ |
1e885ccd HH |
105 | "root=dhcp" 192.168.50.1 -wsize=4096 || return 1 |
106 | ||
9d4c1799 WT |
107 | client_test "NFSv3 Legacy root=/dev/nfs nfsroot=IP:path" 52:54:00:12:34:01 \ |
108 | "root=/dev/nfs nfsroot=192.168.50.1:/nfs/client" 192.168.50.1 -wsize=4096 || return 1 | |
109 | ||
950086e9 HH |
110 | client_test "NFSv3 Legacy root=/dev/nfs DHCP path only" 52:54:00:12:34:00 \ |
111 | "root=/dev/nfs" 192.168.50.1 -wsize=4096 || return 1 | |
112 | ||
113 | client_test "NFSv3 Legacy root=/dev/nfs DHCP IP:path" 52:54:00:12:34:01 \ | |
114 | "root=/dev/nfs" 192.168.50.2 -wsize=4096 || return 1 | |
ae227ca8 DD |
115 | |
116 | client_test "NFSv3 root=dhcp DHCP IP:path" 52:54:00:12:34:01 \ | |
f0aae472 | 117 | "root=dhcp" 192.168.50.2 -wsize=4096 || return 1 |
ae227ca8 | 118 | |
ae227ca8 | 119 | client_test "NFSv3 root=dhcp DHCP proto:IP:path" 52:54:00:12:34:02 \ |
50e7ff76 | 120 | "root=dhcp" 192.168.50.3 -wsize=4096 || return 1 |
9f25b834 | 121 | |
da2643fa | 122 | client_test "NFSv3 root=dhcp DHCP proto:IP:path:options" 52:54:00:12:34:03 \ |
50e7ff76 | 123 | "root=dhcp" 192.168.50.3 wsize=4096 || return 1 |
ae227ca8 | 124 | |
bed87ed9 | 125 | client_test "NFSv3 root=nfs:..." 52:54:00:12:34:04 \ |
50e7ff76 | 126 | "root=nfs:192.168.50.1:/nfs/client" 192.168.50.1 -wsize=4096 || return 1 |
bed87ed9 | 127 | |
798d9506 WT |
128 | client_test "NFSv3 Legacy root=IP:path" 52:54:00:12:34:04 \ |
129 | "root=192.168.50.1:/nfs/client" 192.168.50.1 -wsize=4096 || return 1 | |
130 | ||
297cb80b WT |
131 | # This test must fail: nfsroot= requires root=/dev/nfs |
132 | client_test "NFSv3 Invalid root=dhcp nfsroot=/nfs/client" 52:54:00:12:34:04 \ | |
50e7ff76 | 133 | "root=dhcp nfsroot=/nfs/client" 192.168.50.1 -wsize=4096 && return 1 |
0000e181 | 134 | |
50e7ff76 | 135 | client_test "NFSv3 root=dhcp DHCP path,options" \ |
1e885ccd | 136 | 52:54:00:12:34:05 "root=dhcp" 192.168.50.1 wsize=4096 || return 1 |
0000e181 DD |
137 | |
138 | client_test "NFSv3 root=dhcp DHCP IP:path,options" \ | |
1e885ccd | 139 | 52:54:00:12:34:06 "root=dhcp" 192.168.50.2 wsize=4096 || return 1 |
0000e181 DD |
140 | |
141 | client_test "NFSv3 root=dhcp DHCP proto:IP:path,options" \ | |
142 | 52:54:00:12:34:07 "root=dhcp" 192.168.50.3 wsize=4096 || return 1 | |
6b6805b8 | 143 | } |
0000e181 | 144 | |
6b6805b8 | 145 | test_nfsv4() { |
ae227ca8 DD |
146 | # There is a mandatory 90 second recovery when starting the NFSv4 |
147 | # server, so put these later in the list to avoid a pause when doing | |
148 | # switch_root | |
149 | ||
da2643fa | 150 | client_test "NFSv4 root=dhcp DHCP proto:IP:path" 52:54:00:12:34:82 \ |
50e7ff76 | 151 | "root=dhcp" 192.168.50.3 -wsize=4096 || return 1 |
9f25b834 | 152 | |
da2643fa | 153 | client_test "NFSv4 root=dhcp DHCP proto:IP:path:options" 52:54:00:12:34:83 \ |
50e7ff76 | 154 | "root=dhcp" 192.168.50.3 wsize=4096 || return 1 |
0000e181 | 155 | |
bed87ed9 DD |
156 | client_test "NFSv4 root=nfs4:..." 52:54:00:12:34:84 \ |
157 | "root=nfs4:192.168.50.1:/client" 192.168.50.1 \ | |
158 | -wsize=4096 || return 1 | |
159 | ||
0000e181 DD |
160 | client_test "NFSv4 root=dhcp DHCP proto:IP:path,options" \ |
161 | 52:54:00:12:34:87 "root=dhcp" 192.168.50.3 wsize=4096 || return 1 | |
528277f3 DD |
162 | } |
163 | ||
6b6805b8 DD |
164 | test_run() { |
165 | if ! run_server; then | |
166 | echo "Failed to start server" 1>&2 | |
167 | return 1 | |
168 | fi | |
169 | ||
170 | test_nfsv3 || return 1 | |
171 | test_nfsv4 | |
9ca74ffe HH |
172 | if [[ -s server.pid ]]; then |
173 | sudo kill -TERM $(cat server.pid) | |
174 | rm -f server.pid | |
175 | fi | |
6b6805b8 DD |
176 | } |
177 | ||
528277f3 DD |
178 | test_setup() { |
179 | # Make server root | |
169363e8 | 180 | dd if=/dev/zero of=server.ext2 bs=1M count=60 |
528277f3 DD |
181 | mke2fs -F server.ext2 |
182 | mkdir mnt | |
183 | sudo mount -o loop server.ext2 mnt | |
184 | ||
185 | kernel=$KVERSION | |
186 | ( | |
187 | initdir=mnt | |
188 | . $basedir/dracut-functions | |
189 | dracut_install sh ls shutdown poweroff stty cat ps ln ip \ | |
190 | /lib/terminfo/l/linux dmesg mkdir cp ping exportfs \ | |
45630db1 PS |
191 | modprobe rpc.nfsd rpc.mountd showmount tcpdump \ |
192 | /etc/services sleep mount chmod | |
3da03a60 PS |
193 | which portmap >/dev/null 2>&1 && dracut_install portmap |
194 | which rpcbind >/dev/null 2>&1 && dracut_install rpcbind | |
195 | [ -f /etc/netconfig ] && dracut_install /etc/netconfig | |
45630db1 PS |
196 | which dhcpd >/dev/null 2>&1 && dracut_install dhcpd |
197 | [ -x /usr/sbin/dhcpd3 ] && inst /usr/sbin/dhcpd3 /usr/sbin/dhcpd | |
169363e8 | 198 | instmods nfsd sunrpc ipv6 |
528277f3 | 199 | inst ./server-init /sbin/init |
ba64a17f DD |
200 | inst ./hosts /etc/hosts |
201 | inst ./exports /etc/exports | |
202 | inst ./dhcpd.conf /etc/dhcpd.conf | |
169363e8 HH |
203 | dracut_install /etc/nsswitch.conf /etc/rpc /etc/protocols |
204 | dracut_install rpc.idmapd /etc/idmapd.conf | |
205 | if ldd $(which rpc.idmapd) |grep -q lib64; then | |
206 | LIBDIR="/lib64" | |
207 | else | |
208 | LIBDIR="/lib" | |
209 | fi | |
210 | ||
211 | dracut_install $(ls {/usr,}$LIBDIR/libnfsidmap*.so* 2>/dev/null ) | |
212 | dracut_install $(ls {/usr,}$LIBDIR/libnss*.so 2>/dev/null) | |
528277f3 DD |
213 | ( |
214 | cd "$initdir"; | |
ae227ca8 DD |
215 | mkdir -p dev sys proc etc var/run tmp var/lib/{dhcpd,rpcbind} |
216 | mkdir -p var/lib/nfs/{v4recovery,rpc_pipefs} | |
528277f3 | 217 | chmod 777 var/lib/rpcbind var/lib/nfs |
528277f3 DD |
218 | ) |
219 | inst /etc/nsswitch.conf /etc/nsswitch.conf | |
220 | inst /etc/passwd /etc/passwd | |
221 | inst /etc/group /etc/group | |
ae227ca8 | 222 | for i in /lib*/libnss_files**;do |
528277f3 DD |
223 | inst_library $i |
224 | done | |
225 | ||
226 | /sbin/depmod -a -b "$initdir" $kernel | |
227 | ldconfig -n -r "$initdir" /lib* /usr/lib* | |
228 | ) | |
229 | ||
230 | # Make client root inside server root | |
35b70995 DD |
231 | initdir=mnt/nfs/client |
232 | mkdir -p $initdir | |
528277f3 DD |
233 | |
234 | ( | |
235 | . $basedir/dracut-functions | |
236 | dracut_install sh shutdown poweroff stty cat ps ln ip \ | |
237 | /lib/terminfo/l/linux mount dmesg mkdir \ | |
238 | cp ping grep | |
239 | inst ./client-init /sbin/init | |
240 | ( | |
241 | cd "$initdir" | |
242 | mkdir -p dev sys proc etc | |
243 | mkdir -p var/lib/nfs/rpc_pipefs | |
244 | ) | |
245 | inst /etc/nsswitch.conf /etc/nsswitch.conf | |
246 | inst /etc/passwd /etc/passwd | |
247 | inst /etc/group /etc/group | |
248 | for i in /lib*/libnss_files*;do | |
249 | inst_library $i | |
250 | done | |
251 | ||
252 | ldconfig -n -r "$initdir" /lib* /usr/lib* | |
253 | ) | |
254 | ||
abe9ccc8 DD |
255 | mkdir -p mnt/nfs/nfs3-5 |
256 | mkdir -p mnt/nfs/ip/192.168.50.101 | |
257 | mkdir -p mnt/nfs/tftpboot/nfs4-5 | |
258 | ||
528277f3 DD |
259 | sudo umount mnt |
260 | rm -fr mnt | |
261 | ||
262 | # Make an overlay with needed tools for the test harness | |
263 | ( | |
264 | initdir=overlay | |
265 | mkdir overlay | |
266 | . $basedir/dracut-functions | |
267 | dracut_install poweroff shutdown | |
268 | inst_simple ./hard-off.sh /emergency/01hard-off.sh | |
269 | ) | |
270 | ||
271 | # Make server's dracut image | |
272 | $basedir/dracut -l -i overlay / \ | |
e2dbd86f | 273 | -m "dash udev-rules base rootfs-block debug kernel-modules" \ |
528277f3 DD |
274 | -d "ata_piix ext2 sd_mod e1000" \ |
275 | -f initramfs.server $KVERSION || return 1 | |
276 | ||
277 | # Make client's dracut image | |
278 | $basedir/dracut -l -i overlay / \ | |
5db73403 HH |
279 | -o "plymouth" \ |
280 | -a "debug" \ | |
528277f3 DD |
281 | -d "e1000 nfs sunrpc" \ |
282 | -f initramfs.testing $KVERSION || return 1 | |
528277f3 DD |
283 | } |
284 | ||
285 | test_cleanup() { | |
286 | if [[ -s server.pid ]]; then | |
287 | sudo kill -TERM $(cat server.pid) | |
288 | rm -f server.pid | |
289 | fi | |
290 | rm -rf mnt overlay | |
291 | rm -f server.ext2 client.img initramfs.server initramfs.testing | |
292 | } | |
293 | ||
294 | . $testdir/test-functions |