From 854b38da841fe68a856c273bd3d237fc806d24c2 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 7 Nov 2023 15:54:05 +0100 Subject: [PATCH] tests: allow mount tests to run in parallel --- test/run/test_mount.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/test/run/test_mount.py b/test/run/test_mount.py index c5ed72d80..3104fdef3 100755 --- a/test/run/test_mount.py +++ b/test/run/test_mount.py @@ -15,6 +15,7 @@ import pytest from osbuild import devices, host, meta, mounts +from osbuild.util import linux from ..test import TestBase @@ -27,15 +28,21 @@ def tmpdir_fixture(): @contextmanager def make_arguments(opts): - os.makedirs("/run/osbuild/api") - with open("/run/osbuild/api/arguments", "w", encoding="utf-8") as f: - json.dump(opts, f) - try: - yield - finally: - os.remove("/run/osbuild/api/arguments") - os.rmdir("/run/osbuild/api") - + os.makedirs("/run/osbuild/", exist_ok=True) + # The lock is needed to run the test in parallel, ideally the code + # would allow to point to a different API path *or* just accept + # the data from stdin + with open("/run/osbuild/test-mount-lock", "w") as lck: + linux.fcntl_flock(lck.fileno(), linux.fcntl.F_WRLCK, wait=True) + + os.makedirs("/run/osbuild/api") + with open("/run/osbuild/api/arguments", "w", encoding="utf-8") as f: + json.dump(opts, f) + try: + yield + finally: + os.remove("/run/osbuild/api/arguments") + os.rmdir("/run/osbuild/api") @contextmanager def make_dev_tmpfs(tmpdir):