aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python/ssh.py
diff options
context:
space:
mode:
authorVratko Polak <vrpolak@cisco.com>2018-04-26 15:15:51 +0200
committerPeter Mikus <pmikus@cisco.com>2018-05-04 09:35:22 +0000
commit5e7be479eacd4d1085cab152c35dcb6433a146ed (patch)
tree0d91e7ae63856c3d3d4588654abfd6ed8fa8a76a /resources/libraries/python/ssh.py
parentceb7c2545cda1bc7fe3d4bf35cdf75253efe8c6d (diff)
Fix various pylint 1.5.4 warnings
+ DUTSetup.py:424 Else clause on loop without a break statement + InterfaceUtil.py:400 Else clause on loop without a break statement + QemuUtils.py:564 Wrong continued indentation + SetupDPDKTest.py: Locally enabling broad-except + VatExecutor.py: Catching too general exception Exception + ssh.py:95 No exception type(s) specified. + HTTPRequest.py: Tolerate HTTPCodes.OK + multiple: Drop ":returns: None" from docstrings. There are still several warnings present: - R0902(too-many-instance-attributes) - R0912(too-many-branches) - R0913(too-many-arguments) - R0914(too-many-locals) - R0915(too-many-statements) - R0401(cyclic-import) And there are multiple blocks of similar lines, mainly across various Setup*Test.py files: - R0801(duplicate-code) Change-Id: I582575cb52b85d69d268e6374852f6e74bb71052 Signed-off-by: Vratko Polak <vrpolak@cisco.com>
Diffstat (limited to 'resources/libraries/python/ssh.py')
-rw-r--r--resources/libraries/python/ssh.py34
1 files changed, 21 insertions, 13 deletions
diff --git a/resources/libraries/python/ssh.py b/resources/libraries/python/ssh.py
index 8c064e2729..fe4404b053 100644
--- a/resources/libraries/python/ssh.py
+++ b/resources/libraries/python/ssh.py
@@ -92,11 +92,11 @@ class SSH(object):
format(self._ssh.get_transport().getpeername()))
logger.debug('Connections: {0}'.
format(str(SSH.__existing_connections)))
- except:
+ except RuntimeError as exc:
if attempts > 0:
self._reconnect(attempts-1)
else:
- raise
+ raise exc
def disconnect(self, node):
"""Close SSH connection to the node.
@@ -236,8 +236,8 @@ class SSH(object):
def interactive_terminal_open(self, time_out=30):
"""Open interactive terminal on a new channel on the connected Node.
- :param time_out: Timeout in seconds.
- :returns: SSH channel with opened terminal.
+ FIXME: Convert or document other possible exceptions, such as
+ socket.error or SSHException.
.. warning:: Interruptingcow is used here, and it uses
signal(SIGALRM) to let the operating system interrupt program
@@ -245,6 +245,10 @@ class SSH(object):
handlers only apply to the main thread, so you cannot use this
from other threads. You must not use this in a program that
uses SIGALRM itself (this includes certain profilers)
+
+ :param time_out: Timeout in seconds.
+ :returns: SSH channel with opened terminal.
+ :raise IOError: If receive attempt results in socket.timeout.
"""
chan = self._ssh.get_transport().open_session()
chan.get_pty()
@@ -264,7 +268,8 @@ class SSH(object):
break
except socket.timeout:
logger.error('Socket timeout: {0}'.format(buf))
- raise Exception('Socket timeout: {0}'.format(buf))
+ # TODO: Find out which exception would callers appreciate here.
+ raise IOError('Socket timeout: {0}'.format(buf))
return chan
def interactive_terminal_exec_command(self, chan, cmd, prompt):
@@ -272,18 +277,19 @@ class SSH(object):
interactive_terminal_open() method has to be called first!
- :param chan: SSH channel with opened terminal.
- :param cmd: Command to be executed.
- :param prompt: Command prompt, sequence of characters used to
- indicate readiness to accept commands.
- :returns: Command output.
-
.. warning:: Interruptingcow is used here, and it uses
signal(SIGALRM) to let the operating system interrupt program
execution. This has the following limitations: Python signal
handlers only apply to the main thread, so you cannot use this
from other threads. You must not use this in a program that
uses SIGALRM itself (this includes certain profilers)
+
+ :param chan: SSH channel with opened terminal.
+ :param cmd: Command to be executed.
+ :param prompt: Command prompt, sequence of characters used to
+ indicate readiness to accept commands.
+ :returns: Command output.
+ :raise IOError: If receive attempt results in socket.timeout.
"""
chan.sendall('{c}\n'.format(c=cmd))
buf = ''
@@ -299,8 +305,9 @@ class SSH(object):
except socket.timeout:
logger.error('Socket timeout during execution of command: '
'{0}\nBuffer content:\n{1}'.format(cmd, buf))
- raise Exception('Socket timeout during execution of command: '
- '{0}\nBuffer content:\n{1}'.format(cmd, buf))
+ # TODO: Find out which exception would callers appreciate here.
+ raise IOError('Socket timeout during execution of command: '
+ '{0}\nBuffer content:\n{1}'.format(cmd, buf))
tmp = buf.replace(cmd.replace('\n', ''), '')
for item in prompt:
tmp.replace(item, '')
@@ -353,6 +360,7 @@ class SSH(object):
def exec_cmd(node, cmd, timeout=600, sudo=False):
"""Convenience function to ssh/exec/return rc, out & err.
+ FIXME: Document :param, :type, :raise and similar.
Returns (rc, stdout, stderr).
"""
if node is None: