def test_ssh_to_explodes(self): # Setup ssh_mock = Mock() self.mocks["paramiko"].SSHClient.return_value = ssh_mock self.mocks["paramiko"].RSAKey.from_private_key.return_value = "pkey" ssh_mock.connect.side_effect = Exception("") # Run with self.assertRaises(Exception): ssh_to("user", "ip", u"key")
def test_ssh_to_dont_retry_on_other_socket_errnos(self): # Setup ssh_mock = Mock() self.mocks["paramiko"].SSHClient.return_value = ssh_mock self.mocks["paramiko"].RSAKey.from_private_key.return_value = "pkey" ssh_mock.connect.side_effect = EnvironmentError(errno.ENOTSOCK, "") # Run with self.assertRaises(EnvironmentError): ssh_to("user", "ip", u"key")
def test_ssh_to(self): # Setup ssh_mock = Mock() self.mocks["paramiko"].SSHClient.return_value = ssh_mock self.mocks["paramiko"].RSAKey.from_private_key.return_value = "pkey" # Run ssh = ssh_to("user", "ip", u"key") # Assert self.assertEqual(ssh, ssh_mock) ssh_mock.connect.assert_called_with("ip", username="******", pkey="pkey")
def test_ssh_to_retries_on_certain_socket_errnos(self, errno): # Setup ssh_mock = Mock() self.mocks["paramiko"].SSHClient.return_value = ssh_mock self.mocks["paramiko"].RSAKey.from_private_key.return_value = "pkey" ssh_mock.connect.side_effect = [ EnvironmentError(errno, ""), True, ] # Run ssh = ssh_to("user", "ip", u"key") # Assert self.assertEqual(ssh, ssh_mock) self.assertEqual(2, len(ssh_mock.connect.mock_calls))
def test_ssh_to_retries(self): # Setup ssh_mock = Mock() self.mocks["paramiko"].SSHClient.return_value = ssh_mock self.mocks["paramiko"].RSAKey.from_private_key.return_value = "pkey" ssh_mock.connect.side_effect = [ SocketTimeout, EOFError(""), True, ] # Run ssh = ssh_to("user", "ip", u"key") # Assert self.assertEqual(ssh, ssh_mock) self.assertEqual(3, len(ssh_mock.connect.mock_calls))