fixes "su -" escalation
root_password was not being passed through from the RemoteClient to the SSH client instantiation. Change-Id: I4cd61821dd9fbe099bcdc2097807446d4072f9c4 Closes-Bug:#1362666
This commit is contained in:
parent
5674cbd833
commit
453ffedabd
|
@ -170,7 +170,7 @@ class RemoteShell(ShellMixin):
|
|||
def __init__(self, address, password=None, username=None,
|
||||
private_key=None, key_filename=None, port=None,
|
||||
timeout=None, gateway=None, options=None, interactive=False,
|
||||
protocol='ssh', **kwargs):
|
||||
protocol='ssh', root_password=None, **kwargs):
|
||||
"""An interface for executing shell commands on remote machines.
|
||||
|
||||
:param str host: The ip address or host name of the server
|
||||
|
@ -180,6 +180,10 @@ class RemoteShell(ShellMixin):
|
|||
:param username: The username to authenticate as
|
||||
:param private_key: Private SSH Key string to use
|
||||
(instead of using a filename)
|
||||
:param root_password: root user password to be used if username is
|
||||
not root. This will use username and password
|
||||
to login and then 'su' to root using
|
||||
root_password
|
||||
:param key_filename: a private key filename (path)
|
||||
:param port: tcp/ip port to use (defaults to 22)
|
||||
:param float timeout: an optional timeout (in seconds) for the
|
||||
|
@ -213,7 +217,8 @@ class RemoteShell(ShellMixin):
|
|||
port=port, timeout=timeout,
|
||||
gateway=gateway,
|
||||
options=options,
|
||||
interactive=interactive)
|
||||
interactive=interactive,
|
||||
root_password=root_password)
|
||||
self.host = self._client.host
|
||||
self.port = self._client.port
|
||||
|
||||
|
|
|
@ -138,6 +138,37 @@ class TestRemoteShell(TestBashModule):
|
|||
self.assertEqual(self.resultdict, resultdict)
|
||||
|
||||
|
||||
class TestRemoteShellInit(unittest.TestCase):
|
||||
|
||||
def initpatch(self, ssh_instance, *args, **kwargs):
|
||||
ssh_instance.host = self.host
|
||||
ssh_instance.port = self.port
|
||||
self._instance = ssh_instance
|
||||
|
||||
def setUp(self):
|
||||
self.host = "192.168.2.10"
|
||||
self.port = 23
|
||||
|
||||
@mock.patch.object(bash.ssh.SSH, '__init__', return_value=None,
|
||||
autospec=True)
|
||||
def test_init_contains_kwargs(self, mock_init):
|
||||
mock_init.side_effect = self.initpatch
|
||||
allkwargs = {
|
||||
'password': 'pass',
|
||||
'username': 'user',
|
||||
'private_key': 'pkey',
|
||||
'key_filename': 'pkeyfile',
|
||||
'port': self.port,
|
||||
'timeout': 100,
|
||||
'gateway': 'g',
|
||||
'options': {'StrictHostKeyChecking': False},
|
||||
'interactive': True,
|
||||
'root_password': 'sudopass',
|
||||
}
|
||||
self.remoteshell = bash.RemoteShell(self.host, **allkwargs)
|
||||
mock_init.assert_called_once_with(self._instance, self.host, **allkwargs)
|
||||
|
||||
|
||||
class TestContextManager(utils.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
|
Loading…
Reference in New Issue