def test_ssh(self, mock_exec, mock_conn, mock_set):
mock_log = mock.Mock()
mock_channel = mock.Mock()
mock_exec.return_value = (fake_channel_file(['input']),
fake_channel_file(['out_line1',
'out_line2'],
mock_channel),
fake_channel_file(['err_line1',
'err_line2']))
mock_channel.recv_exit_status.return_value = 0
client = sshclient.SSHClient('ip', 'username', password='password',
log=mock_log)
out, err = client.ssh('fake_command', output=True)
mock_log.debug.assert_called()
mock_exec.assert_called()
mock_log.info.assert_called_with('out_line1\nout_line2')
mock_log.error.assert_called_with('err_line1\nerr_line2')
mock_channel.recv_exit_status.assert_called_with()
self.assertEqual(out, 'out_line1\nout_line2')
self.assertEqual(err, 'err_line1\nerr_line2')
评论列表
文章目录