]>
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 \ | |
15 | -net socket,mcast=230.0.0.1:1234 \ | |
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 \ | |
49 | -net socket,mcast=230.0.0.1:1234 \ | |
50 | -kernel /boot/vmlinuz-$KVERSION \ | |
ba54a4c7 | 51 | -append "$cmdline $DEBUGFAIL rdinitdebug rdinfo rdnetdebug ro quiet console=ttyS0,115200n81 selinux=0 rdshell 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 | |
78 | ||
79 | # Mac Numbering Scheme | |
80 | # ...:00-02 receive IP adresses all others don't | |
81 | # ...:02 receives a dhcp root-path | |
82 | ||
83 | # PXE Style BOOTIF= | |
84 | client_test "MULTINIC root=nfs BOOTIF=" \ | |
85 | 00 01 02 \ | |
86 | "root=nfs:192.168.50.1:/nfs/client BOOTIF=52-54-00-12-34-00" \ | |
87 | "eth0" || return 1 | |
88 | ||
89 | # PXE Style BOOTIF= with dhcp root-path | |
90 | client_test "MULTINIC root=dhcp BOOTIF=" \ | |
91 | 00 01 02 \ | |
92 | "root=dhcp BOOTIF=52-54-00-12-34-02" \ | |
93 | "eth2" || return 1 | |
94 | ||
95 | # Multinic case, where only one nic works | |
96 | client_test "MULTINIC root=nfs ip=dhcp" \ | |
97 | FF 00 FE \ | |
98 | "root=nfs:192.168.50.1:/nfs/client ip=dhcp" \ | |
99 | "eth1" || return 1 | |
100 | ||
101 | # Require two interfaces | |
102 | client_test "MULTINIC root=nfs ip=eth1:dhcp ip=eth2:dhcp bootdev=eth1" \ | |
103 | 00 01 02 \ | |
104 | "root=nfs:192.168.50.1:/nfs/client ip=eth1:dhcp ip=eth2:dhcp bootdev=eth1" \ | |
105 | "eth1 eth2" || return 1 | |
106 | ||
107 | # Require three interfaces with dhcp root-path | |
108 | client_test "MULTINIC root=dhcp ip=eth0:dhcp ip=eth1:dhcp ip=eth2:dhcp bootdev=eth2" \ | |
109 | 00 01 02 \ | |
110 | "root=dhcp ip=eth0:dhcp ip=eth1:dhcp ip=eth2:dhcp bootdev=eth2" \ | |
111 | "eth0 eth1 eth2" || return 1 | |
112 | } | |
113 | ||
114 | test_setup() { | |
115 | # Make server root | |
116 | dd if=/dev/zero of=server.ext2 bs=1M count=60 | |
117 | mke2fs -F server.ext2 | |
118 | mkdir mnt | |
119 | sudo mount -o loop server.ext2 mnt | |
120 | ||
121 | kernel=$KVERSION | |
122 | ( | |
123 | initdir=mnt | |
124 | . $basedir/dracut-functions | |
125 | dracut_install sh ls shutdown poweroff stty cat ps ln ip \ | |
126 | /lib/terminfo/l/linux dmesg mkdir cp ping exportfs \ | |
127 | modprobe rpc.nfsd rpc.mountd showmount tcpdump \ | |
128 | /etc/services sleep mount chmod | |
129 | which portmap >/dev/null 2>&1 && dracut_install portmap | |
130 | which rpcbind >/dev/null 2>&1 && dracut_install rpcbind | |
131 | [ -f /etc/netconfig ] && dracut_install /etc/netconfig | |
132 | which dhcpd >/dev/null 2>&1 && dracut_install dhcpd | |
133 | [ -x /usr/sbin/dhcpd3 ] && inst /usr/sbin/dhcpd3 /usr/sbin/dhcpd | |
134 | instmods nfsd sunrpc ipv6 | |
135 | inst ./server-init /sbin/init | |
136 | inst ./hosts /etc/hosts | |
137 | inst ./exports /etc/exports | |
138 | inst ./dhcpd.conf /etc/dhcpd.conf | |
139 | dracut_install /etc/nsswitch.conf /etc/rpc /etc/protocols | |
140 | dracut_install rpc.idmapd /etc/idmapd.conf | |
141 | if ldd $(which rpc.idmapd) |grep -q lib64; then | |
142 | LIBDIR="/lib64" | |
143 | else | |
144 | LIBDIR="/lib" | |
145 | fi | |
146 | ||
147 | dracut_install $(ls {/usr,}$LIBDIR/libnfsidmap*.so* 2>/dev/null ) | |
148 | dracut_install $(ls {/usr,}$LIBDIR/libnss*.so 2>/dev/null) | |
149 | ( | |
150 | cd "$initdir"; | |
151 | mkdir -p dev sys proc etc var/run tmp var/lib/{dhcpd,rpcbind} | |
152 | mkdir -p var/lib/nfs/{v4recovery,rpc_pipefs} | |
153 | chmod 777 var/lib/rpcbind var/lib/nfs | |
154 | ) | |
155 | inst /etc/nsswitch.conf /etc/nsswitch.conf | |
156 | inst /etc/passwd /etc/passwd | |
157 | inst /etc/group /etc/group | |
158 | for i in /lib*/libnss_files**;do | |
159 | inst_library $i | |
160 | done | |
161 | ||
162 | /sbin/depmod -a -b "$initdir" $kernel | |
163 | ldconfig -n -r "$initdir" /lib* /usr/lib* | |
164 | ) | |
165 | ||
166 | # Make client root inside server root | |
167 | initdir=mnt/nfs/client | |
168 | mkdir -p $initdir | |
169 | ||
170 | ( | |
171 | . $basedir/dracut-functions | |
172 | dracut_install sh shutdown poweroff stty cat ps ln ip \ | |
173 | /lib/terminfo/l/linux mount dmesg mkdir \ | |
174 | cp ping grep | |
175 | inst ./client-init /sbin/init | |
176 | ( | |
177 | cd "$initdir" | |
178 | mkdir -p dev sys proc etc | |
179 | mkdir -p var/lib/nfs/rpc_pipefs | |
180 | ) | |
181 | inst /etc/nsswitch.conf /etc/nsswitch.conf | |
182 | inst /etc/passwd /etc/passwd | |
183 | inst /etc/group /etc/group | |
184 | for i in /lib*/libnss_files*;do | |
185 | inst_library $i | |
186 | done | |
187 | ||
188 | ldconfig -n -r "$initdir" /lib* /usr/lib* | |
189 | ) | |
190 | ||
191 | sudo umount mnt | |
192 | rm -fr mnt | |
193 | ||
194 | # Make an overlay with needed tools for the test harness | |
195 | ( | |
196 | initdir=overlay | |
197 | mkdir overlay | |
198 | . $basedir/dracut-functions | |
199 | dracut_install poweroff shutdown | |
200 | inst_simple ./hard-off.sh /emergency/01hard-off.sh | |
778d2ba2 | 201 | inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules |
a71f1b49 PS |
202 | ) |
203 | ||
204 | # Make server's dracut image | |
205 | $basedir/dracut -l -i overlay / \ | |
206 | -m "dash udev-rules base rootfs-block debug kernel-modules" \ | |
778d2ba2 | 207 | -d "piix ide-gd_mod ata_piix ext2 sd_mod e1000" \ |
a71f1b49 PS |
208 | -f initramfs.server $KVERSION || return 1 |
209 | ||
210 | # Make client's dracut image | |
211 | $basedir/dracut -l -i overlay / \ | |
212 | -o "plymouth" \ | |
213 | -a "debug" \ | |
778d2ba2 | 214 | -d "piix ide-gd_mod e1000 nfs sunrpc" \ |
a71f1b49 PS |
215 | -f initramfs.testing $KVERSION || return 1 |
216 | } | |
217 | ||
218 | test_cleanup() { | |
219 | if [[ -s server.pid ]]; then | |
220 | sudo kill -TERM $(cat server.pid) | |
221 | rm -f server.pid | |
222 | fi | |
223 | rm -rf mnt overlay | |
224 | rm -f server.ext2 client.img initramfs.server initramfs.testing | |
225 | } | |
226 | ||
227 | . $testdir/test-functions |