diff --git a/examples/test/test_bind.py b/examples/test/test_bind.py index cc27ca9e8de8bd8e8fb45adc534300df179fd725..d8df0b3080caa9ac808b36043820557103e86271 100755 --- a/examples/test/test_bind.py +++ b/examples/test/test_bind.py @@ -1,35 +1,16 @@ #!/usr/bin/env python -"""TEST""" +""" +Tests for bind.py +""" import unittest import pexpect -from time import sleep -from mininet.log import setLogLevel -from mininet.clean import cleanup, sh class testBind( unittest.TestCase ): - "Test ping with single switch topology (common code)." 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 ): self.net = pexpect.spawn( 'python -m mininet.examples.bind' ) self.net.expect( "Private Directories: \[([\w\s,'/]+)\]" ) @@ -41,11 +22,39 @@ def setUp( self ): self.assertTrue( len( self.directories ) > 0 ) def testCreateFile( self ): + "Create a file, a.txt, in the first private directory and verify" fileName = 'a.txt' 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 ] ) 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 @@ -54,6 +63,5 @@ def tearDown( self ): self.net.wait() if __name__ == '__main__': - setLogLevel( 'warning' ) unittest.main()