diff options
author | treyad <treyad@viosoft.com> | 2018-11-15 08:31:32 -0800 |
---|---|---|
committer | treyad <treyad@viosoft.com> | 2019-01-14 21:01:36 -0800 |
commit | efd44dbadef7c92253545e9ce2e8034fef259b95 (patch) | |
tree | cdaf8997e0181db35f6367f3932c089cca397738 /yardstick/tests/unit | |
parent | 07c506d3fff732019651d89de14bf42fa8d9a365 (diff) |
Improve SSH to Open/Close interactive terminal
Support Open/Close interactive terminal on a SSH channel.
Support Execute command on interactive terminal.
JIRA: YARDSTICK-1482
Change-Id: I0d1588707c3fb3e5e65fb72115f27e713d4b4828
Signed-off-by: treyad <treyad@viosoft.com>
Diffstat (limited to 'yardstick/tests/unit')
-rw-r--r-- | yardstick/tests/unit/test_ssh.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/yardstick/tests/unit/test_ssh.py b/yardstick/tests/unit/test_ssh.py index 71929f1a2..374fb6644 100644 --- a/yardstick/tests/unit/test_ssh.py +++ b/yardstick/tests/unit/test_ssh.py @@ -286,6 +286,48 @@ class SSHTestCase(unittest.TestCase): mock_paramiko_exec_command.assert_called_once_with('cmd', get_pty=True) + @mock.patch("yardstick.ssh.paramiko") + def test_interactive_terminal_open(self, mock_paramiko): + fake_client = mock.Mock() + fake_session = mock.Mock() + fake_session.recv.return_value = ":~# " + fake_transport = mock.Mock() + fake_transport.open_session.return_value = fake_session + fake_client.get_transport.return_value = fake_transport + mock_paramiko.SSHClient.return_value = fake_client + + test_ssh = ssh.SSH("admin", "example.net", pkey="key") + result = test_ssh.interactive_terminal_open() + self.assertEqual(fake_session, result) + + @mock.patch("yardstick.ssh.paramiko") + def test_interactive_terminal_exec_command(self, mock_paramiko): + fake_client = mock.Mock() + fake_session = mock.Mock() + fake_session.recv.return_value = "stdout fake data" + fake_transport = mock.Mock() + fake_transport.open_session.return_value = fake_session + fake_client.get_transport.return_value = fake_transport + mock_paramiko.SSHClient.return_value = fake_client + + test_ssh = ssh.SSH("admin", "example.net", pkey="key") + with mock.patch.object(fake_session, "sendall") \ + as mock_paramiko_send_command: + result = test_ssh.interactive_terminal_exec_command(fake_session, + 'cmd', "vat# ") + self.assertEqual("stdout fake data", result) + mock_paramiko_send_command.assert_called_once_with('cmd\n') + + @mock.patch("yardstick.ssh.paramiko") + def test_interactive_terminal_close(self, _): + fake_session = mock.Mock() + paramiko_sshclient = self.test_client._get_client() + paramiko_sshclient.get_transport.open_session.return_value = fake_session + with mock.patch.object(fake_session, "close") \ + as mock_paramiko_terminal_close: + self.test_client.interactive_terminal_close(fake_session) + mock_paramiko_terminal_close.assert_called_once_with() + class SSHRunTestCase(unittest.TestCase): """Test SSH.run method in different aspects. |