Pino Toscano
2014-Jan-27 13:51 UTC
[Libguestfs] [PATCH 0/2] Skip test-qemu-drive-libvirt.sh if libvirt is < 1.1.3
Hi, test-qemu-drive-libvirt.sh fails to run with libvirt < 1.1.3, because the <test:runstate> attribute (used to keep the domains shut off) has been introduced in that libvirt version. Create a small (uninstalled) C tool which just does this version check, to be used in all the tests (just one, so far) written in shell/scripting language. Pino Toscano (2): tests: add a a simple libvirt-is-version test tool tests/disks: skip test-qemu-drive-libvirt.sh if libvirt is < 1.1.3 .gitignore | 1 + Makefile.am | 1 + configure.ac | 1 + tests/disks/test-qemu-drive-libvirt.sh | 10 +++++ tests/libvirt/Makefile.am | 32 ++++++++++++++ tests/libvirt/libvirt-is-version.c | 76 ++++++++++++++++++++++++++++++++++ 6 files changed, 121 insertions(+) create mode 100644 tests/libvirt/Makefile.am create mode 100644 tests/libvirt/libvirt-is-version.c -- 1.8.3.1
Pino Toscano
2014-Jan-27 13:51 UTC
[Libguestfs] [PATCH 1/2] tests: add a a simple libvirt-is-version test tool
libvirt-is-version returns successfully in case the available version of libvirt is greater or equal than the specified major/minor/release values. --- .gitignore | 1 + Makefile.am | 1 + configure.ac | 1 + tests/libvirt/Makefile.am | 32 ++++++++++++++++ tests/libvirt/libvirt-is-version.c | 76 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 111 insertions(+) create mode 100644 tests/libvirt/Makefile.am create mode 100644 tests/libvirt/libvirt-is-version.c diff --git a/.gitignore b/.gitignore index f8e6c71..c7da2f2 100644 --- a/.gitignore +++ b/.gitignore @@ -485,6 +485,7 @@ Makefile.in /tests/guests/stamp-fedora-md.img /tests/guests/ubuntu.img /tests/guests/windows.img +/tests/libvirt/libvirt-is-version /tests/mount-local/test-parallel-mount-local /tests/mountable/test-internal-parse-mountable /tests/parallel/test-parallel diff --git a/Makefile.am b/Makefile.am index e39d11f..dbffdda 100644 --- a/Makefile.am +++ b/Makefile.am @@ -34,6 +34,7 @@ SUBDIRS += appliance if ENABLE_APPLIANCE SUBDIRS += tests/qemu SUBDIRS += tests/guests +SUBDIRS += tests/libvirt SUBDIRS += tests/c-api SUBDIRS += tests/tmpdirs SUBDIRS += tests/protocol diff --git a/configure.ac b/configure.ac index c07462e..a454570 100644 --- a/configure.ac +++ b/configure.ac @@ -1756,6 +1756,7 @@ AC_CONFIG_FILES([Makefile tests/hotplug/Makefile tests/http/Makefile tests/journal/Makefile + tests/libvirt/Makefile tests/luks/Makefile tests/lvm/Makefile tests/md/Makefile diff --git a/tests/libvirt/Makefile.am b/tests/libvirt/Makefile.am new file mode 100644 index 0000000..bf5088c --- /dev/null +++ b/tests/libvirt/Makefile.am @@ -0,0 +1,32 @@ +# libguestfs +# Copyright (C) 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. + +include $(top_srcdir)/subdir-rules.mk + +if HAVE_LIBVIRT +noinst_PROGRAMS = libvirt-is-version + +libvirt_is_version_SOURCES = \ + libvirt-is-version.c + +libvirt_is_version_LDADD = \ + $(LIBVIRT_LIBS) + +libvirt_is_version_CFLAGS = \ + $(WARN_CFLAGS) $(WERROR_CFLAGS) \ + $(LIBVIRT_CFLAGS) +endif diff --git a/tests/libvirt/libvirt-is-version.c b/tests/libvirt/libvirt-is-version.c new file mode 100644 index 0000000..47f2e25 --- /dev/null +++ b/tests/libvirt/libvirt-is-version.c @@ -0,0 +1,76 @@ +/* libguestfs + * Copyright (C) 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. + */ + +#include <config.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <errno.h> + +#include <libvirt/libvirt.h> + +static unsigned int argtoint (const char *prog, const char *arg); + +int +main (int argc, char *argv[]) +{ + unsigned long ver; + unsigned int major = 0, minor = 0, release = 0; + + switch (argc) { + case 4: + release = argtoint (argv[0], argv[3]); + /*FALLTHROUGH*/ + case 3: + minor = argtoint (argv[0], argv[2]); + /*FALLTHROUGH*/ + case 2: + major = argtoint (argv[0], argv[1]); + break; + case 1: + fprintf (stderr, "%s: not enough arguments: MAJOR [MINOR [PATCH]]\n", + argv[0]); + exit (EXIT_FAILURE); + break; + } + + virInitialize (); + + virGetVersion (&ver, NULL, NULL); + + return ver >= (major * 1000000 + minor * 1000 + release) + ? EXIT_SUCCESS : EXIT_FAILURE; +} + +static unsigned int +argtoint (const char *prog, const char *arg) +{ + long int res; + char *endptr; + + errno = 0; + res = strtol (arg, &endptr, 10); + if (errno || *endptr) { + fprintf (stderr, "%s: cannot parse integer argument '%s'.\n", prog, arg); + exit (EXIT_FAILURE); + } + + return (unsigned int) res; +} -- 1.8.3.1
Pino Toscano
2014-Jan-27 13:51 UTC
[Libguestfs] [PATCH 2/2] tests/disks: skip test-qemu-drive-libvirt.sh if libvirt is < 1.1.3
This test relies on the <test:runstate> element in the domain XML, which has been introduced in libvirt 1.1.3. --- tests/disks/test-qemu-drive-libvirt.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/disks/test-qemu-drive-libvirt.sh b/tests/disks/test-qemu-drive-libvirt.sh index e85c249..b355371 100755 --- a/tests/disks/test-qemu-drive-libvirt.sh +++ b/tests/disks/test-qemu-drive-libvirt.sh @@ -26,6 +26,16 @@ if [ -z "$abs_srcdir" ]; then exit 1 fi +if [ ! -s ../libvirt/libvirt-is-version ]; then + echo "$0: test skipped because libvirt-is-version is not built yet" + exit 77 +fi + +if ! ../libvirt/libvirt-is-version 1 1 3; then + echo "$0: test skipped because libvirt is too old (< 1.1.3)" + exit 77 +fi + guestfish="\ ../../fish/guestfish -c test://$abs_srcdir/test-qemu-drive-libvirt.xml" -- 1.8.3.1
Richard W.M. Jones
2014-Jan-27 14:37 UTC
Re: [Libguestfs] [PATCH 2/2] tests/disks: skip test-qemu-drive-libvirt.sh if libvirt is < 1.1.3
Can you put the tool into the directory where it is used? Or into some other directory which isn't a new subdirectory of tests/? (Maybe src/?) All the existing tests/ subdirectories are actual tests. Apart from that, looks sensible. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
Maybe Matching Threads
- [PATCH, RFC 3/13] OTP: parity table
- [PATCH net-next v3 00/11] VSOCK: add vsock_test test suite
- [PATCH] Force mountd(8) to a specified port.
- [PATCH v2 0/5] xl: allow for node-wise specification of vcpu pinning
- [PATCH v2 00/11] VSOCK: add vsock_test test suite