Skip to content

Commit 0a3c6fa

Browse files
committed
test: pass -vvv to ssh to debug connection failures
When doing `_init_connection`, set SSHs debug level to most verbose, so that in case a connection failure occurs, we can look at the SSH logs (both local and remote, see man ssh(1)). Usually, SSH debug logs would clobber with output from the actual command being run over the SSH connection, however since we're just running `true`, and are not trying to do anything with its output, that's fine in this case. Signed-off-by: Patrick Roy <[email protected]>
1 parent a31c79a commit 0a3c6fa

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

tests/host_tools/network.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,33 @@ def _init_connection(self):
9090
We'll keep trying to execute a remote command that can't fail
9191
(`/bin/true`), until we get a successful (0) exit code.
9292
"""
93-
self.check_output("true", timeout=10)
93+
self.check_output("true", timeout=10, debug=True)
94+
95+
def run(self, cmd_string, timeout=None, *, check=False, debug=False):
96+
"""
97+
Execute the command passed as a string in the ssh context.
98+
99+
If `debug` is set, pass `-vvv` to `ssh`. Note that this will clobber stderr.
100+
"""
101+
command = [
102+
"ssh",
103+
*self.options,
104+
f"{self.user}@{self.host}",
105+
cmd_string,
106+
]
107+
108+
if debug:
109+
command.insert(1, "-vvv")
94110

95-
def run(self, cmd_string, timeout=None, *, check=False):
96-
"""Execute the command passed as a string in the ssh context."""
97111
return self._exec(
98-
[
99-
"ssh",
100-
*self.options,
101-
f"{self.user}@{self.host}",
102-
cmd_string,
103-
],
112+
command,
104113
timeout,
105114
check=check,
106115
)
107116

108-
def check_output(self, cmd_string, timeout=None):
117+
def check_output(self, cmd_string, timeout=None, *, debug=False):
109118
"""Same as `run`, but raises an exception on non-zero return code of remote command"""
110-
return self.run(cmd_string, timeout, check=True)
119+
return self.run(cmd_string, timeout, check=True, debug=debug)
111120

112121
def _exec(self, cmd, timeout=None, check=False):
113122
"""Private function that handles the ssh client invocation."""

0 commit comments

Comments
 (0)