blob: fdd2c1f012e75de02e46b45cf7ed54e0087bd882 [file] [log] [blame]
GlennRC5147a422015-10-06 17:26:17 -07001class FUNCflow:
2
3 def __init__( self ):
4 self.default = ''
5
6 def CASE1( self, main ):
7 import time
8 import os
9 import imp
10
11 """
12 - Construct tests variables
13 - GIT ( optional )
14 - Checkout ONOS master branch
15 - Pull latest ONOS code
16 - Building ONOS ( optional )
17 - Install ONOS package
18 - Build ONOS package
19 """
20
21 main.case( "Constructing test variables and building ONOS package" )
22 main.step( "Constructing test variables" )
23 stepResult = main.FALSE
24
25 # Test variables
26 main.testOnDirectory = os.path.dirname( os.getcwd ( ) )
27 main.cellName = main.params[ 'ENV' ][ 'cellName' ]
28 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
29 gitBranch = main.params[ 'GIT' ][ 'branch' ]
30 main.dependencyPath = main.testOnDirectory + \
31 main.params[ 'DEPENDENCY' ][ 'path' ]
32 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
33 main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
34 main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
GlennRC94ed2232015-10-07 15:08:57 -070035 main.numSwitches = int( main.params[ 'TOPO' ][ 'numSwitches' ] )
36 main.numHosts = int( main.params[ 'TOPO' ][ 'numHosts' ] )
37 main.numLinks = int( main.params[ 'TOPO' ][ 'numLinks' ] )
GlennRC5147a422015-10-06 17:26:17 -070038 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
GlennRC1704d072015-10-07 18:40:45 -070039 wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ]
GlennRC5147a422015-10-06 17:26:17 -070040 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
41 gitPull = main.params[ 'GIT' ][ 'pull' ]
42 main.cellData = {} # for creating cell file
43 main.CLIs = []
44 main.ONOSip = []
45
46 main.ONOSip = main.ONOSbench.getOnosIps()
47 print main.ONOSip
48
49 # Assigning ONOS cli handles to a list
50 for i in range( 1, main.maxNodes + 1 ):
51 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
52
53 # -- INIT SECTION, ONLY RUNS ONCE -- #
54 main.startUp = imp.load_source( wrapperFile1,
55 main.dependencyPath +
56 wrapperFile1 +
57 ".py" )
58
GlennRC1704d072015-10-07 18:40:45 -070059 main.topo = imp.load_source( wrapperFile2,
60 main.dependencyPath +
61 wrapperFile2 +
62 ".py" )
63
GlennRC94ed2232015-10-07 15:08:57 -070064 copyResult = main.ONOSbench.scp( main.Mininet1,
65 main.dependencyPath+main.topology,
66 main.Mininet1.home+'/custom/',
67 direction="to" )
68
GlennRC5147a422015-10-06 17:26:17 -070069 if main.CLIs:
70 stepResult = main.TRUE
71 else:
72 main.log.error( "Did not properly created list of ONOS CLI handle" )
73 stepResult = main.FALSE
74
75 utilities.assert_equals( expect=main.TRUE,
76 actual=stepResult,
77 onpass="Successfully construct " +
78 "test variables ",
79 onfail="Failed to construct test variables" )
80
81 if gitPull == 'True':
82 main.step( "Building ONOS in " + gitBranch + " branch" )
83 onosBuildResult = main.startUp.onosBuild( main, gitBranch )
84 stepResult = onosBuildResult
85 utilities.assert_equals( expect=main.TRUE,
86 actual=stepResult,
87 onpass="Successfully compiled " +
88 "latest ONOS",
89 onfail="Failed to compile " +
90 "latest ONOS" )
91 else:
92 main.log.warn( "Did not pull new code so skipping mvn " +
93 "clean install" )
94
95 def CASE2( self, main ):
96 """
97 - Set up cell
98 - Create cell file
99 - Set cell file
100 - Verify cell file
101 - Kill ONOS process
102 - Uninstall ONOS cluster
103 - Verify ONOS start up
104 - Install ONOS cluster
105 - Connect to cli
106 """
107
108 main.numCtrls = int( main.maxNodes )
109
110 main.case( "Starting up " + str( main.numCtrls ) +
111 " node(s) ONOS cluster" )
112
113 #kill off all onos processes
114 main.log.info( "Safety check, killing all ONOS processes" +
115 " before initiating enviornment setup" )
116
117 for i in range( main.maxNodes ):
118 main.ONOSbench.onosDie( main.ONOSip[ i ] )
119
120 print "NODE COUNT = ", main.numCtrls
121
122 tempOnosIp = []
123 for i in range( main.numCtrls ):
124 tempOnosIp.append( main.ONOSip[i] )
125
126 main.ONOSbench.createCellFile( main.ONOSbench.ip_address, "temp", main.Mininet1.ip_address, main.apps, tempOnosIp )
127
128 main.step( "Apply cell to environment" )
129 cellResult = main.ONOSbench.setCell( "temp" )
130 verifyResult = main.ONOSbench.verifyCell()
131 stepResult = cellResult and verifyResult
132 utilities.assert_equals( expect=main.TRUE,
133 actual=stepResult,
134 onpass="Successfully applied cell to " + \
135 "environment",
136 onfail="Failed to apply cell to environment " )
137
138 main.step( "Creating ONOS package" )
139 packageResult = main.ONOSbench.onosPackage()
140 stepResult = packageResult
141 utilities.assert_equals( expect=main.TRUE,
142 actual=stepResult,
143 onpass="Successfully created ONOS package",
144 onfail="Failed to create ONOS package" )
145
146 time.sleep( main.startUpSleep )
147 main.step( "Uninstalling ONOS package" )
148 onosUninstallResult = main.TRUE
149 for i in range( main.numCtrls ):
150 onosUninstallResult = onosUninstallResult and \
151 main.ONOSbench.onosUninstall( nodeIp=main.ONOSip[ i ] )
152 stepResult = onosUninstallResult
153 utilities.assert_equals( expect=main.TRUE,
154 actual=stepResult,
155 onpass="Successfully uninstalled ONOS package",
156 onfail="Failed to uninstall ONOS package" )
157
158 time.sleep( main.startUpSleep )
159 main.step( "Installing ONOS package" )
160 onosInstallResult = main.TRUE
161 for i in range( main.numCtrls ):
162 onosInstallResult = onosInstallResult and \
163 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
164 stepResult = onosInstallResult
165 utilities.assert_equals( expect=main.TRUE,
166 actual=stepResult,
167 onpass="Successfully installed ONOS package",
168 onfail="Failed to install ONOS package" )
169
170 time.sleep( main.startUpSleep )
171 main.step( "Starting ONOS service" )
172 stopResult = main.TRUE
173 startResult = main.TRUE
174 onosIsUp = main.TRUE
175
176 for i in range( main.numCtrls ):
177 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
178 if onosIsUp == main.TRUE:
179 main.log.report( "ONOS instance is up and ready" )
180 else:
181 main.log.report( "ONOS instance may not be up, stop and " +
182 "start ONOS again " )
183 for i in range( main.numCtrls ):
184 stopResult = stopResult and \
185 main.ONOSbench.onosStop( main.ONOSip[ i ] )
186 for i in range( main.numCtrls ):
187 startResult = startResult and \
188 main.ONOSbench.onosStart( main.ONOSip[ i ] )
189 stepResult = onosIsUp and stopResult and startResult
190 utilities.assert_equals( expect=main.TRUE,
191 actual=stepResult,
192 onpass="ONOS service is ready",
193 onfail="ONOS service did not start properly" )
194
195 main.step( "Start ONOS cli" )
196 cliResult = main.TRUE
197 for i in range( main.numCtrls ):
198 cliResult = cliResult and \
199 main.CLIs[ i ].startOnosCli( main.ONOSip[ i ] )
200 stepResult = cliResult
201 utilities.assert_equals( expect=main.TRUE,
202 actual=stepResult,
203 onpass="Successfully start ONOS cli",
204 onfail="Failed to start ONOS cli" )
205
GlennRC68449942015-10-16 16:03:12 -0700206 def CASE10( self, main ):
207 '''
208 Start Mininet
209 '''
210 main.case( "Setup mininet and assign switches to controllers" )
211 main.step( "Setup Mininet Topology" )
212 topology = main.Mininet1.home + '/custom/' + main.topology
213 mnCmd = 'mn --custom ' + topology + ' --mac --arp'
214 stepResult1 = main.Mininet1.startNet( mnCmd=mnCmd )
215
216 utilities.assert_equals( expect=main.TRUE,
217 actual=stepResult1,
218 onpass="Successfully loaded topology",
219 onfail="Failed to load topology" )
220
221 main.step( "Assign switches to controllers" )
222 for i in range( main.numSwitches ):
223 stepResult2 = main.Mininet1.assignSwController(
224 sw="s" + str( i+1 ),
225 ip=main.ONOSip )
226 if not stepResult2:
227 break
228
229 utilities.assert_equals( expect=main.TRUE,
230 actual=stepResult2,
231 onpass="Controller assignment successfull",
232 onfail="Controller assignment failed" )
233
234 time.sleep(5)
235
236 caseResult = stepResult1 and stepResult2
237 if not caseResult:
238 main.cleanup()
239 main.exit()
240
241 def CASE11( self, main ):
GlennRC5147a422015-10-06 17:26:17 -0700242 '''
243 Compare topology
244 '''
GlennRC1704d072015-10-07 18:40:45 -0700245 import json
246
247 main.case( "Compare ONOS Topology view to Mininet topology" )
248 main.caseExplanation = "Compare topology elements between Mininet" +\
249 " and ONOS"
250
251 main.step( "Gathering topology information" )
252 # TODO: add a paramaterized sleep here
253 devicesResults = main.TRUE
254 linksResults = main.TRUE
255 hostsResults = main.TRUE
256 devices = main.topo.getAllDevices( main )
257 hosts = main.topo.getAllHosts( main )
258 ports = main.topo.getAllPorts( main )
259 links = main.topo.getAllLinks( main )
260 clusters = main.topo.getAllClusters( main )
261
262 mnSwitches = main.Mininet1.getSwitches()
263 mnLinks = main.Mininet1.getLinks()
264 mnHosts = main.Mininet1.getHosts()
265
266 main.step( "Conmparing MN topology to ONOS topology" )
267 for controller in range( main.numCtrls ):
268 controllerStr = str( controller + 1 )
269 if devices[ controller ] and ports[ controller ] and\
270 "Error" not in devices[ controller ] and\
271 "Error" not in ports[ controller ]:
272
273 currentDevicesResult = main.Mininet1.compareSwitches(
274 mnSwitches,
275 json.loads( devices[ controller ] ),
276 json.loads( ports[ controller ] ) )
277 else:
278 currentDevicesResult = main.FALSE
279 utilities.assert_equals( expect=main.TRUE,
280 actual=currentDevicesResult,
281 onpass="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700282 " Switches view is correct",
GlennRC1704d072015-10-07 18:40:45 -0700283 onfail="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700284 " Switches view is incorrect" )
GlennRC1704d072015-10-07 18:40:45 -0700285 if links[ controller ] and "Error" not in links[ controller ]:
286 currentLinksResult = main.Mininet1.compareLinks(
287 mnSwitches, mnLinks,
288 json.loads( links[ controller ] ) )
289 else:
290 currentLinksResult = main.FALSE
291 utilities.assert_equals( expect=main.TRUE,
292 actual=currentLinksResult,
293 onpass="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700294 " links view is correct",
GlennRC1704d072015-10-07 18:40:45 -0700295 onfail="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700296 " links view is incorrect" )
GlennRC1704d072015-10-07 18:40:45 -0700297
298 if hosts[ controller ] or "Error" not in hosts[ controller ]:
299 currentHostsResult = main.Mininet1.compareHosts(
300 mnHosts,
301 json.loads( hosts[ controller ] ) )
302 else:
303 currentHostsResult = main.FALSE
304 utilities.assert_equals( expect=main.TRUE,
305 actual=currentHostsResult,
306 onpass="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700307 " hosts exist in Mininet",
GlennRC1704d072015-10-07 18:40:45 -0700308 onfail="ONOS" + controllerStr +
GlennRC68449942015-10-16 16:03:12 -0700309 " hosts don't match Mininet")
GlennRCa5391372015-10-14 17:28:15 -0700310
GlennRC68449942015-10-16 16:03:12 -0700311
312
313 def CASE1000( self, main ):
314 '''
315 Add flows
316 '''
317
318 main.step("Add flows through rest")
319
320 deviceId = main.params['MININET']['deviceId']
321 host1_mac = main.params['MININET']['hostMac1']
322 host2_mac = main.params['MININET']['hostMac2']
323
324 # Add flows that connects host1 to host 2
325 stepResult = main.ONOSrest.addFlow( deviceId=deviceId,
326 egressPort=2,
327 ingressPort=1,
328 ethSrc=host1_mac,
329 ethDst=host2_mac)
330
331 stepResult = stepResult and main.ONOSrest.addFlow( deviceId=deviceId,
332 egressPort=1,
333 ingressPort=2,
334 ethSrc=host2_mac,
335 ethDst=host1_mac)
336
GlennRCa5391372015-10-14 17:28:15 -0700337 utilities.assert_equals( expect=main.TRUE,
338 actual=stepResult,
GlennRC68449942015-10-16 16:03:12 -0700339 onpass="Successfully added flows",
340 onfail="Failed add flows" )
GlennRCa5391372015-10-14 17:28:15 -0700341
GlennRC68449942015-10-16 16:03:12 -0700342 def CASE2000( self, main ):
343 '''
344 Check flows are ADDED
345 '''
346 import json
347 main.step("Check flows are in the ADDED state")
348 main.log.info("Check only the flows added through REST")
GlennRC5147a422015-10-06 17:26:17 -0700349
GlennRC68449942015-10-16 16:03:12 -0700350 flows = json.loads( main.ONOSrest.flows() )
351
352 stepResult = main.TRUE
353 for f in flows:
354 if "rest" in f.get("appId"):
355 if "ADDED" in f.get("state"):
356 stepResult = stepResult and main.ONOSrest.removeFlow( deviceId, flowId )
357
358 utilities.assert_equals( expect=main.TRUE,
359 actual=stepResult,
360 onpass="All flows are in the ADDED state",
361 onfail="All flows are in the ADDED state" )
362
363 def CASE3000( self, main ):
364 '''
365 Delete flows that were added through REST
366 '''
367 import json
368 main.step("Remove flows")
369 main.log.info("Remove the flows that were added through rest")
370
371 flows = json.loads( main.ONOSrest.flows() )
372
373 stepResult = main.TRUE
374 for f in flows:
375 if "rest" in f.get("appId"):
376 flowId = f.get("id")
377 deviceId = f.get("deviceId")
378 stepResult = stepResult and main.ONOSrest.removeFlow( deviceId, flowId )
379
380 utilities.assert_equals( expect=main.TRUE,
381 actual=stepResult,
382 onpass="Successfully removed all rest flows",
383 onfail="Failed to remove rest flows" )
384
385 def CASE100( self, main ):
GlennRC5147a422015-10-06 17:26:17 -0700386 '''
387 Report errors/warnings/exceptions
388 '''
389 main.log.info("Error report: \n" )
390 main.ONOSbench.logReport( main.ONOSip[ 0 ],
391 [ "INFO",
392 "FOLLOWER",
393 "WARN",
394 "flow",
395 "ERROR",
396 "Except" ],
GlennRC68449942015-10-16 16:03:12 -0700397 "s" )
GlennRC5147a422015-10-06 17:26:17 -0700398