Skip to content
Snippets Groups Projects
Commit 48c49c54 authored by Brian O'Connor's avatar Brian O'Connor
Browse files

cleaned up and commented test_sshd.py

parent d4993c0b
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python #!/usr/bin/env python
"""TEST""" """
Test for sshd.py
"""
import unittest import unittest
import pexpect import pexpect
from time import sleep from time import sleep
from mininet.log import setLogLevel from mininet.clean import sh
from mininet.clean import cleanup, sh
class testBareSSHD( unittest.TestCase ): class testSSHD( unittest.TestCase ):
"Test ping with single switch topology (common code)."
opts = [ '\(yes/no\)\?', 'refused', 'Welcome', pexpect.EOF, pexpect.TIMEOUT ] opts = [ '\(yes/no\)\?', 'refused', 'Welcome|\$|#', pexpect.EOF, pexpect.TIMEOUT ]
def connected( self, ip ): def connected( self, ip ):
"check connected" "Log into ssh server, check banner, then exit"
p = pexpect.spawn( 'ssh -i /tmp/ssh/test_rsa %s' % ip ) # Note: this test will fail if "Welcome" is not in the sshd banner
# and '#'' or '$'' are not in the prompt
p = pexpect.spawn( 'ssh -i /tmp/ssh/test_rsa %s' % ip, timeout=10 )
while True: while True:
index = p.expect( self.opts ) index = p.expect( self.opts )
if index == 0: if index == 0:
...@@ -38,10 +40,12 @@ def setUp( self ): ...@@ -38,10 +40,12 @@ def setUp( self ):
cmd = ( 'python -m mininet.examples.sshd -D ' cmd = ( 'python -m mininet.examples.sshd -D '
'-o AuthorizedKeysFile=/tmp/ssh/authorized_keys ' '-o AuthorizedKeysFile=/tmp/ssh/authorized_keys '
'-o StrictModes=no' ) '-o StrictModes=no' )
# run example with custom sshd args
self.net = pexpect.spawn( cmd ) self.net = pexpect.spawn( cmd )
self.net.expect( 'mininet>' ) self.net.expect( 'mininet>' )
def testSSH( self ): def testSSH( self ):
"Verify that we can ssh into all hosts (h1 to h4)"
for h in range( 1, 5 ): for h in range( 1, 5 ):
self.assertTrue( self.connected( '10.0.0.%d' % h ) ) self.assertTrue( self.connected( '10.0.0.%d' % h ) )
...@@ -52,6 +56,5 @@ def tearDown( self ): ...@@ -52,6 +56,5 @@ def tearDown( self ):
sh( 'rm -rf /tmp/ssh' ) sh( 'rm -rf /tmp/ssh' )
if __name__ == '__main__': if __name__ == '__main__':
setLogLevel( 'warning' )
unittest.main() unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment