From 449de49de98a35e8a713da7bf6391e7dae0b74a4 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Fri, 7 Nov 2014 10:13:50 -0700 Subject: [PATCH] Mention hostnames in ConnectionLostErrors Signed-off-by: Zack Cerza --- teuthology/exceptions.py | 7 +++++-- teuthology/orchestra/run.py | 5 +++-- teuthology/orchestra/test/test_run.py | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/teuthology/exceptions.py b/teuthology/exceptions.py index 573c335ab3..bf6b49a67a 100644 --- a/teuthology/exceptions.py +++ b/teuthology/exceptions.py @@ -58,11 +58,14 @@ class ConnectionLostError(Exception): """ Exception thrown when the connection is lost """ - def __init__(self, command): + def __init__(self, command, node=None): self.command = command + self.node = node def __str__(self): - return "SSH connection was lost: {command!r}".format( + node_str = 'to %s ' % self.node if self.node else '' + return "SSH connection {node_str}was lost: {command!r}".format( + node_str=node_str, command=self.command, ) diff --git a/teuthology/orchestra/run.py b/teuthology/orchestra/run.py index 6c22d0bfb1..6f7f54889d 100644 --- a/teuthology/orchestra/run.py +++ b/teuthology/orchestra/run.py @@ -95,7 +95,8 @@ class RemoteProcess(object): transport = self.client.get_transport() if transport is None or not transport.is_active(): # look like we lost the connection - raise ConnectionLostError(command=self.command) + raise ConnectionLostError(command=self.command, + node=self.hostname) # connection seems healthy still, assuming it was a # signal; sadly SSH does not tell us which signal @@ -316,7 +317,7 @@ def run( try: (host, port) = client.get_transport().getpeername() except socket.error: - raise ConnectionLostError(command=quote(args)) + raise ConnectionLostError(command=quote(args), node=name) if name is None: name = host diff --git a/teuthology/orchestra/test/test_run.py b/teuthology/orchestra/test/test_run.py index 05de1c4d30..5132768cc6 100644 --- a/teuthology/orchestra/test/test_run.py +++ b/teuthology/orchestra/test/test_run.py @@ -229,7 +229,7 @@ class TestRun(object): ) assert e.command == 'foo' - assert str(e) == "SSH connection was lost: 'foo'" + assert str(e) == "SSH connection to HOST was lost: 'foo'" @fudge.with_fakes def test_run_status_lost_socket(self): -- 2.39.5