-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates process whitelisting to exclude users running slurm (#95)
* Adds grep command for checking proc variables * Breaks filtering logic into seperate functions * Minor docstring fix * Updates type hints * Outline logic for filtering valid slurm users * Fills in missing filter logic * Breaks uitls tests into modules * Debugging commit to test ssh support in CI * Adds tests for filtering orphaned procs * Renames filter functions for clarity * Updates tests for include_user_whitelist * Drops tests for remote ssh * Moves base parser tests into dedicated module * Doc formatting updates * Adds tests for the execute method * Adds tests for exclude_active_slurm_users * Cleanup pass * Minor func name edit
- Loading branch information
1 parent
98cb0ce
commit c33a749
Showing
11 changed files
with
303 additions
and
82 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""Tests for the `cli.Application` class""" | ||
|
||
from unittest import TestCase | ||
from unittest.mock import patch | ||
|
||
from shinigami.cli import Application | ||
|
||
|
||
class MethodRouting(TestCase): | ||
"""Test CLI commands are routed to the correct callable objects""" | ||
|
||
def test_scan_method(self) -> None: | ||
"""Test the `scan` command routes to the `scan` method""" | ||
|
||
with patch.object(Application, 'scan', autospec=True) as scan: | ||
Application().execute(['scan', '-c', 'cluster1']) | ||
scan.assert_called_once() | ||
|
||
def test_terminate_method(self) -> None: | ||
"""Test the `terminate` command routes to the `terminate` method""" | ||
|
||
with patch.object(Application, 'terminate', autospec=True) as scan: | ||
Application().execute(['terminate', '-n', 'node1']) | ||
scan.assert_called_once() |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"""Tests for the `cli.BaseParser` class""" | ||
|
||
from unittest import TestCase | ||
|
||
from shinigami.cli import BaseParser | ||
|
||
|
||
class BaseParsing(TestCase): | ||
"""Test custom parsing logic encapsulated by the `BaseParser` class""" | ||
|
||
def test_errors_raise_system_exit(self) -> None: | ||
"""Test error messages are raised as `SystemExit` instances""" | ||
|
||
with self.assertRaises(SystemExit): | ||
BaseParser().error("This is an error message") | ||
|
||
def test_errors_include_message(self) -> None: | ||
"""Test parser messages are included as error messages""" | ||
|
||
msg = "This is an error message" | ||
with self.assertRaisesRegex(SystemExit, msg): | ||
BaseParser().error(msg) |
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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"""Tests for the `utils.exclude_active_slurm_users` function""" | ||
|
||
import unittest | ||
|
||
import pandas as pd | ||
|
||
from shinigami.utils import exclude_active_slurm_users | ||
|
||
|
||
class ExcludeSlurmUsers(unittest.TestCase): | ||
"""Test the identification of slurm users from a DataFrame of process data""" | ||
|
||
def test_exclude_al_processes_for_user(self) -> None: | ||
"""Test users with slurm processes are excluded from the returned DataFrame""" | ||
|
||
# User 1002 has two processes. | ||
# They BOTH should be excluded because ONE of them is a slurm process. | ||
input_df = pd.DataFrame({ | ||
'UID': [1001, 1002, 1002, 1003, 1004], | ||
'CMD': ['process 1', '... slurmd ...', 'process 3', 'process 4', 'process5']}) | ||
|
||
expected_df = input_df.loc[[0, 3, 4]] | ||
returned_df = exclude_active_slurm_users(input_df) | ||
pd.testing.assert_frame_equal(returned_df, expected_df) | ||
|
||
def test_no_slurm_users(self) -> None: | ||
"""Test the returned dataframe matches the input dataframe when there are no slurm processes""" | ||
|
||
input_df = pd.DataFrame({ | ||
'UID': [1001, 1002, 1003, 1004, 1005], | ||
'CMD': ['process1', 'process2', 'process3', 'process4', 'process5']}) | ||
|
||
returned_df = exclude_active_slurm_users(input_df) | ||
pd.testing.assert_frame_equal(returned_df, input_df) | ||
|
||
def test_all_slurm_users(self) -> None: | ||
"""Test the returned dataframe is empty when all process container `slurmd`""" | ||
|
||
input_df = pd.DataFrame({ | ||
'UID': [1001, 1002, 1003, 1004], | ||
'CMD': ['slurmd', 'prefix slurmd', 'slurmd postfix', 'prfix slurmd postfix']}) | ||
|
||
returned_df = exclude_active_slurm_users(input_df) | ||
self.assertTrue(returned_df.empty) |
Oops, something went wrong.