From 0298dc3c1ab6aed6c1ad4870af404ccd342424c7 Mon Sep 17 00:00:00 2001 From: Tobias Waldekranz Date: Tue, 16 Dec 2025 08:09:14 +0000 Subject: [PATCH] test: ssh: Wait for target SSH server to launch, by default By default, ensure that the target device accepts TCP connections on the specified port before returning the device object. This aligns the SSH implementation with {NET,REST}CONF. This solves the issue where tests that use SSH commands early in their execution would sometimes fail as the remote server had not started up yet. --- test/infamy/ssh.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/infamy/ssh.py b/test/infamy/ssh.py index 9883f532..2db6bde5 100644 --- a/test/infamy/ssh.py +++ b/test/infamy/ssh.py @@ -1,7 +1,7 @@ import subprocess from dataclasses import dataclass -from . import env +from . import env, netutil, util @dataclass @@ -15,6 +15,9 @@ class Location: import subprocess import os +def ssh_syn(addr, port=22): + return netutil.tcp_port_is_open(addr, port) + def fetch_file(remote_user, remote_address, remote_file, local_file, key_file, check=False, remove=False): """ Fetches a file over SSH using scp and the provided private key. @@ -62,9 +65,12 @@ def fetch_file(remote_user, remote_address, remote_file, local_file, key_file, c print(f"Error removing fetched file {local_file}: {e}") class Device(object): - def __init__(self, name: str, location: Location): + def __init__(self, name: str, location: Location, wait: bool=True): self.name = name self.location = location + if wait: + util.until(lambda: ssh_syn(location.host, location.port)) + def __str__(self): nm = f"{self.name}" if env.ENV.ltop: