2121
2222import unittest
2323from pssh import ParallelSSHClient , UnknownHostException , \
24- AuthenticationException , ConnectionErrorException
25- from fake_server .fake_server import start_server , make_socket , logger as server_logger , \
26- paramiko_logger
24+ AuthenticationException , ConnectionErrorException
25+ from fake_server .fake_server import start_server , make_socket , \
26+ logger as server_logger , paramiko_logger
2727import random
2828import logging
2929import gevent
@@ -165,8 +165,9 @@ def test_pssh_client_run_long_command(self):
165165 output = client .run_command (self .long_running_cmd )
166166 self .assertTrue ('127.0.0.1' in output , msg = "Got no output for command" )
167167 stdout = list (output ['127.0.0.1' ]['stdout' ])
168- self .assertTrue (len (stdout ) == expected_lines , msg = "Expected %s lines of response, got %s" %
169- (expected_lines , len (stdout )))
168+ self .assertTrue (len (stdout ) == expected_lines ,
169+ msg = "Expected %s lines of response, got %s" % (
170+ expected_lines , len (stdout )))
170171 del client
171172 server .kill ()
172173
@@ -198,7 +199,8 @@ def test_pssh_client_timeout(self):
198199 gevent .sleep (0.5 )
199200 cmd .get ()
200201 if not server .exception :
201- raise Exception ("Expected gevent.Timeout from socket timeout, got none" )
202+ raise Exception (
203+ "Expected gevent.Timeout from socket timeout, got none" )
202204 raise server .exception
203205 except gevent .Timeout :
204206 pass
@@ -217,7 +219,7 @@ def test_pssh_client_exec_command_password(self):
217219 output = client .get_stdout (cmd )
218220 expected = {'127.0.0.1' : {'exit_code' : 0 }}
219221 self .assertEqual (expected , output ,
220- msg = "Got unexpected command output - %s" % (output ,))
222+ msg = "Got unexpected command output - %s" % (output ,))
221223 del client
222224 server .join ()
223225
@@ -232,8 +234,9 @@ def test_pssh_client_long_running_command(self):
232234 output = client .get_stdout (cmd )
233235 self .assertTrue ('127.0.0.1' in output , msg = "Got no output for command" )
234236 stdout = list (output ['127.0.0.1' ]['stdout' ])
235- self .assertTrue (len (stdout ) == expected_lines , msg = "Expected %s lines of response, got %s" %
236- (expected_lines , len (stdout )))
237+ self .assertTrue (len (stdout ) == expected_lines ,
238+ msg = "Expected %s lines of response, got %s" % (
239+ expected_lines , len (stdout )))
237240 del client
238241 server .kill ()
239242
@@ -242,7 +245,8 @@ def test_pssh_client_retries(self):
242245 expected_num_tries = 2
243246 with self .assertRaises (ConnectionErrorException ) as cm :
244247 client = ParallelSSHClient (['127.0.0.1' ], port = self .listen_port ,
245- pkey = self .user_key , num_retries = expected_num_tries )
248+ pkey = self .user_key ,
249+ num_retries = expected_num_tries )
246250 cmd = client .exec_command ('blah' )[0 ]
247251 cmd .get ()
248252 num_tries = cm .exception .args [- 1 :][0 ]
@@ -273,3 +277,24 @@ def test_pssh_copy_file(self):
273277 os .unlink (filepath )
274278 del client
275279 server .join ()
280+
281+ def test_pssh_pool_size (self ):
282+ """Test pool size logic"""
283+ hosts = ['host-%01d' % d for d in xrange (5 )]
284+ client = ParallelSSHClient (hosts )
285+ expected , actual = len (hosts ), client .pool .size
286+ self .assertEqual (expected , actual ,
287+ msg = "Expected pool size to be %s, got %s" % (
288+ expected , actual ,))
289+ hosts = ['host-%01d' % d for d in xrange (15 )]
290+ client = ParallelSSHClient (hosts )
291+ expected , actual = client .pool_size , client .pool .size
292+ self .assertEqual (expected , actual ,
293+ msg = "Expected pool size to be %s, got %s" % (
294+ expected , actual ,))
295+ hosts = ['host-%01d' % d for d in xrange (15 )]
296+ client = ParallelSSHClient (hosts , pool_size = len (hosts )+ 5 )
297+ expected , actual = len (hosts ), client .pool .size
298+ self .assertEqual (expected , actual ,
299+ msg = "Expected pool size to be %s, got %s" % (
300+ expected , actual ,))
0 commit comments