Skip to content

Commit b03083e

Browse files
committed
testscript: improve wait_for_ssh() network diagnosis and logging
We will be able to better understand if a network issue is caused by the VM host or the VM. Now, in wait_for_ssh() we first wait for ping and then we ssh --> better diagnosis of guest network state, e.g., ping may work but ssh fail A possible missing IP in VM host error might be reported like this: ``` The VM host is not in the same network as IP 192.168.5.2! Networks: [IPv4Network('192.168.1.0/24'), IPv4Network('192.168.2.0/24'), IPv4Network('192.168.3.0/24'), IPv4Network('192.168.4.0/24'), IPv4Network('192.168.100.0/24')] ``` On-behalf-of: SAP philipp.schuster@sap.com Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
1 parent 81b3e6a commit b03083e

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

tests/testscript.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,11 +1975,10 @@ def wait_until_fail(func):
19751975

19761976
def wait_for_ssh(machine: Machine, user="root", password="root", ip="192.168.1.2"):
19771977
"""
1978-
Waits for SSH to become available to connect into the Cloud Hypervisor VM
1979-
hosted on the corresponding machine.
1978+
Waits for the VM to become accessible via SSH.
19801979
1981-
Effectively we use it to wait until the Cloud Hypervisor VM's network is up
1982-
and available.
1980+
It first checks whether the VM responds to ping, and then attempts to
1981+
establish an SSH connection using the provided credentials.
19831982
19841983
:param machine: VM host
19851984
:param user: user for SSH login
@@ -1988,10 +1987,28 @@ def wait_for_ssh(machine: Machine, user="root", password="root", ip="192.168.1.2
19881987
:return: True if the VM became available in a reasonable amount of time
19891988
"""
19901989
retries = 100
1990+
1991+
# Sometimes we experienced test runs where the host lost IPs. We therefore
1992+
# check that early and always for better debuggability.
1993+
assert_ip_in_local_192_168_net24(machine, ip)
1994+
1995+
print(f"Waiting for VM with IP {ip} to become available ...")
1996+
1997+
# First wait until the VM is pingable
1998+
for i in range(retries):
1999+
print(f"Checking ping to {ip} ({i + 1}/{retries}) ...")
2000+
if is_pingable(machine, ip, 1, 1):
2001+
print(f"{ip} is pingable")
2002+
break
2003+
else:
2004+
print(f"{ip} is not reachable via ping after {retries} attempts")
2005+
return False
2006+
19912007
for i in range(retries):
1992-
print(f"Wait for ssh {i}/{retries}")
2008+
print(f"Wait for SSH ({i + 1}/{retries}) ...")
19932009
status, _ = ssh(machine, "echo hello", user, password, ip)
19942010
if status == 0:
2011+
print("SSH available")
19952012
return True
19962013
time.sleep(0.1)
19972014
return False

0 commit comments

Comments
 (0)