From 97ea81eb21e1be849b0e6b8fcdd2a9cda4edcb51 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Mon, 25 Nov 2013 22:49:53 +0000 Subject: [PATCH] tests: Test that network drives are mapped to correct qemu -drive parameters. Although this test only specifically tests the direct backend, the same code is shared with the libvirt backend in some circumstances (eg. creating readonly drives). So this is testing a bit of both. --- tests/disks/Makefile.am | 4 +- tests/disks/debug-qemu.sh | 31 ++++++++ tests/disks/test-qemu-drive.sh | 125 +++++++++++++++++++++++++++++++++ 3 files changed, 159 insertions(+), 1 deletion(-) create mode 100755 tests/disks/debug-qemu.sh create mode 100755 tests/disks/test-qemu-drive.sh diff --git a/tests/disks/Makefile.am b/tests/disks/Makefile.am index 081c32cb3..9aff5e858 100644 --- a/tests/disks/Makefile.am +++ b/tests/disks/Makefile.am @@ -18,9 +18,11 @@ include $(top_srcdir)/subdir-rules.mk TESTS = \ - test-max-disks.pl + test-max-disks.pl \ + test-qemu-drive.sh TESTS_ENVIRONMENT = $(top_builddir)/run --test EXTRA_DIST = \ + debug-qemu.sh \ $(TESTS) diff --git a/tests/disks/debug-qemu.sh b/tests/disks/debug-qemu.sh new file mode 100755 index 000000000..85106a73a --- /dev/null +++ b/tests/disks/debug-qemu.sh @@ -0,0 +1,31 @@ +#!/bin/bash +# Copyright (C) 2013 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. + +# A fake debugging qemu which just dumps out the parameters to a known +# file. + +if [ -z "$DEBUG_QEMU_FILE" ]; then + echo "$0: \$DEBUG_QEMU_FILE environment variable must be set." + exit 1 +fi + +echo "$@" > "$DEBUG_QEMU_FILE" + +# Real qemu would connect back to the daemon socket with a working +# daemon. We don't do that, so the libguestfs parent process will +# always get an error. +exit 0 diff --git a/tests/disks/test-qemu-drive.sh b/tests/disks/test-qemu-drive.sh new file mode 100755 index 000000000..3709c952d --- /dev/null +++ b/tests/disks/test-qemu-drive.sh @@ -0,0 +1,125 @@ +#!/bin/bash +# Copyright (C) 2013 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 + +guestfish=../../fish/guestfish + +export LIBGUESTFS_BACKEND=direct +export LIBGUESTFS_HV="$(pwd)/debug-qemu.sh" +export DEBUG_QEMU_FILE="$(pwd)/test-qemu-drive.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 <