@@ -437,34 +437,39 @@ def test_identical_host_output(self):
437437 self .assertEqual (len (hosts ), len (output .keys ()),
438438 msg = "Host list contains %s identical hosts, only got output for %s" % (
439439 len (hosts ), len (output .keys ())))
440+ del _socket
440441
441442 def test_connection_error_exception (self ):
442443 """Test that we get connection error exception in output with correct arguments"""
443- # Make socket with no server listening on it
444- _socket = make_socket (self .host )
444+ self .server .kill ()
445+ # Make socket with no server listening on it on separate ip
446+ host = '127.0.0.3'
447+ _socket = make_socket (host )
445448 port = _socket .getsockname ()[1 ]
446- hosts = [self . host ]
449+ hosts = [host ]
447450 client = ParallelSSHClient (hosts , port = port ,
448451 pkey = self .user_key )
449452 output = client .run_command (self .fake_cmd , stop_on_errors = False )
450453 client .pool .join ()
451- self .assertTrue ('exception' in output [self . host ],
454+ self .assertTrue ('exception' in output [host ],
452455 msg = "Got no exception for host %s - expected connection error" % (
453- self . host ,))
456+ host ,))
454457 try :
455- raise output [self . host ]['exception' ]
458+ raise output [host ]['exception' ]
456459 except ConnectionErrorException , ex :
457- self .assertEqual (ex .args [1 ], self . host ,
460+ self .assertEqual (ex .args [1 ], host ,
458461 msg = "Exception host argument is %s, should be %s" % (
459- ex .args [1 ], self . host ,))
462+ ex .args [1 ], host ,))
460463 self .assertEqual (ex .args [2 ], port ,
461464 msg = "Exception port argument is %s, should be %s" % (
462465 ex .args [2 ], port ,))
463466 else :
464467 raise Exception ("Expected ConnectionErrorException" )
468+ del _socket
465469
466470 def test_authentication_exception (self ):
467- """Test that we get connection error exception in output with correct arguments"""
471+ """Test that we get authentication exception in output with correct arguments"""
472+ self .server .kill ()
468473 _socket = make_socket (self .host )
469474 port = _socket .getsockname ()[1 ]
470475 server = start_server (_socket , fail_auth = True )
@@ -487,28 +492,34 @@ def test_authentication_exception(self):
487492 ex .args [2 ], port ,))
488493 else :
489494 raise Exception ("Expected AuthenticationException" )
495+ server .kill ()
496+ del _socket
490497
491498 def test_ssh_exception (self ):
492- """Test that we get connection error exception in output with correct arguments"""
493- _socket = make_socket (self .host )
499+ """Test that we get ssh exception in output with correct arguments"""
500+ self .server .kill ()
501+ host = '127.0.0.10'
502+ _socket = make_socket (host )
494503 port = _socket .getsockname ()[1 ]
495504 server = start_server (_socket , ssh_exception = True )
496- hosts = [self . host ]
505+ hosts = [host ]
497506 client = ParallelSSHClient (hosts , port = port ,
498507 pkey = self .user_key )
499508 output = client .run_command (self .fake_cmd , stop_on_errors = False )
500509 client .pool .join ()
501- self .assertTrue ('exception' in output [self . host ],
510+ self .assertTrue ('exception' in output [host ],
502511 msg = "Got no exception for host %s - expected connection error" % (
503- self . host ,))
512+ host ,))
504513 try :
505- raise output [self . host ]['exception' ]
514+ raise output [host ]['exception' ]
506515 except SSHException , ex :
507- self .assertEqual (ex .args [1 ], self . host ,
516+ self .assertEqual (ex .args [1 ], host ,
508517 msg = "Exception host argument is %s, should be %s" % (
509- ex .args [1 ], self . host ,))
518+ ex .args [1 ], host ,))
510519 self .assertEqual (ex .args [2 ], port ,
511520 msg = "Exception port argument is %s, should be %s" % (
512521 ex .args [2 ], port ,))
513522 else :
514523 raise Exception ("Expected SSHException" )
524+ server .kill ()
525+ del _socket
0 commit comments