On 3/10/23 18:54, Andrey Drobyshev wrote:
The test checks that the newly introduced --block-driver option
doesn't
break conversion. Basically its logic somewhat repeats test-v2v-i-disk.sh
and test-v2v-in-place.sh, but with the new option being set.
The checks it performs are:
1. Run disk-sourced conversion (-i disk) based on the phony windows.img
and check that it completes (i.e. produces converted disk and
corresponding domain XML;
2. Run libvirt-sourced in-place conversion based on an XML with virtio
vda disk specified (virtio-blk case) and check that the resulting
image has the phony viostor driver installed.
3. Run libvirt-sourced in-place conversion based on an XML with scsi
sda disk specified (virtio-scsi case) and check that the resulting
image has the phony vioscsi driver installed.
Note that the latter 2 cases aren't really comprehensive as v2v actually
copies all the drivers present in $VIRTIO_WIN, regardless of the block
driver specified. The real difference comes from the PCI ID values written
into the registry. But since we can't test real Windows and evaluate
those values, we're doing the best we can here, i.e. testing that conversion
doesn't break and drivers are still present with --block-driver option
being set explicitly.
Signed-off-by: Andrey Drobyshev <andrey.drobyshev(a)virtuozzo.com>
---
tests/Makefile.am | 2 +
tests/test-v2v-block-driver.sh | 143 +++++++++++++++++++++++++++++++++
2 files changed, 145 insertions(+)
create mode 100755 tests/test-v2v-block-driver.sh
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a4c87398..5c523204 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -78,6 +78,7 @@ TESTS = \
test-v2v-i-disk.sh \
test-v2v-i-ova.sh \
test-v2v-in-place.sh \
+ test-v2v-block-driver.sh \
test-v2v-inspector.sh \
test-v2v-mac.sh \
test-v2v-machine-readable.sh \
@@ -236,6 +237,7 @@ EXTRA_DIST += \
test-v2v-i-vmx-6.vmx \
test-v2v-i-vmx-7.vmx \
test-v2v-in-place.sh \
+ test-v2v-block-driver.sh \
test-v2v-inspector.sh \
test-v2v-it-vddk-io-query.sh \
test-v2v-machine-readable.sh \
diff --git a/tests/test-v2v-block-driver.sh b/tests/test-v2v-block-driver.sh
new file mode 100755
index 00000000..db59a2cf
--- /dev/null
+++ b/tests/test-v2v-block-driver.sh
@@ -0,0 +1,143 @@
+#!/bin/bash -
+# libguestfs virt-v2v test script
+# Copyright (C) 2023 Virtuozzo International GmbH
+#
+# 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 --block-driver option.
+
+set -e
+
+source ./functions.sh
+set -e
+set -x
+
+skip_if_skipped
+img_base="$abs_top_builddir/test-data/phony-guests/windows.img"
+requires test -f $img_base
+
+export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools"
+export VIRTIO_WIN="$srcdir/../test-data/fake-virtio-win"
+
+d=$PWD/test-v2v-block-driver.d
+rm -rf $d
+cleanup_fn rm -rf $d
+mkdir $d
+
+viostor_img="$d/viostor.qcow2"
+vioscsi_img="$d/vioscsi.qcow2"
+qemu-img create -f qcow2 -b $img_base -o compat=1.1,backing_fmt=raw $viostor_img
+qemu-img create -f qcow2 -b $img_base -o compat=1.1,backing_fmt=raw $vioscsi_img
+base_md5="$(do_md5 $img_base)"
+
+viostor_xml="$d/windows-viostor.xml"
+viostor_name=windows-viostor
+cat > $viostor_xml <<EOF
+<node>
+ <domain type='test'>
+ <name>$viostor_name</name>
+ <memory>1048576</memory>
+ <os>
+ <type>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <devices>
+ <disk type='file' device='disk'>
+ <driver name='qemu' type='qcow2'/>
+ <source file='$viostor_img'/>
+ <target dev='vda' bus='virtio'/>
+ </disk>
+ </devices>
+ </domain>
+</node>
+EOF
+
+vioscsi_xml="$d/windows-vioscsi.xml"
+vioscsi_name=windows-vioscsi
+cat > $vioscsi_xml <<EOF
+<node>
+ <domain type='test'>
+ <name>$vioscsi_name</name>
+ <memory>1048576</memory>
+ <os>
+ <type>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <devices>
+ <disk type='file' device='disk'>
+ <driver name='qemu' type='qcow2'/>
+ <source file='$vioscsi_img'/>
+ <target dev='sda' bus='scsi'/>
+ </disk>
+ <controller type='scsi' index='0'
model='virtio-scsi'>
+ <address type='pci' domain='0x0000' bus='0x00'
slot='0x01' function='0x0'/>
+ </controller>
+ </devices>
+ </domain>
+</node>
+EOF
+
+response="$d/response"
+expected="$d/expected"
+
+echo -e "true\ntrue\ntrue\ntrue" >$expected
+
+check_driver_presence ()
+{
+ local img="$1" drv="$2"
+
+ local virtio_dir="/Windows/Drivers/VirtIO"
+
+ guestfish --ro -a "$img" -i >$response <<-EOM
+ is-dir $virtio_dir
+ is-file $virtio_dir/$drv.cat
+ is-file $virtio_dir/$drv.inf
+ is-file $virtio_dir/$drv.sys
+EOM
+
+ diff -u $expected $response
+}
+
+# Test that --block-driver option doesn't break basic "-i disk"
conversion
+$VG virt-v2v --debug-gc --block-driver virtio-scsi \
+ -i disk $img_base -o local -os $d
+
+# Check that libvirt XML metadata and a disk was created.
+test -f $d/windows.xml
+test -f $d/windows-sda
+
+# Test in-place conversion with --block-driver specified
+#
+# Note that v2v actually copies all the drivers present in $VIRTIO_WIN, no
+# matter which block driver we specify. The real difference comes from the
+# PCI ID values written into the registry. Since we can't really test those
+# values, we're doing the best we can here, i.e. testing that conversion
+# doesn't break and drivers are still present with --block-driver option
+# being set explicitly.
+
+# Check that in-place conversion works with --block-driver virtio-blk
+$VG virt-v2v-in-place --debug-gc --block-driver virtio-blk \
+ -i libvirt -ic "test://$viostor_xml" $viostor_name
+
+check_driver_presence $viostor_img "viostor"
+
+# Check that in-place conversion works with --block-driver virtio-scsi
+$VG virt-v2v-in-place --debug-gc --block-driver virtio-scsi \
+ -i libvirt -ic "test://$vioscsi_xml" $vioscsi_name
+
+check_driver_presence $vioscsi_img "vioscsi"
+
+# Finally check that the base image remained untouched
+test "$base_md5" = "$(do_md5 $img_base)"
Reviewed-by: Laszlo Ersek <lersek(a)redhat.com>