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