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.
This commit is contained in:
Richard W.M. Jones
2013-11-25 22:49:53 +00:00
parent 45afcdb307
commit 97ea81eb21
3 changed files with 159 additions and 1 deletions

View File

@@ -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)

31
tests/disks/debug-qemu.sh Executable file
View File

@@ -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

125
tests/disks/test-qemu-drive.sh Executable file
View File

@@ -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 <<EOF ||:
add "/abc-def/ghi-jkl" "format:raw" "protocol:rbd" \
"server:1.2.3.4:1234 1.2.3.5:1235 1.2.3.6:1236"
run
EOF
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"
# HTTP.
$guestfish <<EOF ||:
add "/disk.img" "format:raw" "protocol:http" "server:www.example.com"
run
EOF
check_output
grep -sq -- '-drive file=http://www.example.com/disk.img,' "$DEBUG_QEMU_FILE" || fail
rm "$DEBUG_QEMU_FILE"
# Gluster.
$guestfish <<EOF ||:
add "/volname/image" "format:raw" "protocol:gluster" "server:www.example.com:24007"
run
EOF
check_output
grep -sq -- '-drive file=gluster://www.example.com:24007/volname/image,' "$DEBUG_QEMU_FILE" || fail
rm "$DEBUG_QEMU_FILE"
# iSCSI.
$guestfish <<EOF ||:
add "/target-iqn-name/lun" "format:raw" "protocol:iscsi" "server:www.example.com:3000"
run
EOF
check_output
grep -sq -- '-drive file=iscsi://www.example.com:3000/target-iqn-name/lun,' "$DEBUG_QEMU_FILE" || fail
rm "$DEBUG_QEMU_FILE"
# NBD.
$guestfish <<EOF ||:
add "" "format:raw" "protocol:nbd" "server:1.2.3.4:1234"
run
EOF
check_output
grep -sq -- '-drive file=nbd:1.2.3.4:1234,' "$DEBUG_QEMU_FILE" || fail
rm "$DEBUG_QEMU_FILE"
$guestfish <<EOF ||:
add "" "format:raw" "protocol:nbd" "server:unix:/socket"
run
EOF
check_output
grep -sq -- '-drive file=nbd:unix:/socket,' "$DEBUG_QEMU_FILE" || fail
rm "$DEBUG_QEMU_FILE"
# Sheepdog.
$guestfish <<EOF ||:
add "/volume" "format:raw" "protocol:sheepdog"
run
EOF
check_output
grep -sq -- '-drive file=sheepdog:volume,' "$DEBUG_QEMU_FILE" || fail
rm "$DEBUG_QEMU_FILE"
# SSH.
$guestfish <<EOF ||:
add "/disk.img" "format:raw" "protocol:ssh" "server:example.com" \
"username:rich"
run
EOF
check_output
grep -sq -- '-drive file=ssh://rich@example.com/disk.img,' "$DEBUG_QEMU_FILE" || fail
rm "$DEBUG_QEMU_FILE"