-
Notifications
You must be signed in to change notification settings - Fork 7
/
test-virt-p2v-pxe.sh
executable file
·95 lines (80 loc) · 2.63 KB
/
test-virt-p2v-pxe.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash -
# libguestfs virt-p2v test script
# Copyright (C) 2014-2019 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Test virt-p2v in non-GUI mode with something resembling the
# PXE boot code path. This tests:
# * virt-p2v-make-disk
# * systemd p2v.service
# * launch-virt-p2v
# * networking
# * virt-p2v in kernel command-line mode
set -e
$TEST_FUNCTIONS
slow_test
skip_if_skipped
skip_if_backend uml
skip_unless_arch x86_64
qemu=qemu-system-x86_64
skip_unless $qemu -help
img="test-virt-p2v-pxe.img"
if ! test -f $img; then
echo "$0: test skipped because $img was not created"
exit 77
fi
skip_unless test -f fedora.img
f="$abs_builddir/fedora.img"
d=test-virt-p2v-pxe.d
rm -rf $d
mkdir $d
# Start the ssh server. Kill it if the script exits for any reason.
# Note you must use an absolute path to exec sshd.
`which sshd` -f test-virt-p2v-pxe.sshd_config -D -e &
sshd_pid=$!
cleanup ()
{
kill $sshd_pid
}
trap cleanup INT QUIT TERM EXIT ERR
# Get the randomly assigned sshd port number.
port="$(grep ^Port test-virt-p2v-pxe.sshd_config | awk '{print $2}')"
# Connect as the local user.
username="$(id -un)"
# Output storage path.
os="$(cd $d; pwd)"
# The Linux kernel command line.
cmdline="root=/dev/sda4 ro console=ttyS0 printk.time=1 p2v.server=10.0.2.2 p2v.port=$port p2v.username=$username p2v.identity=file:///var/tmp/id_rsa p2v.name=fedora p2v.o=local p2v.os=$os"
# Run virt-p2v inside qemu.
$qemu \
-no-user-config \
-display none \
-machine accel=kvm:tcg \
-m 2048 \
-kernel test-virt-p2v-pxe.vmlinuz \
-initrd test-virt-p2v-pxe.initramfs \
-append "$cmdline" \
-boot c \
-device virtio-scsi-pci,id=scsi \
-drive file=$img,format=raw,snapshot=on,if=none,index=0,id=hd0 \
-device scsi-hd,drive=hd0 \
-drive file=$f,format=raw,snapshot=on,if=none,index=1,id=hd1 \
-device scsi-hd,drive=hd1 \
-netdev user,id=usernet \
-device virtio-net-pci,netdev=usernet \
-serial stdio
# Test the libvirt XML metadata and a disk was created.
test -f $d/fedora.xml
test -f $d/fedora-sda
rm -r $d