]>
Commit | Line | Data |
---|---|---|
ac4ded91 | 1 | #!/bin/bash |
a3f73298 | 2 | |
43c16bfa | 3 | [ -z "$USE_NETWORK" ] && USE_NETWORK="network-legacy" |
a3f73298 | 4 | |
2aa97ff2 | 5 | # shellcheck disable=SC2034 |
a3f73298 | 6 | TEST_DESCRIPTION="root filesystem over iSCSI with $USE_NETWORK" |
eeb72103 HH |
7 | |
8 | KVERSION=${KVERSION-$(uname -r)} | |
9 | ||
6251f82c | 10 | #DEBUGFAIL="rd.shell rd.break rd.debug loglevel=7 " |
c22c43f8 | 11 | #SERVER_DEBUG="rd.debug loglevel=7" |
b0d6254d | 12 | #SERIAL="tcp:127.0.0.1:9999" |
eeb72103 HH |
13 | |
14 | run_server() { | |
15 | # Start server first | |
16 | echo "iSCSI TEST SETUP: Starting DHCP/iSCSI server" | |
17 | ||
b80ee080 HH |
18 | declare -a disk_args=() |
19 | declare -i disk_index=0 | |
20 | qemu_add_drive_args disk_index disk_args "$TESTDIR"/server.img serverroot 1 | |
21 | qemu_add_drive_args disk_index disk_args "$TESTDIR"/singleroot.img singleroot | |
22 | qemu_add_drive_args disk_index disk_args "$TESTDIR"/raid0-1.img raid0-1 | |
23 | qemu_add_drive_args disk_index disk_args "$TESTDIR"/raid0-2.img raid0-2 | |
24 | ||
2aa97ff2 | 25 | "$testdir"/run-qemu \ |
b80ee080 | 26 | "${disk_args[@]}" \ |
2aa97ff2 | 27 | -serial "${SERIAL:-"file:$TESTDIR/server.log"}" \ |
3905f669 | 28 | -net nic,macaddr=52:54:00:12:34:56,model=e1000 \ |
c22c43f8 | 29 | -net nic,macaddr=52:54:00:12:34:57,model=e1000 \ |
3905f669 | 30 | -net socket,listen=127.0.0.1:12330 \ |
006890a2 | 31 | -append "panic=1 oops=panic softlockup_panic=1 quiet root=/dev/disk/by-id/ata-disk_serverroot rootfstype=ext4 rw console=ttyS0,115200n81 selinux=0 $SERVER_DEBUG" \ |
2aa97ff2 HH |
32 | -initrd "$TESTDIR"/initramfs.server \ |
33 | -pidfile "$TESTDIR"/server.pid -daemonize || return 1 | |
34 | chmod 644 "$TESTDIR"/server.pid || return 1 | |
eeb72103 HH |
35 | |
36 | # Cleanup the terminal if we have one | |
37 | tty -s && stty sane | |
38 | ||
3aae122c | 39 | if ! [[ $SERIAL ]]; then |
b80ee080 HH |
40 | while :; do |
41 | grep Serving "$TESTDIR"/server.log && break | |
f7b9356c | 42 | echo "Waiting for the server to startup" |
b80ee080 | 43 | tail "$TESTDIR"/server.log |
3aae122c HH |
44 | sleep 1 |
45 | done | |
46 | else | |
47 | echo Sleeping 10 seconds to give the server a head start | |
48 | sleep 10 | |
49 | fi | |
b80ee080 | 50 | |
eeb72103 HH |
51 | } |
52 | ||
53 | run_client() { | |
9a52c3fd HH |
54 | local test_name=$1 |
55 | shift | |
9373aec6 | 56 | echo "CLIENT TEST START: $test_name" |
eeb72103 | 57 | |
b80ee080 HH |
58 | dd if=/dev/zero of="$TESTDIR"/marker.img bs=1MiB count=1 |
59 | declare -a disk_args=() | |
60 | declare -i disk_index=0 | |
61 | qemu_add_drive_args disk_index disk_args "$TESTDIR"/marker.img marker | |
eeb72103 | 62 | |
2aa97ff2 | 63 | "$testdir"/run-qemu \ |
b80ee080 | 64 | "${disk_args[@]}" \ |
3905f669 | 65 | -net nic,macaddr=52:54:00:12:34:00,model=e1000 \ |
c22c43f8 | 66 | -net nic,macaddr=52:54:00:12:34:01,model=e1000 \ |
3905f669 | 67 | -net socket,connect=127.0.0.1:12330 \ |
9a752007 | 68 | -acpitable file=ibft.table \ |
b2cf61d9 | 69 | -append "panic=1 oops=panic softlockup_panic=1 systemd.crash_reboot rw rd.auto rd.retry=50 console=ttyS0,115200n81 selinux=0 rd.debug=0 rd.shell=0 $DEBUGFAIL $*" \ |
2aa97ff2 | 70 | -initrd "$TESTDIR"/initramfs.testing |
b80ee080 HH |
71 | |
72 | # shellcheck disable=SC2181 | |
73 | if [[ $? -ne 0 ]] || ! grep -U --binary-files=binary -F -m 1 -q iscsi-OK "$TESTDIR"/marker.img; then | |
2f78bafa HH |
74 | echo "CLIENT TEST END: $test_name [FAILED - BAD EXIT]" |
75 | return 1 | |
0be1785a | 76 | fi |
169f1671 | 77 | |
9373aec6 HH |
78 | echo "CLIENT TEST END: $test_name [OK]" |
79 | return 0 | |
80 | } | |
3905f669 | 81 | |
9373aec6 | 82 | do_test_run() { |
0a66b74b HH |
83 | initiator=$(iscsi-iname) |
84 | ||
c22c43f8 | 85 | run_client "root=dhcp" \ |
b80ee080 | 86 | "root=/dev/root netroot=dhcp ip=enp0s1:dhcp" \ |
9a52c3fd | 87 | "rd.iscsi.initiator=$initiator" \ |
c22c43f8 | 88 | || return 1 |
3905f669 | 89 | |
9a52c3fd HH |
90 | run_client "netroot=iscsi target0" \ |
91 | "root=LABEL=singleroot netroot=iscsi:192.168.50.1::::iqn.2009-06.dracut:target0" \ | |
b80ee080 | 92 | "ip=192.168.50.101::192.168.50.1:255.255.255.0:iscsi-1:enp0s1:off" \ |
9a52c3fd | 93 | "rd.iscsi.initiator=$initiator" \ |
c22c43f8 | 94 | || return 1 |
9373aec6 | 95 | |
9a9c67d6 | 96 | run_client "netroot=iscsi target1 target2" \ |
9a52c3fd HH |
97 | "root=LABEL=sysroot" \ |
98 | "ip=dhcp" \ | |
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.initiator=$initiator" \ | |
9a9c67d6 | 102 | || return 1 |
0a66b74b | 103 | |
9a752007 | 104 | run_client "root=ibft" \ |
9a52c3fd HH |
105 | "root=LABEL=singleroot" \ |
106 | "rd.iscsi.ibft=1" \ | |
107 | "rd.iscsi.firmware=1" \ | |
9a752007 LR |
108 | || return 1 |
109 | ||
d7c9ad50 | 110 | echo "All tests passed [OK]" |
9373aec6 | 111 | return 0 |
eeb72103 | 112 | } |
ac4ded91 HH |
113 | |
114 | test_run() { | |
eeb72103 | 115 | if ! run_server; then |
3905f669 HH |
116 | echo "Failed to start server" 1>&2 |
117 | return 1 | |
eeb72103 | 118 | fi |
9373aec6 | 119 | do_test_run |
54aaad9d | 120 | ret=$? |
0be1785a | 121 | if [[ -s $TESTDIR/server.pid ]]; then |
2aa97ff2 HH |
122 | kill -TERM "$(cat "$TESTDIR"/server.pid)" |
123 | rm -f -- "$TESTDIR"/server.pid | |
eeb72103 | 124 | fi |
54aaad9d | 125 | return $ret |
ac4ded91 HH |
126 | } |
127 | ||
128 | test_setup() { | |
9a52c3fd | 129 | if ! command -v tgtd &> /dev/null || ! command -v tgtadm &> /dev/null; then |
dba97484 | 130 | echo "Need tgtd and tgtadm from scsi-target-utils" |
3905f669 | 131 | return 1 |
eeb72103 HH |
132 | fi |
133 | ||
eeb72103 | 134 | kernel=$KVERSION |
ac4ded91 | 135 | # Create what will eventually be our root filesystem onto an overlay |
2aa97ff2 | 136 | rm -rf -- "$TESTDIR"/overlay |
ac4ded91 | 137 | ( |
2aa97ff2 | 138 | # shellcheck disable=SC2030 |
27fa6044 | 139 | export initdir=$TESTDIR/overlay/source |
2aa97ff2 HH |
140 | # shellcheck disable=SC1090 |
141 | . "$basedir"/dracut-init.sh | |
06853123 | 142 | ( |
2aa97ff2 | 143 | cd "$initdir" || exit |
06853123 HH |
144 | mkdir -p -- dev sys proc etc var/run tmp |
145 | mkdir -p root usr/bin usr/lib usr/lib64 usr/sbin | |
06853123 HH |
146 | mkdir -p -- var/lib/nfs/rpc_pipefs |
147 | ) | |
af119460 | 148 | inst_multiple sh shutdown poweroff stty cat ps ln ip \ |
2aa97ff2 | 149 | mount dmesg mkdir cp ping grep setsid dd sync |
96d22bd7 | 150 | for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do |
3905f669 HH |
151 | [ -f ${_terminfodir}/l/linux ] && break |
152 | done | |
af119460 | 153 | inst_multiple -o ${_terminfodir}/l/linux |
021b2fdd | 154 | inst_simple /etc/os-release |
2aa97ff2 HH |
155 | |
156 | inst_simple "${basedir}/modules.d/99base/dracut-lib.sh" "/lib/dracut-lib.sh" | |
c08bc810 | 157 | inst_simple "${basedir}/modules.d/99base/dracut-dev-lib.sh" "/lib/dracut-dev-lib.sh" |
2aa97ff2 HH |
158 | inst_binary "${basedir}/dracut-util" "/usr/bin/dracut-util" |
159 | ln -s dracut-util "${initdir}/usr/bin/dracut-getarg" | |
160 | ln -s dracut-util "${initdir}/usr/bin/dracut-getargs" | |
161 | ||
552ecca6 | 162 | inst ./client-init.sh /sbin/init |
2aa97ff2 | 163 | cp -a /etc/ld.so.conf* "$initdir"/etc |
4bd0ab61 | 164 | ldconfig -r "$initdir" |
ac4ded91 | 165 | ) |
3b403b32 | 166 | |
ac4ded91 HH |
167 | # second, install the files needed to make the root filesystem |
168 | ( | |
2aa97ff2 HH |
169 | # shellcheck disable=SC2031 |
170 | # shellcheck disable=SC2030 | |
27fa6044 | 171 | export initdir=$TESTDIR/overlay |
2aa97ff2 HH |
172 | # shellcheck disable=SC1090 |
173 | . "$basedir"/dracut-init.sh | |
006890a2 | 174 | inst_multiple sfdisk mkfs.ext4 poweroff cp umount setsid dd sync blockdev |
0f62da04 | 175 | inst_hook initqueue 01 ./create-client-root.sh |
356333b3 | 176 | inst_hook initqueue/finished 01 ./finished-false.sh |
ac4ded91 | 177 | ) |
3b403b32 | 178 | |
ac4ded91 HH |
179 | # create an initramfs that will create the target root filesystem. |
180 | # We do it this way so that we do not risk trashing the host mdraid | |
181 | # devices, volume groups, encrypted partitions, etc. | |
2aa97ff2 | 182 | "$basedir"/dracut.sh -l -i "$TESTDIR"/overlay / \ |
1573bb81 | 183 | -m "dash crypt lvm mdraid kernel-modules qemu" \ |
006890a2 | 184 | -d "piix ide-gd_mod ata_piix ext4 sd_mod" \ |
9a52c3fd | 185 | --no-hostonly-cmdline -N \ |
2aa97ff2 HH |
186 | -f "$TESTDIR"/initramfs.makeroot "$KVERSION" || return 1 |
187 | rm -rf -- "$TESTDIR"/overlay | |
eeb72103 | 188 | |
b80ee080 HH |
189 | dd if=/dev/zero of="$TESTDIR"/marker.img bs=1MiB count=1 |
190 | dd if=/dev/zero of="$TESTDIR"/singleroot.img bs=1MiB count=200 | |
191 | dd if=/dev/zero of="$TESTDIR"/raid0-1.img bs=1MiB count=100 | |
192 | dd if=/dev/zero of="$TESTDIR"/raid0-2.img bs=1MiB count=100 | |
193 | ||
194 | declare -a disk_args=() | |
195 | declare -i disk_index=0 | |
196 | qemu_add_drive_args disk_index disk_args "$TESTDIR"/marker.img marker | |
197 | qemu_add_drive_args disk_index disk_args "$TESTDIR"/singleroot.img singleroot | |
198 | qemu_add_drive_args disk_index disk_args "$TESTDIR"/raid0-1.img raid0-1 | |
199 | qemu_add_drive_args disk_index disk_args "$TESTDIR"/raid0-2.img raid0-2 | |
200 | ||
ac4ded91 | 201 | # Invoke KVM and/or QEMU to actually create the target filesystem. |
2aa97ff2 | 202 | "$testdir"/run-qemu \ |
b80ee080 | 203 | "${disk_args[@]}" \ |
006890a2 | 204 | -append "root=/dev/fakeroot rw rootfstype=ext4 quiet console=ttyS0,115200n81 selinux=0" \ |
2aa97ff2 | 205 | -initrd "$TESTDIR"/initramfs.makeroot || return 1 |
b80ee080 HH |
206 | grep -U --binary-files=binary -F -m 1 -q dracut-root-block-created "$TESTDIR"/marker.img || return 1 |
207 | rm -- "$TESTDIR"/marker.img | |
0f62da04 | 208 | |
909961d0 | 209 | # shellcheck disable=SC2031 |
2aa97ff2 HH |
210 | export kernel=$KVERSION |
211 | rm -rf -- "$TESTDIR"/overlay | |
eeb72103 | 212 | ( |
2aa97ff2 HH |
213 | mkdir -p "$TESTDIR"/overlay/source |
214 | # shellcheck disable=SC2031 | |
215 | # shellcheck disable=SC2030 | |
0f62da04 | 216 | export initdir=$TESTDIR/overlay/source |
2aa97ff2 HH |
217 | # shellcheck disable=SC1090 |
218 | . "$basedir"/dracut-init.sh | |
3905f669 | 219 | ( |
2aa97ff2 | 220 | cd "$initdir" || exit |
3905f669 HH |
221 | mkdir -p dev sys proc etc var/run tmp var/lib/dhcpd /etc/iscsi |
222 | ) | |
223 | inst /etc/passwd /etc/passwd | |
af119460 | 224 | inst_multiple sh ls shutdown poweroff stty cat ps ln ip \ |
69f4e7cd | 225 | dmesg mkdir cp ping modprobe tcpdump setsid \ |
8b2afb08 | 226 | sleep mount chmod pidof |
c22c43f8 | 227 | inst_multiple tgtd tgtadm |
96d22bd7 | 228 | for _terminfodir in /lib/terminfo /etc/terminfo /usr/share/terminfo; do |
3905f669 HH |
229 | [ -f ${_terminfodir}/l/linux ] && break |
230 | done | |
af119460 | 231 | inst_multiple -o ${_terminfodir}/l/linux |
8b2afb08 | 232 | instmods iscsi_tcp crc32c ipv6 af_packet |
af119460 | 233 | [ -f /etc/netconfig ] && inst_multiple /etc/netconfig |
9a52c3fd | 234 | type -P dhcpd > /dev/null && inst_multiple dhcpd |
3905f669 | 235 | [ -x /usr/sbin/dhcpd3 ] && inst /usr/sbin/dhcpd3 /usr/sbin/dhcpd |
552ecca6 | 236 | inst ./server-init.sh /sbin/init |
3905f669 HH |
237 | inst ./hosts /etc/hosts |
238 | inst ./dhcpd.conf /etc/dhcpd.conf | |
8b2afb08 HH |
239 | inst_multiple -o {,/usr}/etc/nsswitch.conf {,/usr}/etc/rpc \ |
240 | {,/usr}/etc/protocols {,/usr}/etc/services \ | |
241 | /etc/group /etc/os-release | |
242 | ||
243 | _nsslibs=$( | |
244 | cat "$dracutsysrootdir"/{,usr/}etc/nsswitch.conf 2> /dev/null \ | |
245 | | sed -e '/^#/d' -e 's/^.*://' -e 's/\[NOTFOUND=return\]//' \ | |
246 | | tr -s '[:space:]' '\n' | sort -u | tr -s '[:space:]' '|' | |
247 | ) | |
248 | _nsslibs=${_nsslibs#|} | |
249 | _nsslibs=${_nsslibs%|} | |
250 | ||
251 | inst_libdir_file -n "$_nsslibs" 'libnss_*.so*' | |
3905f669 | 252 | |
2aa97ff2 | 253 | cp -a /etc/ld.so.conf* "$initdir"/etc |
4bd0ab61 | 254 | ldconfig -r "$initdir" |
67ab4f77 | 255 | dracut_kernel_post |
eeb72103 HH |
256 | ) |
257 | ||
0f62da04 HH |
258 | # second, install the files needed to make the root filesystem |
259 | ( | |
2aa97ff2 HH |
260 | # shellcheck disable=SC2031 |
261 | # shellcheck disable=SC2030 | |
0f62da04 | 262 | export initdir=$TESTDIR/overlay |
2aa97ff2 HH |
263 | # shellcheck disable=SC1090 |
264 | . "$basedir"/dracut-init.sh | |
006890a2 | 265 | inst_multiple sfdisk mkfs.ext4 poweroff cp umount sync dd |
0f62da04 HH |
266 | inst_hook initqueue 01 ./create-server-root.sh |
267 | inst_hook initqueue/finished 01 ./finished-false.sh | |
0f62da04 | 268 | ) |
eeb72103 | 269 | |
0f62da04 HH |
270 | # create an initramfs that will create the target root filesystem. |
271 | # We do it this way so that we do not risk trashing the host mdraid | |
272 | # devices, volume groups, encrypted partitions, etc. | |
2aa97ff2 | 273 | "$basedir"/dracut.sh -l -i "$TESTDIR"/overlay / \ |
1573bb81 | 274 | -m "dash rootfs-block kernel-modules qemu" \ |
006890a2 | 275 | -d "piix ide-gd_mod ata_piix ext4 sd_mod" \ |
9a52c3fd HH |
276 | --nomdadmconf \ |
277 | --no-hostonly-cmdline -N \ | |
2aa97ff2 | 278 | -f "$TESTDIR"/initramfs.makeroot "$KVERSION" || return 1 |
b80ee080 HH |
279 | rm -rf -- "$TESTDIR"/overlay |
280 | ||
281 | dd if=/dev/zero of="$TESTDIR"/server.img bs=1MiB count=60 | |
282 | dd if=/dev/zero of="$TESTDIR"/marker.img bs=1MiB count=1 | |
283 | declare -a disk_args=() | |
284 | # shellcheck disable=SC2034 | |
285 | declare -i disk_index=0 | |
286 | qemu_add_drive_args disk_index disk_args "$TESTDIR"/marker.img marker | |
287 | qemu_add_drive_args disk_index disk_args "$TESTDIR"/server.img root | |
a3f73298 | 288 | |
0f62da04 | 289 | # Invoke KVM and/or QEMU to actually create the target filesystem. |
2aa97ff2 | 290 | "$testdir"/run-qemu \ |
b80ee080 | 291 | "${disk_args[@]}" \ |
006890a2 | 292 | -append "root=/dev/dracut/root rw rootfstype=ext4 quiet console=ttyS0,115200n81 selinux=0" \ |
2aa97ff2 | 293 | -initrd "$TESTDIR"/initramfs.makeroot || return 1 |
b80ee080 HH |
294 | grep -U --binary-files=binary -F -m 1 -q dracut-root-block-created "$TESTDIR"/marker.img || return 1 |
295 | rm -- "$TESTDIR"/marker.img | |
0f62da04 HH |
296 | |
297 | # Make an overlay with needed tools for the test harness | |
a3f73298 | 298 | ( |
2aa97ff2 | 299 | # shellcheck disable=SC2031 |
8b2afb08 | 300 | # shellcheck disable=SC2030 |
a3f73298 | 301 | export initdir=$TESTDIR/overlay |
2aa97ff2 HH |
302 | # shellcheck disable=SC1090 |
303 | . "$basedir"/dracut-init.sh | |
a3f73298 HH |
304 | inst_multiple poweroff shutdown |
305 | inst_hook shutdown-emergency 000 ./hard-off.sh | |
306 | inst_hook emergency 000 ./hard-off.sh | |
8b2afb08 | 307 | inst_simple ./client.link /etc/systemd/network/01-client.link |
a3f73298 | 308 | ) |
8b2afb08 HH |
309 | # Make client's dracut image |
310 | "$basedir"/dracut.sh -l -i "$TESTDIR"/overlay / \ | |
1586621b | 311 | -o "plymouth dmraid nfs" \ |
8b2afb08 HH |
312 | -a "debug ${USE_NETWORK}" \ |
313 | --no-hostonly-cmdline -N \ | |
314 | -f "$TESTDIR"/initramfs.testing "$KVERSION" || return 1 | |
0f62da04 | 315 | |
8b2afb08 HH |
316 | ( |
317 | # shellcheck disable=SC2031 | |
318 | export initdir="$TESTDIR"/overlay | |
319 | # shellcheck disable=SC1090 | |
320 | . "$basedir"/dracut-init.sh | |
321 | rm "$initdir"/etc/systemd/network/01-client.link | |
322 | inst_simple ./server.link /etc/systemd/network/01-server.link | |
323 | inst_hook pre-mount 99 ./wait-if-server.sh | |
4a5785a8 | 324 | inst_multiple sysctl |
8b2afb08 | 325 | ) |
0f62da04 | 326 | # Make server's dracut image |
2aa97ff2 | 327 | "$basedir"/dracut.sh -l -i "$TESTDIR"/overlay / \ |
1573bb81 | 328 | -a "dash rootfs-block debug kernel-modules network network-legacy" \ |
006890a2 | 329 | -d "af_packet piix ide-gd_mod ata_piix ext4 sd_mod e1000 drbg" \ |
9a52c3fd | 330 | --no-hostonly-cmdline -N \ |
2aa97ff2 | 331 | -f "$TESTDIR"/initramfs.server "$KVERSION" || return 1 |
0f62da04 | 332 | |
2aa97ff2 | 333 | rm -rf -- "$TESTDIR"/overlay |
ac4ded91 HH |
334 | } |
335 | ||
336 | test_cleanup() { | |
0be1785a | 337 | if [[ -s $TESTDIR/server.pid ]]; then |
2aa97ff2 HH |
338 | kill -TERM "$(cat "$TESTDIR"/server.pid)" |
339 | rm -f -- "$TESTDIR"/server.pid | |
eeb72103 | 340 | fi |
ac4ded91 HH |
341 | } |
342 | ||
2aa97ff2 HH |
343 | # shellcheck disable=SC1090 |
344 | . "$testdir"/test-functions |