b7c412073a
Ubuntu 20.04 fixes:
- fixes sshd test
- speeds up examples/{treeping64,tree1024}.py
- debugging hacks/output for testLinkChange
- removes cfs from examples/popen.py
- improves nat in nodelib (netplan fixes?)
- makes some tests executable
- waits for switches to connect in tests to
avoid race conditions
-- adds mn -w option and wait CLI command
Changes:
- REMOVES default "-v" argument for Controller()
and adds verbose(=False) option; avoiding logging
makes it faster
- CHANGES waitConnected to wait for 5 seconds
as documented; we may wish to implement an argument
to -w to set this timeout
Issues?
- There may still be an issue with the ovs-netplan-clean
service causing the boot to hang ;-(
61 lines
1.9 KiB
Python
Executable File
61 lines
1.9 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
"""
|
|
Test for sshd.py
|
|
"""
|
|
|
|
import unittest
|
|
from mininet.util import pexpect
|
|
from mininet.clean import sh
|
|
|
|
class testSSHD( unittest.TestCase ):
|
|
|
|
opts = [ '\(yes/no\)\?', 'refused', 'Welcome|\$|#', pexpect.EOF, pexpect.TIMEOUT ]
|
|
|
|
def connected( self, ip ):
|
|
"Log into ssh server, check banner, then exit"
|
|
# Note: this test will fail if "Welcome" is not in the sshd banner
|
|
# and '#'' or '$'' are not in the prompt
|
|
ssh = 'ssh -o StrictHostKeyChecking=no -i /tmp/ssh/test_rsa ' + ip
|
|
p = pexpect.spawn( ssh, timeout=5 )
|
|
while True:
|
|
index = p.expect( self.opts )
|
|
if index == 0:
|
|
print( p.match.group(0) )
|
|
p.sendline( 'yes' )
|
|
elif index == 1:
|
|
return False
|
|
elif index == 2:
|
|
p.sendline( 'exit' )
|
|
p.wait()
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
def setUp( self ):
|
|
# create public key pair for testing
|
|
sh( 'rm -rf /tmp/ssh' )
|
|
sh( 'mkdir /tmp/ssh' )
|
|
sh( "ssh-keygen -t rsa -P '' -f /tmp/ssh/test_rsa" )
|
|
sh( 'cat /tmp/ssh/test_rsa.pub >> /tmp/ssh/authorized_keys' )
|
|
cmd = ( 'python -m mininet.examples.sshd -D '
|
|
'-o AuthorizedKeysFile=/tmp/ssh/authorized_keys '
|
|
'-o StrictModes=no -o UseDNS=no -u0' )
|
|
# run example with custom sshd args
|
|
self.net = pexpect.spawn( cmd )
|
|
self.net.expect( 'mininet>' )
|
|
|
|
def testSSH( self ):
|
|
"Verify that we can ssh into all hosts (h1 to h4)"
|
|
for h in range( 1, 5 ):
|
|
self.assertTrue( self.connected( '10.0.0.%d' % h ) )
|
|
|
|
def tearDown( self ):
|
|
self.net.sendline( 'exit' )
|
|
self.net.wait()
|
|
# remove public key pair
|
|
sh( 'rm -rf /tmp/ssh' )
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|