mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-27 19:11:16 +00:00
In a constrained CI environment, where it is intentional that attempts to write outside the current directory will fail, virsh-snapshot was failing: @@ -1,2 +1,3 @@ error: invalid argument: parent s3 for snapshot s2 not found error: marker +error: Failed to create '/home/travis/.cache/libvirt/virsh': Permission denied FAIL virsh-snapshot (exit status: 1) But we've already solved the problem in virsh-uriprecedence: tell virsh to use XDG locations pointing to somewhere we can write rather than its default of falling back to $HOME with the test being at risk of breaking due to the user's environment and/or unacceptably altering the user's normal cache. Hoist that solution into test-lib.sh, so that all scripts can use it as needed. While at it, fix a latent typo where XDG_RUNTIME_HOME was set to a literal relative directory name "XDG_CACHE_HOME" (the typo did not affect virsh-uriprecedence, but could matter to other clients). Fixes:280a2b41
Fixes:398de147
Reported-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Eric Blake <eblake@redhat.com>
98 lines
2.1 KiB
Bash
Executable File
98 lines
2.1 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
. "$(dirname $0)/test-lib.sh"
|
|
|
|
# This test checks if virsh obeys the proper precedence of different
|
|
# URI settings
|
|
test_intro "virsh-uriprecedence"
|
|
|
|
virsh_bin="$abs_top_builddir/tools/virsh"
|
|
virsh_cmd="$virsh_bin"
|
|
counter=0
|
|
ret=0
|
|
|
|
mock_xdg_ || framework_failure
|
|
|
|
is_uri_good()
|
|
{
|
|
echo "$1" | grep -q -F "$good_uri"
|
|
}
|
|
|
|
test_uri_internal()
|
|
{
|
|
test_name=$1
|
|
test_cmd="$virsh_cmd \"$2\""
|
|
result=0
|
|
|
|
debug "Running '$test_cmd'"
|
|
out="$($virsh_cmd "$2")"
|
|
|
|
if ! is_uri_good "$out"; then
|
|
debug "Invalid output: '$out'"
|
|
result=1
|
|
ret=1
|
|
fi
|
|
|
|
counter="$((counter+1))"
|
|
test_result "$counter" "$1" "$result"
|
|
}
|
|
|
|
test_uri_connect()
|
|
{
|
|
test_uri_internal "$1" "connect; uri"
|
|
}
|
|
|
|
test_uri_noconnect()
|
|
{
|
|
test_uri_internal "$1" "uri"
|
|
}
|
|
|
|
test_uri()
|
|
{
|
|
test_uri_connect "$1"
|
|
test_uri_noconnect "$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"
|
|
if uid_is_privileged_; then
|
|
counter="$((counter+1))"
|
|
test_skip_case "$counter" "User config file" "must not be run as root"
|
|
else
|
|
test_uri "User config file"
|
|
fi
|
|
|
|
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_cmd="$virsh_bin --connect $good_uri"
|
|
test_uri "Parameter"
|
|
|
|
test_final "$counter" "$ret"
|
|
(exit "$ret"); exit "$ret"
|