From 2f71f03fdd29f186c7f7d348d414069739fb28bc Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Fri, 30 Dec 2011 12:23:28 -0800 Subject: [PATCH] misc: simplify reconnect logic Ignore all errors until the timeout expires so we don't have to worry about whitelisting them. --- teuthology/misc.py | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/teuthology/misc.py b/teuthology/misc.py index 0e6b7676c17e2..720b115fc3204 100644 --- a/teuthology/misc.py +++ b/teuthology/misc.py @@ -4,7 +4,6 @@ import os import logging import configobj import getpass -import paramiko import socket import time import urllib2 @@ -319,12 +318,11 @@ def reconnect(ctx, timeout): 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): + while need_reconnect: + for remote in need_reconnect: try: log.info('trying to connect to %s', remote.name) from .orchestra import connection @@ -333,28 +331,12 @@ def reconnect(ctx, timeout): host_key=ctx.config['targets'][remote.name], keep_alive=True, ) - except socket.timeout: - pass - 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: - raise - else: - log.exception('weird socket error without error code') - raise - except paramiko.SSHException: + except Exception: if time.time() - starttime > timeout: raise else: need_reconnect.remove(remote) - if not need_reconnect: - break log.debug('waited {elapsed}'.format(elapsed=str(time.time() - starttime))) time.sleep(1) -- 2.39.5