From 89256fd408571f1f913471fd013f4d170ebaf38c Mon Sep 17 00:00:00 2001 From: Sergei Trofimov Date: Tue, 17 May 2016 14:00:01 +0100 Subject: [PATCH] connetion: fixing None timeout issue Connection objects set timeout to a default value in case a timeout is not specified. However, Target defaults timeout to None and passes that to connection, overridng the default. This commit ensures that default timeout remains set if calling code specified timemout as None. Fix for issue https://github.com/ARM-software/devlib/issues/34 --- devlib/utils/android.py | 5 +++-- devlib/utils/ssh.py | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/devlib/utils/android.py b/devlib/utils/android.py index 66f6f4a..0444b67 100644 --- a/devlib/utils/android.py +++ b/devlib/utils/android.py @@ -152,6 +152,7 @@ class AdbConnection(object): # maintains the count of parallel active connections to a device, so that # adb disconnect is not invoked untill all connections are closed active_connections = defaultdict(int) + default_timeout = 10 @property def name(self): @@ -168,8 +169,8 @@ class AdbConnection(object): else: raise DevlibError("Unknown line ending") - def __init__(self, device=None, timeout=10): - self.timeout = timeout + def __init__(self, device=None, timeout=None): + self.timeout = timeout if timeout is not None else self.default_timeout if device is None: device = adb_get_device(timeout=timeout) self.device = device diff --git a/devlib/utils/ssh.py b/devlib/utils/ssh.py index 8bf17c0..35e4678 100644 --- a/devlib/utils/ssh.py +++ b/devlib/utils/ssh.py @@ -127,6 +127,7 @@ class SshConnection(object): default_password_prompt = '[sudo] password' max_cancel_attempts = 5 + default_timeout=10 @property def name(self): @@ -138,7 +139,7 @@ class SshConnection(object): password=None, keyfile=None, port=None, - timeout=10, + timeout=None, telnet=False, password_prompt=None, ): @@ -150,6 +151,7 @@ class SshConnection(object): self.lock = threading.Lock() self.password_prompt = password_prompt if password_prompt is not None else self.default_password_prompt logger.debug('Logging in {}@{}'.format(username, host)) + timeout = timeout if timeout is not None else self.default_timeout self.conn = ssh_get_shell(host, username, password, self.keyfile, port, timeout, telnet) def push(self, source, dest, timeout=30):