-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for the remote debug via SSH command
- Loading branch information
Showing
3 changed files
with
86 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import pathlib | ||
import subprocess | ||
import time | ||
|
||
from tests.commands.execution.test_watch import no_sleep | ||
from tests.commands.execution.utils import get_execution_data_mock | ||
from tests.fixture_data import EXECUTION_DATA | ||
from valohai_cli.commands.execution.ssh import ssh | ||
|
||
|
||
def test_ssh_in_completed_execution(runner, logged_in_and_linked, monkeypatch): | ||
with get_execution_data_mock(): | ||
counter = EXECUTION_DATA["counter"] | ||
output = runner.invoke(ssh, [str(counter)], catch_exceptions=False).output | ||
assert f"Error: Execution #{counter} is complete. Cannot SSH into it.\n" in output | ||
|
||
EXECUTION_DATA["status"] = "queued" | ||
monkeypatch.setattr(time, "sleep", no_sleep) | ||
|
||
|
||
def test_ssh_in_queued_execution(runner, logged_in_and_linked, monkeypatch): | ||
counter = EXECUTION_DATA["counter"] | ||
EXECUTION_DATA["status"] = "queued" | ||
monkeypatch.setattr(time, "sleep", no_sleep) | ||
with get_execution_data_mock(): | ||
output = runner.invoke(ssh, [str(counter)], catch_exceptions=False).output | ||
assert f"Execution #{counter} is queued. Waiting for it to start...\n" in output | ||
|
||
|
||
def test_ssh_with_no_ssh_details_present(runner, logged_in_and_linked, monkeypatch): | ||
counter = EXECUTION_DATA["counter"] | ||
EXECUTION_DATA["status"] = "started" | ||
monkeypatch.setattr(time, "sleep", lambda x: None) | ||
monkeypatch.setattr("valohai_cli.utils.ssh.find_ssh_details", lambda x: None) | ||
with get_execution_data_mock(): | ||
output = runner.invoke(ssh, [str(counter)], catch_exceptions=False).output | ||
assert "1/5 Retrying: No SSH details found...\n" in output | ||
assert "2/5 Retrying: No SSH details found...\n" in output | ||
assert "3/5 Retrying: No SSH details found...\n" in output | ||
assert "4/5 Retrying: No SSH details found...\n" in output | ||
assert "5/5 Retrying: No SSH details found...\n" in output | ||
|
||
|
||
def test_ssh(runner, logged_in_and_linked, monkeypatch): | ||
counter = EXECUTION_DATA["counter"] | ||
EXECUTION_DATA["status"] = "started" | ||
monkeypatch.setattr(time, "sleep", lambda x: None) | ||
|
||
def mock_prompt(): | ||
return pathlib.Path("/path/to/private") | ||
|
||
monkeypatch.setattr( | ||
"valohai_cli.commands.execution.ssh.select_private_key_from_possible_directories", | ||
mock_prompt, | ||
) | ||
|
||
with get_execution_data_mock(): | ||
output = runner.invoke(ssh, [str(counter)], catch_exceptions=False).output | ||
assert "SSH address is 127.0.0.1:2222" in output | ||
|
||
def mock_ssh_connection(*args, **kwargs): | ||
print("Mock SSH interactive session executed") | ||
return subprocess.CompletedProcess(args=args, returncode=0, stderr=b"") | ||
|
||
monkeypatch.setattr("valohai_cli.commands.execution.ssh.make_ssh_connection", mock_ssh_connection) | ||
|
||
output = runner.invoke(ssh, [str(counter)], input="1", catch_exceptions=False).output | ||
assert "Mock SSH interactive session executed" in output |
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