44
55import unittest
66import gevent
7- from gevent import monkey
8- monkey .patch_all ()
9- from pssh import ParallelSSHClient , UnknownHostException , ConnectionErrorException
7+ from pssh import ParallelSSHClient , UnknownHostException , ConnectionErrorException , _setup_logger
108from paramiko import AuthenticationException
11- from fake_server .fake_server import listen
9+ from fake_server .fake_server import listen , logger as server_logger
1210import random
11+ import logging
12+
13+ # _setup_logger(server_logger)
1314
1415class ParallelSSHClientTest (unittest .TestCase ):
1516
@@ -18,21 +19,31 @@ def setUp(self):
1819 self .fake_resp = 'fake response'
1920
2021 def test_pssh_client_exec_command (self ):
21- listen_port = random .randint (1025 , 65534 )
22+ listen_port = random .randint (1026 , 65534 )
2223 server = gevent .spawn (listen , { self .fake_cmd : self .fake_resp }, listen_port = listen_port )
23- client = ParallelSSHClient (['localhost' ], port = listen_port )
24+ gevent .sleep (.1 )
25+ client = ParallelSSHClient (['localhost' ], port = listen_port )
2426 cmd = client .exec_command (self .fake_cmd )[0 ]
2527 output = client .get_stdout (cmd )
2628 expected = {'localhost' : {'exit_code' : 0 }}
27- self .assertEqual (expected , output , msg = "Got unexpected command output - %s" % (output ,))
29+ self .assertEqual (expected , output ,
30+ msg = "Got unexpected command output - %s" % (output ,))
2831 server .kill ()
32+ del client
2933
3034 def test_pssh_client_auth_failure (self ):
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 )
35+ listen_port = random .randint (2048 , 65534 )
36+ server = gevent .spawn (listen , { self .fake_cmd : self .fake_resp },
37+ listen_port = listen_port , fail_auth = True , )# link_callback=)
38+ gevent .sleep (.1 )
39+ client = ParallelSSHClient (['localhost' ], port = listen_port )
40+ cmd = client .exec_command (self .fake_cmd )[0 ]
41+ # Handle exception
3442 try :
35- cmd = client .exec_command (self .fake_cmd )[0 ]
43+ cmd .get ()
44+ raise Exception ("Expected AuthenticationException, got none" )
3645 except AuthenticationException :
3746 pass
3847 server .kill ()
48+ del client
49+
0 commit comments