@@ -68,6 +68,13 @@ def tearDown(self):
6868 del self .listen_socket
6969 del self .client
7070
71+ def test_pssh_client_exec_command (self ):
72+ cmd = self .client .exec_command (self .fake_cmd )[0 ]
73+ output = self .client .get_stdout (cmd )
74+ self .assertTrue (self .host in output ,
75+ msg = "No output for host" )
76+ self .assertTrue (output [self .host ]['exit_code' ] == 0 )
77+
7178 def test_pssh_client_no_stdout_non_zero_exit_code_immediate_exit (self ):
7279 output = self .client .run_command ('exit 1' )
7380 expected_exit_code = 1
@@ -78,6 +85,31 @@ def test_pssh_client_no_stdout_non_zero_exit_code_immediate_exit(self):
7885 (exit_code ,
7986 expected_exit_code ,))
8087
88+ def test_pssh_client_exec_command_get_buffers (self ):
89+ client = ParallelSSHClient ([self .host ], port = self .listen_port ,
90+ pkey = self .user_key ,
91+ agent = self .agent )
92+ cmd = client .exec_command (self .fake_cmd )[0 ]
93+ output = client .get_stdout (cmd , return_buffers = True )
94+ expected_exit_code = 0
95+ expected_stdout = [self .fake_resp ]
96+ expected_stderr = []
97+ exit_code = output [self .host ]['exit_code' ]
98+ stdout = list (output [self .host ]['stdout' ])
99+ stderr = list (output [self .host ]['stderr' ])
100+ self .assertEqual (expected_exit_code , exit_code ,
101+ msg = "Got unexpected exit code - %s, expected %s" %
102+ (exit_code ,
103+ expected_exit_code ,))
104+ self .assertEqual (expected_stdout , stdout ,
105+ msg = "Got unexpected stdout - %s, expected %s" %
106+ (stdout ,
107+ expected_stdout ,))
108+ self .assertEqual (expected_stderr , stderr ,
109+ msg = "Got unexpected stderr - %s, expected %s" %
110+ (stderr ,
111+ expected_stderr ,))
112+
81113 def test_pssh_client_run_command_get_output (self ):
82114 client = ParallelSSHClient ([self .host ], port = self .listen_port ,
83115 pkey = self .user_key ,
@@ -143,15 +175,21 @@ def test_pssh_client_run_long_command(self):
143175 del client
144176
145177 def test_pssh_client_auth_failure (self ):
146- self .server .kill ()
147- server_socket = make_socket (self .host )
148- listen_port = server_socket .getsockname ()[1 ]
149- server = start_server (server_socket , fail_auth = True )
178+ listen_socket = make_socket (self .host )
179+ listen_port = listen_socket .getsockname ()[1 ]
180+ server = start_server (listen_socket , fail_auth = True )
150181 client = ParallelSSHClient ([self .host ], port = listen_port ,
151182 pkey = self .user_key ,
152183 agent = self .agent )
153- self .assertRaises (AuthenticationException , client .run_command , self .fake_cmd )
184+ cmd = client .exec_command (self .fake_cmd )[0 ]
185+ # Handle exception
186+ try :
187+ cmd .get ()
188+ raise Exception ("Expected AuthenticationException, got none" )
189+ except AuthenticationException :
190+ pass
154191 del client
192+ server .kill ()
155193
156194 def test_pssh_client_hosts_list_part_failure (self ):
157195 """Test getting output for remainder of host list in the case where one
@@ -200,7 +238,6 @@ def test_pssh_client_ssh_exception(self):
200238 server .kill ()
201239
202240 def test_pssh_client_timeout (self ):
203- self .server .kill ()
204241 listen_socket = make_socket (self .host )
205242 listen_port = listen_socket .getsockname ()[1 ]
206243 server_timeout = 0.2
@@ -221,23 +258,40 @@ def test_pssh_client_timeout(self):
221258 raise server .exception
222259 except gevent .Timeout :
223260 pass
261+ # chan_timeout = output[self.host]['channel'].gettimeout()
262+ # self.assertEqual(client_timeout, chan_timeout,
263+ # msg="Channel timeout %s does not match requested timeout %s" %(
264+ # chan_timeout, client_timeout,))
224265 del client
225266 server .kill ()
226267
227- def test_pssh_client_run_command_password (self ):
268+ def test_pssh_client_exec_command_password (self ):
228269 """Test password authentication. Embedded server accepts any password
229270 even empty string"""
230271 client = ParallelSSHClient ([self .host ], port = self .listen_port ,
231272 password = '' )
232- output = client .run_command (self .fake_cmd )
233- client .join ( output )
273+ cmd = client .exec_command (self .fake_cmd )[ 0 ]
274+ output = client .get_stdout ( cmd )
234275 self .assertTrue (self .host in output ,
235276 msg = "No output for host" )
236277 self .assertTrue (output [self .host ]['exit_code' ] == 0 ,
237278 msg = "Expected exit code 0, got %s" % (
238279 output [self .host ]['exit_code' ],))
239280 del client
240281
282+ def test_pssh_client_long_running_command (self ):
283+ expected_lines = 5
284+ client = ParallelSSHClient ([self .host ], port = self .listen_port ,
285+ pkey = self .user_key )
286+ cmd = client .exec_command (self .long_cmd (expected_lines ))[0 ]
287+ output = client .get_stdout (cmd , return_buffers = True )
288+ self .assertTrue (self .host in output , msg = "Got no output for command" )
289+ stdout = list (output [self .host ]['stdout' ])
290+ self .assertTrue (len (stdout ) == expected_lines ,
291+ msg = "Expected %s lines of response, got %s" % (
292+ expected_lines , len (stdout )))
293+ del client
294+
241295 def test_pssh_client_long_running_command_exit_codes (self ):
242296 expected_lines = 5
243297 client = ParallelSSHClient ([self .host ], port = self .listen_port ,
0 commit comments