SSH has an exit code of 255 and prints out an error message when
it reaches a connection timeout. We should catch this and return
a sensible exception.
Also, bit-shift all exit codes by 8 to match what we're now doing
in the client.
From: Jeremy Orlow <jorlow@google.com>
Signed-off-by: John Admanski <jadmanski@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@1170 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/server/hosts/ssh_host.py b/server/hosts/ssh_host.py
index b9517b0..48cb1ff 100644
--- a/server/hosts/ssh_host.py
+++ b/server/hosts/ssh_host.py
@@ -351,10 +351,17 @@
stderr = stderr_tee or sys.stderr
print "ssh: %s" % (command,)
env = " ".join("=".join(pair) for pair in self.env.iteritems())
- full_cmd = '%s "%s %s"' % (self.ssh_command(connect_timeout), env,
- utils.sh_escape(command))
- result = utils.run(full_cmd, timeout, ignore_status,
- stdout, stderr)
+ full_cmd = '%s "%s %s"' % (self.ssh_command(connect_timeout),
+ env, utils.sh_escape(command))
+ result = utils.run(full_cmd, timeout, True, stdout, stderr)
+ if result.exit_status == 255: # ssh's exit status for timeout
+ if re.match(r'^ssh: connect to host .* port .*: ' +
+ r'Connection timed out\r$', result.stderr):
+ raise AutoservSSHTimeout("ssh timed out",
+ result)
+ if not ignore_status and result.exit_status > 0:
+ raise AutoservRunError("command execution error",
+ result)
return result