2424 AuthenticationException , ConnectionErrorException , SSHException , logger as pssh_logger
2525from embedded_server .embedded_server import start_server , make_socket , \
2626 logger as server_logger , paramiko_logger
27+ from embedded_server .fake_agent import FakeAgent
2728import random
2829import logging
2930import gevent
@@ -51,36 +52,39 @@ def setUp(self):
5152 self .listen_socket = make_socket (self .host )
5253 self .listen_port = self .listen_socket .getsockname ()[1 ]
5354 self .server = start_server (self .listen_socket )
54-
55+ self .agent = FakeAgent ()
56+ self .agent .add_key (USER_KEY )
57+ self .client = ParallelSSHClient ([self .host ], port = self .listen_port ,
58+ pkey = self .user_key ,
59+ agent = self .agent )
60+
5561 def tearDown (self ):
5662 del self .server
5763 del self .listen_socket
64+ del self .client
5865
5966 def test_pssh_client_exec_command (self ):
60- client = ParallelSSHClient ([self .host ], port = self .listen_port ,
61- pkey = self .user_key )
62- cmd = client .exec_command (self .fake_cmd )[0 ]
63- output = client .get_stdout (cmd )
67+ cmd = self .client .exec_command (self .fake_cmd )[0 ]
68+ output = self .client .get_stdout (cmd )
6469 expected = {self .host : {'exit_code' : 0 }}
6570 self .assertEqual (expected , output ,
6671 msg = "Got unexpected command output - %s" % (output ,))
6772 self .assertTrue (output [self .host ]['exit_code' ] == 0 )
6873
6974 def test_pssh_client_no_stdout_non_zero_exit_code (self ):
70- client = ParallelSSHClient ([self .host ], port = self .listen_port ,
71- pkey = self .user_key )
72- output = client .run_command ('exit 1' )
75+ output = self .client .run_command ('exit 1' )
7376 expected_exit_code = 1
7477 exit_code = output [self .host ]['exit_code' ]
75- client .pool .join ()
78+ self . client .pool .join ()
7679 self .assertEqual (expected_exit_code , exit_code ,
7780 msg = "Got unexpected exit code - %s, expected %s" %
7881 (exit_code ,
7982 expected_exit_code ,))
8083
8184 def test_pssh_client_exec_command_get_buffers (self ):
8285 client = ParallelSSHClient ([self .host ], port = self .listen_port ,
83- pkey = self .user_key )
86+ pkey = self .user_key ,
87+ agent = self .agent )
8488 cmd = client .exec_command (self .fake_cmd )[0 ]
8589 output = client .get_stdout (cmd , return_buffers = True )
8690 expected_exit_code = 0
@@ -104,7 +108,8 @@ def test_pssh_client_exec_command_get_buffers(self):
104108
105109 def test_pssh_client_run_command_get_output (self ):
106110 client = ParallelSSHClient ([self .host ], port = self .listen_port ,
107- pkey = self .user_key )
111+ pkey = self .user_key ,
112+ agent = self .agent )
108113 output = client .run_command (self .fake_cmd )
109114 expected_exit_code = 0
110115 expected_stdout = [self .fake_resp ]
@@ -170,7 +175,8 @@ def test_pssh_client_auth_failure(self):
170175 listen_port = listen_socket .getsockname ()[1 ]
171176 server = start_server (listen_socket , fail_auth = True )
172177 client = ParallelSSHClient ([self .host ], port = listen_port ,
173- pkey = self .user_key )
178+ pkey = self .user_key ,
179+ agent = self .agent )
174180 cmd = client .exec_command (self .fake_cmd )[0 ]
175181 # Handle exception
176182 try :
@@ -191,7 +197,7 @@ def test_pssh_client_hosts_list_part_failure(self):
191197 client = ParallelSSHClient (hosts ,
192198 port = self .listen_port ,
193199 pkey = self .user_key ,
194- )
200+ agent = self . agent )
195201 output = client .run_command (self .fake_cmd ,
196202 stop_on_errors = False )
197203 self .assertTrue (hosts [0 ] in output ,
@@ -258,7 +264,7 @@ def test_pssh_client_timeout(self):
258264 server .join ()
259265
260266 def test_pssh_client_exec_command_password (self ):
261- """Test password authentication. Fake server accepts any password
267+ """Test password authentication. Embedded server accepts any password
262268 even empty string"""
263269 client = ParallelSSHClient ([self .host ], port = self .listen_port ,
264270 password = '' )
@@ -501,7 +507,8 @@ def test_authentication_exception(self):
501507 server = start_server (_socket , fail_auth = True )
502508 hosts = [self .host ]
503509 client = ParallelSSHClient (hosts , port = port ,
504- pkey = self .user_key )
510+ pkey = self .user_key ,
511+ agent = self .agent )
505512 output = client .run_command (self .fake_cmd , stop_on_errors = False )
506513 client .pool .join ()
507514 self .assertTrue ('exception' in output [self .host ],
0 commit comments