psss / rpms / libguestfs

Forked from rpms/libguestfs 5 years ago
Clone

Blame 0041-tests-Add-a-regression-test-for-libvirt-authenticati.patch

4bf3775
From eb10843058334e17735e7e90ad40a8ef1fdfaa32 Mon Sep 17 00:00:00 2001
1a34115
From: "Richard W.M. Jones" <rjones@redhat.com>
1a34115
Date: Wed, 8 Jan 2014 20:22:21 +0000
1a34115
Subject: [PATCH] tests: Add a regression test for libvirt authentication
1a34115
 (RHBZ#1044014).
1a34115
1a34115
This tests the virConnectAuthPtrDefault wrapper path.
1a34115
1a34115
(cherry picked from commit 746a0b1f19667606ee63c8d3ab6a75531a8bd71c)
1a34115
---
1a34115
 .gitignore                        |  2 ++
bf9044c
 tests/regressions/Makefile.am     | 28 ++++++++++++++++
1a34115
 tests/regressions/rhbz1044014.c   | 69 ++++++++++++++++++++++++++++++++++++++
1a34115
 tests/regressions/rhbz1044014.in  |  1 +
1a34115
 tests/regressions/rhbz1044014.sh  | 70 +++++++++++++++++++++++++++++++++++++++
1a34115
 tests/regressions/rhbz1044014.xml |  5 +++
bf9044c
 6 files changed, 175 insertions(+)
1a34115
 create mode 100644 tests/regressions/rhbz1044014.c
1a34115
 create mode 100644 tests/regressions/rhbz1044014.in
1a34115
 create mode 100755 tests/regressions/rhbz1044014.sh
1a34115
 create mode 100644 tests/regressions/rhbz1044014.xml
1a34115
1a34115
diff --git a/.gitignore b/.gitignore
bf9044c
index bce35f0..2d61d77 100644
1a34115
--- a/.gitignore
1a34115
+++ b/.gitignore
bf9044c
@@ -485,6 +485,8 @@ Makefile.in
1a34115
 /tests/regressions/rhbz501893
1a34115
 /tests/regressions/rhbz790721
1a34115
 /tests/regressions/rhbz914931
1a34115
+/tests/regressions/rhbz1044014
1a34115
+/tests/regressions/rhbz1044014.out
51fb412
 /tests/regressions/rhbz1055452
1a34115
 /tests/rsync/rsyncd.pid
1a34115
 /tests/syslinux/extlinux-guest.img
1a34115
diff --git a/tests/regressions/Makefile.am b/tests/regressions/Makefile.am
bf9044c
index 15333b7..563f87f 100644
1a34115
--- a/tests/regressions/Makefile.am
1a34115
+++ b/tests/regressions/Makefile.am
bf9044c
@@ -35,6 +35,9 @@ EXTRA_DIST = \
bf9044c
 	rhbz957772.sh \
bf9044c
 	rhbz975797.sh \
bf9044c
 	rhbz1001875.sh \
bf9044c
+	rhbz1044014.sh \
bf9044c
+	rhbz1044014.in \
bf9044c
+	rhbz1044014.xml \
bf9044c
 	test-noexec-stack.pl
bf9044c
 
bf9044c
 TESTS = \
bf9044c
@@ -57,6 +60,10 @@ TESTS = \
51fb412
 	rhbz1055452 \
1a34115
 	test-noexec-stack.pl
1a34115
 
1a34115
+if HAVE_LIBVIRT
1a34115
+TESTS += rhbz1044014.sh
1a34115
+endif
1a34115
+
1a34115
 tests_not_run = \
1a34115
 	rhbz727178.sh \
1a34115
 	rhbz909624.sh
bf9044c
@@ -71,6 +78,10 @@ check_PROGRAMS = \
51fb412
 	rhbz914931 \
51fb412
 	rhbz1055452
1a34115
 
1a34115
+if HAVE_LIBVIRT
1a34115
+check_PROGRAMS += rhbz1044014
1a34115
+endif
1a34115
+
1a34115
 rhbz501893_SOURCES = rhbz501893.c
1a34115
 rhbz501893_CPPFLAGS = \
1a34115
 	-I$(top_srcdir)/src -I$(top_builddir)/src
bf9044c
@@ -101,6 +112,23 @@ rhbz914931_CFLAGS = \
1a34115
 rhbz914931_LDADD = \
1a34115
 	$(top_builddir)/src/libguestfs.la
1a34115
 
1a34115
+if HAVE_LIBVIRT
1a34115
+rhbz1044014_SOURCES = rhbz1044014.c
1a34115
+rhbz1044014_CPPFLAGS = \
1a34115
+	-I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib \
1a34115
+	-I$(top_srcdir)/src -I$(top_builddir)/src
1a34115
+rhbz1044014_CFLAGS = \
1a34115
+	$(WARN_CFLAGS) $(WERROR_CFLAGS) \
1a34115
+	$(GPROF_CFLAGS) $(GCOV_CFLAGS) \
1a34115
+	$(LIBVIRT_CFLAGS)
1a34115
+rhbz1044014_LDADD = \
1a34115
+        $(top_builddir)/src/libutils.la \
1a34115
+        $(top_builddir)/src/libguestfs.la \
1a34115
+        $(LIBVIRT_LIBS) \
1a34115
+        $(LIBXML2_LIBS) \
1a34115
+        $(top_builddir)/gnulib/lib/libgnu.la
1a34115
+endif
1a34115
+
51fb412
 rhbz1055452_SOURCES = rhbz1055452.c
51fb412
 rhbz1055452_CPPFLAGS = \
51fb412
 	-I$(top_srcdir)/src -I$(top_builddir)/src \
1a34115
diff --git a/tests/regressions/rhbz1044014.c b/tests/regressions/rhbz1044014.c
1a34115
new file mode 100644
1a34115
index 0000000..18ce4a7
1a34115
--- /dev/null
1a34115
+++ b/tests/regressions/rhbz1044014.c
1a34115
@@ -0,0 +1,69 @@
1a34115
+/* libguestfs
1a34115
+ * Copyright (C) 2014 Red Hat Inc.
1a34115
+ *
1a34115
+ * This program is free software; you can redistribute it and/or modify
1a34115
+ * it under the terms of the GNU General Public License as published by
1a34115
+ * the Free Software Foundation; either version 2 of the License, or
1a34115
+ * (at your option) any later version.
1a34115
+ *
1a34115
+ * This program is distributed in the hope that it will be useful,
1a34115
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1a34115
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1a34115
+ * GNU General Public License for more details.
1a34115
+ *
1a34115
+ * You should have received a copy of the GNU General Public License
1a34115
+ * along with this program; if not, write to the Free Software
1a34115
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1a34115
+ */
1a34115
+
1a34115
+/* Regression test for RHBZ#1044014.
1a34115
+ *
1a34115
+ * The only reason to write this in C is so we can easily check the
1a34115
+ * version of libvirt >= 1.2.1.  In the future when we can assume a
1a34115
+ * newer libvirt, we can just have the main rhbz1044014.sh script set
1a34115
+ * some environment variables and use guestfish.
1a34115
+ */
1a34115
+
1a34115
+#include <config.h>
1a34115
+
1a34115
+#include <stdio.h>
1a34115
+#include <stdlib.h>
1a34115
+#include <string.h>
1a34115
+#include <unistd.h>
1a34115
+#include <errno.h>
1a34115
+
1a34115
+#include <libvirt/libvirt.h>
1a34115
+
1a34115
+#include "guestfs.h"
1a34115
+#include "guestfs-internal-frontend.h"
1a34115
+
1a34115
+int
1a34115
+main (int argc, char *argv[])
1a34115
+{
1a34115
+  unsigned long ver;
1a34115
+  guestfs_h *g;
1a34115
+
1a34115
+  virInitialize ();
1a34115
+
1a34115
+  /* Check that the version of libvirt we are linked against
1a34115
+   * supports the new test-driver auth feature.
1a34115
+   */
1a34115
+  virGetVersion (&ver, NULL, NULL);
1a34115
+  if (ver < 1002001) {
1a34115
+    fprintf (stderr, "%s: test skipped because libvirt is too old (%lu)\n",
1a34115
+             argv[0], ver);
1a34115
+    exit (77);
1a34115
+  }
1a34115
+
1a34115
+  g = guestfs_create ();
1a34115
+  if (!g)
1a34115
+    exit (EXIT_FAILURE);
1a34115
+
1a34115
+  /* This will ask the user for credentials.  It will also fail
1a34115
+   * (expectedly) because the test driver does not support qemu/KVM.
1a34115
+   */
1a34115
+  guestfs_launch (g);
1a34115
+
1a34115
+  guestfs_close (g);
1a34115
+  exit (EXIT_SUCCESS);
1a34115
+}
1a34115
diff --git a/tests/regressions/rhbz1044014.in b/tests/regressions/rhbz1044014.in
1a34115
new file mode 100644
1a34115
index 0000000..3f382dd
1a34115
--- /dev/null
1a34115
+++ b/tests/regressions/rhbz1044014.in
1a34115
@@ -0,0 +1 @@
1a34115
+rich
1a34115
diff --git a/tests/regressions/rhbz1044014.sh b/tests/regressions/rhbz1044014.sh
1a34115
new file mode 100755
1a34115
index 0000000..f1e458c
1a34115
--- /dev/null
1a34115
+++ b/tests/regressions/rhbz1044014.sh
1a34115
@@ -0,0 +1,70 @@
1a34115
+#!/bin/bash -
1a34115
+# libguestfs
1a34115
+# Copyright (C) 2014 Red Hat Inc.
1a34115
+#
1a34115
+# This program is free software; you can redistribute it and/or modify
1a34115
+# it under the terms of the GNU General Public License as published by
1a34115
+# the Free Software Foundation; either version 2 of the License, or
1a34115
+# (at your option) any later version.
1a34115
+#
1a34115
+# This program is distributed in the hope that it will be useful,
1a34115
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1a34115
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1a34115
+# GNU General Public License for more details.
1a34115
+#
1a34115
+# You should have received a copy of the GNU General Public License
1a34115
+# along with this program; if not, write to the Free Software
1a34115
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1a34115
+
1a34115
+# Regression test for:
1a34115
+# https://bugzilla.redhat.com/show_bug.cgi?id=1044014
1a34115
+
1a34115
+set -e
1a34115
+export LANG=C
1a34115
+
1a34115
+if [ -n "$SKIP_TEST_RHBZ1044014_SH" ]; then
1a34115
+    echo "$0: test skipped because environment variable is set."
1a34115
+    exit 77
1a34115
+fi
1a34115
+
1a34115
+# Check we are running against the libvirt backend.
1a34115
+backend="$(../../fish/guestfish get-backend)"
1a34115
+if [[ ! ( "$backend" =~ ^libvirt ) ]]; then
1a34115
+    echo "$0: test skipped because backend ($backend) is not libvirt."
1a34115
+    exit 77
1a34115
+fi
1a34115
+
1a34115
+# Set the backend to the test driver.
1a34115
+export LIBGUESTFS_BACKEND="libvirt:test://$(pwd)/$srcdir/rhbz1044014.xml"
1a34115
+
1a34115
+rm -f rhbz1044014.out
1a34115
+
1a34115
+./rhbz1044014 < $srcdir/rhbz1044014.in > rhbz1044014.out 2>&1 || {
1a34115
+    r=$?
1a34115
+    if [ $r -ne 0 ]; then
1a34115
+        cat rhbz1044014.out
1a34115
+        exit $r
1a34115
+    fi
1a34115
+}
1a34115
+
1a34115
+# We are expecting this message to be printed (see commit which fixed
1a34115
+# RHBZ#1044014).
1a34115
+grep "libvirt needs authentication to connect to libvirt URI" rhbz1044014.out || {
1a34115
+    echo "$0: expecting to see message from commit which fixed RHBZ#1044014"
1a34115
+    echo
1a34115
+    echo "actual output was:"
1a34115
+    echo
1a34115
+    cat rhbz1044014.out
1a34115
+    exit 1
1a34115
+}
1a34115
+
1a34115
+# This is the error we are expecting to see.  If we see it then it
1a34115
+# indicates that authentication was successful.
1a34115
+grep "error: libvirt hypervisor doesn't support qemu or KVM" rhbz1044014.out || {
1a34115
+    echo "$0: unexpected output:"
1a34115
+    echo
1a34115
+    cat rhbz1044014.out
1a34115
+    exit 1
1a34115
+}
1a34115
+
1a34115
+rm rhbz1044014.out
1a34115
diff --git a/tests/regressions/rhbz1044014.xml b/tests/regressions/rhbz1044014.xml
1a34115
new file mode 100644
1a34115
index 0000000..72feaf4
1a34115
--- /dev/null
1a34115
+++ b/tests/regressions/rhbz1044014.xml
1a34115
@@ -0,0 +1,5 @@
1a34115
+<node>
1a34115
+  <auth>
1a34115
+    <user>rich</user>
1a34115
+  </auth>
1a34115
+</node>
1a34115
-- 
4bf3775
1.8.5.3
1a34115