From 2b753be88c8f03d05b4f6ab3ae04ce657cda5b1a Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Sun, 19 Jul 2015 09:02:02 +0200 Subject: [PATCH] ssh_keyscan_wait: blocking version of ssh_keysscan 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 --- teuthology/misc.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/teuthology/misc.py b/teuthology/misc.py index 2ced9f4d74..5ae39425c2 100644 --- a/teuthology/misc.py +++ b/teuthology/misc.py @@ -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. -- 2.39.5