8 from mininet.util import pexpect
10 class testBind( unittest.TestCase ):
15 self.net = pexpect.spawn( 'python -m mininet.examples.bind' )
16 self.net.expect( "Private Directories: \[([\w\s,'/]+)\]" )
18 # parse directories from mn output
19 for d in self.net.match.group(1).split(', '):
20 self.directories.append( d.strip("'") )
21 self.net.expect( self.prompt )
22 self.assertTrue( len( self.directories ) > 0 )
24 def testCreateFile( self ):
25 "Create a file, a.txt, in the first private directory and verify"
27 directory = self.directories[ 0 ]
28 path = directory + '/' + fileName
29 self.net.sendline( 'h1 touch %s; ls %s' % ( path, directory ) )
30 index = self.net.expect( [ fileName, self.prompt ] )
31 self.assertTrue( index == 0 )
32 self.net.expect( self.prompt )
33 self.net.sendline( 'h1 rm %s' % path )
34 self.net.expect( self.prompt )
36 def testIsolation( self ):
37 "Create a file in two hosts and verify that contents are different"
39 directory = self.directories[ 0 ]
40 path = directory + '/' + fileName
41 contents = { 'h1' : '1', 'h2' : '2' }
42 # Verify file doesn't exist, then write private copy of file
44 value = contents[ host ]
45 self.net.sendline( '%s cat %s' % ( host, path ) )
46 self.net.expect( 'No such file' )
47 self.net.expect( self.prompt )
48 self.net.sendline( '%s echo %s > %s' % ( host, value, path ) )
49 self.net.expect( self.prompt )
50 # Verify file contents
52 value = contents[ host ]
53 self.net.sendline( '%s cat %s' % ( host, path ) )
54 self.net.expect( value )
55 self.net.expect( self.prompt )
56 self.net.sendline( '%s rm %s' % ( host, path ) )
57 self.net.expect( self.prompt )
59 # TODO: need more tests
62 self.net.sendline( 'exit' )
65 if __name__ == '__main__':