]>
Commit | Line | Data |
---|---|---|
a71f1b49 PS |
1 | #!/bin/bash |
2 | TEST_DESCRIPTION="root filesystem on NFS with multiple nics" | |
3 | ||
4 | KVERSION=${KVERSION-$(uname -r)} | |
5 | ||
6 | # Uncomment this to debug failures | |
40ef4325 | 7 | #DEBUGFAIL="rdshell" |
a71f1b49 PS |
8 | |
9 | run_server() { | |
10 | # Start server first | |
11 | echo "MULTINIC TEST SETUP: Starting DHCP/NFS server" | |
12 | ||
13 | $testdir/run-qemu -hda server.ext2 -m 256M -nographic \ | |
14 | -net nic,macaddr=52:54:00:12:34:56,model=e1000 \ | |
0c887426 | 15 | -net socket,listen=127.0.0.1:12345 \ |
a71f1b49 PS |
16 | -serial udp:127.0.0.1:9999 \ |
17 | -kernel /boot/vmlinuz-$KVERSION \ | |
ba54a4c7 | 18 | -append "selinux=0 root=/dev/sda rdinitdebug rdinfo rdnetdebug rw quiet console=ttyS0,115200n81" \ |
a71f1b49 PS |
19 | -initrd initramfs.server -pidfile server.pid -daemonize || return 1 |
20 | sudo chmod 644 server.pid || return 1 | |
21 | ||
22 | # Cleanup the terminal if we have one | |
23 | tty -s && stty sane | |
24 | ||
25 | echo Sleeping 10 seconds to give the server a head start | |
26 | sleep 10 | |
27 | } | |
28 | ||
29 | client_test() { | |
30 | local test_name="$1" | |
31 | local mac1="$2" | |
32 | local mac2="$3" | |
33 | local mac3="$4" | |
34 | local cmdline="$5" | |
35 | local check="$6" | |
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 | |
44 | ||
45 | $testdir/run-qemu -hda client.img -m 512M -nographic \ | |
46 | -net nic,macaddr=52:54:00:12:34:$mac1,model=e1000 \ | |
47 | -net nic,macaddr=52:54:00:12:34:$mac2,model=e1000 \ | |
48 | -net nic,macaddr=52:54:00:12:34:$mac3,model=e1000 \ | |
0c887426 | 49 | -net socket,connect=127.0.0.1:12345 \ |
a71f1b49 | 50 | -kernel /boot/vmlinuz-$KVERSION \ |
85fd75f9 | 51 | -append "$cmdline $DEBUGFAIL rd_retry=5 rdinitdebug rdinfo rdnetdebug ro quiet console=ttyS0,115200n81 selinux=0 rdcopystate" \ |
a71f1b49 PS |
52 | -initrd initramfs.testing |
53 | ||
54 | if [[ $? -ne 0 ]] || ! grep -m 1 -q OK client.img; then | |
55 | echo "CLIENT TEST END: $test_name [FAILED - BAD EXIT]" | |
56 | return 1 | |
57 | fi | |
58 | ||
59 | ||
60 | for i in $check ; do | |
61 | echo $i | |
62 | if ! grep -m 1 -q $i client.img; then | |
63 | echo "CLIENT TEST END: $test_name [FAILED - BAD IF]" | |
64 | return 1 | |
65 | fi | |
66 | done | |
67 | ||
68 | echo "CLIENT TEST END: $test_name [OK]" | |
69 | return 0 | |
70 | } | |
71 | ||
72 | ||
73 | test_run() { | |
74 | if ! run_server; then | |
75 | echo "Failed to start server" 1>&2 | |
76 | return 1 | |
77 | fi | |
6c980807 HH |
78 | test_client || { kill_server; return 1; } |
79 | } | |
a71f1b49 | 80 | |
6c980807 | 81 | test_client() { |
a71f1b49 PS |
82 | # Mac Numbering Scheme |
83 | # ...:00-02 receive IP adresses all others don't | |
84 | # ...:02 receives a dhcp root-path | |
85 | ||
86 | # PXE Style BOOTIF= | |
87 | client_test "MULTINIC root=nfs BOOTIF=" \ | |
88 | 00 01 02 \ | |
89 | "root=nfs:192.168.50.1:/nfs/client BOOTIF=52-54-00-12-34-00" \ | |
90 | "eth0" || return 1 | |
91 | ||
92 | # PXE Style BOOTIF= with dhcp root-path | |
93 | client_test "MULTINIC root=dhcp BOOTIF=" \ | |
94 | 00 01 02 \ | |
95 | "root=dhcp BOOTIF=52-54-00-12-34-02" \ | |
96 | "eth2" || return 1 | |
97 | ||
98 | # Multinic case, where only one nic works | |
99 | client_test "MULTINIC root=nfs ip=dhcp" \ | |
100 | FF 00 FE \ | |
101 | "root=nfs:192.168.50.1:/nfs/client ip=dhcp" \ | |
102 | "eth1" || return 1 | |
103 | ||
104 | # Require two interfaces | |
105 | client_test "MULTINIC root=nfs ip=eth1:dhcp ip=eth2:dhcp bootdev=eth1" \ | |
106 | 00 01 02 \ | |
107 | "root=nfs:192.168.50.1:/nfs/client ip=eth1:dhcp ip=eth2:dhcp bootdev=eth1" \ | |
108 | "eth1 eth2" || return 1 | |
109 | ||
110 | # Require three interfaces with dhcp root-path | |
111 | client_test "MULTINIC root=dhcp ip=eth0:dhcp ip=eth1:dhcp ip=eth2:dhcp bootdev=eth2" \ | |
112 | 00 01 02 \ | |
113 | "root=dhcp ip=eth0:dhcp ip=eth1:dhcp ip=eth2:dhcp bootdev=eth2" \ | |
114 | "eth0 eth1 eth2" || return 1 | |
115 | } | |
116 | ||
117 | test_setup() { | |
118 | # Make server root | |
119 | dd if=/dev/zero of=server.ext2 bs=1M count=60 | |
120 | mke2fs -F server.ext2 | |
121 | mkdir mnt | |
122 | sudo mount -o loop server.ext2 mnt | |
123 | ||
124 | kernel=$KVERSION | |
125 | ( | |
126 | initdir=mnt | |
127 | . $basedir/dracut-functions | |
128 | dracut_install sh ls shutdown poweroff stty cat ps ln ip \ | |
129 | /lib/terminfo/l/linux dmesg mkdir cp ping exportfs \ | |
130 | modprobe rpc.nfsd rpc.mountd showmount tcpdump \ | |
131 | /etc/services sleep mount chmod | |
132 | which portmap >/dev/null 2>&1 && dracut_install portmap | |
133 | which rpcbind >/dev/null 2>&1 && dracut_install rpcbind | |
134 | [ -f /etc/netconfig ] && dracut_install /etc/netconfig | |
135 | which dhcpd >/dev/null 2>&1 && dracut_install dhcpd | |
136 | [ -x /usr/sbin/dhcpd3 ] && inst /usr/sbin/dhcpd3 /usr/sbin/dhcpd | |
137 | instmods nfsd sunrpc ipv6 | |
138 | inst ./server-init /sbin/init | |
139 | inst ./hosts /etc/hosts | |
140 | inst ./exports /etc/exports | |
141 | inst ./dhcpd.conf /etc/dhcpd.conf | |
142 | dracut_install /etc/nsswitch.conf /etc/rpc /etc/protocols | |
143 | dracut_install rpc.idmapd /etc/idmapd.conf | |
144 | if ldd $(which rpc.idmapd) |grep -q lib64; then | |
145 | LIBDIR="/lib64" | |
146 | else | |
147 | LIBDIR="/lib" | |
148 | fi | |
149 | ||
150 | dracut_install $(ls {/usr,}$LIBDIR/libnfsidmap*.so* 2>/dev/null ) | |
c5ef4b63 | 151 | dracut_install $(ls {/usr,}$LIBDIR/libnfsidmap/*.so 2>/dev/null ) |
a71f1b49 | 152 | dracut_install $(ls {/usr,}$LIBDIR/libnss*.so 2>/dev/null) |
c5ef4b63 HH |
153 | |
154 | ||
155 | nsslibs=$(sed -e '/^#/d' -e 's/^.*://' -e 's/\[NOTFOUND=return\]//' /etc/nsswitch.conf \ | |
156 | | tr -s '[:space:]' '\n' | sort -u | tr -s '[:space:]' '|') | |
157 | nsslibs=${nsslibs#|} | |
158 | nsslibs=${nsslibs%|} | |
159 | ||
160 | dracut_install $(for i in $(ls {/usr,}$LIBDIR/libnss*.so 2>/dev/null); do echo $i;done | egrep "$nsslibs") | |
a71f1b49 PS |
161 | ( |
162 | cd "$initdir"; | |
163 | mkdir -p dev sys proc etc var/run tmp var/lib/{dhcpd,rpcbind} | |
164 | mkdir -p var/lib/nfs/{v4recovery,rpc_pipefs} | |
165 | chmod 777 var/lib/rpcbind var/lib/nfs | |
166 | ) | |
167 | inst /etc/nsswitch.conf /etc/nsswitch.conf | |
168 | inst /etc/passwd /etc/passwd | |
169 | inst /etc/group /etc/group | |
170 | for i in /lib*/libnss_files**;do | |
171 | inst_library $i | |
172 | done | |
173 | ||
174 | /sbin/depmod -a -b "$initdir" $kernel | |
8a080127 PS |
175 | cp -a /etc/ld.so.conf* $initdir/etc |
176 | sudo ldconfig -r "$initdir" | |
a71f1b49 PS |
177 | ) |
178 | ||
179 | # Make client root inside server root | |
180 | initdir=mnt/nfs/client | |
181 | mkdir -p $initdir | |
182 | ||
183 | ( | |
184 | . $basedir/dracut-functions | |
185 | dracut_install sh shutdown poweroff stty cat ps ln ip \ | |
186 | /lib/terminfo/l/linux mount dmesg mkdir \ | |
187 | cp ping grep | |
188 | inst ./client-init /sbin/init | |
189 | ( | |
190 | cd "$initdir" | |
191 | mkdir -p dev sys proc etc | |
192 | mkdir -p var/lib/nfs/rpc_pipefs | |
193 | ) | |
194 | inst /etc/nsswitch.conf /etc/nsswitch.conf | |
195 | inst /etc/passwd /etc/passwd | |
196 | inst /etc/group /etc/group | |
197 | for i in /lib*/libnss_files*;do | |
198 | inst_library $i | |
199 | done | |
200 | ||
8a080127 PS |
201 | cp -a /etc/ld.so.conf* $initdir/etc |
202 | sudo ldconfig -r "$initdir" | |
a71f1b49 PS |
203 | ) |
204 | ||
205 | sudo umount mnt | |
206 | rm -fr mnt | |
207 | ||
208 | # Make an overlay with needed tools for the test harness | |
209 | ( | |
210 | initdir=overlay | |
211 | mkdir overlay | |
212 | . $basedir/dracut-functions | |
213 | dracut_install poweroff shutdown | |
214 | inst_simple ./hard-off.sh /emergency/01hard-off.sh | |
778d2ba2 | 215 | inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules |
a71f1b49 PS |
216 | ) |
217 | ||
218 | # Make server's dracut image | |
219 | $basedir/dracut -l -i overlay / \ | |
220 | -m "dash udev-rules base rootfs-block debug kernel-modules" \ | |
778d2ba2 | 221 | -d "piix ide-gd_mod ata_piix ext2 sd_mod e1000" \ |
a71f1b49 PS |
222 | -f initramfs.server $KVERSION || return 1 |
223 | ||
224 | # Make client's dracut image | |
225 | $basedir/dracut -l -i overlay / \ | |
226 | -o "plymouth" \ | |
227 | -a "debug" \ | |
da4e6443 | 228 | -d "piix sd_mod sr_mod ata_piix ide-gd_mod e1000 nfs sunrpc" \ |
a71f1b49 PS |
229 | -f initramfs.testing $KVERSION || return 1 |
230 | } | |
231 | ||
6c980807 | 232 | kill_server() { |
a71f1b49 PS |
233 | if [[ -s server.pid ]]; then |
234 | sudo kill -TERM $(cat server.pid) | |
235 | rm -f server.pid | |
236 | fi | |
6c980807 HH |
237 | } |
238 | ||
239 | test_cleanup() { | |
a71f1b49 PS |
240 | rm -rf mnt overlay |
241 | rm -f server.ext2 client.img initramfs.server initramfs.testing | |
242 | } | |
243 | ||
244 | . $testdir/test-functions |