]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: Avoid writing into $HOME during virsh-snapshot
authorEric Blake <eblake@redhat.com>
Wed, 27 Mar 2019 18:42:45 +0000 (13:42 -0500)
committerEric Blake <eblake@redhat.com>
Thu, 4 Apr 2019 14:35:40 +0000 (09:35 -0500)
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>
tests/test-lib.sh
tests/virsh-snapshot
tests/virsh-uriprecedence

index 49e8d220957235cb788c96435e2d1316a4aec663..ef5a47b5650cb87fdbbf4f092ee23f928cbf5a24 100644 (file)
@@ -222,6 +222,19 @@ mkfifo_or_skip_()
   fi
 }
 
+# Create mock XDG files/directories to avoid permission problems.
+# As it points inside $test_dir_, it is automatically cleaned.
+mock_xdg_()
+{
+  export XDG_CONFIG_HOME="$t_/.config"
+  export XDG_CACHE_HOME="$t_/.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"
+}
+
 test_dir_=$(pwd)
 
 this_test_() { echo "./$0" | sed 's,.*/,,'; }
index fb8a99dd43ec72a64ea6d9efafafc7f87446d83e..cb498cf54e4b6f6d18a195e0aaffb79d0de7d6a8 100755 (executable)
@@ -26,6 +26,8 @@ fi
 
 fail=0
 
+mock_xdg_ || framework_failure
+
 # The test driver loses states between restarts, so we perform a script
 # with some convenient markers for later post-processing of output.
 $abs_top_builddir/tools/virsh --connect test:///default >out 2>err '
index 564e3dc42c72b99c3bf6708f064c75754e5c3eb4..fd6ce108c039370f530768fa051f1ec82d6f0b89 100755 (executable)
@@ -11,17 +11,7 @@ virsh_cmd="$virsh_bin"
 counter=0
 ret=0
 
-cleanup_() { rm -rf "$tmphome"; }
-
-# Create all mock files/directories to avoid permission problems
-tmphome="$PWD/tmp_home"
-export XDG_CONFIG_HOME="$tmphome/.config"
-export XDG_CACHE_HOME="$tmphome/.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"
+mock_xdg_ || framework_failure
 
 is_uri_good()
 {