]>
Commit | Line | Data |
---|---|---|
a71f1b49 | 1 | #!/bin/bash |
d6862983 HH |
2 | # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- |
3 | # ex: ts=8 sw=4 sts=4 et filetype=sh | |
a71f1b49 PS |
4 | TEST_DESCRIPTION="root filesystem on NFS with multiple nics" |
5 | ||
6 | KVERSION=${KVERSION-$(uname -r)} | |
7 | ||
8 | # Uncomment this to debug failures | |
fa7ada31 | 9 | #DEBUGFAIL="rd.shell" |
67ab4f77 | 10 | #SERIAL="tcp:127.0.0.1:9999" |
a71f1b49 PS |
11 | |
12 | run_server() { | |
13 | # Start server first | |
14 | echo "MULTINIC TEST SETUP: Starting DHCP/NFS server" | |
15 | ||
b093aa2d | 16 | fsck -a "$TESTDIR"/server.ext3 || return 1 |
2e111dd5 | 17 | $testdir/run-qemu \ |
b093aa2d | 18 | -hda "$TESTDIR"/server.ext3 \ |
bb278147 | 19 | -m 512M -smp 2 \ |
44f870be | 20 | -display none \ |
a8986425 HH |
21 | -net socket,listen=127.0.0.1:12350 \ |
22 | -net nic,macaddr=52:54:01:12:34:56,model=e1000 \ | |
b093aa2d | 23 | ${SERIAL+-serial "$SERIAL"} \ |
23d6dcd1 | 24 | -watchdog i6300esb -watchdog-action poweroff \ |
b093aa2d | 25 | -kernel /boot/vmlinuz-"$KVERSION" \ |
44d832c5 | 26 | -append "loglevel=7 root=/dev/sda rootfstype=ext3 rw console=ttyS0,115200n81 selinux=0" \ |
b093aa2d HH |
27 | -initrd "$TESTDIR"/initramfs.server \ |
28 | -pidfile "$TESTDIR"/server.pid -daemonize || return 1 | |
29 | sudo chmod 644 -- "$TESTDIR"/server.pid || return 1 | |
a71f1b49 PS |
30 | |
31 | # Cleanup the terminal if we have one | |
32 | tty -s && stty sane | |
33 | ||
34 | echo Sleeping 10 seconds to give the server a head start | |
35 | sleep 10 | |
36 | } | |
37 | ||
38 | client_test() { | |
39 | local test_name="$1" | |
40 | local mac1="$2" | |
41 | local mac2="$3" | |
42 | local mac3="$4" | |
43 | local cmdline="$5" | |
44 | local check="$6" | |
45 | ||
46 | echo "CLIENT TEST START: $test_name" | |
47 | ||
48 | # Need this so kvm-qemu will boot (needs non-/dev/zero local disk) | |
b093aa2d | 49 | if ! dd if=/dev/zero of="$TESTDIR"/client.img bs=1M count=1; then |
d6862983 HH |
50 | echo "Unable to make client sda image" 1>&2 |
51 | return 1 | |
a71f1b49 PS |
52 | fi |
53 | ||
b093aa2d | 54 | $testdir/run-qemu -hda "$TESTDIR"/client.img -m 512M -smp 2 -nographic \ |
a8986425 HH |
55 | -net socket,connect=127.0.0.1:12350 \ |
56 | -net nic,macaddr=52:54:00:12:34:$mac1,model=e1000 \ | |
57 | -net nic,macaddr=52:54:00:12:34:$mac2,model=e1000 \ | |
58 | -net nic,macaddr=52:54:00:12:34:$mac3,model=e1000 \ | |
23d6dcd1 | 59 | -watchdog i6300esb -watchdog-action poweroff \ |
b093aa2d | 60 | -kernel /boot/vmlinuz-"$KVERSION" \ |
44d832c5 | 61 | -append "$cmdline $DEBUGFAIL rd.retry=5 ro console=ttyS0,115200n81 selinux=0 init=/sbin/init rd.debug systemd.log_target=console loglevel=7" \ |
b093aa2d | 62 | -initrd "$TESTDIR"/initramfs.testing |
a71f1b49 | 63 | |
b093aa2d | 64 | if [[ $? -ne 0 ]] || ! grep -F -m 1 -q OK -- "$TESTDIR"/client.img; then |
d6862983 HH |
65 | echo "CLIENT TEST END: $test_name [FAILED - BAD EXIT]" |
66 | return 1 | |
a71f1b49 PS |
67 | fi |
68 | ||
69 | ||
70 | for i in $check ; do | |
d6862983 | 71 | echo $i |
b093aa2d | 72 | if ! grep -F -m 1 -q $i -- "$TESTDIR"/client.img; then |
d6862983 HH |
73 | echo "CLIENT TEST END: $test_name [FAILED - BAD IF]" |
74 | return 1 | |
75 | fi | |
a71f1b49 PS |
76 | done |
77 | ||
78 | echo "CLIENT TEST END: $test_name [OK]" | |
79 | return 0 | |
80 | } | |
81 | ||
82 | ||
83 | test_run() { | |
84 | if ! run_server; then | |
d6862983 HH |
85 | echo "Failed to start server" 1>&2 |
86 | return 1 | |
a71f1b49 | 87 | fi |
6c980807 HH |
88 | test_client || { kill_server; return 1; } |
89 | } | |
a71f1b49 | 90 | |
6c980807 | 91 | test_client() { |
a71f1b49 PS |
92 | # Mac Numbering Scheme |
93 | # ...:00-02 receive IP adresses all others don't | |
94 | # ...:02 receives a dhcp root-path | |
95 | ||
96 | # PXE Style BOOTIF= | |
e0641277 HH |
97 | client_test "MULTINIC root=nfs BOOTIF=" \ |
98 | 00 01 02 \ | |
99 | "root=nfs:192.168.50.1:/nfs/client BOOTIF=52-54-00-12-34-00" \ | |
aa23dcd8 | 100 | "ens3" || return 1 |
a71f1b49 PS |
101 | |
102 | # PXE Style BOOTIF= with dhcp root-path | |
103 | client_test "MULTINIC root=dhcp BOOTIF=" \ | |
d6862983 HH |
104 | 00 01 02 \ |
105 | "root=dhcp BOOTIF=52-54-00-12-34-02" \ | |
aa23dcd8 | 106 | "ens5" || return 1 |
a71f1b49 PS |
107 | |
108 | # Multinic case, where only one nic works | |
109 | client_test "MULTINIC root=nfs ip=dhcp" \ | |
d6862983 HH |
110 | FF 00 FE \ |
111 | "root=nfs:192.168.50.1:/nfs/client ip=dhcp" \ | |
aa23dcd8 | 112 | "ens4" || return 1 |
a71f1b49 PS |
113 | |
114 | # Require two interfaces | |
aa23dcd8 | 115 | client_test "MULTINIC root=nfs ip=ens4:dhcp ip=ens5:dhcp bootdev=ens4" \ |
d6862983 | 116 | 00 01 02 \ |
aa23dcd8 HH |
117 | "root=nfs:192.168.50.1:/nfs/client ip=ens4:dhcp ip=ens5:dhcp bootdev=ens4" \ |
118 | "ens4 ens5" || return 1 | |
a71f1b49 PS |
119 | |
120 | # Require three interfaces with dhcp root-path | |
aa23dcd8 | 121 | client_test "MULTINIC root=dhcp ip=ens3:dhcp ip=ens4:dhcp ip=ens5:dhcp bootdev=ens5" \ |
d6862983 | 122 | 00 01 02 \ |
aa23dcd8 HH |
123 | "root=dhcp ip=ens3:dhcp ip=ens4:dhcp ip=ens5:dhcp bootdev=ens5" \ |
124 | "ens3 ens4 ens5" || return 1 | |
8f4c0660 HH |
125 | |
126 | kill_server | |
127 | return 0 | |
a71f1b49 PS |
128 | } |
129 | ||
130 | test_setup() { | |
131 | # Make server root | |
b093aa2d HH |
132 | dd if=/dev/null of="$TESTDIR"/server.ext3 bs=1M seek=60 |
133 | mke2fs -j -F -- "$TESTDIR"/server.ext3 | |
134 | mkdir -- "$TESTDIR"/mnt | |
135 | sudo mount -o loop -- "$TESTDIR"/server.ext3 "$TESTDIR"/mnt | |
3eca0cc8 | 136 | |
3eca0cc8 | 137 | ( |
b093aa2d HH |
138 | export initdir="$TESTDIR"/mnt |
139 | . "$basedir"/dracut-functions.sh | |
d6862983 HH |
140 | |
141 | ( | |
142 | cd "$initdir"; | |
b093aa2d HH |
143 | mkdir -p -- dev sys proc run etc var/run tmp var/lib/{dhcpd,rpcbind} |
144 | mkdir -p -- var/lib/nfs/{v4recovery,rpc_pipefs} | |
145 | chmod 777 -- var/lib/rpcbind var/lib/nfs | |
d6862983 HH |
146 | ) |
147 | ||
148 | for _f in modules.builtin.bin modules.builtin; do | |
149 | [[ $srcmods/$_f ]] && break | |
150 | done || { | |
151 | dfatal "No modules.builtin.bin and modules.builtin found!" | |
152 | return 1 | |
153 | } | |
3eca0cc8 HH |
154 | |
155 | for _f in modules.builtin.bin modules.builtin modules.order; do | |
d6862983 HH |
156 | [[ $srcmods/$_f ]] && inst_simple "$srcmods/$_f" "/lib/modules/$kernel/$_f" |
157 | done | |
3eca0cc8 | 158 | |
d6862983 HH |
159 | dracut_install sh ls shutdown poweroff stty cat ps ln ip \ |
160 | dmesg mkdir cp ping exportfs \ | |
161 | modprobe rpc.nfsd rpc.mountd showmount tcpdump \ | |
162 | /etc/services sleep mount chmod | |
96d22bd7 | 163 | for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do |
b093aa2d | 164 | [ -f "${_terminfodir}"/l/linux ] && break |
d6862983 | 165 | done |
b093aa2d | 166 | dracut_install -o "${_terminfodir}"/l/linux |
d6862983 HH |
167 | type -P portmap >/dev/null && dracut_install portmap |
168 | type -P rpcbind >/dev/null && dracut_install rpcbind | |
169 | [ -f /etc/netconfig ] && dracut_install /etc/netconfig | |
170 | type -P dhcpd >/dev/null && dracut_install dhcpd | |
171 | [ -x /usr/sbin/dhcpd3 ] && inst /usr/sbin/dhcpd3 /usr/sbin/dhcpd | |
ec897491 | 172 | instmods nfsd sunrpc ipv6 lockd af_packet |
021b2fdd | 173 | inst_simple /etc/os-release |
d6862983 HH |
174 | inst ./server-init.sh /sbin/init |
175 | inst ./hosts /etc/hosts | |
176 | inst ./exports /etc/exports | |
177 | inst ./dhcpd.conf /etc/dhcpd.conf | |
178 | dracut_install /etc/nsswitch.conf /etc/rpc /etc/protocols | |
179 | ||
180 | dracut_install rpc.idmapd /etc/idmapd.conf | |
181 | ||
182 | inst_libdir_file 'libnfsidmap_nsswitch.so*' | |
183 | inst_libdir_file 'libnfsidmap/*.so*' | |
184 | inst_libdir_file 'libnfsidmap*.so*' | |
c5ef4b63 | 185 | |
3eca0cc8 | 186 | _nsslibs=$(sed -e '/^#/d' -e 's/^.*://' -e 's/\[NOTFOUND=return\]//' /etc/nsswitch.conf \ |
d6862983 | 187 | | tr -s '[:space:]' '\n' | sort -u | tr -s '[:space:]' '|') |
3eca0cc8 HH |
188 | _nsslibs=${_nsslibs#|} |
189 | _nsslibs=${_nsslibs%|} | |
c5ef4b63 | 190 | |
167a320e | 191 | inst_libdir_file -n "$_nsslibs" 'libnss_*.so*' |
c5ef4b63 | 192 | |
d6862983 HH |
193 | inst /etc/nsswitch.conf /etc/nsswitch.conf |
194 | inst /etc/passwd /etc/passwd | |
195 | inst /etc/group /etc/group | |
3eca0cc8 | 196 | |
b093aa2d HH |
197 | cp -a -- /etc/ld.so.conf* "$initdir"/etc |
198 | sudo ldconfig -r -- "$initdir" | |
67ab4f77 | 199 | dracut_kernel_post |
3eca0cc8 | 200 | ) |
a71f1b49 PS |
201 | |
202 | # Make client root inside server root | |
a71f1b49 | 203 | ( |
b093aa2d HH |
204 | export initdir="$TESTDIR"/mnt/nfs/client |
205 | . "$basedir"/dracut-functions.sh | |
d6862983 | 206 | dracut_install sh shutdown poweroff stty cat ps ln ip \ |
3eca0cc8 | 207 | mount dmesg mkdir cp ping grep ls |
96d22bd7 | 208 | for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do |
b093aa2d | 209 | [[ -f ${_terminfodir}/l/linux ]] && break |
d6862983 | 210 | done |
b093aa2d | 211 | dracut_install -o "${_terminfodir}"/l/linux |
021b2fdd | 212 | inst_simple /etc/os-release |
d6862983 HH |
213 | inst ./client-init.sh /sbin/init |
214 | ( | |
215 | cd "$initdir" | |
b093aa2d HH |
216 | mkdir -p -- dev sys proc etc run |
217 | mkdir -p -- var/lib/nfs/rpc_pipefs | |
d6862983 HH |
218 | ) |
219 | inst /etc/nsswitch.conf /etc/nsswitch.conf | |
220 | inst /etc/passwd /etc/passwd | |
221 | inst /etc/group /etc/group | |
222 | ||
223 | dracut_install rpc.idmapd /etc/idmapd.conf | |
224 | inst_libdir_file 'libnfsidmap_nsswitch.so*' | |
225 | inst_libdir_file 'libnfsidmap/*.so*' | |
226 | inst_libdir_file 'libnfsidmap*.so*' | |
3eca0cc8 | 227 | |
b093aa2d | 228 | _nsslibs=$(sed -e '/^#/d' -e 's/^.*://' -e 's/\[NOTFOUND=return\]//' -- /etc/nsswitch.conf \ |
d6862983 | 229 | | tr -s '[:space:]' '\n' | sort -u | tr -s '[:space:]' '|') |
3eca0cc8 HH |
230 | _nsslibs=${_nsslibs#|} |
231 | _nsslibs=${_nsslibs%|} | |
232 | ||
167a320e | 233 | inst_libdir_file -n "$_nsslibs" 'libnss_*.so*' |
a71f1b49 | 234 | |
b093aa2d | 235 | cp -a -- /etc/ld.so.conf* "$initdir"/etc |
d6862983 | 236 | sudo ldconfig -r "$initdir" |
3eca0cc8 HH |
237 | ) |
238 | ||
b093aa2d HH |
239 | sudo umount "$TESTDIR"/mnt |
240 | rm -fr -- "$TESTDIR"/mnt | |
a71f1b49 PS |
241 | |
242 | # Make an overlay with needed tools for the test harness | |
243 | ( | |
b093aa2d HH |
244 | export initdir="$TESTDIR"/overlay |
245 | . "$basedir"/dracut-functions.sh | |
d6862983 HH |
246 | dracut_install poweroff shutdown |
247 | inst_hook emergency 000 ./hard-off.sh | |
248 | inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules | |
a71f1b49 PS |
249 | ) |
250 | ||
251 | # Make server's dracut image | |
b093aa2d | 252 | $basedir/dracut.sh -l -i "$TESTDIR"/overlay / \ |
2dbd71b7 | 253 | -m "dash udev-rules base rootfs-block debug kernel-modules watchdog" \ |
a8986425 | 254 | -d "af_packet piix ide-gd_mod ata_piix ext3 sd_mod nfsv2 nfsv3 nfsv4 nfs_acl nfs_layout_nfsv41_files nfsd e1000 i6300esb ib700wdt" \ |
b093aa2d | 255 | -f "$TESTDIR"/initramfs.server "$KVERSION" || return 1 |
a71f1b49 PS |
256 | |
257 | # Make client's dracut image | |
b093aa2d | 258 | $basedir/dracut.sh -l -i "$TESTDIR"/overlay / \ |
2dbd71b7 | 259 | -o "plymouth" \ |
67ab4f77 | 260 | -a "debug" \ |
a8986425 | 261 | -d "af_packet piix sd_mod sr_mod ata_piix ide-gd_mod e1000 nfsv2 nfsv3 nfsv4 nfs_acl nfs_layout_nfsv41_files sunrpc i6300esb ib700wdt" \ |
b093aa2d | 262 | -f "$TESTDIR"/initramfs.testing "$KVERSION" || return 1 |
a71f1b49 PS |
263 | } |
264 | ||
6c980807 | 265 | kill_server() { |
b093aa2d HH |
266 | if [[ -s "$TESTDIR"/server.pid ]]; then |
267 | sudo kill -TERM -- $(cat "$TESTDIR"/server.pid) | |
268 | rm -f -- "$TESTDIR"/server.pid | |
a71f1b49 | 269 | fi |
6c980807 HH |
270 | } |
271 | ||
272 | test_cleanup() { | |
0be1785a | 273 | kill_server |
a71f1b49 PS |
274 | } |
275 | ||
b093aa2d | 276 | . "$testdir"/test-functions |