From nobody Sat May 18 23:55:25 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 155371247121168.12373939173199; Wed, 27 Mar 2019 11:47:51 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 14FDB3087936; Wed, 27 Mar 2019 18:47:49 +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 F2FD887A8; Wed, 27 Mar 2019 18:47:47 +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 0598B1803387; Wed, 27 Mar 2019 18:47:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2RIlgWT031716 for ; Wed, 27 Mar 2019 14:47:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9F8951001DC0; Wed, 27 Mar 2019 18:47:42 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-59.phx2.redhat.com [10.3.116.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 521F3100164A; Wed, 27 Mar 2019 18:47:40 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 27 Mar 2019 13:47:37 -0500 Message-Id: <20190327184737.21783-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 27 Mar 2019 18:47:49 +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. Fixes: 280a2b41e Reported-by: Daniel P. Berrang=C3=A9 Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 --- 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..64f0b0d401 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"$test_dir_/.config" + export XDG_CACHE_HOME=3D"$test_dir_/.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