backup: Wire up qemu full pull backup commands over QMP
[libvirt/ericb.git] / tests / virsh-uriprecedence
blobfd6ce108c039370f530768fa051f1ec82d6f0b89
1 #!/bin/sh
3 . "$(dirname $0)/test-lib.sh"
5 # This test checks if virsh obeys the proper precedence of different
6 # URI settings
7 test_intro "virsh-uriprecedence"
9 virsh_bin="$abs_top_builddir/tools/virsh"
10 virsh_cmd="$virsh_bin"
11 counter=0
12 ret=0
14 mock_xdg_ || framework_failure
16 is_uri_good()
18 echo "$1" | grep -q -F "$good_uri"
21 test_uri_internal()
23 test_name=$1
24 test_cmd="$virsh_cmd \"$2\""
25 result=0
27 debug "Running '$test_cmd'"
28 out="$($virsh_cmd "$2")"
30 if ! is_uri_good "$out"; then
31 debug "Invalid output: '$out'"
32 result=1
33 ret=1
36 counter="$((counter+1))"
37 test_result "$counter" "$1" "$result"
40 test_uri_connect()
42 test_uri_internal "$1" "connect; uri"
45 test_uri_noconnect()
47 test_uri_internal "$1" "uri"
50 test_uri()
52 test_uri_connect "$1"
53 test_uri_noconnect "$1"
56 # Precedence is the following (lowest priority first):
58 # 1) if run as root, 'uri_default' from /etc/libvirtd/libvirt.conf,
59 # otherwise qemu:///session. There is no way to mock this file for
60 # virsh/libvirt.so and the user may have set anything in there that
61 # would spoil the test, so we don't test this
63 # 2) 'uri_default' from $XDG_CONFIG_HOME/libvirt/libvirt.conf
65 # 3) LIBVIRT_DEFAULT_URI
67 # 4) VIRSH_DEFAULT_CONNECT_URI
69 # 5) parameter -c (--connect)
71 unset LIBVIRT_DEFAULT_URI
72 unset VIRSH_DEFAULT_CONNECT_URI
73 bad_uri="test:///default?bad_uri"
74 good_uri="test:///default?good_uri"
76 printf "uri_default=\"%s\"\n" "$good_uri" >"$XDG_CONFIG_HOME/libvirt/libvirt.conf"
77 if uid_is_privileged_; then
78 counter="$((counter+1))"
79 test_skip_case "$counter" "User config file" "must not be run as root"
80 else
81 test_uri "User config file"
84 printf "uri_default=\"%s\"\n" "$bad_uri" >"$XDG_CONFIG_HOME/libvirt/libvirt.conf"
85 export LIBVIRT_DEFAULT_URI="$good_uri"
86 test_uri "LIBVIRT_DEFAULT_URI"
88 export LIBVIRT_DEFAULT_URI="$bad_uri"
89 export VIRSH_DEFAULT_CONNECT_URI="$good_uri"
90 test_uri "VIRSH_DEFAULT_CONNECT_URI"
92 export VIRSH_DEFAULT_CONNECT_URI="$bad_uri"
93 virsh_cmd="$virsh_bin --connect $good_uri"
94 test_uri "Parameter"
96 test_final "$counter" "$ret"
97 (exit "$ret"); exit "$ret"