Skip to content

Commit

Permalink
Fix tests executed in Toolbx with host libvirt
Browse files Browse the repository at this point in the history
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:
cockpit-project/bots#6941
  • Loading branch information
jkonecny12 committed Oct 7, 2024
1 parent 4dc8321 commit bf89731
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion test/anacondalib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 []),
Expand Down

0 comments on commit bf89731

Please sign in to comment.