]> git.ipfire.org Git - thirdparty/dracut.git/blame - test/TEST-50-MULTINIC/test.sh
nfs: extend libnss wildcard
[thirdparty/dracut.git] / test / TEST-50-MULTINIC / test.sh
CommitLineData
a71f1b49
PS
1#!/bin/bash
2TEST_DESCRIPTION="root filesystem on NFS with multiple nics"
3
4KVERSION=${KVERSION-$(uname -r)}
5
6# Uncomment this to debug failures
fa7ada31 7#DEBUGFAIL="rd.shell"
51b28ba9
HH
8#SERIAL="udp:127.0.0.1:9999"
9SERIAL="null"
a71f1b49
PS
10
11run_server() {
12 # Start server first
13 echo "MULTINIC TEST SETUP: Starting DHCP/NFS server"
14
0be1785a 15 $testdir/run-qemu -hda $TESTDIR/server.ext2 -m 256M -nographic \
a71f1b49 16 -net nic,macaddr=52:54:00:12:34:56,model=e1000 \
0be1785a 17 -net socket,listen=127.0.0.1:12350 \
51b28ba9 18 -serial $SERIAL \
a71f1b49 19 -kernel /boot/vmlinuz-$KVERSION \
fa7ada31 20 -append "selinux=0 root=/dev/sda rd.debug rd.info rw quiet console=ttyS0,115200n81" \
0be1785a
HH
21 -initrd $TESTDIR/initramfs.server -pidfile $TESTDIR/server.pid -daemonize || return 1
22 sudo chmod 644 $TESTDIR/server.pid || return 1
a71f1b49
PS
23
24 # Cleanup the terminal if we have one
25 tty -s && stty sane
26
27 echo Sleeping 10 seconds to give the server a head start
28 sleep 10
29}
30
31client_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"
38
39 echo "CLIENT TEST START: $test_name"
40
41 # Need this so kvm-qemu will boot (needs non-/dev/zero local disk)
0be1785a 42 if ! dd if=/dev/zero of=$TESTDIR/client.img bs=1M count=1; then
a71f1b49
PS
43 echo "Unable to make client sda image" 1>&2
44 return 1
45 fi
46
0be1785a 47 $testdir/run-qemu -hda $TESTDIR/client.img -m 512M -nographic \
a71f1b49
PS
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 \
0be1785a 51 -net socket,connect=127.0.0.1:12350 \
b2559a88 52 -hdc /dev/null \
a71f1b49 53 -kernel /boot/vmlinuz-$KVERSION \
fa7ada31 54 -append "$cmdline $DEBUGFAIL rd.retry=5 rd.debug rd.info ro quiet console=ttyS0,115200n81 selinux=0 rd.copystate" \
0be1785a 55 -initrd $TESTDIR/initramfs.testing
a71f1b49 56
0be1785a 57 if [[ $? -ne 0 ]] || ! grep -m 1 -q OK $TESTDIR/client.img; then
a71f1b49
PS
58 echo "CLIENT TEST END: $test_name [FAILED - BAD EXIT]"
59 return 1
60 fi
61
62
63 for i in $check ; do
64 echo $i
0be1785a 65 if ! grep -m 1 -q $i $TESTDIR/client.img; then
a71f1b49
PS
66 echo "CLIENT TEST END: $test_name [FAILED - BAD IF]"
67 return 1
68 fi
69 done
70
71 echo "CLIENT TEST END: $test_name [OK]"
72 return 0
73}
74
75
76test_run() {
77 if ! run_server; then
78 echo "Failed to start server" 1>&2
79 return 1
80 fi
6c980807
HH
81 test_client || { kill_server; return 1; }
82}
a71f1b49 83
6c980807 84test_client() {
a71f1b49
PS
85 # Mac Numbering Scheme
86 # ...:00-02 receive IP adresses all others don't
87 # ...:02 receives a dhcp root-path
88
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
94
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
100
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
106
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
112
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
8f4c0660
HH
118
119 kill_server
120 return 0
a71f1b49
PS
121}
122
123test_setup() {
124 # Make server root
0be1785a
HH
125 dd if=/dev/null of=$TESTDIR/server.ext2 bs=1M seek=60
126 mke2fs -F $TESTDIR/server.ext2
127 mkdir $TESTDIR/mnt
128 sudo mount -o loop $TESTDIR/server.ext2 $TESTDIR/mnt
a71f1b49
PS
129
130 kernel=$KVERSION
131 (
0be1785a 132 initdir=$TESTDIR/mnt
552ecca6 133 . $basedir/dracut-functions.sh
a71f1b49 134 dracut_install sh ls shutdown poweroff stty cat ps ln ip \
96d22bd7 135 dmesg mkdir cp ping exportfs \
a71f1b49
PS
136 modprobe rpc.nfsd rpc.mountd showmount tcpdump \
137 /etc/services sleep mount chmod
96d22bd7
HH
138 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
139 [ -f ${_terminfodir}/l/linux ] && break
140 done
141 dracut_install -o ${_terminfodir}/l/linux
f3af7bd6
142 type -P portmap >/dev/null && dracut_install portmap
143 type -P rpcbind >/dev/null && dracut_install rpcbind
3b403b32 144 [ -f /etc/netconfig ] && dracut_install /etc/netconfig
f3af7bd6 145 type -P dhcpd >/dev/null && dracut_install dhcpd
a71f1b49
PS
146 [ -x /usr/sbin/dhcpd3 ] && inst /usr/sbin/dhcpd3 /usr/sbin/dhcpd
147 instmods nfsd sunrpc ipv6
552ecca6 148 inst ./server-init.sh /sbin/init
a71f1b49
PS
149 inst ./hosts /etc/hosts
150 inst ./exports /etc/exports
151 inst ./dhcpd.conf /etc/dhcpd.conf
152 dracut_install /etc/nsswitch.conf /etc/rpc /etc/protocols
153 dracut_install rpc.idmapd /etc/idmapd.conf
f3af7bd6 154 if ldd $(type -P rpc.idmapd) |grep -q lib64; then
a71f1b49
PS
155 LIBDIR="/lib64"
156 else
157 LIBDIR="/lib"
158 fi
159
160 dracut_install $(ls {/usr,}$LIBDIR/libnfsidmap*.so* 2>/dev/null )
c5ef4b63 161 dracut_install $(ls {/usr,}$LIBDIR/libnfsidmap/*.so 2>/dev/null )
a71f1b49 162 dracut_install $(ls {/usr,}$LIBDIR/libnss*.so 2>/dev/null)
c5ef4b63
HH
163
164
165 nsslibs=$(sed -e '/^#/d' -e 's/^.*://' -e 's/\[NOTFOUND=return\]//' /etc/nsswitch.conf \
166 | tr -s '[:space:]' '\n' | sort -u | tr -s '[:space:]' '|')
167 nsslibs=${nsslibs#|}
168 nsslibs=${nsslibs%|}
169
170 dracut_install $(for i in $(ls {/usr,}$LIBDIR/libnss*.so 2>/dev/null); do echo $i;done | egrep "$nsslibs")
a71f1b49
PS
171 (
172 cd "$initdir";
173 mkdir -p dev sys proc etc var/run tmp var/lib/{dhcpd,rpcbind}
174 mkdir -p var/lib/nfs/{v4recovery,rpc_pipefs}
175 chmod 777 var/lib/rpcbind var/lib/nfs
176 )
177 inst /etc/nsswitch.conf /etc/nsswitch.conf
178 inst /etc/passwd /etc/passwd
179 inst /etc/group /etc/group
180 for i in /lib*/libnss_files**;do
181 inst_library $i
182 done
183
184 /sbin/depmod -a -b "$initdir" $kernel
8a080127
PS
185 cp -a /etc/ld.so.conf* $initdir/etc
186 sudo ldconfig -r "$initdir"
a71f1b49
PS
187 )
188
189 # Make client root inside server root
0be1785a 190 initdir=$TESTDIR/mnt/nfs/client
a71f1b49
PS
191 mkdir -p $initdir
192
193 (
552ecca6 194 . $basedir/dracut-functions.sh
a71f1b49 195 dracut_install sh shutdown poweroff stty cat ps ln ip \
96d22bd7
HH
196 mount dmesg mkdir \
197 cp ping grep ls
198 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
199 [ -f ${_terminfodir}/l/linux ] && break
200 done
201 dracut_install -o ${_terminfodir}/l/linux
552ecca6 202 inst ./client-init.sh /sbin/init
a71f1b49
PS
203 (
204 cd "$initdir"
8a6ecb19 205 mkdir -p dev sys proc etc run
a71f1b49
PS
206 mkdir -p var/lib/nfs/rpc_pipefs
207 )
208 inst /etc/nsswitch.conf /etc/nsswitch.conf
209 inst /etc/passwd /etc/passwd
210 inst /etc/group /etc/group
211 for i in /lib*/libnss_files*;do
212 inst_library $i
213 done
214
8a080127
PS
215 cp -a /etc/ld.so.conf* $initdir/etc
216 sudo ldconfig -r "$initdir"
a71f1b49
PS
217 )
218
0be1785a
HH
219 sudo umount $TESTDIR/mnt
220 rm -fr $TESTDIR/mnt
a71f1b49
PS
221
222 # Make an overlay with needed tools for the test harness
223 (
0be1785a
HH
224 initdir=$TESTDIR/overlay
225 mkdir $TESTDIR/overlay
552ecca6 226 . $basedir/dracut-functions.sh
a71f1b49 227 dracut_install poweroff shutdown
0b53ca70 228 inst_hook emergency 000 ./hard-off.sh
778d2ba2 229 inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
a71f1b49
PS
230 )
231
232 # Make server's dracut image
552ecca6 233 $basedir/dracut.sh -l -i $TESTDIR/overlay / \
a71f1b49 234 -m "dash udev-rules base rootfs-block debug kernel-modules" \
778d2ba2 235 -d "piix ide-gd_mod ata_piix ext2 sd_mod e1000" \
0be1785a 236 -f $TESTDIR/initramfs.server $KVERSION || return 1
a71f1b49
PS
237
238 # Make client's dracut image
552ecca6 239 $basedir/dracut.sh -l -i $TESTDIR/overlay / \
a71f1b49
PS
240 -o "plymouth" \
241 -a "debug" \
da4e6443 242 -d "piix sd_mod sr_mod ata_piix ide-gd_mod e1000 nfs sunrpc" \
0be1785a 243 -f $TESTDIR/initramfs.testing $KVERSION || return 1
a71f1b49
PS
244}
245
6c980807 246kill_server() {
0be1785a
HH
247 if [[ -s $TESTDIR/server.pid ]]; then
248 sudo kill -TERM $(cat $TESTDIR/server.pid)
249 rm -f $TESTDIR/server.pid
a71f1b49 250 fi
6c980807
HH
251}
252
253test_cleanup() {
0be1785a 254 kill_server
a71f1b49
PS
255}
256
257. $testdir/test-functions