generated from kbase/kbase-template
-
Notifications
You must be signed in to change notification settings - Fork 1
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 hub permission issue #91
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 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 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 |
---|---|---|
|
@@ -32,8 +32,14 @@ def spawner(): | |
@patch.object(VirtualEnvSpawner, '_ensure_virtual_environment') | ||
@patch.object(VirtualEnvSpawner, '_configure_environment') | ||
@patch.object(VirtualEnvSpawner, '_configure_notebook_dir') | ||
def test_start(mock_configure_notebook_dir, mock_configure_environment, mock_ensure_virtual_environment, | ||
mock_ensure_user_jupyter_directory, mock_ensure_user_directory, mock_ensure_system_user, | ||
@patch.object(VirtualEnvSpawner, '_ensure_workspace_permission') | ||
def test_start(mock_ensure_workspace_permission, | ||
mock_configure_notebook_dir, | ||
mock_configure_environment, | ||
mock_ensure_virtual_environment, | ||
mock_ensure_user_jupyter_directory, | ||
mock_ensure_user_directory, | ||
mock_ensure_system_user, | ||
spawner): | ||
|
||
# set spawner.environment (_configure_environment is mocked, so `self.environment` won't be set by the method) | ||
|
@@ -165,17 +171,9 @@ def test_ensure_system_user_error(mock_run): | |
mock_run.assert_has_calls(expected_calls, any_order=False) | ||
|
||
|
||
@patch('pwd.getpwnam') | ||
@patch('os.chown') | ||
def test_ensure_user_directory_with_logging(mock_chown, mock_getpwnam, caplog): | ||
def test_ensure_user_directory_with_logging(caplog): | ||
username = 'testuser' | ||
|
||
# Mock pwd.getpwnam to return a mock user info | ||
mock_user_info = MagicMock() | ||
mock_user_info.pw_uid = 1000 | ||
mock_user_info.pw_gid = 1000 | ||
mock_getpwnam.return_value = mock_user_info | ||
|
||
with tempfile.TemporaryDirectory() as temp_dir: | ||
user_dir = Path(temp_dir) / username | ||
|
||
|
@@ -187,44 +185,10 @@ def test_ensure_user_directory_with_logging(mock_chown, mock_getpwnam, caplog): | |
assert user_dir.exists() | ||
assert user_dir.is_dir() | ||
|
||
# Assert that chown was called with correct parameters | ||
mock_chown.assert_called_once_with(user_dir, 1000, 1000) | ||
|
||
# Check directory permissions | ||
st = os.stat(user_dir) | ||
# Permissions should be 0o750 (rwxr-x---) | ||
assert (st.st_mode & 0o777) == 0o750 | ||
|
||
# Check log messages | ||
assert f'Getting user info for {username}' in caplog.text | ||
assert f'Creating user directory for {username}' in caplog.text | ||
|
||
|
||
@patch('pwd.getpwnam') | ||
def test_ensure_user_directory_user_not_found(mock_getpwnam, caplog): | ||
username = 'nonexistentuser' | ||
|
||
# Mock pwd.getpwnam to raise KeyError (simulating that the user does not exist) | ||
mock_getpwnam.side_effect = KeyError | ||
|
||
with tempfile.TemporaryDirectory() as temp_dir: | ||
user_dir = Path(temp_dir) / username | ||
|
||
with caplog.at_level(logging.INFO): | ||
with pytest.raises(ValueError, match=f'System user {username} does not exist'): | ||
spawner = VirtualEnvSpawner() | ||
spawner._ensure_user_directory(user_dir, username) | ||
|
||
# Check that the directory was not created | ||
assert not user_dir.exists() | ||
|
||
# Check log messages | ||
assert f'Getting user info for {username}' in caplog.text | ||
|
||
|
||
@patch('os.chown') | ||
@patch('os.chmod') | ||
def test_ensure_user_directory_reuse_existing(mock_chown, mock_chmod, caplog): | ||
def test_ensure_user_directory_reuse_existing(caplog): | ||
username = 'testuser' | ||
|
||
with tempfile.TemporaryDirectory() as temp_dir: | ||
|
@@ -237,10 +201,7 @@ def test_ensure_user_directory_reuse_existing(mock_chown, mock_chmod, caplog): | |
spawner = VirtualEnvSpawner() | ||
spawner._ensure_user_directory(user_dir, username) | ||
|
||
# Check that mkdir, chown, and chmod were not called since directory exists | ||
assert user_dir.exists() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like you should keep this line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
mock_chown.assert_not_called() | ||
mock_chmod.assert_not_called() | ||
|
||
# Check log message | ||
assert f'Reusing user directory for {username}' in caplog.text | ||
|
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.
After exploring DockerSpawner, I'm confident that switching to it will resolve the issue, as each user's directory is mounted individually per container.