From nobody Sat May 4 22:23:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1554388900200837.293698042996; Thu, 4 Apr 2019 07:41:40 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E7E9981112; Thu, 4 Apr 2019 14:41:36 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 42AFB608BB; Thu, 4 Apr 2019 14:41:33 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B10ED181AC44; Thu, 4 Apr 2019 14:41:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x34EfLHu003298 for ; Thu, 4 Apr 2019 10:41:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id A50508645A; Thu, 4 Apr 2019 14:41:21 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-67.phx2.redhat.com [10.3.116.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 40F6D9800; Thu, 4 Apr 2019 14:41:19 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Thu, 4 Apr 2019 09:41:16 -0500 Message-Id: <20190404144116.32212-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: abologna@redhat.com Subject: [libvirt] [PATCH v2] tests: Avoid writing into $HOME during virsh-snapshot X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 04 Apr 2019 14:41:38 +0000 (UTC) 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 de= nied 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=C3=A9 Signed-off-by: Eric Blake Reviewed-by: Andrea Bolognani --- in v2: - fix typo in XDG_RUNTIME_HOME [Andrea] - fix 'make distcheck' by using actual per-test tempdir (tests/lv-TEST.XXX/) rather than tests/ as the XDG root [Andrea] tests/test-lib.sh | 13 +++++++++++++ tests/virsh-snapshot | 2 ++ tests/virsh-uriprecedence | 12 +----------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/tests/test-lib.sh b/tests/test-lib.sh index 49e8d22095..ef5a47b565 100644 --- a/tests/test-lib.sh +++ b/tests/test-lib.sh @@ -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=3D"$t_/.config" + export XDG_CACHE_HOME=3D"$t_/.cache" + export XDG_RUNTIME_HOME=3D"$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_=3D$(pwd) this_test_() { echo "./$0" | sed 's,.*/,,'; } diff --git a/tests/virsh-snapshot b/tests/virsh-snapshot index fb8a99dd43..cb498cf54e 100755 --- a/tests/virsh-snapshot +++ b/tests/virsh-snapshot @@ -26,6 +26,8 @@ fi fail=3D0 +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 ' diff --git a/tests/virsh-uriprecedence b/tests/virsh-uriprecedence index 564e3dc42c..fd6ce108c0 100755 --- a/tests/virsh-uriprecedence +++ b/tests/virsh-uriprecedence @@ -11,17 +11,7 @@ virsh_cmd=3D"$virsh_bin" counter=3D0 ret=3D0 -cleanup_() { rm -rf "$tmphome"; } - -# Create all mock files/directories to avoid permission problems -tmphome=3D"$PWD/tmp_home" -export XDG_CONFIG_HOME=3D"$tmphome/.config" -export XDG_CACHE_HOME=3D"$tmphome/.cache" -export XDG_RUNTIME_HOME=3D"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() { --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list