From cb05374c6df96223a8bc0a414bd7d907fa5f4bd1 Mon Sep 17 00:00:00 2001 From: Rob Walton Date: Fri, 8 Mar 2019 12:13:23 +0000 Subject: [PATCH] Work around https://github.com/paramiko/paramiko/issues/673 (#27) * Attempt workaround for https://github.com/paramiko/paramiko/issues/673 Add a delay and attempt to connect again when an SSHException occurs --- mbl/cli/utils/ssh.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/mbl/cli/utils/ssh.py b/mbl/cli/utils/ssh.py index e811505..e72119e 100644 --- a/mbl/cli/utils/ssh.py +++ b/mbl/cli/utils/ssh.py @@ -9,6 +9,7 @@ import functools import logging import platform +import time import paramiko import scp @@ -83,11 +84,19 @@ def __init__(self, device): def __enter__(self): """Enter the context, connect to the ssh session.""" - self._client.connect( - self.device.address, - username=self.device.username, - password=self.device.password, - ) + try: + self._client.connect( + self.device.address, + username=self.device.username, + password=self.device.password, + ) + except paramiko.SSHException: + time.sleep(0.2) + self._client.connect( + self.device.address, + username=self.device.username, + password=self.device.password, + ) return self def __exit__(self, *exception_info):