From b5859f877a6617177a92202a36c1fed2249c9dcc Mon Sep 17 00:00:00 2001 From: Greg Farnum Date: Wed, 10 Aug 2011 10:37:04 -0700 Subject: [PATCH] Move reconnect function from kernel task to misc.py Signed-off-by: Greg Farnum --- teuthology/misc.py | 47 +++++++++++++++++++++++++++++++++++++ teuthology/task/kernel.py | 49 +-------------------------------------- 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/teuthology/misc.py b/teuthology/misc.py index 031f89abcf..12b3cc0f09 100644 --- a/teuthology/misc.py +++ b/teuthology/misc.py @@ -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=[ diff --git a/teuthology/task/kernel.py b/teuthology/task/kernel.py index bf6d36aeed..e9a5c090af 100644 --- a/teuthology/task/kernel.py +++ b/teuthology/task/kernel.py @@ -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)) -- 2.39.5