66
77import unittest
88import pexpect
9- from time import sleep
109from mininet .clean import cleanup , sh
1110
1211class testBareSSHD ( unittest .TestCase ):
1312
14- opts = [ '\(yes/no\)\?' , ' Welcome to h1' , 'refused ' , pexpect .EOF , pexpect .TIMEOUT ]
13+ opts = [ 'Welcome to h1' , pexpect .EOF , pexpect .TIMEOUT ]
1514
1615 def connected ( self ):
1716 "Log into ssh server, check banner, then exit"
18- p = pexpect .spawn ( 'ssh 10.0.0.1 -i /tmp/ssh/test_rsa exit' )
17+ p = pexpect .spawn ( 'ssh 10.0.0.1 -o StrictHostKeyChecking=no - i /tmp/ssh/test_rsa exit' )
1918 while True :
2019 index = p .expect ( self .opts )
2120 if index == 0 :
22- p .sendline ( 'yes' )
23- elif index == 1 :
2421 return True
2522 else :
2623 return False
@@ -37,18 +34,23 @@ def setUp( self ):
3734 cmd = ( 'python -m mininet.examples.baresshd '
3835 '-o AuthorizedKeysFile=/tmp/ssh/authorized_keys '
3936 '-o StrictModes=no' )
40- sh ( cmd )
37+ p = pexpect .spawn ( cmd )
38+ runOpts = [ 'You may now ssh into h1 at 10.0.0.1' ,
39+ 'after 5 seconds, h1 is not listening on port 22' ,
40+ pexpect .EOF , pexpect .TIMEOUT ]
41+ while True :
42+ index = p .expect ( runOpts )
43+ if index == 0 :
44+ break
45+ else :
46+ self .tearDown ()
47+ self .fail ( 'sshd failed to start in host h1' )
4148
4249 def testSSH ( self ):
4350 "Simple test to verify that we can ssh into h1"
4451 result = False
4552 # try to connect up to 3 times; sshd can take a while to start
46- for _ in range ( 3 ):
47- result = self .connected ()
48- if result :
49- break
50- else :
51- sleep ( 1 )
53+ result = self .connected ()
5254 self .assertTrue ( result )
5355
5456 def tearDown ( self ):
0 commit comments