66import gevent
77from gevent import monkey
88monkey .patch_all ()
9- from pssh import ParallelSSHClient , UnknownHostException
9+ from pssh import ParallelSSHClient , UnknownHostException , ConnectionErrorException
1010from paramiko import AuthenticationException
1111from fake_server .fake_server import listen
12+ import random
1213
1314class ParallelSSHClientTest (unittest .TestCase ):
1415
@@ -17,18 +18,21 @@ def setUp(self):
1718 self .fake_resp = 'fake response'
1819
1920 def test_pssh_client_exec_command (self ):
20- server = gevent .spawn (listen , { self .fake_cmd : self .fake_resp })
21- client = ParallelSSHClient (['localhost' ], port = 2200 )
21+ listen_port = random .randint (1025 , 65534 )
22+ server = gevent .spawn (listen , { self .fake_cmd : self .fake_resp }, listen_port = listen_port )
23+ client = ParallelSSHClient (['localhost' ], port = listen_port )
2224 cmd = client .exec_command (self .fake_cmd )[0 ]
2325 output = client .get_stdout (cmd )
2426 expected = {'localhost' : {'exit_code' : 0 }}
2527 self .assertEqual (expected , output , msg = "Got unexpected command output - %s" % (output ,))
2628 server .kill ()
2729
2830 def test_pssh_client_auth_failure (self ):
29- server = gevent .spawn (listen , { self .fake_cmd : self .fake_resp }, listen_port = 2201 , fail_auth = True )
30- client = ParallelSSHClient (['localhost' ], port = 2201 )
31+ listen_port = random .randint (1025 , 65534 )
32+ server = gevent .spawn (listen , { self .fake_cmd : self .fake_resp }, listen_port = listen_port , fail_auth = True )
33+ client = ParallelSSHClient (['localhost' ], port = listen_port )
3134 try :
3235 cmd = client .exec_command (self .fake_cmd )[0 ]
3336 except AuthenticationException :
3437 pass
38+ server .kill ()
0 commit comments