mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-01-19 12:24:32 +00:00
ssh: Back-port ssh_get_shell from devlib
This back-ports ssh_get_shell implementation from devlib. It includes the following changes: - original_prompt for Telnet verison of the connection can now be passed as an argument. - Multiple attempts to connect with a timeout. - Some additional implementation to the tty, including setting the size.
This commit is contained in:
parent
42a4831092
commit
51db53d979
@ -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()
|
||||||
if telnet:
|
start_time = time.time()
|
||||||
if keyfile:
|
while True:
|
||||||
raise ConfigError('keyfile may not be used with a telnet connection.')
|
if telnet:
|
||||||
conn = TelnetConnection()
|
if keyfile:
|
||||||
else: # ssh
|
raise ValueError('keyfile may not be used with a telnet connection.')
|
||||||
conn = pxssh.pxssh() # pylint: disable=redefined-variable-type
|
conn = TelnetPxssh(original_prompt=original_prompt)
|
||||||
try:
|
else: # ssh
|
||||||
if keyfile:
|
conn = pxssh.pxssh()
|
||||||
conn.login(host, username, ssh_key=keyfile, port=port, login_timeout=timeout)
|
|
||||||
else:
|
try:
|
||||||
conn.login(host, username, password, port=port, login_timeout=timeout)
|
if keyfile:
|
||||||
except EOF:
|
conn.login(host, username, ssh_key=keyfile, port=port, login_timeout=timeout)
|
||||||
raise DeviceError('Could not connect to {}; is the host name correct?'.format(host))
|
else:
|
||||||
|
conn.login(host, username, password, port=port, login_timeout=timeout)
|
||||||
|
break
|
||||||
|
except EOF:
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user