]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Raise ConnectionLostError when the socket dies
authorZack Cerza <zack.cerza@inktank.com>
Fri, 19 Sep 2014 15:42:36 +0000 (09:42 -0600)
committerZack Cerza <zack.cerza@inktank.com>
Fri, 19 Sep 2014 15:42:36 +0000 (09:42 -0600)
Signed-off-by: Zack Cerza <zack.cerza@inktank.com>
teuthology/orchestra/run.py
teuthology/orchestra/test/test_run.py

index 2d9edd291cbd7da3fec2684e90fb041244c3685a..ea41efda52b0e05c0b90ed68479c123a2c5dd515 100644 (file)
@@ -6,6 +6,7 @@ from paramiko import ChannelFile
 
 import gevent
 import gevent.event
+import socket
 import pipes
 import logging
 import shutil
@@ -309,7 +310,10 @@ def run(
     :param name: Human readable name (probably hostname) of the destination
                  host
     """
-    (host, port) = client.get_transport().getpeername()
+    try:
+        (host, port) = client.get_transport().getpeername()
+    except socket.error:
+        raise ConnectionLostError(command=quote(args))
 
     if name is None:
         name = host
index 65c08600c4928d526001de785e11049645f14204..05de1c4d30ae86dca9316960e68b452f50137777 100644 (file)
@@ -2,6 +2,7 @@ from cStringIO import StringIO
 
 import fudge
 import logging
+import socket
 
 from .. import run
 from teuthology.exceptions import (CommandCrashedError, CommandFailedError,
@@ -230,6 +231,27 @@ class TestRun(object):
         assert e.command == 'foo'
         assert str(e) == "SSH connection was lost: 'foo'"
 
+    @fudge.with_fakes
+    def test_run_status_lost_socket(self):
+        fudge.clear_expectations()
+        ssh = fudge.Fake('SSHConnection')
+        out = fudge.Fake('ChannelFile').is_a_stub()
+        logger = fudge.Fake('logger').is_a_stub()
+        channel = fudge.Fake('channel')
+        out.has_attr(channel=channel)
+        transport = ssh.expects('get_transport').with_args().returns_fake()
+        transport.expects('getpeername').with_args().raises(socket.error)
+        e = assert_raises(
+            ConnectionLostError,
+            run.run,
+            client=ssh,
+            logger=logger,
+            args=['foo'],
+            )
+
+        assert e.command == 'foo'
+        assert str(e) == "SSH connection was lost: 'foo'"
+
     @fudge.with_fakes
     def test_run_status_lost_nocheck(self):
         fudge.clear_expectations()