[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).
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user