|
34 | 34 | import time |
35 | 35 |
|
36 | 36 |
|
37 | | -from gevent import joinall |
| 37 | +from gevent import joinall, spawn |
38 | 38 | from pssh.clients.native import ParallelSSHClient |
39 | 39 | from pssh.exceptions import UnknownHostException, \ |
40 | 40 | AuthenticationException, ConnectionErrorException, SessionError, \ |
@@ -276,19 +276,29 @@ def test_pssh_client_timeout(self): |
276 | 276 | self.assertIsInstance(output[self.host].exception, |
277 | 277 | Timeout) |
278 | 278 |
|
279 | | -# def test_pssh_client_run_command_password(self): |
280 | | -# """Test password authentication. Embedded server accepts any password |
281 | | -# even empty string""" |
282 | | -# client = ParallelSSHClient([self.host], port=self.listen_port, |
283 | | -# password='') |
284 | | -# output = client.run_command(self.fake_cmd) |
285 | | -# stdout = list(output[self.host]['stdout']) |
286 | | -# self.assertTrue(self.host in output, |
287 | | -# msg="No output for host") |
288 | | -# self.assertTrue(output[self.host]['exit_code'] == 0, |
289 | | -# msg="Expected exit code 0, got %s" % ( |
290 | | -# output[self.host]['exit_code'],)) |
291 | | -# self.assertEqual(stdout, [self.fake_resp]) |
| 279 | + def test_connection_timeout(self): |
| 280 | + client_timeout = .01 |
| 281 | + host = 'fakehost.com' |
| 282 | + client = ParallelSSHClient([host], port=self.port, |
| 283 | + pkey=self.user_key, |
| 284 | + timeout=client_timeout, |
| 285 | + num_retries=1) |
| 286 | + cmd = spawn(client.run_command, 'sleep 1', stop_on_errors=False) |
| 287 | + output = cmd.get(timeout=client_timeout * 200) |
| 288 | + self.assertIsInstance(output[host].exception, |
| 289 | + ConnectionErrorException) |
| 290 | + |
| 291 | + def test_zero_timeout(self): |
| 292 | + host = '127.0.0.2' |
| 293 | + server = OpenSSHServer(listen_ip=host, port=self.port) |
| 294 | + server.start_server() |
| 295 | + client = ParallelSSHClient([self.host, host], |
| 296 | + port=self.port, |
| 297 | + pkey=self.user_key, |
| 298 | + timeout=0) |
| 299 | + cmd = spawn(client.run_command, 'sleep 1', stop_on_errors=False) |
| 300 | + output = cmd.get(timeout=3) |
| 301 | + self.assertTrue(output[self.host].exception is None) |
292 | 302 |
|
293 | 303 | def test_pssh_client_long_running_command_exit_codes(self): |
294 | 304 | expected_lines = 2 |
|
0 commit comments