1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-07-25 16:29:50 +01:00

Merge pull request from setrofim/master

ssh: Back-port ssh_get_shell from devlib
This commit is contained in:
setrofim
2017-06-14 13:13:23 +01:00
committed by GitHub

@@ -22,6 +22,7 @@ import re
import threading import threading
import tempfile import tempfile
import shutil import shutil
import time
from pexpect import EOF, TIMEOUT, spawn, pxssh from pexpect import EOF, TIMEOUT, spawn, pxssh
@@ -36,21 +37,34 @@ sshpass = None
logger = logging.getLogger('ssh') logger = logging.getLogger('ssh')
def ssh_get_shell(host, username, password=None, keyfile=None, port=None, timeout=10, telnet=False): def ssh_get_shell(host, username, password=None, keyfile=None, port=None, timeout=10, telnet=False, original_prompt=None):
_check_env() _check_env()
start_time = time.time()
while True:
if telnet: if telnet:
if keyfile: if keyfile:
raise ConfigError('keyfile may not be used with a telnet connection.') raise ValueError('keyfile may not be used with a telnet connection.')
conn = TelnetConnection() conn = TelnetPxssh(original_prompt=original_prompt)
else: # ssh else: # ssh
conn = pxssh.pxssh() # pylint: disable=redefined-variable-type conn = pxssh.pxssh()
try: try:
if keyfile: if keyfile:
conn.login(host, username, ssh_key=keyfile, port=port, login_timeout=timeout) conn.login(host, username, ssh_key=keyfile, port=port, login_timeout=timeout)
else: else:
conn.login(host, username, password, port=port, login_timeout=timeout) conn.login(host, username, password, port=port, login_timeout=timeout)
break
except EOF: except EOF:
raise DeviceError('Could not connect to {}; is the host name correct?'.format(host)) timeout -= time.time() - start_time
if timeout <= 0:
message = 'Could not connect to {}; is the host name correct?'
raise TargetError(message.format(host))
time.sleep(5)
conn.setwinsize(500,200)
conn.sendline('')
conn.prompt()
conn.setecho(False)
return conn return conn