From f62a978781205988c9ecf15885fa56570f2fdc52 Mon Sep 17 00:00:00 2001 From: Patrick Roy Date: Wed, 16 Oct 2024 07:39:15 +0100 Subject: [PATCH 1/2] 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 --- tests/host_tools/network.py | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/tests/host_tools/network.py b/tests/host_tools/network.py index 316fdec5424..4aba89da603 100644 --- a/tests/host_tools/network.py +++ b/tests/host_tools/network.py @@ -90,24 +90,33 @@ def _init_connection(self): We'll keep trying to execute a remote command that can't fail (`/bin/true`), until we get a successful (0) exit code. """ - self.check_output("true", timeout=10) + self.check_output("true", timeout=10, debug=True) + + def run(self, cmd_string, timeout=None, *, check=False, debug=False): + """ + Execute the command passed as a string in the ssh context. + + If `debug` is set, pass `-vvv` to `ssh`. Note that this will clobber stderr. + """ + command = [ + "ssh", + *self.options, + f"{self.user}@{self.host}", + cmd_string, + ] + + if debug: + command.insert(1, "-vvv") - def run(self, cmd_string, timeout=None, *, check=False): - """Execute the command passed as a string in the ssh context.""" return self._exec( - [ - "ssh", - *self.options, - f"{self.user}@{self.host}", - cmd_string, - ], + command, timeout, check=check, ) - def check_output(self, cmd_string, timeout=None): + def check_output(self, cmd_string, timeout=None, *, debug=False): """Same as `run`, but raises an exception on non-zero return code of remote command""" - return self.run(cmd_string, timeout, check=True) + return self.run(cmd_string, timeout, check=True, debug=debug) def _exec(self, cmd, timeout=None, check=False): """Private function that handles the ssh client invocation.""" From 108a941b76e78831d40d8cfca8ac131ab8703f03 Mon Sep 17 00:00:00 2001 From: Patrick Roy Date: Wed, 16 Oct 2024 07:44:43 +0100 Subject: [PATCH 2/2] test: fix doccomment for utils.run_cmd it was referring to a `no_shell` parameter, instead of the `shell` parameter. Fixes: cb61379d6ce607c4050e6703de0e8a08d9b5bff5 Signed-off-by: Patrick Roy --- tests/framework/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/framework/utils.py b/tests/framework/utils.py index d154b7af249..b5fb324cbd7 100644 --- a/tests/framework/utils.py +++ b/tests/framework/utils.py @@ -381,7 +381,7 @@ def run_cmd(cmd, check=False, shell=True, cwd=None, timeout=None) -> CommandRetu :param cmd: command to execute :param check: whether a non-zero return code should result in a `ChildProcessError` or not. - :param no_shell: don't run the command in a sub-shell + :param shell: run the command in a sub-shell :param cwd: sets the current directory before the child is executed :param timeout: Time before command execution should be aborted with a `TimeoutExpired` exception :return: return code, stdout, stderr