mirror of
https://github.com/borgbackup/borg.git
synced 2026-06-12 18:30:18 -04:00
Merge pull request #9763 from ThomasWaldmann/fix-stale-fuse-mounts
Some checks are pending
Lint / lint (push) Waiting to run
CI / lint (push) Waiting to run
CI / security (push) Waiting to run
CI / asan_ubsan (push) Blocked by required conditions
CI / native_tests (push) Blocked by required conditions
CI / vm_tests (NetBSD, false, netbsd, 10.1) (push) Blocked by required conditions
CI / vm_tests (OmniOS, false, omnios, r151056) (push) Blocked by required conditions
CI / vm_tests (OpenBSD, false, openbsd, 7.8) (push) Blocked by required conditions
CI / vm_tests (borg-freebsd-14-x86_64-gh, FreeBSD, true, freebsd, 14.3) (push) Blocked by required conditions
CI / windows_tests (push) Blocked by required conditions
CodeQL / Analyze (push) Waiting to run
Some checks are pending
Lint / lint (push) Waiting to run
CI / lint (push) Waiting to run
CI / security (push) Waiting to run
CI / asan_ubsan (push) Blocked by required conditions
CI / native_tests (push) Blocked by required conditions
CI / vm_tests (NetBSD, false, netbsd, 10.1) (push) Blocked by required conditions
CI / vm_tests (OmniOS, false, omnios, r151056) (push) Blocked by required conditions
CI / vm_tests (OpenBSD, false, openbsd, 7.8) (push) Blocked by required conditions
CI / vm_tests (borg-freebsd-14-x86_64-gh, FreeBSD, true, freebsd, 14.3) (push) Blocked by required conditions
CI / windows_tests (push) Blocked by required conditions
CodeQL / Analyze (push) Waiting to run
testsuite: sweep stale borg FUSE mounts left by aborted runs
This commit is contained in:
commit
08b1a67928
1 changed files with 58 additions and 0 deletions
|
|
@ -1,5 +1,7 @@
|
|||
import getpass
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
import pytest
|
||||
|
||||
|
|
@ -16,6 +18,62 @@ from borg.testsuite import has_lchflags, has_llfuse, has_pyfuse3, has_mfusepy #
|
|||
from borg.testsuite import are_symlinks_supported, are_hardlinks_supported, is_utime_fully_supported # noqa: E402
|
||||
from borg.testsuite.archiver import BORG_EXES
|
||||
from borg.testsuite.platform.platform_test import fakeroot_detected # noqa: E402
|
||||
from borg.helpers import umount # noqa: E402
|
||||
|
||||
|
||||
def _pytest_tmp_root():
|
||||
# Mirror the parent of pytest's basetemp: <temproot>/pytest-of-<user>.
|
||||
# Old (already-removed-from-retention) run dirs live here too, which is where
|
||||
# FUSE mounts orphaned by aborted runs hide.
|
||||
try:
|
||||
user = getpass.getuser()
|
||||
except Exception:
|
||||
user = "unknown"
|
||||
return os.path.join(tempfile.gettempdir(), f"pytest-of-{user}")
|
||||
|
||||
|
||||
def _looks_mounted(path):
|
||||
# A live FUSE mount reports as a mount point; a dead/stale one makes the
|
||||
# directory inaccessible (os.path.ismount swallows that and returns False).
|
||||
if os.path.ismount(path):
|
||||
return True
|
||||
try:
|
||||
os.listdir(path)
|
||||
except OSError:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def _sweep_stale_fuse_mounts():
|
||||
# The fuse test helper always mounts at a directory named "mountpoint" under the
|
||||
# pytest temp tree and unmounts it in a finally block. If a run is aborted, that
|
||||
# cleanup is skipped and the mount lingers, so the next run's temp-dir GC (rm_rf)
|
||||
# trips over it ("Resource busy" etc.). Walk the temp tree, find such leftover
|
||||
# mountpoints and unmount them with borg's own (cross-platform) umount helper.
|
||||
root = _pytest_tmp_root()
|
||||
for dirpath, dirnames, filenames in os.walk(root, onerror=lambda err: None):
|
||||
if "mountpoint" not in dirnames:
|
||||
continue
|
||||
dirnames.remove("mountpoint") # never descend into a (possibly stale) mount
|
||||
mountpoint = os.path.join(dirpath, "mountpoint")
|
||||
if _looks_mounted(mountpoint):
|
||||
try:
|
||||
umount(mountpoint)
|
||||
except Exception: # nosec B110
|
||||
pass # best-effort: never let cleanup break the test session
|
||||
|
||||
|
||||
def pytest_sessionstart(session):
|
||||
# Run once in the main process (not in each xdist worker), before any temp-dir
|
||||
# GC, to clear mounts left behind by a previous, aborted session.
|
||||
if not hasattr(session.config, "workerinput"):
|
||||
_sweep_stale_fuse_mounts()
|
||||
|
||||
|
||||
def pytest_sessionfinish(session, exitstatus):
|
||||
# Safety net for anything stranded by this session (e.g. a hard interrupt).
|
||||
if not hasattr(session.config, "workerinput"):
|
||||
_sweep_stale_fuse_mounts()
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
|
|
|
|||
Loading…
Reference in a new issue