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 96 97 98 99 100 101 102 103 104
|
#!/bin/bash -
# libguestfs virt-v2v test script
# Copyright (C) 2014-2025 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# Test virt-v2v on real guests.
set -e
source ./functions.sh
set -e
set -x
slow_test
skip_if_skipped "$script"
requires_arch x86_64
guestname="$1"
if [ -z "$guestname" ]; then
echo "$script: guestname parameter not set, don't run this test directly."
exit 1
fi
disk="real-$guestname.img"
xml="real-$guestname.xml"
os="real-$guestname.d"
rm -f "$disk" "$xml"
rm -rf "$os"
cleanup_fn rm -f "$disk" "$xml"
cleanup_fn rm -rf "$os"
mkdir "$os"
# If the guest doesn't exist in virt-builder, skip. This is because
# we test some RHEL guests which most users won't have access to.
skip_unless_virt_builder_guest "$guestname"
# Some guests need special virt-builder parameters.
# See virt-builder --notes "$guestname"
declare -a extra
# Don't try to update Windows versions.
case "$guestname" in
windows*)
;;
*)
extra[${#extra[*]}]='--update'
;;
esac
# Build a guest (using virt-builder).
virt-builder "$guestname" --quiet -o "$disk" "${extra[@]}"
# Create some minimal test metadata.
cat > "$xml" <<EOF
<domain type='test'>
<name>$guestname</name>
<memory>1048576</memory>
<os>
<type>hvm</type>
<boot dev='hd'/>
</os>
<devices>
<disk type='file' device='disk'>
<driver name='qemu' type='raw'/>
<source file='$(pwd)/$disk'/>
<target dev='vda' bus='virtio'/>
</disk>
</devices>
</domain>
EOF
virt-v2v --debug-gc -i libvirtxml "$xml" -o local -os "$os"
# Test the libvirt XML metadata and a disk was created.
test -f "$os/$guestname.xml"
test -f "$os/$guestname-sda"
# Test the libvirt XML is valid.
# XXX This does not check bits depending on the QEMU version.
virt-xml-validate "$os/$guestname.xml"
# Test the disk has a similar size to the original.
size_before="$(du $disk | awk '{print $1}')"
size_after="$(du $os/$guestname-sda | awk '{print $1}')"
diff="$(( 100 * size_after / size_before ))"
if test $diff -lt 50; then
echo "$script: disk image may have been corrupted or truncated"
echo "size_before=$size_before size_after=$size_after diff=$diff"
ls -l "$disk" "$os/$guestname-sda"
exit 1
fi
|