Skip to content

Commit 0298dc3

Browse files
committed
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.
1 parent 7fcbc88 commit 0298dc3

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

test/infamy/ssh.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import subprocess
22

33
from dataclasses import dataclass
4-
from . import env
4+
from . import env, netutil, util
55

66

77
@dataclass
@@ -15,6 +15,9 @@ class Location:
1515
import subprocess
1616
import os
1717

18+
def ssh_syn(addr, port=22):
19+
return netutil.tcp_port_is_open(addr, port)
20+
1821
def fetch_file(remote_user, remote_address, remote_file, local_file, key_file, check=False, remove=False):
1922
"""
2023
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
6265
print(f"Error removing fetched file {local_file}: {e}")
6366

6467
class Device(object):
65-
def __init__(self, name: str, location: Location):
68+
def __init__(self, name: str, location: Location, wait: bool=True):
6669
self.name = name
6770
self.location = location
71+
if wait:
72+
util.until(lambda: ssh_syn(location.host, location.port))
73+
6874
def __str__(self):
6975
nm = f"{self.name}"
7076
if env.ENV.ltop:

0 commit comments

Comments
 (0)