From 12de29e4d13ccf0518d106f94b00be615b1df30b Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Thu, 19 Mar 2015 14:32:58 -0600 Subject: [PATCH] Use safe_while instead of an unsafe loop If ssh-keyscan fails, we would hang forever. Stop that nonsense, and give up eventually, print a warning, and move on. Signed-off-by: Zack Cerza --- teuthology/lock.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/teuthology/lock.py b/teuthology/lock.py index 8c2ae86e90..82a176e064 100644 --- a/teuthology/lock.py +++ b/teuthology/lock.py @@ -6,7 +6,6 @@ import yaml import re import collections import os -import time import requests import urllib from distutils.spawn import find_executable @@ -15,6 +14,7 @@ import teuthology from . import misc from . import provision from .config import config +from .contextutil import safe_while from .lockstatus import get_status log = logging.getLogger(__name__) @@ -544,10 +544,12 @@ def update_lock(name, description=None, status=None, ssh_pub_key=None): if not status: status_info = get_status(name) if status_info['is_vm']: - ssh_key = None - while not ssh_key: - time.sleep(10) - ssh_key = ssh_keyscan([name]) + with safe_while(sleep=10, tries=3, _raise=False, + action='ssh-keyscan') as proceed: + while proceed(): + ssh_key = ssh_keyscan([name]) + if ssh_key: + break updated = {} if description is not None: updated['description'] = description -- 2.39.5