File: test_bind.py

package info (click to toggle)
mininet 2.3.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,588 kB
  • sloc: python: 11,181; ansic: 1,332; sh: 967; makefile: 87
file content (66 lines) | stat: -rwxr-xr-x 2,288 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python

"""
Tests for bind.py
"""

import unittest
from mininet.util import pexpect

class testBind( unittest.TestCase ):

    prompt = 'mininet>'

    def setUp( self ):
        self.net = pexpect.spawn( 'python -m mininet.examples.bind' )
        self.net.expect( "Private Directories: \[([\w\s,'/]+)\]" )
        self.directories = []
        # parse directories from mn output
        for d in self.net.match.group(1).split(', '):
            self.directories.append( d.strip("'") )
        self.net.expect( self.prompt )
        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 ]
        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

    def tearDown( self ):
        self.net.sendline( 'exit' )
        self.net.wait()

if __name__ == '__main__':
    unittest.main()