conductor(checkpoint): Checkpoint end of Phase 1
This commit is contained in:
@@ -55,4 +55,37 @@ def test_restart_allocation(mock_run):
|
||||
mock_run.assert_called_with(
|
||||
["nomad", "alloc", "restart", "abc12345"],
|
||||
capture_output=True, text=True, check=True
|
||||
)
|
||||
)
|
||||
|
||||
@patch("subprocess.run")
|
||||
def test_exec_command(mock_run):
|
||||
"""Test executing a command in an allocation."""
|
||||
m = MagicMock()
|
||||
m.stdout = "Command output"
|
||||
m.return_code = 0
|
||||
mock_run.return_value = m
|
||||
|
||||
output = nomad_client.exec_command("abc12345", ["ls", "/data"])
|
||||
assert output == "Command output"
|
||||
mock_run.assert_called_with(
|
||||
["nomad", "alloc", "exec", "-task", "navidrome", "abc12345", "ls", "/data"],
|
||||
capture_output=True, text=True, check=True
|
||||
)
|
||||
|
||||
@patch("subprocess.run")
|
||||
def test_exec_command_failure(mock_run):
|
||||
"""Test executing a command handles failure gracefully."""
|
||||
mock_run.side_effect = subprocess.CalledProcessError(1, "nomad", stderr="Nomad error")
|
||||
|
||||
output = nomad_client.exec_command("abc12345", ["ls", "/data"])
|
||||
assert "Nomad Error" in output
|
||||
assert "Nomad error" not in output # The exception str might not contain stderr directly depending on python version
|
||||
|
||||
@patch("subprocess.run")
|
||||
def test_get_node_map_failure(mock_run):
|
||||
"""Test get_node_map handles failure."""
|
||||
mock_run.side_effect = FileNotFoundError("No such file")
|
||||
|
||||
# It should not raise
|
||||
node_map = nomad_client.get_node_map()
|
||||
assert node_map == {}
|
||||
Reference in New Issue
Block a user