nixos_test_lib/setup_ssh_connection: no forward in container tests

This commit is contained in:
Jörg Thalheim
2025-07-29 14:54:43 +02:00
parent f44b8c63c2
commit fdfbed1a3f

View File

@@ -27,10 +27,15 @@ def setup_ssh_connection(
SSHConnection with host_port and ssh_key path SSHConnection with host_port and ssh_key path
""" """
host_port = find_free_port() host_port = find_free_port()
target.wait_for_unit("sshd.service")
target.wait_for_open_port(22) target.wait_for_open_port(22)
setup_port_forwarding(target, host_port) # Check if this is a container test (doesn't have forward_port method)
if hasattr(target, "forward_port"):
setup_port_forwarding(target, host_port)
else:
# In container tests, we use the host network namespace
# so we can connect directly to the container's SSH port
host_port = 22
ssh_key = Path(temp_dir) / "id_ed25519" ssh_key = Path(temp_dir) / "id_ed25519"
with ssh_key.open("w") as f, Path(assets_ssh_privkey).open() as src: with ssh_key.open("w") as f, Path(assets_ssh_privkey).open() as src: