]> git.ipfire.org Git - thirdparty/dracut.git/blob - test/TEST-50-MULTINIC/test.sh
test: use ldconfig processing for roots as well
[thirdparty/dracut.git] / test / TEST-50-MULTINIC / test.sh
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
7 #DEBUGFAIL="rdshell"
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 \
18 -append "selinux=0 root=/dev/sda rdinitdebug rdinfo rdnetdebug rw quiet console=ttyS0,115200n81" \
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 \
51 -append "$cmdline $DEBUGFAIL rdinitdebug rdinfo rdnetdebug ro quiet console=ttyS0,115200n81 selinux=0 rdshell rdcopystate" \
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 cp -a /etc/ld.so.conf* $initdir/etc
164 sudo ldconfig -r "$initdir"
165 )
166
167 # Make client root inside server root
168 initdir=mnt/nfs/client
169 mkdir -p $initdir
170
171 (
172 . $basedir/dracut-functions
173 dracut_install sh shutdown poweroff stty cat ps ln ip \
174 /lib/terminfo/l/linux mount dmesg mkdir \
175 cp ping grep
176 inst ./client-init /sbin/init
177 (
178 cd "$initdir"
179 mkdir -p dev sys proc etc
180 mkdir -p var/lib/nfs/rpc_pipefs
181 )
182 inst /etc/nsswitch.conf /etc/nsswitch.conf
183 inst /etc/passwd /etc/passwd
184 inst /etc/group /etc/group
185 for i in /lib*/libnss_files*;do
186 inst_library $i
187 done
188
189 cp -a /etc/ld.so.conf* $initdir/etc
190 sudo ldconfig -r "$initdir"
191 )
192
193 sudo umount mnt
194 rm -fr mnt
195
196 # Make an overlay with needed tools for the test harness
197 (
198 initdir=overlay
199 mkdir overlay
200 . $basedir/dracut-functions
201 dracut_install poweroff shutdown
202 inst_simple ./hard-off.sh /emergency/01hard-off.sh
203 inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
204 )
205
206 # Make server's dracut image
207 $basedir/dracut -l -i overlay / \
208 -m "dash udev-rules base rootfs-block debug kernel-modules" \
209 -d "piix ide-gd_mod ata_piix ext2 sd_mod e1000" \
210 -f initramfs.server $KVERSION || return 1
211
212 # Make client's dracut image
213 $basedir/dracut -l -i overlay / \
214 -o "plymouth" \
215 -a "debug" \
216 -d "piix ide-gd_mod e1000 nfs sunrpc" \
217 -f initramfs.testing $KVERSION || return 1
218 }
219
220 test_cleanup() {
221 if [[ -s server.pid ]]; then
222 sudo kill -TERM $(cat server.pid)
223 rm -f server.pid
224 fi
225 rm -rf mnt overlay
226 rm -f server.ext2 client.img initramfs.server initramfs.testing
227 }
228
229 . $testdir/test-functions