1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-09-01 10:52:33 +01:00

Parameterizing password prompt for sudo in Ssh interface.

On some devices, sudo presents a different prompt when asking for a
password. All the prompt to be specified in device configruation to
handle such cases.
This commit is contained in:
Sergei Trofimov
2015-04-10 09:03:48 +01:00
parent b41d316fd6
commit fea32de3d3
2 changed files with 9 additions and 4 deletions

View File

@@ -83,7 +83,10 @@ class TelnetConnection(pxssh.pxssh):
class SshShell(object):
def __init__(self, timeout=10):
default_password_prompt = '[sudo] password'
def __init__(self, password_prompt=None, timeout=10):
self.password_prompt = password_prompt if password_prompt is not None else self.default_password_prompt
self.timeout = timeout
self.conn = None
@@ -135,7 +138,7 @@ class SshShell(object):
if log:
logger.debug(command)
self.conn.sendline(command)
index = self.conn.expect_exact(['[sudo] password', TIMEOUT], timeout=0.5)
index = self.conn.expect_exact([self.password_prompt, TIMEOUT], timeout=0.5)
if index == 0:
self.conn.sendline(self.password)
timed_out = not self.conn.prompt(timeout)