This tests that libvirt domain XML (ie. guestfish -d option) is parsed
correctly and results in the correct qemu command line when using the
direct backend.
This is a good end-to-end test of various layers.
---
.gitignore | 1 +
configure.ac | 1 +
tests/disks/Makefile.am | 6 ++-
tests/disks/test-qemu-drive-libvirt.sh | 82 ++++++++++++++++++++++++++++++
tests/disks/test-qemu-drive-libvirt.xml.in | 80 +++++++++++++++++++++++++++++
5 files changed, 169 insertions(+), 1 deletion(-)
create mode 100755 tests/disks/test-qemu-drive-libvirt.sh
create mode 100644 tests/disks/test-qemu-drive-libvirt.xml.in
diff --git a/.gitignore b/.gitignore
index 26d5549..f8e6c71 100644
--- a/.gitignore
+++ b/.gitignore
@@ -468,6 +468,7 @@ Makefile.in
/tests/data/initrd-x86_64.img.gz
/tests/data/test-grep.txt.gz
/tests/data/test.iso
+/tests/disks/test-qemu-drive-libvirt.xml
/tests/events/test-libvirt-auth-callbacks
/tests/guests/blank-*.img
/tests/guests/debian.img
diff --git a/configure.ac b/configure.ac
index 3d7f034..15ef432 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1747,6 +1747,7 @@ AC_CONFIG_FILES([Makefile
tests/charsets/Makefile
tests/data/Makefile
tests/disks/Makefile
+ tests/disks/test-qemu-drive-libvirt.xml
tests/disk-labels/Makefile
tests/events/Makefile
tests/fuzz/Makefile
diff --git a/tests/disks/Makefile.am b/tests/disks/Makefile.am
index 9aff5e8..1315e71 100644
--- a/tests/disks/Makefile.am
+++ b/tests/disks/Makefile.am
@@ -19,10 +19,14 @@ include $(top_srcdir)/subdir-rules.mk
TESTS = \
test-max-disks.pl \
+ test-qemu-drive-libvirt.sh \
test-qemu-drive.sh
-TESTS_ENVIRONMENT = $(top_builddir)/run --test
+TESTS_ENVIRONMENT = \
+ abs_srcdir=$(abs_srcdir) \
+ $(top_builddir)/run --test
EXTRA_DIST = \
debug-qemu.sh \
+ test-qemu-drive-libvirt.xml \
$(TESTS)
diff --git a/tests/disks/test-qemu-drive-libvirt.sh
b/tests/disks/test-qemu-drive-libvirt.sh
new file mode 100755
index 0000000..dd0ca0e
--- /dev/null
+++ b/tests/disks/test-qemu-drive-libvirt.sh
@@ -0,0 +1,82 @@
+#!/bin/bash
+# Copyright (C) 2013-2014 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 that disks map to the correct qemu -drive parameter.
+
+export LANG=C
+
+set -e
+
+if [ -z "$abs_srcdir" ]; then
+ echo "$0: abs_srcdir environment variable must be set"
+ exit 1
+fi
+
+guestfish="\
+ ../../fish/guestfish -c test://$abs_srcdir/test-qemu-drive-libvirt.xml"
+
+export LIBGUESTFS_BACKEND=direct
+export LIBGUESTFS_HV="$(pwd)/debug-qemu.sh"
+export DEBUG_QEMU_FILE="$(pwd)/test-qemu-drive-libvirt.out"
+
+function check_output ()
+{
+ if [ ! -f "$DEBUG_QEMU_FILE" ]; then
+ echo "$0: guestfish command failed, see previous error messages"
+ exit 1
+ fi
+}
+
+function fail ()
+{
+ echo "$0: Test failed. Command line output was:"
+ cat "$DEBUG_QEMU_FILE"
+ exit 1
+}
+
+rm -f "$DEBUG_QEMU_FILE"
+
+# Ceph (RBD).
+
+$guestfish -d ceph1 run ||:
+check_output
+grep -sq -- '-drive
file=rbd:abc-def/ghi-jkl:mon_host=1.2.3.4\\:1234\\;1.2.3.5\\:1235\\;1.2.3.6\\:1236:auth_supported=none,'
"$DEBUG_QEMU_FILE" || fail
+rm "$DEBUG_QEMU_FILE"
+
+$guestfish -d ceph2 run ||:
+check_output
+grep -sq -- '-drive file=rbd:abc-def/ghi-jkl:auth_supported=none,'
"$DEBUG_QEMU_FILE" || fail
+rm "$DEBUG_QEMU_FILE"
+
+# NBD.
+
+$guestfish -d nbd run ||:
+check_output
+grep -sq -- '-drive file=nbd:1.2.3.4:1234,' "$DEBUG_QEMU_FILE" || fail
+rm "$DEBUG_QEMU_FILE"
+
+# To do:
+
+# HTTP - curl not yet supported by libvirt
+
+# Gluster.
+
+# iSCSI.
+
+# Sheepdog.
+
+# SSH.
diff --git a/tests/disks/test-qemu-drive-libvirt.xml.in
b/tests/disks/test-qemu-drive-libvirt.xml.in
new file mode 100644
index 0000000..dea739d
--- /dev/null
+++ b/tests/disks/test-qemu-drive-libvirt.xml.in
@@ -0,0 +1,80 @@
+<!--
+ @configure_input@
+ Copyright (C) 2013-2014 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 XML for test-qemu-drive-libvirt.sh
+-->
+<node>
+
+ <domain type='test'
xmlns:test='http://libvirt.org/schemas/domain/test/1.0'>
+ <test:runstate>5</test:runstate> <!-- 5 == VIR_DOMAIN_SHUTOFF -->
+ <name>ceph1</name>
+ <memory>1048576</memory>
+ <os>
+ <type>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <devices>
+ <disk type='network' device='disk'>
+ <driver name='qemu'/>
+ <source protocol='rbd' name='abc-def/ghi-jkl'>
+ <host name='1.2.3.4' port='1234'/>
+ <host name='1.2.3.5' port='1235'/>
+ <host name='1.2.3.6' port='1236'/>
+ </source>
+ <target dev='vda' bus='virtio'/>
+ </disk>
+ </devices>
+ </domain>
+
+ <domain type='test'
xmlns:test='http://libvirt.org/schemas/domain/test/1.0'>
+ <test:runstate>5</test:runstate> <!-- 5 == VIR_DOMAIN_SHUTOFF -->
+ <name>ceph2</name>
+ <memory>1048576</memory>
+ <os>
+ <type>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <devices>
+ <disk type='network' device='disk'>
+ <driver name='qemu'/>
+ <source protocol='rbd' name='abc-def/ghi-jkl'/>
+ <target dev='vda' bus='virtio'/>
+ </disk>
+ </devices>
+ </domain>
+
+ <domain type='test'
xmlns:test='http://libvirt.org/schemas/domain/test/1.0'>
+ <test:runstate>5</test:runstate> <!-- 5 == VIR_DOMAIN_SHUTOFF -->
+ <name>nbd</name>
+ <memory>1048576</memory>
+ <os>
+ <type>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <devices>
+ <disk type='network' device='disk'>
+ <driver name='qemu'/>
+ <source protocol='nbd'>
+ <host name='1.2.3.4' port='1234'/>
+ </source>
+ <target dev='vda' bus='virtio'/>
+ </disk>
+ </devices>
+ </domain>
+
+</node>
--
1.8.4.2