]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Add retries to orchestra.connection.connect()
authorZack Cerza <zack@cerza.org>
Mon, 12 May 2014 21:06:40 +0000 (16:06 -0500)
committerZack Cerza <zack@cerza.org>
Mon, 12 May 2014 21:09:30 +0000 (16:09 -0500)
This is an attempt to fix: http://tracker.ceph.com/issues/8314

Signed-off-by: Zack Cerza <zack.cerza@inktank.com>
teuthology/orchestra/connection.py
teuthology/orchestra/test/test_connection.py

index 9317d695bd2b8e827f4254b5cac4fe4d125dd1cd..c1f51a7e0ee97e438d5b4f224631e48c089a9b60 100644 (file)
@@ -4,7 +4,12 @@ Connection utilities
 import base64
 import paramiko
 import os
+import logging
+
 from ..config import config
+from ..contextutil import safe_while
+
+log = logging.getLogger(__name__)
 
 
 def split_user(user_at_host):
@@ -85,7 +90,15 @@ def connect(user_at_host, host_key=None, keep_alive=False,
             if opt_name in opts:
                 connect_args[arg_name] = opts[opt_name]
 
+    log.info(connect_args)
+
     # just let the exceptions bubble up to caller
-    ssh.connect(**connect_args)
+    with safe_while(sleep=1, action='connect to ' + host) as proceed:
+        while proceed():
+            try:
+                ssh.connect(**connect_args)
+                break
+            except paramiko.AuthenticationException:
+                log.exception("Error connecting to {host}".format(host=host))
     ssh.get_transport().set_keepalive(keep_alive)
     return ssh
index 951a6742340205243add4a397e14f0db7b3ef19c..5dd3861860f941a63a94fc0369fd6c4356fa195c 100644 (file)
@@ -1,13 +1,15 @@
-from teuthology import config
-
 import fudge
 
+from teuthology import config
 from .util import assert_raises
-
 from .. import connection
 
 
 class TestConnection(object):
+    def setup(self):
+        import time
+        time.sleep = lambda s: True
+
     def clear_config(self):
         config.config.teuthology_yaml = ''
         config.config.load_files()