|
|
43fe83 |
From 5eb44efbfb8d5d2bbfdca1d3fbaef8aa78afa1d2 Mon Sep 17 00:00:00 2001
|
|
|
43fe83 |
Message-Id: <5eb44efbfb8d5d2bbfdca1d3fbaef8aa78afa1d2.1377873640.git.jdenemar@redhat.com>
|
|
|
43fe83 |
From: Martin Kletzander <mkletzan@redhat.com>
|
|
|
43fe83 |
Date: Thu, 22 Aug 2013 15:39:04 +0200
|
|
|
43fe83 |
Subject: [PATCH] tests: Add URI precedence checking
|
|
|
43fe83 |
|
|
|
43fe83 |
https://bugzilla.redhat.com/show_bug.cgi?id=999323
|
|
|
43fe83 |
|
|
|
43fe83 |
Commit a0b6a36f is fixing what commit abfff210 broke, so to avoid having
|
|
|
43fe83 |
to deal with this issue again, herec comes "virsh-uriprecedence".
|
|
|
43fe83 |
|
|
|
43fe83 |
(cherry picked from commit 398de14734c1a9a8053f23ffbbaf47bac1b3f716)
|
|
|
43fe83 |
---
|
|
|
43fe83 |
tests/Makefile.am | 2 ++
|
|
|
43fe83 |
tests/virsh-uriprecedence | 76 +++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
43fe83 |
2 files changed, 78 insertions(+)
|
|
|
43fe83 |
create mode 100755 tests/virsh-uriprecedence
|
|
|
43fe83 |
|
|
|
43fe83 |
diff --git a/tests/Makefile.am b/tests/Makefile.am
|
|
|
43fe83 |
index efd28e3..0c6e5ee 100644
|
|
|
43fe83 |
--- a/tests/Makefile.am
|
|
|
43fe83 |
+++ b/tests/Makefile.am
|
|
|
43fe83 |
@@ -98,6 +98,7 @@ EXTRA_DIST = \
|
|
|
43fe83 |
storagevolxml2xmlout \
|
|
|
43fe83 |
sysinfodata \
|
|
|
43fe83 |
test-lib.sh \
|
|
|
43fe83 |
+ virsh-uriprecedence \
|
|
|
43fe83 |
vmx2xmldata \
|
|
|
43fe83 |
xencapsdata \
|
|
|
43fe83 |
xmconfigdata \
|
|
|
43fe83 |
@@ -234,6 +235,7 @@ test_scripts += \
|
|
|
43fe83 |
read-bufsiz \
|
|
|
43fe83 |
read-non-seekable \
|
|
|
43fe83 |
start \
|
|
|
43fe83 |
+ virsh-uriprecedence \
|
|
|
43fe83 |
vcpupin \
|
|
|
43fe83 |
virsh-all \
|
|
|
43fe83 |
virsh-optparse \
|
|
|
43fe83 |
diff --git a/tests/virsh-uriprecedence b/tests/virsh-uriprecedence
|
|
|
43fe83 |
new file mode 100755
|
|
|
43fe83 |
index 0000000..f4d84a4
|
|
|
43fe83 |
--- /dev/null
|
|
|
43fe83 |
+++ b/tests/virsh-uriprecedence
|
|
|
43fe83 |
@@ -0,0 +1,76 @@
|
|
|
43fe83 |
+#!/bin/sh
|
|
|
43fe83 |
+
|
|
|
43fe83 |
+: ${srcdir=.}
|
|
|
43fe83 |
+. $srcdir/test-lib.sh
|
|
|
43fe83 |
+
|
|
|
43fe83 |
+# This test checks if virsh obeys the proper precedence of different
|
|
|
43fe83 |
+# URI settings
|
|
|
43fe83 |
+test_intro "virsh-uriprecedence"
|
|
|
43fe83 |
+
|
|
|
43fe83 |
+virsh_bin="$abs_top_builddir/tools/virsh"
|
|
|
43fe83 |
+counter=1
|
|
|
43fe83 |
+ret=0
|
|
|
43fe83 |
+
|
|
|
43fe83 |
+cleanup_() { rm -rf "$tmphome"; }
|
|
|
43fe83 |
+
|
|
|
43fe83 |
+# Create all mock files/directories to avoid permission problems
|
|
|
43fe83 |
+tmphome="$PWD/tmp_home"
|
|
|
43fe83 |
+export XDG_CONFIG_HOME="$tmphome/.config"
|
|
|
43fe83 |
+export XDG_CACHE_HOME="$tmphome/.cache"
|
|
|
43fe83 |
+export XDG_RUNTIME_HOME="XDG_CACHE_HOME"
|
|
|
43fe83 |
+
|
|
|
43fe83 |
+mkdir -p "$XDG_CONFIG_HOME/libvirt" "$XDG_CONFIG_HOME/virsh"
|
|
|
43fe83 |
+mkdir -p "$XDG_CACHE_HOME/libvirt" "$XDG_CACHE_HOME/virsh"
|
|
|
43fe83 |
+mkdir -p "$XDG_RUNTIME_HOME/libvirt" "$XDG_RUNTIME_HOME/virsh"
|
|
|
43fe83 |
+
|
|
|
43fe83 |
+# Main function checking for the proper uri being returned
|
|
|
43fe83 |
+test_uri()
|
|
|
43fe83 |
+{
|
|
|
43fe83 |
+ result=0
|
|
|
43fe83 |
+ if [ "$($virsh_bin uri)" != "$good_uri" ]; then
|
|
|
43fe83 |
+ result=1
|
|
|
43fe83 |
+ ret=1
|
|
|
43fe83 |
+ fi
|
|
|
43fe83 |
+ test_result "$counter" "$1" "$result"
|
|
|
43fe83 |
+ counter="$((counter+1))"
|
|
|
43fe83 |
+}
|
|
|
43fe83 |
+
|
|
|
43fe83 |
+# Precedence is the following (lowest priority first):
|
|
|
43fe83 |
+#
|
|
|
43fe83 |
+# 1) if run as root, 'uri_default' from /etc/libvirtd/libvirt.conf,
|
|
|
43fe83 |
+# otherwise qemu:///session. There is no way to mock this file for
|
|
|
43fe83 |
+# virsh/libvirt.so and the user may have set anything in there that
|
|
|
43fe83 |
+# would spoil the test, so we don't test this
|
|
|
43fe83 |
+#
|
|
|
43fe83 |
+# 2) 'uri_default' from $XDG_CONFIG_HOME/libvirt/libvirt.conf
|
|
|
43fe83 |
+#
|
|
|
43fe83 |
+# 3) LIBVIRT_DEFAULT_URI
|
|
|
43fe83 |
+#
|
|
|
43fe83 |
+# 4) VIRSH_DEFAULT_CONNECT_URI
|
|
|
43fe83 |
+#
|
|
|
43fe83 |
+# 5) parameter -c (--connect)
|
|
|
43fe83 |
+
|
|
|
43fe83 |
+unset LIBVIRT_DEFAULT_URI
|
|
|
43fe83 |
+unset VIRSH_DEFAULT_CONNECT_URI
|
|
|
43fe83 |
+bad_uri="test:///default?bad_uri"
|
|
|
43fe83 |
+good_uri="test:///default?good_uri"
|
|
|
43fe83 |
+
|
|
|
43fe83 |
+printf "uri_default=\"%s\"\n" "$good_uri" >"$XDG_CONFIG_HOME/libvirt/libvirt.conf"
|
|
|
43fe83 |
+test_uri "User config file"
|
|
|
43fe83 |
+
|
|
|
43fe83 |
+printf "uri_default=\"%s\"\n" "$bad_uri" >"$XDG_CONFIG_HOME/libvirt/libvirt.conf"
|
|
|
43fe83 |
+export LIBVIRT_DEFAULT_URI="$good_uri"
|
|
|
43fe83 |
+test_uri "LIBVIRT_DEFAULT_URI"
|
|
|
43fe83 |
+
|
|
|
43fe83 |
+export LIBVIRT_DEFAULT_URI="$bad_uri"
|
|
|
43fe83 |
+export VIRSH_DEFAULT_CONNECT_URI="$good_uri"
|
|
|
43fe83 |
+test_uri "VIRSH_DEFAULT_CONNECT_URI"
|
|
|
43fe83 |
+
|
|
|
43fe83 |
+export VIRSH_DEFAULT_CONNECT_URI="$bad_uri"
|
|
|
43fe83 |
+virsh_bin="$virsh_bin --connect $good_uri"
|
|
|
43fe83 |
+test_uri "Parameter"
|
|
|
43fe83 |
+
|
|
|
43fe83 |
+# test_uri() increases $counter even for the last test, so we must
|
|
|
43fe83 |
+# decrement it
|
|
|
43fe83 |
+test_final "$((counter-1))" "$ret"
|
|
|
43fe83 |
+(exit "$ret"); exit "$ret"
|
|
|
43fe83 |
--
|
|
|
43fe83 |
1.8.3.2
|
|
|
43fe83 |
|