[Libguestfs] [PATCH v2 17/17] v2v: add test for --in-place

Roman Kagan rkagan at virtuozzo.com
Tue Aug 11 17:00:36 UTC 2015


Signed-off-by: Roman Kagan <rkagan at virtuozzo.com>
---
changes from v1:
 - split out from code and doc
 - put the new option in alphabetical order WRT others

 v2v/Makefile.am          |   1 +
 v2v/test-v2v-in-place.sh | 101 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 102 insertions(+)
 create mode 100755 v2v/test-v2v-in-place.sh

diff --git a/v2v/Makefile.am b/v2v/Makefile.am
index e957a15..35df563 100644
--- a/v2v/Makefile.am
+++ b/v2v/Makefile.am
@@ -232,6 +232,7 @@ TESTS += \
 	test-v2v-cdrom.sh \
 	test-v2v-i-ova.sh \
 	test-v2v-i-disk.sh \
+	test-v2v-in-place.sh \
 	test-v2v-machine-readable.sh \
 	test-v2v-networks-and-bridges.sh \
 	test-v2v-no-copy.sh \
diff --git a/v2v/test-v2v-in-place.sh b/v2v/test-v2v-in-place.sh
new file mode 100755
index 0000000..bd10aa2
--- /dev/null
+++ b/v2v/test-v2v-in-place.sh
@@ -0,0 +1,101 @@
+#!/bin/bash -
+# libguestfs virt-v2v test script
+# Copyright (C) 2014 Red Hat Inc.
+# Copyright (C) 2015 Parallels IP Holdings 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 --in-place.
+
+unset CDPATH
+export LANG=C
+set -e
+
+if [ -n "$SKIP_TEST_V2V_IN_PLACE_SH" ]; then
+    echo "$0: test skipped because environment variable is set"
+    exit 77
+fi
+
+if [ "$(guestfish get-backend)" = "uml" ]; then
+    echo "$0: test skipped because UML backend does not support network"
+    exit 77
+fi
+
+# You shouldn't be running the tests as root anyway, but in this case
+# it's especially bad because we don't want to start creating guests
+# or storage pools in the system namespace.
+if [ "$(id -u)" -eq 0 ]; then
+    echo "$0: test skipped because you're running tests as root.  Don't do that!"
+    exit 77
+fi
+
+here_dir="$(cd $(dirname $0) && pwd)"
+guests_dir="$(cd $here_dir/../tests/guests && pwd)"
+
+img_base="$guests_dir/windows.img"
+if ! test -f $img_base || ! test -s $img_base; then
+    echo "$0: test skipped because phony Windows image was not created"
+    exit 77
+fi
+
+virt_tools_data_dir=${VIRT_TOOLS_DATA_DIR:-/usr/share/virt-tools}
+if ! test -r $virt_tools_data_dir/rhsrvany.exe; then
+    echo "$0: test skipped because rhsrvany.exe is not installed"
+    exit 77
+fi
+
+img="$here_dir/test-v2v-in-place.qcow2"
+rm -f $img
+qemu-img create -f qcow2 -b $img_base -o compat=1.1,backing_fmt=raw $img
+md5="$(md5sum $img_base)"
+
+libvirt_xml="$here_dir/test-v2v-in-place.xml"
+rm -f $libvirt_xml
+n=windows-overlay
+cat > $libvirt_xml <<EOF
+<node>
+  <domain type='test'>
+    <name>$n</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='$img'/>
+        <target dev='vda' bus='virtio'/>
+      </disk>
+    </devices>
+  </domain>
+</node>
+EOF
+
+$VG virt-v2v --debug-gc -i libvirt -ic "test://$libvirt_xml" $n --in-place
+
+# Test some aspects of the target disk image.
+guestfish --ro -a $img -i <<EOF
+  is-dir "/Program Files/Red Hat/Firstboot"
+  is-file "/Program Files/Red Hat/Firstboot/firstboot.bat"
+  is-dir "/Program Files/Red Hat/Firstboot/scripts"
+  is-dir "/Windows/Drivers/VirtIO"
+EOF
+
+# Test the base image remained untouched
+test "$md5" = "$(md5sum $img_base)"
+
+# Clean up.
+rm -r $img
-- 
2.4.3




More information about the Libguestfs mailing list