From bf897319b973eea4b81836baedda6b3dcd2b8b6d Mon Sep 17 00:00:00 2001 From: Jiri Konecny Date: Mon, 7 Oct 2024 18:39:59 +0200 Subject: [PATCH] Fix tests executed in Toolbx with host libvirt Issue with Toolbx is that it shares the user libvirt socket so if libvirt is started on the host system first the container will use this host libvirt socket and won't start its own. That works fine until container starts creating libvirt resources which are not shared with the host. In that case libvirt fails to get these resources. To avoid this issue use /run/host/var/tmp when available so the /var/tmp is still used but still accessible by the host system. The /run/host is a way how toolbx can access host system resources so what is there is available in both container and host system. Similar fix is already part of the Cockpit tests: https://github.com/cockpit-project/bots/pull/6941 --- test/anacondalib.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/test/anacondalib.py b/test/anacondalib.py index a174920c9..1935b43a2 100644 --- a/test/anacondalib.py +++ b/test/anacondalib.py @@ -43,6 +43,21 @@ class VirtInstallMachineCase(MachineCase): disk_size = 15 MachineCase.machine_class = VirtInstallMachine + @property + def temp_dir(self): + """Get temp directory for libvirt resources + + We need to set the directory based on the fact if the test is started in the toolbx + """ + # toolbox compatibility: /tmp is shared with the host, but may be too small for big overlays (tmpfs!) + # $HOME is shared, but we don't want to put our junk there (NFS, backups) + # /var/tmp is not shared with the host but the right place; just in case session libvirtd is already + # running, use the shared path so that the daemon can actually see our overlay. + # But this only makes sense if the host also has /run/host set up (toolbox ships a tmpfiles.d) + if os.path.exists("/run/host/var/tmp") and os.path.exists("/run/host/run/host"): + return "/run/host/var/tmp" + return "/var/tmp" + @classmethod def setUpClass(cls): VirtInstallMachine.efi = cls.efi @@ -102,7 +117,7 @@ def rem_disk(self, disk): def _create_disk_image(self, size, image_path=None, backing_file=None): if not image_path: - _, image_path = tempfile.mkstemp(suffix='.qcow2', prefix=f"disk-anaconda-{self.machine.label}", dir="/var/tmp") + _, image_path = tempfile.mkstemp(suffix='.qcow2', prefix=f"disk-anaconda-{self.machine.label}", dir=self.temp_dir) subprocess.check_call([ "qemu-img", "create", "-f", "qcow2", *(["-o", f"backing_file={backing_file},backing_fmt=qcow2"] if backing_file else []),