add tests for paramiko socket closing
@@ -802,3 +802,35 @@ class ParamikoSSHClientTestCase(unittest2.TestCase):
call_kwargs = mock_client.connect.call_args[1]
self.assertEqual(call_kwargs['port'], 9999)
+
+ @patch('paramiko.SSHClient', Mock)
+ @patch.object(ParamikoSSHClient, '_is_key_file_needs_passphrase',
+ MagicMock(return_value=False))
+
+ def test_socket_closed(self):
+ conn_params = {'hostname': 'dummy.host.org',
+ 'username': 'ubuntu',
+ 'password': 'pass',
+ 'timeout': '600'}
+ ssh_client = ParamikoSSHClient(**conn_params)
+ ssh_client.connect()
+
+ # Make sure .close() doesn't actually call anything real
+ ssh_client.client = Mock()
+ ssh_client.sftp_client = None
+ ssh_client.bastion_client = None
+
+ ssh_client.socket = Mock()
+
+ # Make sure we havent called any close methods at this point
+ self.assertEqual(ssh_client.socket.process.kill.call_count, 0)
+ self.assertEqual(ssh_client.socket.process.poll.call_count, 0)
+
+ # Call the function that has changed
+ ssh_client.close()
+
+ # Make sure we have called kill and poll
+ self.assertEqual(ssh_client.socket.process.kill.call_count, 1)
+ self.assertEqual(ssh_client.socket.process.poll.call_count, 1)
+
+
