35
35
from pssh .exceptions import UnknownHostException , \
36
36
AuthenticationException , ConnectionErrorException , \
37
37
HostArgumentException , SFTPError , SFTPIOError , Timeout , SCPError , \
38
- PKeyFileError , ShellError , HostArgumentError , NoIPv6AddressFoundError
38
+ PKeyFileError , ShellError , HostArgumentError , NoIPv6AddressFoundError , \
39
+ AuthenticationError
39
40
from pssh .output import HostOutput
40
41
41
42
from .base_ssh2_case import PKEY_FILENAME , PUB_FILE
@@ -276,7 +277,7 @@ def test_pssh_client_hosts_list_part_failure(self):
276
277
self .assertTrue (client .finished (output ))
277
278
self .assertEqual (len (hosts ), len (output ))
278
279
self .assertIsNotNone (output [1 ].exception )
279
- self .assertEqual (output [1 ].exception . args [ 1 ] , hosts [1 ])
280
+ self .assertEqual (output [1 ].host , hosts [1 ])
280
281
self .assertIsInstance (output [1 ].exception , ConnectionErrorException )
281
282
282
283
def test_pssh_client_timeout (self ):
@@ -350,23 +351,23 @@ def test_pssh_client_long_running_command_exit_codes_no_stdout(self):
350
351
351
352
def test_pssh_client_retries (self ):
352
353
"""Test connection error retries"""
353
- listen_port = self .make_random_port ()
354
+ # listen_port = self.make_random_port()
354
355
expected_num_tries = 2
355
- client = ParallelSSHClient ([self .host ], port = listen_port ,
356
- pkey = self . user_key ,
356
+ client = ParallelSSHClient ([self .host ], port = self . port ,
357
+ pkey = b"fake" ,
357
358
num_retries = expected_num_tries ,
358
359
retry_delay = .1 ,
359
360
)
360
- self .assertRaises (ConnectionErrorException , client .run_command , 'blah' )
361
+ self .assertRaises (AuthenticationError , client .run_command , 'blah' )
361
362
try :
362
363
client .run_command ('blah' )
363
- except ConnectionErrorException as ex :
364
+ except AuthenticationError as ex :
365
+ max_tries = ex .args [- 2 :][0 ]
364
366
num_tries = ex .args [- 1 :][0 ]
365
- self .assertEqual (expected_num_tries , num_tries ,
366
- msg = "Got unexpected number of retries %s - "
367
- "expected %s" % (num_tries , expected_num_tries ,))
367
+ self .assertEqual (expected_num_tries , max_tries )
368
+ self .assertEqual (expected_num_tries , num_tries )
368
369
else :
369
- raise Exception ('No ConnectionErrorException ' )
370
+ raise Exception ('No AuthenticationError ' )
370
371
371
372
def test_sftp_exceptions (self ):
372
373
# Port with no server listening on it on separate ip
@@ -380,7 +381,8 @@ def test_sftp_exceptions(self):
380
381
try :
381
382
cmd .get ()
382
383
except Exception as ex :
383
- self .assertEqual (ex .args [1 ], self .host )
384
+ self .assertEqual (ex .args [2 ], self .host )
385
+ self .assertEqual (ex .args [3 ], port )
384
386
self .assertIsInstance (ex , ConnectionErrorException )
385
387
else :
386
388
raise Exception ("Expected ConnectionErrorException, got none" )
@@ -859,7 +861,7 @@ def test_identical_hosts_in_host_list(self):
859
861
_host_stdout = list (host_out .stdout )
860
862
self .assertListEqual (_host_stdout , expected_stdout )
861
863
862
- def test_connection_error_exception (self ):
864
+ def test_connection_error (self ):
863
865
"""Test that we get connection error exception in output with correct arguments"""
864
866
# Make port with no server listening on it on separate ip
865
867
host = '127.0.0.3'
@@ -874,13 +876,7 @@ def test_connection_error_exception(self):
874
876
for host_output in output :
875
877
exit_code = host_output .exit_code
876
878
self .assertEqual (exit_code , None )
877
- try :
878
- raise output [0 ].exception
879
- except ConnectionErrorException as ex :
880
- self .assertEqual (ex .args [1 ], host )
881
- self .assertEqual (ex .args [2 ], port )
882
- else :
883
- raise Exception ("Expected ConnectionErrorException" )
879
+ self .assertIsInstance (output [0 ].exception , ConnectionError )
884
880
885
881
def test_bad_pkey_path (self ):
886
882
self .assertRaises (PKeyFileError , ParallelSSHClient , [self .host ], port = self .port ,
0 commit comments