Blob Blame History Raw
From f5ce839611e01ae4aed4125d24690644bb609ef8 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Wed, 22 Jun 2016 14:48:22 +0100
Subject: [PATCH] v2v: Add a regression test for floppy assignment
 (RHBZ#1309706).

(cherry picked from commit 0421c5afa330b80c17d8dce88abed2cb53f4f5cc)
---
 v2v/Makefile.am              |  3 ++
 v2v/test-v2v-floppy.expected |  8 +++++
 v2v/test-v2v-floppy.sh       | 77 ++++++++++++++++++++++++++++++++++++++++++++
 v2v/test-v2v-floppy.xml      | 42 ++++++++++++++++++++++++
 4 files changed, 130 insertions(+)
 create mode 100644 v2v/test-v2v-floppy.expected
 create mode 100755 v2v/test-v2v-floppy.sh
 create mode 100644 v2v/test-v2v-floppy.xml

diff --git a/v2v/Makefile.am b/v2v/Makefile.am
index 5bffbfe..a996e5d 100644
--- a/v2v/Makefile.am
+++ b/v2v/Makefile.am
@@ -25,6 +25,8 @@ EXTRA_DIST = \
 	HACKING \
 	test-v2v-cdrom.expected \
 	test-v2v-cdrom.xml \
+	test-v2v-floppy.expected \
+	test-v2v-floppy.xml \
 	test-v2v-i-ova.ovf \
 	test-v2v-i-ova.xml \
 	test-v2v-i-ova-formats.expected \
@@ -303,6 +305,7 @@ endif
 if ENABLE_APPLIANCE
 TESTS += \
 	test-v2v-cdrom.sh \
+	test-v2v-floppy.sh \
 	test-v2v-i-ova.sh \
 	test-v2v-i-disk.sh \
 	test-v2v-machine-readable.sh \
diff --git a/v2v/test-v2v-floppy.expected b/v2v/test-v2v-floppy.expected
new file mode 100644
index 0000000..dd74ed9
--- /dev/null
+++ b/v2v/test-v2v-floppy.expected
@@ -0,0 +1,8 @@
+    <disk type='file' device='disk'>
+      <driver name='qemu' type='raw' cache='none'/>
+      <target dev='vda' bus='virtio'/>
+    </disk>
+    <disk device='floppy' type='file'>
+      <driver name='qemu' type='raw'/>
+      <target dev='fda'/>
+    </disk>
diff --git a/v2v/test-v2v-floppy.sh b/v2v/test-v2v-floppy.sh
new file mode 100755
index 0000000..d4ecfba
--- /dev/null
+++ b/v2v/test-v2v-floppy.sh
@@ -0,0 +1,77 @@
+#!/bin/bash -
+# libguestfs virt-v2v test script
+# Copyright (C) 2015-2016 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 converting a guest with a floppy disk.
+# https://bugzilla.redhat.com/show_bug.cgi?id=1309706
+
+unset CDPATH
+export LANG=C
+set -e
+
+if [ -n "$SKIP_TEST_V2V_FLOPPY_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
+
+abs_builddir="$(pwd)"
+libvirt_uri="test://$abs_builddir/test-v2v-floppy.xml"
+
+f=../test-data/phony-guests/windows.img
+if ! test -f $f || ! test -s $f; then
+    echo "$0: test skipped because phony Windows image was not created"
+    exit 77
+fi
+
+f=../test-data/phony-guests/blank-disk.img
+if ! test -f $f || ! test -s $f; then
+    echo "$0: test skipped because blank-disk.img was not created"
+    exit 77
+fi
+
+export VIRT_TOOLS_DATA_DIR="$srcdir/../test-data/fake-virt-tools"
+export VIRTIO_WIN="$srcdir/../test-data/fake-virtio-win"
+
+d=test-v2v-floppy.d
+rm -rf $d
+mkdir $d
+
+$VG virt-v2v --debug-gc \
+    -i libvirt -ic "$libvirt_uri" windows \
+    -o local -os $d --no-copy
+
+# Test the libvirt XML metadata was created.
+test -f $d/windows.xml
+
+# Grab just the <disk>..</disk> output and compare it to what we
+# expect.  https://stackoverflow.com/questions/16587218
+awk '/<disk /{p=1;print;next} p&&/<\/disk>/{p=0;print;next} ;p' \
+    $d/windows.xml |
+    grep -v '<source file' > $d/disks
+
+if ! diff -u test-v2v-floppy.expected $d/disks; then
+    echo "$0: unexpected disk assignments"
+    cat $d/disks
+    exit 1
+fi
+
+rm -r $d
diff --git a/v2v/test-v2v-floppy.xml b/v2v/test-v2v-floppy.xml
new file mode 100644
index 0000000..41e1bef
--- /dev/null
+++ b/v2v/test-v2v-floppy.xml
@@ -0,0 +1,42 @@
+<!--
+libguestfs virt-v2v tool
+Copyright (C) 2009-2016 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.
+-->
+<node>
+  <domain type='test'>
+    <name>windows</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='../test-data/phony-guests/windows.img'/>
+        <!-- virt-v2v should install virtio drivers and turn this
+             into dev='vda' bus='virtio' -->
+        <target dev='hda' bus='ide'/>
+      </disk>
+      <disk type='file' device='floppy'>
+        <driver name='qemu' type='raw'/>
+        <source file='../test-data/phony-guests/blank-disk.img'/>
+        <target dev='fda' />
+      </disk>
+    </devices>
+  </domain>
+</node>
-- 
2.7.4