mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-03-21 18:18:41 +00: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:
parent
b41d316fd6
commit
fea32de3d3
@ -744,6 +744,8 @@ class LinuxDevice(BaseLinuxDevice):
|
||||
Parameter('password', description='Password for the account on the device (for password-based auth).'),
|
||||
Parameter('keyfile', description='Keyfile to be used for key-based authentication.'),
|
||||
Parameter('port', kind=int, description='SSH port number on the device.'),
|
||||
Parameter('password_prompt', default='[sudo] password',
|
||||
description='Prompt presented by sudo when requesting the password.'),
|
||||
|
||||
Parameter('use_telnet', kind=boolean, default=False,
|
||||
description='Optionally, telnet may be used instead of ssh, though this is discouraged.'),
|
||||
@ -793,7 +795,7 @@ class LinuxDevice(BaseLinuxDevice):
|
||||
self._is_rooted = None
|
||||
|
||||
def validate(self):
|
||||
if not self.password and not self.keyfile:
|
||||
if self.password is None and not self.keyfile:
|
||||
raise ConfigError('Either a password or a keyfile must be provided.')
|
||||
if self.working_directory is None: # pylint: disable=access-member-before-definition
|
||||
if self.username == 'root':
|
||||
@ -823,7 +825,7 @@ class LinuxDevice(BaseLinuxDevice):
|
||||
self.reset()
|
||||
|
||||
def connect(self): # NOQA pylint: disable=R0912
|
||||
self.shell = SshShell(timeout=self.default_timeout)
|
||||
self.shell = SshShell(password_prompt=self.password_prompt, timeout=self.default_timeout)
|
||||
self.shell.login(self.host, self.username, self.password, self.keyfile, self.port, telnet=self.use_telnet)
|
||||
self._is_ready = True
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user