cleaned up and commented test_bind.py; added one new test
This commit is contained in:
+32
-24
@@ -1,35 +1,16 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
"""TEST"""
|
"""
|
||||||
|
Tests for bind.py
|
||||||
|
"""
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import pexpect
|
import pexpect
|
||||||
from time import sleep
|
|
||||||
from mininet.log import setLogLevel
|
|
||||||
from mininet.clean import cleanup, sh
|
|
||||||
|
|
||||||
class testBind( unittest.TestCase ):
|
class testBind( unittest.TestCase ):
|
||||||
"Test ping with single switch topology (common code)."
|
|
||||||
|
|
||||||
prompt = 'mininet>'
|
prompt = 'mininet>'
|
||||||
|
|
||||||
def connected( self, ip ):
|
|
||||||
"check connected"
|
|
||||||
p = pexpect.spawn( 'ssh -i /tmp/ssh/test_rsa %s' % ip )
|
|
||||||
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 ):
|
def setUp( self ):
|
||||||
self.net = pexpect.spawn( 'python -m mininet.examples.bind' )
|
self.net = pexpect.spawn( 'python -m mininet.examples.bind' )
|
||||||
self.net.expect( "Private Directories: \[([\w\s,'/]+)\]" )
|
self.net.expect( "Private Directories: \[([\w\s,'/]+)\]" )
|
||||||
@@ -41,11 +22,39 @@ class testBind( unittest.TestCase ):
|
|||||||
self.assertTrue( len( self.directories ) > 0 )
|
self.assertTrue( len( self.directories ) > 0 )
|
||||||
|
|
||||||
def testCreateFile( self ):
|
def testCreateFile( self ):
|
||||||
|
"Create a file, a.txt, in the first private directory and verify"
|
||||||
fileName = 'a.txt'
|
fileName = 'a.txt'
|
||||||
directory = self.directories[ 0 ]
|
directory = self.directories[ 0 ]
|
||||||
self.net.sendline( 'h1 touch %s/%s; ls %s' % ( directory, fileName, directory ) )
|
path = directory + '/' + fileName
|
||||||
|
self.net.sendline( 'h1 touch %s; ls %s' % ( path, directory ) )
|
||||||
index = self.net.expect( [ fileName, self.prompt ] )
|
index = self.net.expect( [ fileName, self.prompt ] )
|
||||||
self.assertTrue( index == 0 )
|
self.assertTrue( index == 0 )
|
||||||
|
self.net.expect( self.prompt )
|
||||||
|
self.net.sendline( 'h1 rm %s' % path )
|
||||||
|
self.net.expect( self.prompt )
|
||||||
|
|
||||||
|
def testIsolation( self ):
|
||||||
|
"Create a file in two hosts and verify that contents are different"
|
||||||
|
fileName = 'b.txt'
|
||||||
|
directory = self.directories[ 0 ]
|
||||||
|
path = directory + '/' + fileName
|
||||||
|
contents = { 'h1' : '1', 'h2' : '2' }
|
||||||
|
# Verify file doesn't exist, then write private copy of file
|
||||||
|
for host in contents:
|
||||||
|
value = contents[ host ]
|
||||||
|
self.net.sendline( '%s cat %s' % ( host, path ) )
|
||||||
|
self.net.expect( 'No such file' )
|
||||||
|
self.net.expect( self.prompt )
|
||||||
|
self.net.sendline( '%s echo %s > %s' % ( host, value, path ) )
|
||||||
|
self.net.expect( self.prompt )
|
||||||
|
# Verify file contents
|
||||||
|
for host in contents:
|
||||||
|
value = contents[ host ]
|
||||||
|
self.net.sendline( '%s cat %s' % ( host, path ) )
|
||||||
|
self.net.expect( value )
|
||||||
|
self.net.expect( self.prompt )
|
||||||
|
self.net.sendline( '%s rm %s' % ( host, path ) )
|
||||||
|
self.net.expect( self.prompt )
|
||||||
|
|
||||||
# TODO: need more tests
|
# TODO: need more tests
|
||||||
|
|
||||||
@@ -54,6 +63,5 @@ class testBind( unittest.TestCase ):
|
|||||||
self.net.wait()
|
self.net.wait()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
setLogLevel( 'warning' )
|
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user