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.
This commit is contained in:
Tobias Waldekranz
2025-12-16 09:33:51 +01:00
parent 7fcbc88105
commit 0298dc3c1a
+8 -2
View File
@@ -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: