]> git.ipfire.org Git - thirdparty/dracut.git/blame - test/TEST-31-ISCSI-MULTI/test.sh
Revert "test: run-qemu refactor common qemu parameters"
[thirdparty/dracut.git] / test / TEST-31-ISCSI-MULTI / test.sh
CommitLineData
66a3d405 1#!/bin/bash
604c09b1 2TEST_DESCRIPTION="root filesystem over multiple iSCSI"
66a3d405
HH
3
4KVERSION=${KVERSION-$(uname -r)}
5
0f294d90 6#DEBUGFAIL="loglevel=1"
66a3d405 7#DEBUGFAIL="rd.shell rd.break rd.debug loglevel=7 "
0f294d90 8DEBUGFAIL="rd.debug loglevel=7 "
66a3d405
HH
9#SERVER_DEBUG="rd.debug loglevel=7"
10#SERIAL="tcp:127.0.0.1:9999"
11
12run_server() {
13 # Start server first
14 echo "iSCSI TEST SETUP: Starting DHCP/iSCSI server"
15
16 $testdir/run-qemu \
17 -drive format=raw,index=0,media=disk,file=$TESTDIR/server.ext3 \
18 -drive format=raw,index=1,media=disk,file=$TESTDIR/root.ext3 \
19 -drive format=raw,index=2,media=disk,file=$TESTDIR/iscsidisk2.img \
20 -drive format=raw,index=3,media=disk,file=$TESTDIR/iscsidisk3.img \
4b60a347
HH
21 -m 512M -smp 2 \
22 -display none \
66a3d405
HH
23 ${SERIAL:+-serial "$SERIAL"} \
24 ${SERIAL:--serial file:"$TESTDIR"/server.log} \
25 -net nic,macaddr=52:54:00:12:34:56,model=e1000 \
26 -net nic,macaddr=52:54:00:12:34:57,model=e1000 \
ffbd37d7 27 -net socket,listen=127.0.0.1:12331 \
4b60a347 28 -no-reboot \
7934c6f9 29 -append "panic=1 systemd.crash_reboot root=/dev/sda rootfstype=ext3 rw console=ttyS0,115200n81 selinux=0 $SERVER_DEBUG" \
66a3d405
HH
30 -initrd $TESTDIR/initramfs.server \
31 -pidfile $TESTDIR/server.pid -daemonize || return 1
4bd0ab61 32 chmod 644 $TESTDIR/server.pid || return 1
66a3d405
HH
33
34 # Cleanup the terminal if we have one
35 tty -s && stty sane
36
3aae122c
HH
37 if ! [[ $SERIAL ]]; then
38 echo "Waiting for the server to startup"
39 while : ; do
40 grep Serving "$TESTDIR"/server.log && break
41 sleep 1
42 done
43 else
44 echo Sleeping 10 seconds to give the server a head start
45 sleep 10
46 fi
66a3d405
HH
47}
48
49run_client() {
50 local test_name=$1; shift
51 echo "CLIENT TEST START: $test_name"
52
53 dd if=/dev/zero of=$TESTDIR/client.img bs=1M count=1
54
55 $testdir/run-qemu \
56 -drive format=raw,index=0,media=disk,file=$TESTDIR/client.img \
4b60a347 57 -m 512M -smp 2 -nographic \
66a3d405
HH
58 -net nic,macaddr=52:54:00:12:34:00,model=e1000 \
59 -net nic,macaddr=52:54:00:12:34:01,model=e1000 \
ffbd37d7 60 -net socket,connect=127.0.0.1:12331 \
4b60a347 61 -no-reboot \
7934c6f9 62 -append "panic=1 systemd.crash_reboot rw rd.auto rd.retry=50 console=ttyS0,115200n81 selinux=0 rd.debug=0 rd.shell=0 $DEBUGFAIL $*" \
66a3d405
HH
63 -initrd $TESTDIR/initramfs.testing
64 if ! grep -F -m 1 -q iscsi-OK $TESTDIR/client.img; then
2f78bafa
HH
65 echo "CLIENT TEST END: $test_name [FAILED - BAD EXIT]"
66 return 1
66a3d405
HH
67 fi
68
69 echo "CLIENT TEST END: $test_name [OK]"
70 return 0
71}
72
73do_test_run() {
74 initiator=$(iscsi-iname)
75 run_client "netroot=iscsi target1 target2" \
76 "root=LABEL=sysroot" \
77 "ip=192.168.50.101:::255.255.255.0::ens3:off" \
78 "ip=192.168.51.101:::255.255.255.0::ens4:off" \
79 "netroot=iscsi:192.168.51.1::::iqn.2009-06.dracut:target1" \
80 "netroot=iscsi:192.168.50.1::::iqn.2009-06.dracut:target2" \
81 "rd.iscsi.initiator=$initiator" \
82 || return 1
83
28a68f1f
HH
84 run_client "netroot=iscsi target1 target2 rd.iscsi.waitnet=0" \
85 "root=LABEL=sysroot" \
86 "ip=192.168.50.101:::255.255.255.0::ens3:off" \
87 "ip=192.168.51.101:::255.255.255.0::ens4:off" \
88 "netroot=iscsi:192.168.51.1::::iqn.2009-06.dracut:target1" \
89 "netroot=iscsi:192.168.50.1::::iqn.2009-06.dracut:target2" \
90 "rd.iscsi.firmware" \
91 "rd.iscsi.initiator=$initiator" \
92 "rd.iscsi.waitnet=0" \
93 || return 1
94
95 run_client "netroot=iscsi target1 target2 rd.iscsi.waitnet=0 rd.iscsi.testroute=0" \
96 "root=LABEL=sysroot" \
97 "ip=192.168.50.101:::255.255.255.0::ens3:off" \
98 "ip=192.168.51.101:::255.255.255.0::ens4:off" \
99 "netroot=iscsi:192.168.51.1::::iqn.2009-06.dracut:target1" \
100 "netroot=iscsi:192.168.50.1::::iqn.2009-06.dracut:target2" \
101 "rd.iscsi.firmware" \
102 "rd.iscsi.initiator=$initiator" \
103 "rd.iscsi.waitnet=0 rd.iscsi.testroute=0" \
104 || return 1
105
106 run_client "netroot=iscsi target1 target2 rd.iscsi.waitnet=0 rd.iscsi.testroute=0 default GW" \
107 "root=LABEL=sysroot" \
108 "ip=192.168.50.101::192.168.50.1:255.255.255.0::ens3:off" \
109 "ip=192.168.51.101::192.168.51.1:255.255.255.0::ens4:off" \
110 "netroot=iscsi:192.168.51.1::::iqn.2009-06.dracut:target1" \
111 "netroot=iscsi:192.168.50.1::::iqn.2009-06.dracut:target2" \
112 "rd.iscsi.firmware" \
113 "rd.iscsi.initiator=$initiator" \
114 "rd.iscsi.waitnet=0 rd.iscsi.testroute=0" \
115 || return 1
66a3d405
HH
116
117 echo "All tests passed [OK]"
118 return 0
119}
120
121test_run() {
122 if ! run_server; then
123 echo "Failed to start server" 1>&2
124 return 1
125 fi
126 do_test_run
127 ret=$?
128 if [[ -s $TESTDIR/server.pid ]]; then
4bd0ab61 129 kill -TERM $(cat $TESTDIR/server.pid)
66a3d405
HH
130 rm -f -- $TESTDIR/server.pid
131 fi
132 return $ret
133}
134
135test_setup() {
136 if ! command -v tgtd &>/dev/null || ! command -v tgtadm &>/dev/null; then
137 echo "Need tgtd and tgtadm from scsi-target-utils"
138 return 1
139 fi
140
141 # Create the blank file to use as a root filesystem
e318ba30
LR
142 dd if=/dev/null of=$TESTDIR/root.ext3 bs=1M seek=45
143 dd if=/dev/null of=$TESTDIR/iscsidisk2.img bs=1M seek=45
144 dd if=/dev/null of=$TESTDIR/iscsidisk3.img bs=1M seek=45
66a3d405
HH
145
146 kernel=$KVERSION
147 # Create what will eventually be our root filesystem onto an overlay
148 (
149 export initdir=$TESTDIR/overlay/source
150 . $basedir/dracut-init.sh
151 (
152 cd "$initdir"
153 mkdir -p -- dev sys proc etc var/run tmp
154 mkdir -p root usr/bin usr/lib usr/lib64 usr/sbin
155 for i in bin sbin lib lib64; do
156 ln -sfnr usr/$i $i
157 done
158 mkdir -p -- var/lib/nfs/rpc_pipefs
159 )
160 inst_multiple sh shutdown poweroff stty cat ps ln ip \
2f78bafa 161 mount dmesg mkdir cp ping grep setsid
66a3d405
HH
162 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
163 [ -f ${_terminfodir}/l/linux ] && break
164 done
165 inst_multiple -o ${_terminfodir}/l/linux
166 inst_simple /etc/os-release
167 inst ./client-init.sh /sbin/init
168 cp -a /etc/ld.so.conf* $initdir/etc
4bd0ab61 169 ldconfig -r "$initdir"
66a3d405
HH
170 )
171
172 # second, install the files needed to make the root filesystem
173 (
174 export initdir=$TESTDIR/overlay
175 . $basedir/dracut-init.sh
176 inst_multiple sfdisk mkfs.ext3 poweroff cp umount setsid
177 inst_hook initqueue 01 ./create-root.sh
178 inst_hook initqueue/finished 01 ./finished-false.sh
179 inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
180 )
181
182 # create an initramfs that will create the target root filesystem.
183 # We do it this way so that we do not risk trashing the host mdraid
184 # devices, volume groups, encrypted partitions, etc.
185 $basedir/dracut.sh -l -i $TESTDIR/overlay / \
2f78bafa
HH
186 -m "dash crypt lvm mdraid udev-rules base rootfs-block fs-lib kernel-modules qemu" \
187 -d "piix ide-gd_mod ata_piix ext3 sd_mod" \
188 --no-hostonly-cmdline -N \
189 -f $TESTDIR/initramfs.makeroot $KVERSION || return 1
66a3d405
HH
190 rm -rf -- $TESTDIR/overlay
191
192
193 # Need this so kvm-qemu will boot (needs non-/dev/zero local disk)
194 if ! dd if=/dev/null of=$TESTDIR/client.img bs=1M seek=1; then
195 echo "Unable to make client sdb image" 1>&2
196 return 1
197 fi
198 # Invoke KVM and/or QEMU to actually create the target filesystem.
199 $testdir/run-qemu \
200 -drive format=raw,index=0,media=disk,file=$TESTDIR/root.ext3 \
201 -drive format=raw,index=1,media=disk,file=$TESTDIR/client.img \
202 -drive format=raw,index=2,media=disk,file=$TESTDIR/iscsidisk2.img \
203 -drive format=raw,index=3,media=disk,file=$TESTDIR/iscsidisk3.img \
4b60a347 204 -smp 2 -m 512M -nographic -net none \
66a3d405
HH
205 -append "root=/dev/fakeroot rw rootfstype=ext3 quiet console=ttyS0,115200n81 selinux=0" \
206 -initrd $TESTDIR/initramfs.makeroot || return 1
207 grep -F -m 1 -q dracut-root-block-created $TESTDIR/client.img || return 1
208 rm -- $TESTDIR/client.img
209 (
210 export initdir=$TESTDIR/overlay
211 . $basedir/dracut-init.sh
212 inst_multiple poweroff shutdown
213 inst_hook shutdown-emergency 000 ./hard-off.sh
214 inst_hook emergency 000 ./hard-off.sh
215 inst_simple ./99-idesymlinks.rules /etc/udev/rules.d/99-idesymlinks.rules
216 )
4bd0ab61 217 $basedir/dracut.sh -l -i $TESTDIR/overlay / \
2f78bafa
HH
218 -o "dash plymouth dmraid nfs" \
219 -a "debug" \
220 -d "af_packet piix ide-gd_mod ata_piix ext3 sd_mod" \
221 --no-hostonly-cmdline -N \
222 -f $TESTDIR/initramfs.testing $KVERSION || return 1
66a3d405
HH
223
224 # Make server root
225 dd if=/dev/null of=$TESTDIR/server.ext3 bs=1M seek=60
226 mkfs.ext3 -j -F $TESTDIR/server.ext3
227 mkdir $TESTDIR/mnt
4bd0ab61 228 mount -o loop $TESTDIR/server.ext3 $TESTDIR/mnt
66a3d405
HH
229
230 kernel=$KVERSION
231 (
232 export initdir=$TESTDIR/mnt
233 . $basedir/dracut-init.sh
234 (
235 cd "$initdir";
236 mkdir -p dev sys proc etc var/run tmp var/lib/dhcpd /etc/iscsi
237 )
238 inst /etc/passwd /etc/passwd
239 inst_multiple sh ls shutdown poweroff stty cat ps ln ip \
2f78bafa
HH
240 dmesg mkdir cp ping \
241 modprobe tcpdump setsid \
242 /etc/services sleep mount chmod
66a3d405
HH
243 inst_multiple tgtd tgtadm
244 for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do
245 [ -f ${_terminfodir}/l/linux ] && break
246 done
247 inst_multiple -o ${_terminfodir}/l/linux
248 instmods iscsi_tcp crc32c ipv6
249 [ -f /etc/netconfig ] && inst_multiple /etc/netconfig
250 type -P dhcpd >/dev/null && inst_multiple dhcpd
251 [ -x /usr/sbin/dhcpd3 ] && inst /usr/sbin/dhcpd3 /usr/sbin/dhcpd
252 inst_simple /etc/os-release
253 inst ./server-init.sh /sbin/init
254 inst ./hosts /etc/hosts
255 inst ./dhcpd.conf /etc/dhcpd.conf
256 inst_multiple /etc/nsswitch.conf /etc/rpc /etc/protocols
257 inst /etc/group /etc/group
258
259 cp -a /etc/ld.so.conf* $initdir/etc
4bd0ab61 260 ldconfig -r "$initdir"
66a3d405
HH
261 dracut_kernel_post
262 )
263
4bd0ab61 264 umount $TESTDIR/mnt
66a3d405
HH
265 rm -fr -- $TESTDIR/mnt
266
267 # Make server's dracut image
268 $basedir/dracut.sh -l -i $TESTDIR/overlay / \
2f78bafa
HH
269 -a "dash udev-rules base rootfs-block fs-lib debug kernel-modules" \
270 -d "af_packet piix ide-gd_mod ata_piix ext3 sd_mod e1000 drbg" \
271 --no-hostonly-cmdline -N \
272 -f $TESTDIR/initramfs.server $KVERSION || return 1
66a3d405
HH
273
274}
275
276test_cleanup() {
277 if [[ -s $TESTDIR/server.pid ]]; then
4bd0ab61 278 kill -TERM $(cat $TESTDIR/server.pid)
66a3d405
HH
279 rm -f -- $TESTDIR/server.pid
280 fi
281}
282
283. $testdir/test-functions