-
Notifications
You must be signed in to change notification settings - Fork 1
[DPE-7584] Fix temp tablespace directory permissions #10
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
98fe3e0
Fix temp tablespace directory permissions
marceloneppel daf5a6e
Merge remote-tracking branch 'origin/16/edge' into temp-storage-permi…
marceloneppel c80e55f
Move permissions value to a literal
marceloneppel 04b0ce5
Move snap user to a literal
marceloneppel c7eaa49
Bumb version to 16.0.0
marceloneppel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Copyright 2025 Canonical Ltd. | ||
| # See LICENSE file for licensing details. | ||
| """Filesystem utilities.""" | ||
|
|
||
| import os | ||
| import pwd | ||
|
|
||
| from ..config.literals import SNAP_USER | ||
|
|
||
|
|
||
| def change_owner(path: str) -> None: | ||
| """Change the ownership of a file or a directory to the snap user. | ||
|
|
||
| Args: | ||
| path: path to a file or directory. | ||
| """ | ||
| # Get the uid/gid for the snap user. | ||
| user_database = pwd.getpwnam(SNAP_USER) | ||
| # Set the correct ownership for the file or directory. | ||
| os.chown(path, uid=user_database.pw_uid, gid=user_database.pw_gid) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # Copyright 2025 Canonical Ltd. | ||
| # See LICENSE file for licensing details. | ||
| from tempfile import NamedTemporaryFile | ||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| import pytest | ||
| from single_kernel_postgresql.utils.filesystem import change_owner | ||
|
|
||
|
|
||
| def test_change_owner_calls_pwd_and_os_chown_with_daemon_user(): | ||
| with ( | ||
| patch("single_kernel_postgresql.utils.filesystem.pwd.getpwnam") as getpwnam, | ||
| patch("single_kernel_postgresql.utils.filesystem.os.chown") as chown, | ||
| NamedTemporaryFile(delete=True) as tmp, | ||
| ): | ||
| # Simulate pwd entry | ||
| pw_entry = MagicMock() | ||
| pw_entry.pw_uid = 1234 | ||
| pw_entry.pw_gid = 4321 | ||
| getpwnam.return_value = pw_entry | ||
|
|
||
| change_owner(tmp.name) | ||
|
|
||
| getpwnam.assert_called_once_with("_daemon_") | ||
| chown.assert_called_once_with(tmp.name, uid=1234, gid=4321) | ||
|
|
||
|
|
||
| def test_change_owner_raises_when_user_missing(): | ||
| # When the _daemon_ user is not present, pwd.getpwnam raises KeyError | ||
| with ( | ||
| patch("single_kernel_postgresql.utils.filesystem.pwd.getpwnam", side_effect=KeyError), | ||
| pytest.raises(KeyError), | ||
| NamedTemporaryFile(delete=True) as tmp, | ||
| ): | ||
| change_owner(tmp.name) | ||
|
|
||
|
|
||
| def test_change_owner_bubbles_up_os_error(): | ||
| # Ensure we surface OSError coming from os.chown | ||
| with ( | ||
| patch("single_kernel_postgresql.utils.filesystem.pwd.getpwnam") as getpwnam, | ||
| patch("single_kernel_postgresql.utils.filesystem.os.chown", side_effect=OSError("denied")), | ||
| NamedTemporaryFile(delete=True) as tmp, | ||
| ): | ||
| entry = MagicMock() | ||
| entry.pw_uid = 1 | ||
| entry.pw_gid = 1 | ||
| getpwnam.return_value = entry | ||
| with pytest.raises(OSError): | ||
| change_owner(tmp.name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may need to tweak in the future for k8s compatibility.