From 4e482dc339ec0322ad76d2da85b601a3da4d4025 Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Wed, 17 Jul 2013 09:47:28 +0200 Subject: [PATCH] [entropy.transceivers] do not mandate to test the connection on __init__() Besides making context support complex, it doesn't do any good because connectivity errors are generally transient anyway (apart from misconfigs). --- .../plugins/interfaces/ftp_plugin.py | 5 ----- .../plugins/interfaces/ssh_plugin.py | 20 ------------------- lib/entropy/transceivers/uri_handlers/skel.py | 3 --- 3 files changed, 28 deletions(-) diff --git a/lib/entropy/transceivers/uri_handlers/plugins/interfaces/ftp_plugin.py b/lib/entropy/transceivers/uri_handlers/plugins/interfaces/ftp_plugin.py index e56dce028..8fdfe8014 100644 --- a/lib/entropy/transceivers/uri_handlers/plugins/interfaces/ftp_plugin.py +++ b/lib/entropy/transceivers/uri_handlers/plugins/interfaces/ftp_plugin.py @@ -71,11 +71,6 @@ class EntropyFtpUriHandler(EntropyUriHandler): self._init_vars() - # as documentation suggests - # test out connection first - self._connect() - self._disconnect() - def __enter__(self): pass # self.__connect_if_not() diff --git a/lib/entropy/transceivers/uri_handlers/plugins/interfaces/ssh_plugin.py b/lib/entropy/transceivers/uri_handlers/plugins/interfaces/ssh_plugin.py index 558781e60..b74ff2e49 100644 --- a/lib/entropy/transceivers/uri_handlers/plugins/interfaces/ssh_plugin.py +++ b/lib/entropy/transceivers/uri_handlers/plugins/interfaces/ssh_plugin.py @@ -63,32 +63,12 @@ class EntropySshUriHandler(EntropyUriHandler): self.__user, self.__port, self.__dir = self.__extract_scp_data( self._uri) - # as documentation suggests - # test out connection first - self.__test_connection() - def __enter__(self): pass def __exit__(self, exc_type, exc_value, traceback): self.close() - def __test_connection(self): - tries = 5 - while tries: - tries -= 1 - try: - sock = self._socket.create_connection( - (self.__host, self.__port), 5) - sock.close() - return - except self._socket.error: - time.sleep(5) - continue - - raise TransceiverConnectionError("cannot connect to %s on port %s" % ( - self.__host, self.__port,)) - def __extract_scp_data(self, uri): no_ssh_split = uri.split("ssh://")[-1] diff --git a/lib/entropy/transceivers/uri_handlers/skel.py b/lib/entropy/transceivers/uri_handlers/skel.py index 3b909bd05..c3a1dfee1 100644 --- a/lib/entropy/transceivers/uri_handlers/skel.py +++ b/lib/entropy/transceivers/uri_handlers/skel.py @@ -30,9 +30,6 @@ class EntropyUriHandler(TextInterface): def __init__(self, uri): """ EntropyUriHandler constructor. - When constructor is called, instance should perform a connection and - permissions check and raise TransceiverConnectionError in case - of issues. @param uri: URI to handle @type uri: string