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