3 .
"$(dirname $0)/test-lib.sh"
5 # This test checks if virsh obeys the proper precedence of different
7 test_intro
"virsh-uriprecedence"
9 virsh_bin
="$abs_top_builddir/tools/virsh"
10 virsh_cmd
="$virsh_bin"
14 mock_xdg_ || framework_failure
18 echo "$1" |
grep -q -F "$good_uri"
24 test_cmd
="$virsh_cmd \"$2\""
27 debug
"Running '$test_cmd'"
28 out
="$($virsh_cmd "$2")"
30 if ! is_uri_good
"$out"; then
31 debug
"Invalid output: '$out'"
36 counter
="$((counter+1))"
37 test_result
"$counter" "$1" "$result"
42 test_uri_internal
"$1" "connect; uri"
47 test_uri_internal
"$1" "uri"
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"
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"
96 test_final
"$counter" "$ret"
97 (exit "$ret"); exit "$ret"