3535from pssh .exceptions import UnknownHostException , \
3636 AuthenticationException , ConnectionErrorException , \
3737 HostArgumentException , SFTPError , SFTPIOError , Timeout , SCPError , \
38- PKeyFileError , ShellError , HostArgumentError , NoIPv6AddressFoundError
38+ PKeyFileError , ShellError , HostArgumentError , NoIPv6AddressFoundError , \
39+ AuthenticationError
3940from pssh .output import HostOutput
4041
4142from .base_ssh2_case import PKEY_FILENAME , PUB_FILE
@@ -276,7 +277,7 @@ def test_pssh_client_hosts_list_part_failure(self):
276277 self .assertTrue (client .finished (output ))
277278 self .assertEqual (len (hosts ), len (output ))
278279 self .assertIsNotNone (output [1 ].exception )
279- self .assertEqual (output [1 ].exception . args [ 1 ] , hosts [1 ])
280+ self .assertEqual (output [1 ].host , hosts [1 ])
280281 self .assertIsInstance (output [1 ].exception , ConnectionErrorException )
281282
282283 def test_pssh_client_timeout (self ):
@@ -350,23 +351,23 @@ def test_pssh_client_long_running_command_exit_codes_no_stdout(self):
350351
351352 def test_pssh_client_retries (self ):
352353 """Test connection error retries"""
353- listen_port = self .make_random_port ()
354+ # listen_port = self.make_random_port()
354355 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" ,
357358 num_retries = expected_num_tries ,
358359 retry_delay = .1 ,
359360 )
360- self .assertRaises (ConnectionErrorException , client .run_command , 'blah' )
361+ self .assertRaises (AuthenticationError , client .run_command , 'blah' )
361362 try :
362363 client .run_command ('blah' )
363- except ConnectionErrorException as ex :
364+ except AuthenticationError as ex :
365+ max_tries = ex .args [- 2 :][0 ]
364366 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 )
368369 else :
369- raise Exception ('No ConnectionErrorException ' )
370+ raise Exception ('No AuthenticationError ' )
370371
371372 def test_sftp_exceptions (self ):
372373 # Port with no server listening on it on separate ip
@@ -380,7 +381,8 @@ def test_sftp_exceptions(self):
380381 try :
381382 cmd .get ()
382383 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 )
384386 self .assertIsInstance (ex , ConnectionErrorException )
385387 else :
386388 raise Exception ("Expected ConnectionErrorException, got none" )
@@ -859,7 +861,7 @@ def test_identical_hosts_in_host_list(self):
859861 _host_stdout = list (host_out .stdout )
860862 self .assertListEqual (_host_stdout , expected_stdout )
861863
862- def test_connection_error_exception (self ):
864+ def test_connection_error (self ):
863865 """Test that we get connection error exception in output with correct arguments"""
864866 # Make port with no server listening on it on separate ip
865867 host = '127.0.0.3'
@@ -874,13 +876,7 @@ def test_connection_error_exception(self):
874876 for host_output in output :
875877 exit_code = host_output .exit_code
876878 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 )
884880
885881 def test_bad_pkey_path (self ):
886882 self .assertRaises (PKeyFileError , ParallelSSHClient , [self .host ], port = self .port ,
0 commit comments