Skip to content

Commit 7b7f6c4

Browse files
author
Dan
committed
Added sftp exception tests
1 parent 01a7409 commit 7b7f6c4

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

tests/test_pssh_client.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import random
3030
import logging
3131
import gevent
32-
import threading
3332
import paramiko
3433
import os
3534
import warnings
@@ -308,7 +307,7 @@ def test_pssh_client_long_running_command_exit_codes(self):
308307
msg="Got non-zero exit code %s" % (
309308
output[self.host]['exit_code'],))
310309
del client
311-
310+
312311
def test_pssh_client_retries(self):
313312
"""Test connection error retries"""
314313
listen_socket = make_socket(self.host)
@@ -327,7 +326,19 @@ def test_pssh_client_retries(self):
327326
% (num_tries, expected_num_tries,))
328327
else:
329328
raise Exception('No ConnectionErrorException')
330-
329+
330+
def test_sftp_exceptions(self):
331+
self.server.kill()
332+
# Make socket with no server listening on it on separate ip
333+
host = '127.0.0.3'
334+
_socket = make_socket(host)
335+
port = _socket.getsockname()[1]
336+
client = ParallelSSHClient([self.host], port=port, num_retries=1)
337+
cmds = client.copy_file("test", "test")
338+
client.pool.join()
339+
for cmd in cmds:
340+
self.assertRaises(ConnectionErrorException, cmd.get)
341+
331342
def test_pssh_copy_file(self):
332343
"""Test parallel copy file"""
333344
test_file_data = 'test'
@@ -348,7 +359,7 @@ def test_pssh_copy_file(self):
348359
for filepath in [local_filename, remote_filename]:
349360
os.unlink(filepath)
350361
del client
351-
362+
352363
def test_pssh_client_directory(self):
353364
"""Tests copying directories with SSH client. Copy all the files from
354365
local directory to server, then make sure they are all present."""
@@ -378,7 +389,7 @@ def test_pssh_client_directory(self):
378389
self.assertTrue(os.path.isfile(path))
379390
shutil.rmtree(local_test_path)
380391
shutil.rmtree(remote_test_path)
381-
392+
382393
def test_pssh_pool_size(self):
383394
"""Test setting pool size to non default values"""
384395
hosts = ['host-%01d' % d for d in xrange(5)]

tests/test_ssh_client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ def test_ssh_client_mkdir_single(self):
110110
shutil.rmtree(remote_dir)
111111
del client
112112

113+
def test_sftp_exceptions(self):
114+
self.server.kill()
115+
# Make socket with no server listening on it on separate ip
116+
host = '127.0.0.3'
117+
_socket = make_socket(host)
118+
port = _socket.getsockname()[1]
119+
self.assertRaises(ConnectionErrorException, SSHClient,
120+
host, port=port, num_retries=1)
121+
del _socket
122+
113123
def test_ssh_client_sftp(self):
114124
"""Test SFTP features of SSHClient. Copy local filename to server,
115125
check that data in both files is the same, make new directory on

0 commit comments

Comments
 (0)