Skip to content

Commit fd235f8

Browse files
committed
testscript: improve ssh() network diagnosis and logging
On-behalf-of: SAP philipp.schuster@sap.com Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
1 parent 9f1ebad commit fd235f8

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

tests/testscript.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,9 +2026,19 @@ def ssh(machine: Machine, cmd, user="root", password="root", ip="192.168.1.2"):
20262026
:param ip: SSH host to log into
20272027
:return: status and output
20282028
"""
2029+
2030+
# Sometimes we experienced test runs where the host lost IPs. We therefore
2031+
# check that early and always for better debuggability.
2032+
assert_ip_in_local_192_168_net24(machine, ip)
2033+
2034+
# Check VM is pingable
2035+
machine.succeed(f"ping -c 1 -W 1 {ip}")
2036+
2037+
# And here we check if the guest also responds via SSH.
20292038
status, out = machine.execute(
20302039
f"sshpass -p {password} ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no {user}@{ip} {cmd}"
20312040
)
2041+
# TODO, this could be refactored to raise an exception on error
20322042
return status, out
20332043

20342044

0 commit comments

Comments
 (0)