]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
ssh_keyscan_wait: blocking version of ssh_keysscan 577/head
authorLoic Dachary <ldachary@redhat.com>
Sun, 19 Jul 2015 07:02:02 +0000 (09:02 +0200)
committerLoic Dachary <ldachary@redhat.com>
Sun, 19 Jul 2015 07:11:55 +0000 (09:11 +0200)
ssh_keyscan is designed to return almost immediately if there is no
connection (the timeout is 1 second). ssh_keyscan_wait will wait up to
10 minutes and report progress every 6 seconds.

Signed-off-by: Loic Dachary <loic@dachary.org>
teuthology/misc.py

index 2ced9f4d740c3a22b573d8f23ff79802e8dbd892..5ae39425c2971e6de7f05b9af4654511127a9511 100644 (file)
@@ -1147,6 +1147,23 @@ def ssh_keyscan(hostnames):
     return keys_dict
 
 
+def ssh_keyscan_wait(hostname):
+    """
+    Run ssh-keyscan against a host, return True if it succeeds,
+    False otherwise. Try again if ssh-keyscan timesout.
+    :param hostname: on which ssh-keyscan is run
+    """
+    with safe_while(sleep=6, tries=100,
+                    action="ssh_keyscan_wait " + hostname) as proceed:
+        success = False
+        while proceed():
+            keys_dict = ssh_keyscan([hostname])
+            if len(keys_dict) == 1:
+                success = True
+                break
+            log.info("try ssh_keyscan again for " + str(hostname))
+        return success
+
 def stop_daemons_of_type(ctx, type_):
     """
     :param type_: type of daemons to be stopped.