本文整理汇总了Python中ncclient.transport.ssh.SSHSession类的典型用法代码示例。如果您正苦于以下问题:Python SSHSession类的具体用法?Python SSHSession怎么用?Python SSHSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SSHSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_auth_exception
def test_auth_exception(self, mock_auth_password):
mock_auth_password.side_effect = Exception
device_handler = JunosDeviceHandler({'name': 'junos'})
obj = SSHSession(device_handler)
obj._transport = paramiko.Transport(MagicMock())
self.assertRaises(AuthenticationError,
obj._auth, 'user', 'password', [], False, True)
示例2: test_auth_keyfiles_exception
def test_auth_keyfiles_exception(self, mock_get_key, mock_auth_public_key):
key = paramiko.PKey()
mock_get_key.side_effect = paramiko.ssh_exception.PasswordRequiredException
device_handler = JunosDeviceHandler({'name': 'junos'})
obj = SSHSession(device_handler)
obj._transport = paramiko.Transport(MagicMock())
self.assertRaises(AuthenticationError,
obj._auth,'user', None, ["key_file_name"], False, True)
示例3: test_close
def test_close(self, mock_close):
device_handler = JunosDeviceHandler({'name': 'junos'})
obj = SSHSession(device_handler)
obj._transport = paramiko.Transport(MagicMock())
obj._transport.active = True
obj._connected = True
obj.close()
mock_close.assert_called_once_with()
self.assertFalse(obj._connected)
示例4: test_auth_password
def test_auth_password(self, mock_auth_password):
device_handler = JunosDeviceHandler({'name': 'junos'})
obj = SSHSession(device_handler)
obj._transport = paramiko.Transport(MagicMock())
obj._auth('user', 'password', [], False, True)
self.assertEqual(
mock_auth_password.call_args_list[0][0],
('user',
'password'))
示例5: test_auth_agent_exception
def test_auth_agent_exception(self, mock_get_key, mock_auth_public_key):
key = paramiko.PKey()
mock_get_key.return_value = [key]
mock_auth_public_key.side_effect = paramiko.ssh_exception.AuthenticationException
device_handler = JunosDeviceHandler({'name': 'junos'})
obj = SSHSession(device_handler)
obj._transport = paramiko.Transport(MagicMock())
self.assertRaises(AuthenticationError,
obj._auth,'user', None, [], True, False)
示例6: test_auth_keyfiles
def test_auth_keyfiles(self, mock_get_key, mock_auth_public_key):
key = paramiko.PKey()
mock_get_key.return_value = key
device_handler = JunosDeviceHandler({'name': 'junos'})
obj = SSHSession(device_handler)
obj._transport = paramiko.Transport(MagicMock())
obj._auth('user', 'password', ["key_file_name"], False, True)
self.assertEqual(
(mock_auth_public_key.call_args_list[0][0][1]).__repr__(),
key.__repr__())
示例7: test_auth_agent
def test_auth_agent(self, mock_get_key, mock_auth_public_key):
key = paramiko.PKey(msg="hello")
mock_get_key.return_value = [key]
device_handler = JunosDeviceHandler({'name': 'junos'})
obj = SSHSession(device_handler)
obj._transport = paramiko.Transport(MagicMock())
obj._auth('user', 'password', [], True, True)
self.assertEqual(
(mock_auth_public_key.call_args_list[0][0][1]).__repr__(),
key.__repr__())
示例8: test_auth_default_keyfiles_exception
def test_auth_default_keyfiles_exception(self, mock_get_key,
mock_auth_public_key, mock_is_file):
key = paramiko.PKey()
mock_is_file.return_value = True
mock_get_key.side_effect = paramiko.ssh_exception.PasswordRequiredException
device_handler = JunosDeviceHandler({'name': 'junos'})
obj = SSHSession(device_handler)
obj._transport = paramiko.Transport(None)
self.assertRaises(AuthenticationError,
obj._auth,'user', None, [], False, True)
示例9: test_run_receive_py2
def test_run_receive_py2(self, mock_error, mock_selector, mock_recv, mock_close):
mock_selector.select.return_value = True
mock_recv.return_value = 0
device_handler = JunosDeviceHandler({'name': 'junos'})
obj = SSHSession(device_handler)
obj._channel = paramiko.Channel("c100")
obj.run()
self.assertTrue(
isinstance(
mock_error.call_args_list[0][0][0],
SessionCloseError))
示例10: __init__
def __init__(self, device_handler):
SSHSession.__init__(self, device_handler)
self._host_keys = None
self._transport = None
self._connected = False
self._channel = None
self._channel_id = None
self._channel_name = None
self._buffer = StringIO() # for incoming data
# parsing-related, see _parse()
self._parsing_state = 0
self._parsing_pos = 0
self._device_handler = device_handler
示例11: test_run_send
def test_run_send(self, mock_error, mock_send, mock_ready, mock_close):
mock_ready.return_value = True
mock_send.return_value = -1
device_handler = JunosDeviceHandler({'name': 'junos'})
obj = SSHSession(device_handler)
obj._channel = paramiko.Channel("c100")
obj._q.put("rpc")
obj.run()
self.assertEqual(mock_send.call_args_list[0][0][0], "rpc")
self.assertTrue(
isinstance(
mock_error.call_args_list[0][0][0],
SessionCloseError))
示例12: test_parse_incomplete_delimiter
def test_parse_incomplete_delimiter(self, mock_dispatch):
device_handler = JunosDeviceHandler({'name': 'junos'})
obj = SSHSession(device_handler)
if sys.version >= "3.0":
b = bytes(rpc_reply_part_1, "utf-8")
obj._buffer.write(b)
obj._parse()
self.assertFalse(mock_dispatch.called)
b = bytes(rpc_reply_part_2, "utf-8")
obj._buffer.write(b)
obj._parse()
self.assertTrue(mock_dispatch.called)
else:
obj._buffer.write(rpc_reply_part_1)
obj._parse()
self.assertFalse(mock_dispatch.called)
obj._buffer.write(rpc_reply_part_2)
obj._parse()
self.assertTrue(mock_dispatch.called)
示例13: test_load_host_key_2
def test_load_host_key_2(self, mock_load, mock_os):
mock_os.return_value = "file_name"
device_handler = JunosDeviceHandler({'name': 'junos'})
obj = SSHSession(device_handler)
obj.load_known_hosts()
mock_load.assert_called_once_with("file_name")
示例14: test_load_host_key
def test_load_host_key(self, mock_load):
device_handler = JunosDeviceHandler({'name': 'junos'})
obj = SSHSession(device_handler)
obj.load_known_hosts("file_name")
mock_load.assert_called_once_with("file_name")
示例15: test_auth_no_methods_exception
def test_auth_no_methods_exception(self):
device_handler = JunosDeviceHandler({'name': 'junos'})
obj = SSHSession(device_handler)
obj._transport = paramiko.Transport(MagicMock())
self.assertRaises(AuthenticationError,
obj._auth,'user', None, [], False, False)