Linux building in chroot does fail `test_socket_permissions` and `test_with_socket`
Have you checked borgbackup docs, FAQ, and open GitHub issues?
Yeah
Is this a BUG / ISSUE report or a QUESTION?
Bug/Issue
System information. For client/server mode post info for both machines.
Your borg version (borg -V).
2.0.0b9
Operating system (distribution) and version.
ArchLinux (CachyOS flavor)
Hardware / network configuration, and filesystems used.
ZFS filesystem / Intel i11 processor / x86_64 / 16 GB memory / Linux 6.10.0 / Python 3.12.4 / cython 3.0.10 / gcc 14.1.1
How much data is handled by borg?
None
Full borg commandline that lead to the problem (leave away excludes and passwords)
None
Describe the problem you're observing.
I'm maintaining the borg2 AUR package for ArchLinux. While building borg 2.0.0b9 in a chroot the checks test_socket_permissions and test_with_socket fail due to missing permissions.
It would be nice if either these checks could skip in a chroot or skip if they see the permission error.
Can you reproduce the problem? If so, describe how. If not, describe troubleshooting steps you took before opening the issue.
Yes
Include any warning/errors/backtraces from the system logs
==================================== ERRORS ====================================
______________________ ERROR at setup of test_with_socket ______________________
path = '/run/user/1000/pytest', mode = 511, pretty_deadly = True
def ensure_dir(path, mode=stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO, pretty_deadly=True):
"""
Ensures that the dir exists with the right permissions.
1) Make sure the directory exists in a race-free operation
2) If mode is not None and the directory has been created, give the right
permissions to the leaf directory. The current umask value is masked out first.
3) If pretty_deadly is True, catch exceptions, reraise them with a pretty
message.
Returns if the directory has been created and has the right permissions,
An exception otherwise. If a deadly exception happened it is reraised.
"""
try:
> os.makedirs(path, mode=mode, exist_ok=True)
E PermissionError: [Errno 13] Permission denied: '/run/user'
borg/helpers/fs.py:37: PermissionError
During handling of the above exception, another exception occurred:
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x74a2b9504ef0>
@pytest.fixture
def serve_socket(monkeypatch):
have_a_short_runtime_dir(monkeypatch)
# use a random unique socket filename, so tests can run in parallel.
> socket_file = tempfile.mktemp(suffix=".sock", prefix="borg-", dir=get_runtime_dir())
borg/testsuite/archiver/serve_cmd.py:25:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
borg/helpers/fs.py:117: in get_runtime_dir
ensure_dir(runtime_dir)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
path = '/run/user/1000/pytest', mode = 511, pretty_deadly = True
def ensure_dir(path, mode=stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO, pretty_deadly=True):
"""
Ensures that the dir exists with the right permissions.
1) Make sure the directory exists in a race-free operation
2) If mode is not None and the directory has been created, give the right
permissions to the leaf directory. The current umask value is masked out first.
3) If pretty_deadly is True, catch exceptions, reraise them with a pretty
message.
Returns if the directory has been created and has the right permissions,
An exception otherwise. If a deadly exception happened it is reraised.
"""
try:
os.makedirs(path, mode=mode, exist_ok=True)
except OSError as e:
if pretty_deadly:
> raise Error(str(e))
E borg.helpers.errors.Error: Error: [Errno 13] Permission denied: '/run/user'
borg/helpers/fs.py:40: Error
__________________ ERROR at setup of test_socket_permissions ___________________
path = '/run/user/1000/pytest', mode = 511, pretty_deadly = True
def ensure_dir(path, mode=stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO, pretty_deadly=True):
"""
Ensures that the dir exists with the right permissions.
1) Make sure the directory exists in a race-free operation
2) If mode is not None and the directory has been created, give the right
permissions to the leaf directory. The current umask value is masked out first.
3) If pretty_deadly is True, catch exceptions, reraise them with a pretty
message.
Returns if the directory has been created and has the right permissions,
An exception otherwise. If a deadly exception happened it is reraised.
"""
try:
> os.makedirs(path, mode=mode, exist_ok=True)
E PermissionError: [Errno 13] Permission denied: '/run/user'
borg/helpers/fs.py:37: PermissionError
During handling of the above exception, another exception occurred:
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x74a2b8bd3350>
@pytest.fixture
def serve_socket(monkeypatch):
have_a_short_runtime_dir(monkeypatch)
# use a random unique socket filename, so tests can run in parallel.
> socket_file = tempfile.mktemp(suffix=".sock", prefix="borg-", dir=get_runtime_dir())
borg/testsuite/archiver/serve_cmd.py:25:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
borg/helpers/fs.py:117: in get_runtime_dir
ensure_dir(runtime_dir)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
path = '/run/user/1000/pytest', mode = 511, pretty_deadly = True
def ensure_dir(path, mode=stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO, pretty_deadly=True):
"""
Ensures that the dir exists with the right permissions.
1) Make sure the directory exists in a race-free operation
2) If mode is not None and the directory has been created, give the right
permissions to the leaf directory. The current umask value is masked out first.
3) If pretty_deadly is True, catch exceptions, reraise them with a pretty
message.
Returns if the directory has been created and has the right permissions,
An exception otherwise. If a deadly exception happened it is reraised.
"""
try:
os.makedirs(path, mode=mode, exist_ok=True)
except OSError as e:
if pretty_deadly:
> raise Error(str(e))
E borg.helpers.errors.Error: Error: [Errno 13] Permission denied: '/run/user'
borg/helpers/fs.py:40: Error
It expects /run/user/1000/pytest directory to either exist or be creatable (so that files, like that socket, can be created in that directory).
That directory is the "user runtime directory" returned by platformdirs.user_runtime_dir.
https://platformdirs.readthedocs.io/en/latest/api.html#platformdirs.unix.Unix.user_runtime_dir
I'm having the same test failures, but I checked that the directory exists and is fully owned by my user with 700 rwx access.
My error is on missing "borg" cmd as this is the first install/build on my machine. But that also indicates that the test itself is not being properly applied to the tested artifact, and will instead use the first "borg" command in PATH (as far as I know), therefore it will (usually) test the installed version of Borg.
============================================================================================================================================================ ERRORS ============================================================================================================================================================
______________________________________________________________________________________________________________________________________________ ERROR at setup of test_with_socket ______________________________________________________________________________________________________________________________________________
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7f6f57e6bcb0>
@pytest.fixture
def serve_socket(monkeypatch):
have_a_short_runtime_dir(monkeypatch)
# use a random unique socket filename, so tests can run in parallel.
socket_file = tempfile.mktemp(suffix=".sock", prefix="borg-", dir=get_runtime_dir())
> with subprocess.Popen(["borg", "serve", f"--socket={socket_file}"]) as p:
borg/testsuite/archiver/serve_cmd_test.py:26:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib/python3.13/subprocess.py:1038: in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
...
...
...
E FileNotFoundError: [Errno 2] No such file or directory: 'borg'
/usr/lib/python3.13/subprocess.py:1974: FileNotFoundError
@maricn The tests assume that the to-be-tested borg is installed. Usually tox creates a virtual env and installs borg into that and then runs the tests within that venv.