]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
Use safe_while instead of an unsafe loop
authorZack Cerza <zack@redhat.com>
Thu, 19 Mar 2015 20:32:58 +0000 (14:32 -0600)
committerZack Cerza <zack@redhat.com>
Thu, 19 Mar 2015 20:32:58 +0000 (14:32 -0600)
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 <zack@redhat.com>
teuthology/lock.py

index 8c2ae86e90cdfe7834eb03329f30a91f7a35a718..82a176e064326bc78252ed41dfd4898383ada0d6 100644 (file)
@@ -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