[Pkg-libvirt-commits] [libguestfs] 18/233: tests: Add a regression test for libvirt authentication (RHBZ#1044014).

Hilko Bengen bengen at moszumanska.debian.org
Wed Feb 19 21:10:42 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to branch experimental
in repository libguestfs.

commit 746a0b1f19667606ee63c8d3ab6a75531a8bd71c
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Wed Jan 8 20:22:21 2014 +0000

    tests: Add a regression test for libvirt authentication (RHBZ#1044014).
    
    This tests the virConnectAuthPtrDefault wrapper path.
---
 .gitignore                        |  2 ++
 tests/regressions/Makefile.am     | 29 +++++++++++++++-
 tests/regressions/rhbz1044014.c   | 69 ++++++++++++++++++++++++++++++++++++++
 tests/regressions/rhbz1044014.in  |  1 +
 tests/regressions/rhbz1044014.sh  | 70 +++++++++++++++++++++++++++++++++++++++
 tests/regressions/rhbz1044014.xml |  5 +++
 6 files changed, 175 insertions(+), 1 deletion(-)

diff --git a/.gitignore b/.gitignore
index 45d3a7d..27ce4d6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -489,6 +489,8 @@ Makefile.in
 /tests/regressions/rhbz501893
 /tests/regressions/rhbz790721
 /tests/regressions/rhbz914931
+/tests/regressions/rhbz1044014
+/tests/regressions/rhbz1044014.out
 /tests/rsync/rsyncd.pid
 /tests/syslinux/extlinux-guest.img
 /tests/syslinux/syslinux-guest.img
diff --git a/tests/regressions/Makefile.am b/tests/regressions/Makefile.am
index 2bbfa5d..5bdea3f 100644
--- a/tests/regressions/Makefile.am
+++ b/tests/regressions/Makefile.am
@@ -38,6 +38,10 @@ TESTS = \
 	rhbz1001875.sh \
 	test-noexec-stack.pl
 
+if HAVE_LIBVIRT
+TESTS += rhbz1044014.sh
+endif
+
 tests_not_run = \
 	rhbz727178.sh \
 	rhbz909624.sh
@@ -51,6 +55,10 @@ check_PROGRAMS = \
 	rhbz790721 \
 	rhbz914931
 
+if HAVE_LIBVIRT
+check_PROGRAMS += rhbz1044014
+endif
+
 rhbz501893_SOURCES = rhbz501893.c
 rhbz501893_CPPFLAGS = \
 	-I$(top_srcdir)/src -I$(top_builddir)/src
@@ -81,11 +89,30 @@ rhbz914931_CFLAGS = \
 rhbz914931_LDADD = \
 	$(top_builddir)/src/libguestfs.la
 
+if HAVE_LIBVIRT
+rhbz1044014_SOURCES = rhbz1044014.c
+rhbz1044014_CPPFLAGS = \
+	-I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib \
+	-I$(top_srcdir)/src -I$(top_builddir)/src
+rhbz1044014_CFLAGS = \
+	$(WARN_CFLAGS) $(WERROR_CFLAGS) \
+	$(GPROF_CFLAGS) $(GCOV_CFLAGS) \
+	$(LIBVIRT_CFLAGS)
+rhbz1044014_LDADD = \
+        $(top_builddir)/src/libutils.la \
+        $(top_builddir)/src/libguestfs.la \
+        $(LIBVIRT_LIBS) \
+        $(LIBXML2_LIBS) \
+        $(top_builddir)/gnulib/lib/libgnu.la
+endif
+
 EXTRA_DIST = \
 	$(TESTS) \
 	$(tests_not_run) \
 	rhbz557655-expected.stdout \
-	rhbz557655-expected.stderr
+	rhbz557655-expected.stderr \
+	rhbz1044014.in \
+	rhbz1044014.xml
 
 check-slow:
 	$(MAKE) TESTS="rhbz909624.sh" check
diff --git a/tests/regressions/rhbz1044014.c b/tests/regressions/rhbz1044014.c
new file mode 100644
index 0000000..18ce4a7
--- /dev/null
+++ b/tests/regressions/rhbz1044014.c
@@ -0,0 +1,69 @@
+/* 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.
+ */
+
+/* Regression test for RHBZ#1044014.
+ *
+ * The only reason to write this in C is so we can easily check the
+ * version of libvirt >= 1.2.1.  In the future when we can assume a
+ * newer libvirt, we can just have the main rhbz1044014.sh script set
+ * some environment variables and use guestfish.
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <libvirt/libvirt.h>
+
+#include "guestfs.h"
+#include "guestfs-internal-frontend.h"
+
+int
+main (int argc, char *argv[])
+{
+  unsigned long ver;
+  guestfs_h *g;
+
+  virInitialize ();
+
+  /* Check that the version of libvirt we are linked against
+   * supports the new test-driver auth feature.
+   */
+  virGetVersion (&ver, NULL, NULL);
+  if (ver < 1002001) {
+    fprintf (stderr, "%s: test skipped because libvirt is too old (%lu)\n",
+             argv[0], ver);
+    exit (77);
+  }
+
+  g = guestfs_create ();
+  if (!g)
+    exit (EXIT_FAILURE);
+
+  /* This will ask the user for credentials.  It will also fail
+   * (expectedly) because the test driver does not support qemu/KVM.
+   */
+  guestfs_launch (g);
+
+  guestfs_close (g);
+  exit (EXIT_SUCCESS);
+}
diff --git a/tests/regressions/rhbz1044014.in b/tests/regressions/rhbz1044014.in
new file mode 100644
index 0000000..3f382dd
--- /dev/null
+++ b/tests/regressions/rhbz1044014.in
@@ -0,0 +1 @@
+rich
diff --git a/tests/regressions/rhbz1044014.sh b/tests/regressions/rhbz1044014.sh
new file mode 100755
index 0000000..f1e458c
--- /dev/null
+++ b/tests/regressions/rhbz1044014.sh
@@ -0,0 +1,70 @@
+#!/bin/bash -
+# 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.
+
+# Regression test for:
+# https://bugzilla.redhat.com/show_bug.cgi?id=1044014
+
+set -e
+export LANG=C
+
+if [ -n "$SKIP_TEST_RHBZ1044014_SH" ]; then
+    echo "$0: test skipped because environment variable is set."
+    exit 77
+fi
+
+# Check we are running against the libvirt backend.
+backend="$(../../fish/guestfish get-backend)"
+if [[ ! ( "$backend" =~ ^libvirt ) ]]; then
+    echo "$0: test skipped because backend ($backend) is not libvirt."
+    exit 77
+fi
+
+# Set the backend to the test driver.
+export LIBGUESTFS_BACKEND="libvirt:test://$(pwd)/$srcdir/rhbz1044014.xml"
+
+rm -f rhbz1044014.out
+
+./rhbz1044014 < $srcdir/rhbz1044014.in > rhbz1044014.out 2>&1 || {
+    r=$?
+    if [ $r -ne 0 ]; then
+        cat rhbz1044014.out
+        exit $r
+    fi
+}
+
+# We are expecting this message to be printed (see commit which fixed
+# RHBZ#1044014).
+grep "libvirt needs authentication to connect to libvirt URI" rhbz1044014.out || {
+    echo "$0: expecting to see message from commit which fixed RHBZ#1044014"
+    echo
+    echo "actual output was:"
+    echo
+    cat rhbz1044014.out
+    exit 1
+}
+
+# This is the error we are expecting to see.  If we see it then it
+# indicates that authentication was successful.
+grep "error: libvirt hypervisor doesn't support qemu or KVM" rhbz1044014.out || {
+    echo "$0: unexpected output:"
+    echo
+    cat rhbz1044014.out
+    exit 1
+}
+
+rm rhbz1044014.out
diff --git a/tests/regressions/rhbz1044014.xml b/tests/regressions/rhbz1044014.xml
new file mode 100644
index 0000000..72feaf4
--- /dev/null
+++ b/tests/regressions/rhbz1044014.xml
@@ -0,0 +1,5 @@
+<node>
+  <auth>
+    <user>rich</user>
+  </auth>
+</node>

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list