Skip to content

Commit

Permalink
Merge pull request #468 from jkonecny12/main-fix-var-tmp-is-not-acces…
Browse files Browse the repository at this point in the history
…sible

Fix tests executed in Toolbx with host libvirt
  • Loading branch information
KKoukiou authored Oct 8, 2024
2 parents 4dc8321 + bf89731 commit c4a7fcb
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 c4a7fcb

Please sign in to comment.