]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Move reconnect function from kernel task to misc.py
authorGreg Farnum <gregory.farnum@dreamhost.com>
Wed, 10 Aug 2011 17:37:04 +0000 (10:37 -0700)
committerGreg Farnum <gregory.farnum@dreamhost.com>
Wed, 10 Aug 2011 21:37:24 +0000 (14:37 -0700)
Signed-off-by: Greg Farnum <gregory.farnum@dreamhost.com>
teuthology/misc.py
teuthology/task/kernel.py

index 031f89abcfa3a6e28328ca6fb2cb408bfc70a68b..12b3cc0f0965baca6e3073056b207b22a3429611 100644 (file)
@@ -279,6 +279,53 @@ def wait_until_fuse_mounted(remote, fuse, mountpoint):
         time.sleep(5)
     log.info('cfuse is mounted on %s', mountpoint)
 
+def reconnect(ctx, timeout):
+    """
+    Connect to all the machines in ctx.cluster.
+
+    Presumably, some of them won't be up. Handle this
+    by waiting for them, unless the wait time exceeds
+    the specified timeout.
+
+    ctx needs to contain the cluster of machines you
+    wish it to try and connect to, as well as a config
+    holding the ssh keys for each of them. As long as it
+    contains this data, you can construct a context
+    that is a subset of your full cluster.
+    """
+    import errno
+    log.info('Re-opening connections...')
+    starttime = time.time()
+    need_reconnect = ctx.cluster.remotes.keys()
+    while True:
+        for remote in list(need_reconnect):
+            try:
+                from orchestra import connection
+                remote.ssh = connection.connect(
+                    user_at_host=remote.name,
+                    host_key=ctx.config['targets'][remote.name],
+                    )
+            except socket.error as e:
+                if hasattr(e, '__getitem__'):
+                    if e[0] not in [errno.ECONNREFUSED, errno.ETIMEDOUT,
+                                errno.EHOSTUNREACH, errno.EHOSTDOWN]:
+                        log.exception('unknown socket error: %s', repr(e))
+                        raise
+                    else:
+                        if time.time() - starttime > timeout:
+                            log.exception('timed out waiting for %s', remote.name)
+                            raise
+                else:
+                    log.exception('weird socket error without error code')
+                    raise
+            else:
+                need_reconnect.remove(remote)
+
+        if not need_reconnect:
+            break
+        log.debug('waited {elapsed}'.format(elapsed=str(time.time() - starttime)))
+        time.sleep(1)
+
 def write_secret_file(remote, role, filename):
     remote.run(
         args=[
index bf6d36aeed2a98d91fa6aed03b6cf20247024b46..e9a5c090af25b711e2949a79ae7209f967dfe7e5 100644 (file)
@@ -1,7 +1,6 @@
 from cStringIO import StringIO
 
 import logging
-import errno
 import socket
 import time
 
@@ -136,52 +135,6 @@ def install_and_reboot(ctx, config):
         proc.exitstatus.get()
 
 
-def reconnect(ctx, timeout):
-    """
-    Connect to all the machines in ctx.cluster.
-
-    Presumably, some of them won't be up. Handle this
-    by waiting for them, unless the wait time exceeds
-    the specified timeout.
-
-    ctx needs to contain the cluster of machines you
-    wish it to try and connect to, as well as a config
-    holding the ssh keys for each of them. As long as it
-    contains this data, you can construct a context
-    that is a subset of your full cluster.
-    """
-    log.info('Re-opening connections...')
-    starttime = time.time()
-    need_reconnect = ctx.cluster.remotes.keys()
-    while True:
-        for remote in list(need_reconnect):
-            try:
-                remote.ssh = connection.connect(
-                    user_at_host=remote.name,
-                    host_key=ctx.config['targets'][remote.name],
-                    )
-            except socket.error as e:
-                if hasattr(e, '__getitem__'):
-                    if e[0] not in [errno.ECONNREFUSED, errno.ETIMEDOUT,
-                                errno.EHOSTUNREACH, errno.EHOSTDOWN]:
-                        log.exception('unknown socket error: %s', repr(e))
-                        raise
-                    else if time.time() - starttime > timeout:
-                        log.exception('timed out waiting for %s', remote.name)
-                        raise
-
-                else:
-                    log.exception('weird socket error without error code')
-                    raise
-            else:
-                need_reconnect.remove(remote)
-
-        if not need_reconnect:
-            break
-        log.debug('waited {elapsed}'.format(elapsed=str(time.time() - starttime)))
-        time.sleep(1)
-
-
 def task(ctx, config):
     """
     Make sure the specified kernel is installed.
@@ -250,7 +203,7 @@ def task(ctx, config):
 
     if len(need_install) > 0:
         install_and_reboot(ctx, need_install)
-        reconnect(ctx, timeout)
+        teuthology.reconnect(ctx, timeout)
 
     for client, sha1 in need_install.iteritems():
         log.info('Checking client {client} for new kernel version...'.format(client=client))