blob: 61ea6d913a92221fb88cec58d0e5d465385ef099 [file] [log] [blame]
kelvin-onlab0fd25b92015-02-04 09:42:44 -08001"""
2Description: This test is an example of a simple single node ONOS test
3with 2 different topology on one test test
4List of test cases:
5CASE1: Compile ONOS and push it to the test machine: Also starts first topology
6CASE2: Assign mastership to controller: first topology
7CASE3: Pingall
8CASE4: Creates new topology: second topology
9CASE5: Assign mastership to controller: second topology
10"""
11class MoveHostExample:
12
13 def __init__( self ):
14 self.default = ''
15
16 def CASE1( self, main ):
17 """
18 CASE1 is to compile ONOS and push it to the test machines
19
20 Startup sequence:
21 git pull
22 mvn clean install
23 onos-package
24 cell <name>
25 onos-verify-cell
26 onos-install -f
27 onos-wait-for-start
28 """
29 desc = "Testing ping all function on two topology in one test run"
30 main.log.report( desc )
31 main.case( "Setting up test environment" )
32
33 # load some vairables from the params file
34 PULLCODE = False
35 if main.params[ 'Git' ] == 'True':
36 PULLCODE = True
37 cellName = main.params[ 'ENV' ][ 'cellName' ]
38
39 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
40
41 main.step( "Applying cell variable to environment" )
42 cellResult = main.ONOSbench.setCell( cellName )
43 verifyResult = main.ONOSbench.verifyCell()
44
45 main.log.report( "Uninstalling ONOS" )
46 main.ONOSbench.onosUninstall( ONOS1Ip )
47
48 cleanInstallResult = main.TRUE
49 gitPullResult = main.TRUE
50
51 main.step( "Compiling the latest version of ONOS" )
52 if PULLCODE:
53 main.step( "Git checkout and pull master" )
54 main.ONOSbench.gitCheckout( "master" )
55 gitPullResult = main.ONOSbench.gitPull()
56
57 main.step( "Using mvn clean & install" )
58 cleanInstallResult = main.TRUE
59 if gitPullResult == main.TRUE:
60 cleanInstallResult = main.ONOSbench.cleanInstall()
61 else:
62 main.log.warn( "Did not pull new code so skipping mvn " +
63 "clean install" )
64 main.ONOSbench.getVersion( report=True )
65
66 cellResult = main.ONOSbench.setCell( cellName )
67 verifyResult = main.ONOSbench.verifyCell()
68 main.step( "Creating ONOS package" )
69 packageResult = main.ONOSbench.onosPackage()
70
71 main.step( "Installing ONOS package" )
72 onos1InstallResult = main.ONOSbench.onosInstall( options="-f",
73 node=ONOS1Ip )
74
75 main.step( "Checking if ONOS is up yet" )
76 for i in range( 2 ):
77 onos1Isup = main.ONOSbench.isup( ONOS1Ip )
78 if onos1Isup:
79 break
80 if not onos1Isup:
81 main.log.report( "ONOS1 didn't start!" )
82
83 # TODO: if it becomes an issue, we can retry this step a few times
84
85 cliResult = main.ONOScli1.startOnosCli( ONOS1Ip )
86
87 case1Result = ( cleanInstallResult and packageResult and
88 cellResult and verifyResult and
89 onos1InstallResult and
90 onos1Isup and cliResult )
91
92 utilities.assert_equals( expect=main.TRUE, actual=case1Result,
93 onpass="Test startup successful",
94 onfail="Test startup NOT successful" )
95
96 if case1Result == main.FALSE:
97 main.cleanup()
98 main.exit()
99
100 main.step( "Starting Mininet Topology..." )
101 netIsUp = main.Mininet1.startNet()
102 if netIsUp:
103 main.log.info("Mininet topology is up")
104 else:
105 main.log.info("Mininet did not start")
106
107 def CASE2( self, main ):
108 """
109 Assign mastership to controller : topology 1 has 13 switches
110 """
111 import re
112
113 main.log.report( "Assigning switches to controller" )
114 main.case( "Assigning Controller" )
115 main.step( "Assign switches to controller" )
116
117 ONOS1Ip = main.params[ 'CTRL' ][ 'ip1' ]
118 ONOS1Port = main.params[ 'CTRL' ][ 'port1' ]
119
120 for i in range( 1, 4 ):
121 main.Mininet1.assignSwController(
122 sw=str( i ),
123 ip1=ONOS1Ip,
124 port1=ONOS1Port )
125
126 mastershipCheck = main.TRUE
127 for i in range( 1, 4 ):
128 response = main.Mininet1.getSwController( "s" + str( i ) )
129 try:
130 main.log.info( str( response ) )
131 except:
132 main.log.info( repr( response ) )
133 if re.search( "tcp:" + ONOS1Ip, response ):
134 mastershipCheck = mastershipCheck and main.TRUE
135 else:
136 mastershipCheck = main.FALSE
137 if mastershipCheck == main.TRUE:
138 main.log.report( "Switch mastership assigned correctly" )
139 utilities.assert_equals(
140 expect=main.TRUE,
141 actual=mastershipCheck,
142 onpass="Switch mastership assigned correctly",
143 onfail="Switches not assigned correctly to controllers" )
144
145 def CASE3( self, main ):
146 """
147 Assign intents
148 """
149 import time
150
151 main.log.report( "Run Pingall" )
152 main.case( "Run Pingall" )
153
154 # install onos-app-fwd
155 main.log.info( "Install reactive forwarding app" )
156 main.ONOScli1.featureInstall( "onos-app-fwd" )
157
158 # REACTIVE FWD test
159 pingResult = main.FALSE
160 time1 = time.time()
161 pingResult = main.Mininet1.pingall()
162 time2 = time.time()
163 main.log.info( "Time for pingall: %2f seconds" % ( time2 - time1 ) )
164
165 # uninstall onos-app-fwd
166 # main.log.info( "Uninstall reactive forwarding app" )
167 # main.ONOScli1.featureUninstall( "onos-app-fwd" )
168
169 utilities.assert_equals( expect=main.TRUE, actual=pingResult,
170 onpass="All hosts are reachable",
171 onfail="Some pings failed" )
172
173 def CASE4( self, main):
174 """
175 Stop mininet and start a new one using different topology
176 """
177 main.log.info ("Starts new topology")
178 main.log.info( "Stopping Mininet..." )
179 main.Mininet1.stopNet()
180
181 main.log.info( "Starting Mininet..." )
182 topoFile = main.params[ 'TOPO1' ][ 'file' ]
183 args = main.params[ 'TOPO1' ][ 'args' ]
184
185 isMnUp = main.FALSE
186 isMnUp = main.Mininet1.startNet(topoFile = topoFile, args = args)
187 utilities.assert_equals(
188 expect=main.TRUE,
189 actual=isMnUp,
190 onpass="New mininet topology is up and runing",
191 onfail="New mininet topology failed to run" )
192
193
194 def CASE5( self, main):
195 """
196 Move a host from one switch to another
197 """
198
199 main.log.info("Moving a host...")
200 hostToMove = main.params['MN']['host']
201 oldSw = main.params['MN']['oldSw']
202 newSw = main.params['MN']['newSw']
203 main.log.info( "Moving " + hostToMove + " from " + oldSw + " to " + newSw)
204 print "Pingall before host is moved"
205 pingResult = main.Mininet1.pingall()
206
207 isHostMoved = main.Mininet1.moveHost(hostToMove,oldSw,newSw)
208 print "Pingall after host is moved"
209
210 case4Result = pingResult and isHostMoved
211 utilities.assert_equals( expect=main.TRUE, actual=case4Result,
212 onpass= "All hosts are reachable",
213 onfail= "Some pings failed" )
214
215