Add tests for SSH transport and template deployment functionality
- Introduced a new test to verify behavior when SSH transport connects but is not ready, ensuring it returns False after the deadline. - Added comprehensive tests for the `deploy-linux` template, covering various scenarios including missing public keys, VM directory existence, SHA256 mismatches, and failures during ISO creation and VM conversion. - Implemented tests for SSH-related functions, including connection retries and streaming command execution, ensuring proper handling of exit statuses and progress indications. - Enhanced existing tests to cover edge cases and ensure robustness in the deployment process.
This commit is contained in:
@@ -443,3 +443,38 @@ def test_connect_reuses_existing_client(monkeypatch: pytest.MonkeyPatch) -> None
|
||||
assert client.commands == ["first", "second"]
|
||||
# Only one connect attempt.
|
||||
assert client.connect_kwargs["hostname"] == "10.0.0.2"
|
||||
|
||||
|
||||
# ── run_streaming: progressed=True but exit not yet ready → loop back ─────────
|
||||
|
||||
|
||||
def test_run_streaming_progressed_no_sleep_loops_back(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Data received (progressed=True) but exit_status_ready()=False on first check.
|
||||
|
||||
Covers the ``if not progressed: time.sleep(0.05)`` branch when progressed
|
||||
is True — no sleep occurs, loop continues (branch 170->150).
|
||||
"""
|
||||
slept: list[float] = []
|
||||
monkeypatch.setattr("ci_orchestrator.transport.ssh.time.sleep", slept.append)
|
||||
|
||||
class _ProgressedNoBreakChannel(_FakeStreamingChannel):
|
||||
def __init__(self) -> None:
|
||||
super().__init__([b"hello"], [], rc=0)
|
||||
self._ready_count = 0
|
||||
|
||||
def exit_status_ready(self) -> bool:
|
||||
# First call: stdout already drained but signal exit not yet ready.
|
||||
# Subsequent calls: ready → break.
|
||||
self._ready_count += 1
|
||||
return self._ready_count > 1
|
||||
|
||||
chan = _ProgressedNoBreakChannel()
|
||||
client = _FakeSSHClientWithTransport(chan)
|
||||
_install_fake_paramiko(monkeypatch, client)
|
||||
t = SshTransport("10.0.0.2", key_path="/tmp/key")
|
||||
result = t.run_streaming("cmd")
|
||||
assert result.stdout == "hello"
|
||||
# sleep must NOT have been called (progressed=True skips sleep branch)
|
||||
assert not slept
|
||||
|
||||
Reference in New Issue
Block a user