@@ -133,6 +133,8 @@ def test_client_shells_read_timeout(self):
133
133
def test_client_shells_timeout (self ):
134
134
client = ParallelSSHClient ([self .host ], pkey = self .user_key , port = self .port ,
135
135
timeout = 0.01 , num_retries = 1 )
136
+ client ._make_ssh_client = MagicMock ()
137
+ client ._make_ssh_client .side_effect = Timeout
136
138
self .assertRaises (Timeout , client .open_shell )
137
139
138
140
def test_client_shells_join_timeout (self ):
@@ -1517,8 +1519,8 @@ def test_scp_send_dir_recurse(self):
1517
1519
except OSError :
1518
1520
pass
1519
1521
1520
- def test_scp_send_large_files_timeout (self ):
1521
- hosts = ['127.0.0.1%s' % (i ,) for i in range (1 , 10 )]
1522
+ def test_scp_send_larger_files (self ):
1523
+ hosts = ['127.0.0.1%s' % (i ,) for i in range (1 , 3 )]
1522
1524
servers = [OpenSSHServer (host , port = self .port ) for host in hosts ]
1523
1525
for server in servers :
1524
1526
server .start_server ()
@@ -1535,7 +1537,7 @@ def test_scp_send_large_files_timeout(self):
1535
1537
remote_file_names = [arg ['remote_file' ] for arg in copy_args ]
1536
1538
sha = sha256 ()
1537
1539
with open (local_filename , 'wb' ) as file_h :
1538
- for _ in range (5000 ):
1540
+ for _ in range (10000 ):
1539
1541
data = os .urandom (1024 )
1540
1542
file_h .write (data )
1541
1543
sha .update (data )
@@ -1547,13 +1549,15 @@ def test_scp_send_large_files_timeout(self):
1547
1549
except Exception :
1548
1550
raise
1549
1551
else :
1550
- sleep ( .2 )
1552
+ del client
1551
1553
for remote_file_name in remote_file_names :
1552
1554
remote_file_abspath = os .path .expanduser ('~/' + remote_file_name )
1553
1555
self .assertTrue (os .path .isfile (remote_file_abspath ))
1554
1556
with open (remote_file_abspath , 'rb' ) as remote_fh :
1555
- for data in remote_fh :
1557
+ data = remote_fh .read (10240 )
1558
+ while data :
1556
1559
sha .update (data )
1560
+ data = remote_fh .read (10240 )
1557
1561
remote_file_sha = sha .hexdigest ()
1558
1562
sha = sha256 ()
1559
1563
self .assertEqual (source_file_sha , remote_file_sha )
@@ -1679,6 +1683,60 @@ def test_scp_recv(self):
1679
1683
except Exception :
1680
1684
pass
1681
1685
1686
+ def test_scp_recv_larger_files (self ):
1687
+ hosts = ['127.0.0.1%s' % (i ,) for i in range (1 , 3 )]
1688
+ servers = [OpenSSHServer (host , port = self .port ) for host in hosts ]
1689
+ for server in servers :
1690
+ server .start_server ()
1691
+ client = ParallelSSHClient (
1692
+ hosts , port = self .port , pkey = self .user_key , num_retries = 1 , timeout = 1 ,
1693
+ pool_size = len (hosts ),
1694
+ )
1695
+ dir_name = os .path .dirname (__file__ )
1696
+ remote_filename = 'test_file'
1697
+ remote_filepath = os .path .join (dir_name , remote_filename )
1698
+ local_filename = 'file_copy'
1699
+ copy_args = [{
1700
+ 'remote_file' : remote_filepath ,
1701
+ 'local_file' : os .path .expanduser ("~/" + 'host_%s_%s' % (n , local_filename ))}
1702
+ for n in range (len (hosts ))
1703
+ ]
1704
+ local_file_names = [
1705
+ arg ['local_file' ] for arg in copy_args ]
1706
+ sha = sha256 ()
1707
+ with open (remote_filepath , 'wb' ) as file_h :
1708
+ for _ in range (10000 ):
1709
+ data = os .urandom (1024 )
1710
+ file_h .write (data )
1711
+ sha .update (data )
1712
+ file_h .flush ()
1713
+ source_file_sha = sha .hexdigest ()
1714
+ sha = sha256 ()
1715
+ cmds = client .scp_recv ('%(remote_file)s' , '%(local_file)s' , copy_args = copy_args )
1716
+ try :
1717
+ joinall (cmds , raise_error = True )
1718
+ except Exception :
1719
+ raise
1720
+ else :
1721
+ del client
1722
+ for _local_file_name in local_file_names :
1723
+ self .assertTrue (os .path .isfile (_local_file_name ))
1724
+ with open (_local_file_name , 'rb' ) as fh :
1725
+ data = fh .read (10240 )
1726
+ while data :
1727
+ sha .update (data )
1728
+ data = fh .read (10240 )
1729
+ local_file_sha = sha .hexdigest ()
1730
+ sha = sha256 ()
1731
+ self .assertEqual (source_file_sha , local_file_sha )
1732
+ finally :
1733
+ try :
1734
+ os .unlink (remote_filepath )
1735
+ for _local_file_name in local_file_names :
1736
+ os .unlink (_local_file_name )
1737
+ except OSError :
1738
+ pass
1739
+
1682
1740
def test_bad_hosts_value (self ):
1683
1741
self .assertRaises (TypeError , ParallelSSHClient , 'a host' )
1684
1742
self .assertRaises (TypeError , ParallelSSHClient , b'a host' )
0 commit comments