[PATCH] tests: Add URI precedence checking

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Commit a0b6a36f is fixing what commit abfff210 broke, so to avoid having
to deal with this issue again, I present you The "uriprecedencetest".

Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx>
---
 tests/Makefile.am       |  2 ++
 tests/uriprecedencetest | 77 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 79 insertions(+)
 create mode 100755 tests/uriprecedencetest

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 09144d6..419db8b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -98,6 +98,7 @@ EXTRA_DIST =		\
 	storagevolxml2xmlout \
 	sysinfodata \
 	test-lib.sh	\
+	uriprecedencetest \
 	vmx2xmldata \
 	xencapsdata \
 	xmconfigdata \
@@ -235,6 +236,7 @@ test_scripts +=				\
 	read-bufsiz			\
 	read-non-seekable		\
 	start				\
+	uriprecedencetest		\
 	vcpupin				\
 	virsh-all			\
 	virsh-optparse			\
diff --git a/tests/uriprecedencetest b/tests/uriprecedencetest
new file mode 100755
index 0000000..9515e63
--- /dev/null
+++ b/tests/uriprecedencetest
@@ -0,0 +1,77 @@
+#!/bin/sh
+
+: ${srcdir=.}
+. $srcdir/test-lib.sh
+
+# This test checks if virsh obeys the proper precedence of different
+# URI settings
+test_intro "uriprecedencetest"
+
+virsh_bin="$abs_top_builddir/tools/virsh"
+counter=1
+ret=0
+
+tmpdir="$(mktemp -d)"
+cleanup_() { rm -rf "$tmpdir"; }
+
+# Create all mock files/directories to avoid permission problems
+tmphome="$tmpdir/tmp_home"
+export XDG_CONFIG_HOME="$tmpdir/.config"
+export XDG_CACHE_HOME="$tmpdir/.cache"
+export XDG_RUNTIME_HOME="XDG_CACHE_HOME"
+
+mkdir -p "$XDG_CONFIG_HOME/libvirt" "$XDG_CONFIG_HOME/virsh"
+mkdir -p "$XDG_CACHE_HOME/libvirt" "$XDG_CACHE_HOME/virsh"
+mkdir -p "$XDG_RUNTIME_HOME/libvirt" "$XDG_RUNTIME_HOME/virsh"
+
+# Main function checking for the proper uri being returned
+test_uri()
+{
+  result=0
+  if [ "$($virsh_bin uri)" != "$good_uri" ]; then
+      result=1
+      ret=1
+  fi
+  test_result "$counter" "$1" "$result"
+  counter="$((counter+1))"
+}
+
+# Precedence is the following (lowest priority first):
+#
+# 1) if run as root, 'uri_default' from /etc/libvirtd/libvirt.conf,
+#    otherwise qemu:///session.  There is no way to mock this file for
+#    virsh/libvirt.so and the user may have set anything in there that
+#    would spoil the test, so we don't test this
+#
+# 2) 'uri_default' from $XDG_CONFIG_HOME/libvirt/libvirt.conf
+#
+# 3) LIBVIRT_DEFAULT_URI
+#
+# 4) VIRSH_DEFAULT_CONNECT_URI
+#
+# 5) parameter -c (--connect)
+
+unset LIBVIRT_DEFAULT_URI
+unset VIRSH_DEFAULT_CONNECT_URI
+bad_uri="test:///default?bad_uri"
+good_uri="test:///default?good_uri"
+
+printf "uri_default=\"%s\"\n" "$good_uri" >"$XDG_CONFIG_HOME/libvirt/libvirt.conf"
+test_uri "User config file"
+
+printf "uri_default=\"%s\"\n" "$bad_uri" >"$XDG_CONFIG_HOME/libvirt/libvirt.conf"
+export LIBVIRT_DEFAULT_URI="$good_uri"
+test_uri "LIBVIRT_DEFAULT_URI"
+
+export LIBVIRT_DEFAULT_URI="$bad_uri"
+export VIRSH_DEFAULT_CONNECT_URI="$good_uri"
+test_uri "VIRSH_DEFAULT_CONNECT_URI"
+
+export VIRSH_DEFAULT_CONNECT_URI="$bad_uri"
+virsh_bin="$virsh_bin --connect $good_uri"
+test_uri "Parameter"
+
+# test_uri() increases $counter even for the last test, so we must
+# decrement it
+test_final "$((counter-1))" "$ret"
+(exit "$ret"); exit "$ret"
-- 
1.8.3.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]