From: Zack Cerza Date: Thu, 19 Mar 2015 20:32:58 +0000 (-0600) Subject: Use safe_while instead of an unsafe loop X-Git-Tag: 1.1.0~985^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=12de29e4d13ccf0518d106f94b00be615b1df30b;p=teuthology.git 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 --- diff --git a/teuthology/lock.py b/teuthology/lock.py index 8c2ae86e9..82a176e06 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