Add tests for SSH transport and template deployment functionality
Lint / pssa (push) Successful in 11s
Lint / python (push) Failing after 17s

- 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:
2026-05-27 22:53:24 +02:00
parent d0f67ce807
commit 3eb29b404f
4 changed files with 1957 additions and 0 deletions
+42
View File
@@ -1588,3 +1588,45 @@ def test_job_sigterm_triggers_keyboard_interrupt(
assert registered_handler, "signal.signal(SIGTERM, ...) should have been called"
with pytest.raises(KeyboardInterrupt):
registered_handler[-1](_signal.SIGTERM, None)
# ── _probe_transport: SSH connects but is_ready()=False ──────────────────────
def test_probe_transport_ssh_not_ready_returns_false(
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""SSH transport __enter__ succeeds but is_ready()=False → deadline passes → False.
Covers the ``time.sleep(poll)`` at line 189 in the SSH branch of
_probe_transport (branch 185->189).
"""
class _NotReadySsh:
def __enter__(self) -> _NotReadySsh:
return self
def __exit__(self, *_: object) -> None:
return None
def is_ready(self) -> bool:
return False
monkeypatch.setattr(job_module, "SshTransport", lambda *a, **k: _NotReadySsh())
monkeypatch.setattr(job_module.time, "sleep", lambda _s: None)
# Two-tick clock: first iteration inside deadline, second outside.
seq = iter([0.0, 2.0])
monkeypatch.setattr(job_module, "_now", lambda: next(seq))
result = job_module._probe_transport(
guest_os="linux",
ip_address="10.0.0.1",
deadline=1.0,
poll=0.001,
credential_target="",
ssh_user="ci_build",
ssh_key_path=None,
ssh_known_hosts=None,
)
assert result is False