Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failing test on OpenBSD #7652

Closed
wants to merge 1 commit into from
Closed

Fix failing test on OpenBSD #7652

wants to merge 1 commit into from

Conversation

bket
Copy link
Contributor

@bket bket commented Jun 13, 2023

A borgbackup-2.0.0b6 test fails on OpenBSD with the message below.

=================================== FAILURES ===================================
_____________________________ test_get_runtime_dir _____________________________

path = '/run/user/55/borg', 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)

build/lib.openbsd-7.3-amd64-cpython-310/borg/helpers/fs.py:37:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
...
...

I think /run/user is something that is created by systemd, which is not used on OpenBSD. Despite of
https://github.com/borgbackup/borg/blob/master/src/borg/platformflags.py#L4, proposal is to test if we are on OpenBSD, and act accordingly. Reason for this shortcut is that adding is_openbsd to platformflags.py results in more code, and I'm not sure this makes sense for a unit test.

A borgbackup-2.0.0b6 test fails on OpenBSD with the message below.

```
=================================== FAILURES ===================================
_____________________________ test_get_runtime_dir _____________________________

path = '/run/user/55/borg', 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)

build/lib.openbsd-7.3-amd64-cpython-310/borg/helpers/fs.py:37:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
...
...
```

I think `/run/user` is something that is created by systemd, which is not used
on OpenBSD. Despite of
https://github.com/borgbackup/borg/blob/master/src/borg/platformflags.py#L4,
proposal is to test if we are on OpenBSD, and act accordingly. Reason for this
shortcut is that adding `is_openbsd` to `platformflags.py` results in more
code, and I'm not sure this makes sense for a unit test.
@RayyanAnsari
Copy link
Contributor

RayyanAnsari commented Jun 13, 2023

#7638 could be relevant.

@ThomasWaldmann
Copy link
Member

@bket thanks for the PR, but the fix needed is in platformdirs package, it needs to return something that works on BSD.

@bket
Copy link
Contributor Author

bket commented Jun 13, 2023

@ThomasWaldmann, forgot to mention: initially I was seeing more failing tests. After setting BORG_RUNTIME_DIR=/whatever (#7638) all except one passed. This PR addresses assert get_runtime_dir() == os.path.join("/run/user", str(os.getuid()), "borg"), which if understand correctly, will always fail on at least OpenBSD.

@ThomasWaldmann
Copy link
Member

I guess we need to wait for someone fixing the problem in platformdirs and triggering a release of that.

After we know how it should behave, we can fix our test for its behaviour.

Comment on lines -803 to +804
assert get_runtime_dir() == os.path.join("/run/user", str(os.getuid()), "borg")
if not sys.platform.startswith("openbsd"):
assert get_runtime_dir() == os.path.join("/run/user", str(os.getuid()), "borg")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've seen some fix in platformdirs - can you re-test / adapt the test code with a current version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

retested with platformdirs-3.8.0, and the issue is still there. Pull request still works for me, and is used locally

Copy link
Member

@ThomasWaldmann ThomasWaldmann Jul 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, the linux test would still fail, but it now returns a valid directory for openbsd i guess, so the test could be adapted to check that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Included with platformdirs-3.8.0 is tox-dev/platformdirs@a02fb04, which causes platformdirs.user_runtime_dir to default to /var/run/user/{getuid()} on several BSD's, including OpenBSD. /var/run/user is not part of OpenBS's base as shown by hier(7), and is therefore not a valid directory. Additionally, it seems that XDG's runtime directory is normally set by pam_systemd, which is not supported by OpenBSD.

I'm guessing that the recent change to platformdirs has not been tested on OpenBSD. Way forward is to discuss this with upstream of platformdirs.

I think it makes sense to address this issue in OpenBSD's port of borgbackup (until it has been resolved in platformdirs), and close this PR.

@ThomasWaldmann, What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess getting platformdirs fixed would benefit a lot of software using that.
And if it is fixed there, no change in borg is needed.

@bket bket closed this Jul 3, 2023
@bket bket mentioned this pull request Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants