blob: 9d8e0d6dd201c61aeadf1d74f6b76717400c08b2 [file] [log] [blame]
You Wangdb927a52016-02-26 11:03:28 -08001"""
2CHOTestMonkey class
3Author: you@onlab.us
4"""
5
6import sys
7import os
8import re
9import time
10import json
11import itertools
12
13class CHOTestMonkey:
14
15 def __init__( self ):
16 self.default = ''
17
18 def CASE0( self, main ):
19 """
20 Startup sequence:
21 apply cell <name>
22 git pull
23 mvn clean install
24 onos-package
25 onos-verify-cell
26 onos-uninstall
27 onos-install
28 onos-start-cli
29 Set IPv6 cfg parameters for Neighbor Discovery
30 start event scheduler
31 start event listener
32 """
33 import time
34 from threading import Lock, Condition
You Wang221db322016-06-03 15:45:52 -070035 from core.graph import Graph
You Wangdb927a52016-02-26 11:03:28 -080036 from tests.CHOTestMonkey.dependencies.elements.ONOSElement import Controller
37 from tests.CHOTestMonkey.dependencies.EventGenerator import EventGenerator
38 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduler
39
40 gitPull = main.params[ 'TEST' ][ 'autoPull' ]
41 onosPackage = main.params[ 'TEST' ][ 'package' ]
42 gitBranch = main.params[ 'TEST' ][ 'branch' ]
43 karafTimeout = main.params[ 'TEST' ][ 'karafCliTimeout' ]
44 main.enableIPv6 = main.params[ 'TEST' ][ 'IPv6' ]
45 main.enableIPv6 = True if main.enableIPv6 == "on" else False
46 main.caseSleep = int( main.params[ 'TEST' ][ 'caseSleep' ] )
You Wang2d32ef42017-03-03 14:09:44 -080047 main.numCtrls = int( main.params[ 'TEST' ][ 'numCtrl' ] )
48 main.ONOSip = []
49 main.AllONOSip = main.ONOSbench.getOnosIps()
You Wangdb927a52016-02-26 11:03:28 -080050 main.controllers = []
You Wang2d32ef42017-03-03 14:09:44 -080051 for i in range( 1, main.numCtrls + 1 ):
52 main.ONOSip.append( main.AllONOSip[ i-1 ] )
You Wangdb927a52016-02-26 11:03:28 -080053 newController = Controller( i )
54 newController.setCLI( getattr( main, 'ONOScli' + str( i ) ) )
55 main.controllers.append( newController )
56 main.devices = []
57 main.links = []
58 main.hosts = []
59 main.intents = []
60 main.enabledEvents = {}
61 for eventName in main.params[ 'EVENT' ].keys():
62 if main.params[ 'EVENT' ][ eventName ][ 'status' ] == 'on':
63 main.enabledEvents[ int( main.params[ 'EVENT' ][ eventName ][ 'typeIndex' ] ) ] = eventName
64 print main.enabledEvents
You Wang221db322016-06-03 15:45:52 -070065 main.graph = Graph()
You Wangdb927a52016-02-26 11:03:28 -080066 main.eventScheduler = EventScheduler()
67 main.eventGenerator = EventGenerator()
68 main.variableLock = Lock()
69 main.mininetLock = Lock()
70 main.ONOSbenchLock = Lock()
71 main.threadID = 0
72 main.eventID = 0
73 main.caseResult = main.TRUE
74
75 main.case( "Set up test environment" )
76 main.log.report( "Set up test environment" )
77 main.log.report( "_______________________" )
78
79 main.step( "Apply Cell environment for ONOS" )
80 if ( main.onoscell ):
81 cellName = main.onoscell
82 cellResult = main.ONOSbench.setCell( cellName )
83 utilities.assert_equals( expect=main.TRUE,
84 actual=cellResult,
85 onpass="Test step PASS",
86 onfail="Test step FAIL" )
87 else:
88 main.log.error( "Please provide onoscell option at TestON CLI to run CHO tests" )
89 main.log.error( "Example: ~/TestON/bin/cli.py run CHOTestMonkey onoscell <cellName>" )
90 main.cleanup()
91 main.exit()
92
93 main.step( "Git checkout and pull " + gitBranch )
94 if gitPull == 'on':
95 checkoutResult = main.ONOSbench.gitCheckout( gitBranch )
96 pullResult = main.ONOSbench.gitPull()
97 cpResult = ( checkoutResult and pullResult )
98 else:
99 checkoutResult = main.TRUE
100 pullResult = main.TRUE
101 main.log.info( "Skipped git checkout and pull as they are disabled in params file" )
102 cpResult = ( checkoutResult and pullResult )
103 utilities.assert_equals( expect=main.TRUE,
104 actual=cpResult,
105 onpass="Test step PASS",
106 onfail="Test step FAIL" )
107
108 main.step( "mvn clean & install" )
109 if gitPull == 'on':
110 mvnResult = main.ONOSbench.cleanInstall()
111 else:
112 mvnResult = main.TRUE
113 main.log.info( "Skipped mvn clean install as it is disabled in params file" )
114 utilities.assert_equals( expect=main.TRUE,
115 actual=mvnResult,
116 onpass="Test step PASS",
117 onfail="Test step FAIL" )
118 main.ONOSbench.getVersion( report=True )
119
120 main.step( "Create ONOS package" )
121 if onosPackage == 'on':
Jon Hallbd60ea02016-08-23 10:03:59 -0700122 packageResult = main.ONOSbench.buckBuild()
You Wangdb927a52016-02-26 11:03:28 -0800123 else:
124 packageResult = main.TRUE
125 main.log.info( "Skipped onos package as it is disabled in params file" )
126 utilities.assert_equals( expect=main.TRUE,
127 actual=packageResult,
128 onpass="Test step PASS",
129 onfail="Test step FAIL" )
130
131 main.step( "Uninstall ONOS package on all Nodes" )
132 uninstallResult = main.TRUE
You Wang2d32ef42017-03-03 14:09:44 -0800133 for i in range( main.numCtrls ):
134 main.log.info( "Uninstalling package on ONOS Node IP: " + main.ONOSip[i] )
135 uResult = main.ONOSbench.onosUninstall( main.ONOSip[i] )
You Wangdb927a52016-02-26 11:03:28 -0800136 utilities.assert_equals( expect=main.TRUE,
137 actual=uResult,
138 onpass="Test step PASS",
139 onfail="Test step FAIL" )
140 uninstallResult = ( uninstallResult and uResult )
141
142 main.step( "Install ONOS package on all Nodes" )
143 installResult = main.TRUE
You Wang2d32ef42017-03-03 14:09:44 -0800144 for i in range( main.numCtrls ):
145 main.log.info( "Installing package on ONOS Node IP: " + main.ONOSip[i] )
146 iResult = main.ONOSbench.onosInstall( node=main.ONOSip[i] )
You Wangdb927a52016-02-26 11:03:28 -0800147 utilities.assert_equals( expect=main.TRUE,
148 actual=iResult,
149 onpass="Test step PASS",
150 onfail="Test step FAIL" )
151 installResult = ( installResult and iResult )
152
Chiyu Chengef109502016-11-21 15:51:38 -0800153 main.step( "Set up ONOS secure SSH" )
154 secureSshResult = main.TRUE
You Wang2d32ef42017-03-03 14:09:44 -0800155 for i in range( main.numCtrls ):
156 secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=main.ONOSip[i] )
Chiyu Chengef109502016-11-21 15:51:38 -0800157 utilities.assert_equals( expect=main.TRUE, actual=secureSshResult,
158 onpass="Test step PASS",
159 onfail="Test step FAIL" )
160
You Wang0357c432017-01-09 16:13:33 -0800161 time.sleep( 5 )
162 main.step( "Starting ONOS service" )
163 stopResult = main.TRUE
164 startResult = main.TRUE
165 onosIsUp = main.TRUE
166 for i in range( main.numCtrls ):
167 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
168 if onosIsUp == main.TRUE:
169 main.log.report( "ONOS instance is up and ready" )
170 else:
171 main.log.report( "ONOS instance may not be up, stop and " +
172 "start ONOS again " )
173 for i in range( main.numCtrls ):
174 stopResult = stopResult and \
175 main.ONOSbench.onosStop( main.ONOSip[ i ] )
176 for i in range( main.numCtrls ):
177 startResult = startResult and \
178 main.ONOSbench.onosStart( main.ONOSip[ i ] )
179 stepResult = onosIsUp and stopResult and startResult
180 utilities.assert_equals( expect=main.TRUE,
181 actual=stepResult,
182 onpass="ONOS service is ready",
183 onfail="ONOS service did not start properly" )
184
You Wangdb927a52016-02-26 11:03:28 -0800185 main.step( "Start ONOS CLI on all nodes" )
186 cliResult = main.TRUE
187 startCliResult = main.TRUE
188 pool = []
189 for controller in main.controllers:
190 t = main.Thread( target=controller.startCLI,
191 threadID=main.threadID,
192 name="startOnosCli",
193 args=[ ] )
194 pool.append(t)
195 t.start()
196 main.threadID = main.threadID + 1
197 for t in pool:
198 t.join()
199 startCliResult = startCliResult and t.result
200 if not startCliResult:
201 main.log.info( "ONOS CLI did not start up properly" )
202 main.cleanup()
203 main.exit()
204 else:
205 main.log.info( "Successful CLI startup" )
206 startCliResult = main.TRUE
207 utilities.assert_equals( expect=main.TRUE,
208 actual=startCliResult,
209 onpass="Test step PASS",
210 onfail="Test step FAIL" )
211
212 main.step( "Set IPv6 cfg parameters for Neighbor Discovery" )
213 setIPv6CfgSleep = int( main.params[ 'TEST' ][ 'setIPv6CfgSleep' ] )
214 if main.enableIPv6:
215 time.sleep( setIPv6CfgSleep )
You Wang5f4f36e2016-09-21 15:30:30 -0700216 cfgResult1 = main.controllers[ 0 ].CLI.setCfg( "org.onosproject.incubator.net.neighbour.impl.NeighbourResolutionManager",
217 "ndpEnabled",
You Wangdb927a52016-02-26 11:03:28 -0800218 "true" )
219 time.sleep( setIPv6CfgSleep )
220 cfgResult2 = main.controllers[ 0 ].CLI.setCfg( "org.onosproject.provider.host.impl.HostLocationProvider",
You Wang092d9b22016-11-22 13:38:01 -0800221 "useIpv6ND",
You Wangdb927a52016-02-26 11:03:28 -0800222 "true" )
223 else:
224 main.log.info( "Skipped setting IPv6 cfg parameters as it is disabled in params file" )
225 cfgResult1 = main.TRUE
226 cfgResult2 = main.TRUE
227 cfgResult = cfgResult1 and cfgResult2
228 utilities.assert_equals( expect=main.TRUE,
229 actual=cfgResult,
230 onpass="ipv6NeighborDiscovery cfg is set to true",
231 onfail="Failed to cfg set ipv6NeighborDiscovery" )
232
233 main.step( "Start a thread for the scheduler" )
234 t = main.Thread( target=main.eventScheduler.startScheduler,
235 threadID=main.threadID,
236 name="startScheduler",
237 args=[] )
238 t.start()
239 stepResult = main.TRUE
240 with main.variableLock:
241 main.threadID = main.threadID + 1
242
243 utilities.assert_equals( expect=main.TRUE,
244 actual=stepResult,
245 onpass="Test step PASS",
246 onfail="Test step FAIL" )
247
248 main.step( "Start a thread to listen to and handle network, ONOS and application events" )
249 t = main.Thread( target=main.eventGenerator.startListener,
250 threadID=main.threadID,
251 name="startListener",
252 args=[] )
253 t.start()
254 with main.variableLock:
255 main.threadID = main.threadID + 1
256
257 caseResult = installResult and uninstallResult and startCliResult and cfgResult
258 utilities.assert_equals( expect=main.TRUE,
259 actual=caseResult,
260 onpass="Set up test environment PASS",
261 onfail="Set up test environment FAIL" )
262
263 def CASE1( self, main ):
264 """
265 Load Mininet topology and balances all switches
266 """
267 import re
268 import time
269 import copy
270
271 main.topoIndex = "topo" + str ( main.params[ 'TEST' ][ 'topo' ] )
272
273 main.log.report( "Load Mininet topology and Balance all Mininet switches across controllers" )
274 main.log.report( "________________________________________________________________________" )
275 main.case( "Assign and Balance all Mininet switches across controllers" )
276
277 main.step( "Start Mininet topology" )
278 newTopo = main.params[ 'TOPO' ][ main.topoIndex ][ 'fileName' ]
279 mininetDir = main.Mininet1.home + "/custom/"
280 topoPath = main.testDir + "/" + main.TEST + "/dependencies/topologies/" + newTopo
281 main.ONOSbench.secureCopy( main.Mininet1.user_name, main.Mininet1.ip_address, topoPath, mininetDir, direction="to" )
282 topoPath = mininetDir + newTopo
283 startStatus = main.Mininet1.startNet( topoFile = topoPath )
284 main.mininetSwitches = main.Mininet1.getSwitches()
285 main.mininetHosts = main.Mininet1.getHosts()
You Wang55503a32016-06-27 15:11:40 -0700286 main.mininetLinks = main.Mininet1.getLinks( timeout=60 )
You Wangdb927a52016-02-26 11:03:28 -0800287 utilities.assert_equals( expect=main.TRUE,
288 actual=startStatus,
289 onpass="Start Mininet topology test PASS",
290 onfail="Start Mininet topology test FAIL" )
291
292 main.step( "Assign switches to controllers" )
293 switchMastership = main.TRUE
294 for switchName in main.mininetSwitches.keys():
You Wang2d32ef42017-03-03 14:09:44 -0800295 main.Mininet1.assignSwController( sw=switchName, ip=main.ONOSip )
You Wangdb927a52016-02-26 11:03:28 -0800296 response = main.Mininet1.getSwController( switchName )
297 print( "Response is " + str( response ) )
You Wang2d32ef42017-03-03 14:09:44 -0800298 if re.search( "tcp:" + main.ONOSip[ 0 ], response ):
You Wangdb927a52016-02-26 11:03:28 -0800299 switchMastership = switchMastership and main.TRUE
300 else:
301 switchMastership = main.FALSE
302 utilities.assert_equals( expect=main.TRUE,
303 actual=switchMastership,
304 onpass="Assign switches to controllers test PASS",
305 onfail="Assign switches to controllers test FAIL" )
306 # Waiting here to make sure topology converges across all nodes
307 sleep = int( main.params[ 'TEST' ][ 'loadTopoSleep' ] )
308 time.sleep( sleep )
309
310 main.step( "Balance devices across controllers" )
311 balanceResult = main.ONOScli1.balanceMasters()
312 # giving some breathing time for ONOS to complete re-balance
313 time.sleep( sleep )
314
315 caseResult = ( startStatus and switchMastership and balanceResult )
316 utilities.assert_equals( expect=main.TRUE,
317 actual=caseResult,
318 onpass="Starting new Att topology test PASS",
319 onfail="Starting new Att topology test FAIL" )
320
321 def CASE2( self, main ):
322 """
323 Collect and store device and link data from ONOS
324 """
325 import json
326 from tests.CHOTestMonkey.dependencies.elements.NetworkElement import Device, Link
327
328 main.log.report( "Collect and Store topology details from ONOS" )
329 main.log.report( "____________________________________________________________________" )
330 main.case( "Collect and Store Topology Details from ONOS" )
331 topoResult = main.TRUE
332 topologyOutput = main.ONOScli1.topology()
333 topologyResult = main.ONOScli1.getTopology( topologyOutput )
334 ONOSDeviceNum = int( topologyResult[ 'devices' ] )
335 ONOSLinkNum = int( topologyResult[ 'links' ] )
336 mininetSwitchNum = len( main.mininetSwitches )
337 mininetLinkNum = ( len( main.mininetLinks ) - len( main.mininetHosts ) ) * 2
338 if mininetSwitchNum == ONOSDeviceNum and mininetLinkNum == ONOSLinkNum:
339 main.step( "Collect and store device data" )
340 stepResult = main.TRUE
341 dpidToName = {}
342 for key, value in main.mininetSwitches.items():
343 dpidToName[ 'of:' + str( value[ 'dpid' ] ) ] = key
344 devicesRaw = main.ONOScli1.devices()
345 devices = json.loads( devicesRaw )
346 deviceInitIndex = 0
347 for device in devices:
348 name = dpidToName[ device[ 'id' ] ]
349 newDevice = Device( deviceInitIndex, name, device[ 'id' ] )
350 print newDevice
351 main.devices.append( newDevice )
352 deviceInitIndex += 1
353 utilities.assert_equals( expect=main.TRUE,
354 actual=stepResult,
355 onpass="Successfully collected and stored device data",
356 onfail="Failed to collect and store device data" )
357
358 main.step( "Collect and store link data" )
359 stepResult = main.TRUE
360 linksRaw = main.ONOScli1.links()
361 links = json.loads( linksRaw )
362 linkInitIndex = 0
363 for link in links:
364 for device in main.devices:
365 if device.dpid == link[ 'src' ][ 'device' ]:
366 deviceA = device
367 elif device.dpid == link[ 'dst' ][ 'device' ]:
368 deviceB = device
369 assert deviceA != None and deviceB != None
370 newLink = Link( linkInitIndex, deviceA, link[ 'src' ][ 'port' ], deviceB, link[ 'dst' ][ 'port' ] )
371 print newLink
372 main.links.append( newLink )
373 linkInitIndex += 1
374 # Set backward links and outgoing links of devices
375 for linkA in main.links:
376 linkA.deviceA.outgoingLinks.append( linkA )
377 if linkA.backwardLink != None:
378 continue
379 for linkB in main.links:
380 if linkB.backwardLink != None:
381 continue
382 if linkA.deviceA == linkB.deviceB and\
383 linkA.deviceB == linkB.deviceA and\
384 linkA.portA == linkB.portB and\
385 linkA.portB == linkB.portA:
386 linkA.setBackwardLink( linkB )
387 linkB.setBackwardLink( linkA )
388 utilities.assert_equals( expect=main.TRUE,
389 actual=stepResult,
390 onpass="Successfully collected and stored link data",
391 onfail="Failed to collect and store link data" )
392 else:
393 main.log.info( "Devices (expected): %s, Links (expected): %s" % ( mininetSwitchNum, mininetLinkNum ) )
394 main.log.info( "Devices (actual): %s, Links (actual): %s" % ( ONOSDeviceNum, ONOSLinkNum ) )
395 topoResult = main.FALSE
396
397 caseResult = topoResult
398 utilities.assert_equals( expect=main.TRUE,
399 actual=caseResult,
400 onpass="Saving ONOS topology data test PASS",
401 onfail="Saving ONOS topology data test FAIL" )
402
403 if not caseResult:
404 main.log.info("Topology does not match, exiting test...")
405 main.cleanup()
406 main.exit()
407
408 def CASE3( self, main ):
409 """
410 Collect and store host data from ONOS
411 """
412 import json
413 from tests.CHOTestMonkey.dependencies.elements.NetworkElement import Host
414
415 main.log.report( "Collect and store host adta from ONOS" )
416 main.log.report( "______________________________________________" )
417 main.case( "Use fwd app and pingall to discover all the hosts, then collect and store host data" )
418
419 main.step( "Enable Reactive forwarding" )
420 appResult = main.controllers[ 0 ].CLI.activateApp( "org.onosproject.fwd" )
421 cfgResult1 = main.TRUE
422 cfgResult2 = main.TRUE
423 if main.enableIPv6:
424 cfgResult1 = main.controllers[ 0 ].CLI.setCfg( "org.onosproject.fwd.ReactiveForwarding", "ipv6Forwarding", "true" )
425 cfgResult2 = main.controllers[ 0 ].CLI.setCfg( "org.onosproject.fwd.ReactiveForwarding", "matchIpv6Address", "true" )
426 stepResult = appResult and cfgResult1 and cfgResult2
427 utilities.assert_equals( expect=main.TRUE,
428 actual=stepResult,
429 onpass="Successfully enabled reactive forwarding",
430 onfail="Failed to enable reactive forwarding" )
431
432 main.step( "Discover hosts using pingall" )
433 stepResult = main.TRUE
434 main.Mininet1.pingall()
435 if main.enableIPv6:
436 ping6Result = main.Mininet1.pingall( protocol="IPv6" )
437 hosts = main.controllers[ 0 ].CLI.hosts()
438 hosts = json.loads( hosts )
439 if not len( hosts ) == len( main.mininetHosts ):
440 stepResult = main.FALSE
441 utilities.assert_equals( expect=main.TRUE,
442 actual=stepResult,
443 onpass="Host discovery PASS",
444 onfail="Host discovery FAIL" )
445 if not stepResult:
446 main.log.debug( hosts )
447 main.cleanup()
448 main.exit()
449
450 main.step( "Disable Reactive forwarding" )
451 appResult = main.controllers[ 0 ].CLI.deactivateApp( "org.onosproject.fwd" )
452 stepResult = appResult
453 utilities.assert_equals( expect=main.TRUE,
454 actual=stepResult,
455 onpass="Successfully deactivated fwd app",
456 onfail="Failed to deactivate fwd app" )
457
458 main.step( "Collect and store host data" )
459 stepResult = main.TRUE
460 macToName = {}
461 for key, value in main.mininetHosts.items():
462 macToName[ value[ 'interfaces' ][ 0 ][ 'mac' ].upper() ] = key
463 dpidToDevice = {}
464 for device in main.devices:
465 dpidToDevice[ device.dpid ] = device
466 hostInitIndex = 0
467 for host in hosts:
468 name = macToName[ host[ 'mac' ] ]
469 dpid = host[ 'location' ][ 'elementId' ]
470 device = dpidToDevice[ dpid ]
471 newHost = Host( hostInitIndex,
472 name, host[ 'id' ], host[ 'mac' ],
473 device, host[ 'location' ][ 'port' ],
474 host[ 'vlan' ], host[ 'ipAddresses' ] )
475 print newHost
476 main.hosts.append( newHost )
477 main.devices[ device.index ].hosts.append( newHost )
478 hostInitIndex += 1
479 utilities.assert_equals( expect=main.TRUE,
480 actual=stepResult,
481 onpass="Successfully collected and stored host data",
482 onfail="Failed to collect and store host data" )
483
484 main.step( "Create one host component for each host and then start host cli" )
485 for host in main.hosts:
486 main.Mininet1.createHostComponent( host.name )
487 hostHandle = getattr( main, host.name )
488 main.log.info( "Starting CLI on host " + str( host.name ) )
489 startCLIResult = hostHandle.startHostCli()
490 host.setHandle( hostHandle )
491 stepResult = startCLIResult
492 utilities.assert_equals( expect=main.TRUE,
493 actual=startCLIResult,
494 onpass="Host CLI started",
495 onfail="Failed to start host CLI" )
496
497 def CASE10( self, main ):
498 """
499 Run all enabled checks
500 """
501 import time
502 from tests.CHOTestMonkey.dependencies.events.Event import EventType
503 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
504
505 main.log.report( "Run all enabled checks" )
506 main.log.report( "__________________________________________________" )
507 main.case( "Run all enabled checks" )
508 main.step( "Run all enabled checks" )
509 main.caseResult = main.TRUE
510 main.eventGenerator.triggerEvent( EventType().CHECK_ALL, EventScheduleMethod().RUN_BLOCK )
511 # Wait for the scheduler to become idle before going to the next testcase
512 with main.eventScheduler.idleCondition:
513 while not main.eventScheduler.isIdle():
514 main.eventScheduler.idleCondition.wait()
515 utilities.assert_equals( expect=main.TRUE,
516 actual=main.caseResult,
517 onpass="All enabled checks passed",
518 onfail="Not all enabled checks passed" )
519 time.sleep( main.caseSleep )
520
521 def CASE20( self, main ):
522 """
523 Bring down/up links and check topology and ping
524 """
525 import time
526 from tests.CHOTestMonkey.dependencies.events.Event import EventType
527 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
528
529 main.log.report( "Bring down/up links and check topology and ping" )
530 main.log.report( "__________________________________________________" )
531 main.case( "Bring down/up links and check topology and ping" )
532 main.step( "Bring down/up links and check topology and ping" )
533 main.caseResult = main.TRUE
534 linkToggleNum = int( main.params[ 'CASE20' ][ 'linkToggleNum' ] )
535 linkDownUpInterval = int( main.params[ 'CASE20' ][ 'linkDownUpInterval' ] )
536 for i in range( 0, linkToggleNum ):
537 main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_RANDOM_TOGGLE, EventScheduleMethod().RUN_BLOCK, linkDownUpInterval )
538 with main.eventScheduler.idleCondition:
539 while not main.eventScheduler.isIdle():
540 main.eventScheduler.idleCondition.wait()
541 utilities.assert_equals( expect=main.TRUE,
542 actual=main.caseResult,
543 onpass="Toggle network links test passed",
544 onfail="Toggle network links test failed" )
545 time.sleep( main.caseSleep )
546
547 def CASE21( self, main ):
548 """
549 Bring down/up a group of links and check topology and ping
550 """
551 import time
552 from tests.CHOTestMonkey.dependencies.events.Event import EventType
553 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
554
555 main.log.report( "Bring down/up a group of links and check topology and ping" )
556 main.log.report( "__________________________________________________" )
557 main.case( "Bring down/up a group of links and check topology and ping" )
558 main.step( "Bring down/up a group of links and check topology and ping" )
559 main.caseResult = main.TRUE
560 linkGroupSize = int( main.params[ 'CASE21' ][ 'linkGroupSize' ] )
561 linkDownDownInterval = int( main.params[ 'CASE21' ][ 'linkDownDownInterval' ] )
562 linkDownUpInterval = int( main.params[ 'CASE21' ][ 'linkDownUpInterval' ] )
563 main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_GROUP_RANDOM_TOGGLE, EventScheduleMethod().RUN_BLOCK, linkGroupSize, linkDownDownInterval, linkDownUpInterval )
564 with main.eventScheduler.idleCondition:
565 while not main.eventScheduler.isIdle():
566 main.eventScheduler.idleCondition.wait()
567 utilities.assert_equals( expect=main.TRUE,
568 actual=main.caseResult,
569 onpass="Toggle network link group test passed",
570 onfail="Toggle network link group test failed" )
571 time.sleep( main.caseSleep )
572
573 def CASE30( self, main ):
574 """
575 Install host intents and check intent states and ping
576 """
577 import time
578 from tests.CHOTestMonkey.dependencies.events.Event import EventType
579 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
580
581 main.log.report( "Install host intents and check intent states and ping" )
582 main.log.report( "__________________________________________________" )
583 main.case( "Install host intents and check intent states and ping" )
584 main.step( "Install host intents and check intent states and ping" )
585 main.caseResult = main.TRUE
586 main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_ADD_ALL, EventScheduleMethod().RUN_BLOCK )
587 with main.eventScheduler.idleCondition:
588 while not main.eventScheduler.isIdle():
589 main.eventScheduler.idleCondition.wait()
590 utilities.assert_equals( expect=main.TRUE,
591 actual=main.caseResult,
592 onpass="Install host intents test passed",
593 onfail="Install host intents test failed" )
594 time.sleep( main.caseSleep )
595
596 def CASE31( self, main ):
597 """
598 Uninstall host intents and check intent states and ping
599 """
600 import time
601 from tests.CHOTestMonkey.dependencies.events.Event import EventType
602 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
603
604 main.log.report( "Uninstall host intents and check intent states and ping" )
605 main.log.report( "__________________________________________________" )
606 main.case( "Uninstall host intents and check intent states and ping" )
607 main.step( "Uninstall host intents and check intent states and ping" )
608 main.caseResult = main.TRUE
609 main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_DEL_ALL, EventScheduleMethod().RUN_BLOCK )
610 with main.eventScheduler.idleCondition:
611 while not main.eventScheduler.isIdle():
612 main.eventScheduler.idleCondition.wait()
613 utilities.assert_equals( expect=main.TRUE,
614 actual=main.caseResult,
615 onpass="Uninstall host intents test passed",
616 onfail="Uninstall host intents test failed" )
617 time.sleep( main.caseSleep )
618
619 def CASE32( self, main ):
620 """
621 Install point intents and check intent states and ping
622 """
623 import time
624 from tests.CHOTestMonkey.dependencies.events.Event import EventType
625 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
626
627 main.log.report( "Install point intents and check intent states and ping" )
628 main.log.report( "__________________________________________________" )
629 main.case( "Install point intents and check intent states and ping" )
630 main.step( "Install point intents and check intent states and ping" )
631 main.caseResult = main.TRUE
632 main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_ADD_ALL, EventScheduleMethod().RUN_BLOCK )
633 with main.eventScheduler.idleCondition:
634 while not main.eventScheduler.isIdle():
635 main.eventScheduler.idleCondition.wait()
636 utilities.assert_equals( expect=main.TRUE,
637 actual=main.caseResult,
638 onpass="Install point intents test passed",
639 onfail="Install point intents test failed" )
640 time.sleep( main.caseSleep )
641
642 def CASE33( self, main ):
643 """
644 Uninstall point intents and check intent states and ping
645 """
646 import time
647 from tests.CHOTestMonkey.dependencies.events.Event import EventType
648 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
649
650 main.log.report( "Uninstall point intents and check intent states and ping" )
651 main.log.report( "__________________________________________________" )
652 main.case( "Uninstall point intents and check intent states and ping" )
653 main.step( "Uninstall point intents and check intent states and ping" )
654 main.caseResult = main.TRUE
655 main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_DEL_ALL, EventScheduleMethod().RUN_BLOCK )
656 with main.eventScheduler.idleCondition:
657 while not main.eventScheduler.isIdle():
658 main.eventScheduler.idleCondition.wait()
659 utilities.assert_equals( expect=main.TRUE,
660 actual=main.caseResult,
661 onpass="Uninstall point intents test passed",
662 onfail="Uninstall point intents test failed" )
663 time.sleep( main.caseSleep )
664
665 def CASE40( self, main ):
666 """
667 Randomly bring down one ONOS node
668 """
669 import time
670 import random
671 from tests.CHOTestMonkey.dependencies.events.Event import EventType
672 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
673
674 main.log.report( "Randomly bring down one ONOS node" )
675 main.log.report( "__________________________________________________" )
676 main.case( "Randomly bring down one ONOS node" )
677 main.step( "Randomly bring down one ONOS node" )
678 main.caseResult = main.TRUE
679 availableControllers = []
680 for controller in main.controllers:
681 if controller.isUp():
682 availableControllers.append( controller.index )
683 if len( availableControllers ) == 0:
684 main.log.warn( "No available controllers" )
685 main.caseResult = main.FALSE
686 else:
687 index = random.sample( availableControllers, 1 )
688 main.eventGenerator.triggerEvent( EventType().ONOS_ONOS_DOWN, EventScheduleMethod().RUN_BLOCK, index[ 0 ] )
689 with main.eventScheduler.idleCondition:
690 while not main.eventScheduler.isIdle():
691 main.eventScheduler.idleCondition.wait()
692 utilities.assert_equals( expect=main.TRUE,
693 actual=main.caseResult,
694 onpass="Randomly bring down ONOS test passed",
695 onfail="Randomly bring down ONOS test failed" )
696 time.sleep( main.caseSleep )
697
698 def CASE41( self, main ):
699 """
700 Randomly bring up one ONOS node that is down
701 """
702 import time
703 import random
704 from tests.CHOTestMonkey.dependencies.events.Event import EventType
705 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
706
707 main.log.report( "Randomly bring up one ONOS node that is down" )
708 main.log.report( "__________________________________________________" )
709 main.case( "Randomly bring up one ONOS node that is down" )
710 main.step( "Randomly bring up one ONOS node that is down" )
711 main.caseResult = main.TRUE
712 targetControllers = []
713 for controller in main.controllers:
714 if not controller.isUp():
715 targetControllers.append( controller.index )
716 if len( targetControllers ) == 0:
717 main.log.warn( "All controllers are up" )
718 main.caseResult = main.FALSE
719 else:
720 index = random.sample( targetControllers, 1 )
721 main.eventGenerator.triggerEvent( EventType().ONOS_ONOS_UP, EventScheduleMethod().RUN_BLOCK, index[ 0 ] )
722 with main.eventScheduler.idleCondition:
723 while not main.eventScheduler.isIdle():
724 main.eventScheduler.idleCondition.wait()
725 utilities.assert_equals( expect=main.TRUE,
726 actual=main.caseResult,
727 onpass="Randomly bring up ONOS test passed",
728 onfail="Randomly bring up ONOS test failed" )
729 time.sleep( main.caseSleep )
730
731 def CASE50( self, main ):
732 """
733 Set FlowObjective to True
734 """
735 import time
736 from tests.CHOTestMonkey.dependencies.events.Event import EventType
737 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
738
739 main.log.report( "Set FlowObjective to True" )
740 main.log.report( "__________________________________________________" )
741 main.case( "Set FlowObjective to True" )
742 main.step( "Set FlowObjective to True" )
743 main.caseResult = main.TRUE
744 main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'true' )
745 with main.eventScheduler.idleCondition:
746 while not main.eventScheduler.isIdle():
747 main.eventScheduler.idleCondition.wait()
748 utilities.assert_equals( expect=main.TRUE,
749 actual=main.caseResult,
750 onpass="Set FlowObjective test passed",
751 onfail="Set FlowObjective test failed" )
752 time.sleep( main.caseSleep )
753
754 def CASE51( self, main ):
755 """
756 Set FlowObjective to False
757 """
758 import time
759 from tests.CHOTestMonkey.dependencies.events.Event import EventType
760 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
761
762 main.log.report( "Set FlowObjective to False" )
763 main.log.report( "__________________________________________________" )
764 main.case( "Set FlowObjective to False" )
765 main.step( "Set FlowObjective to False" )
766 main.caseResult = main.TRUE
767 main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'false' )
768 with main.eventScheduler.idleCondition:
769 while not main.eventScheduler.isIdle():
770 main.eventScheduler.idleCondition.wait()
771 utilities.assert_equals( expect=main.TRUE,
772 actual=main.caseResult,
773 onpass="Set FlowObjective test passed",
774 onfail="Set FlowObjective test failed" )
775 time.sleep( main.caseSleep )
776
777 def CASE60( self, main ):
778 """
779 Balance device masters
780 """
781 import time
782 from tests.CHOTestMonkey.dependencies.events.Event import EventType
783 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
784
785 main.log.report( "Balance device masters" )
786 main.log.report( "__________________________________________________" )
787 main.case( "Balance device masters" )
788 main.step( "Balance device masters" )
789 main.caseResult = main.TRUE
790 main.eventGenerator.triggerEvent( EventType().ONOS_BALANCE_MASTERS, EventScheduleMethod().RUN_BLOCK )
791 with main.eventScheduler.idleCondition:
792 while not main.eventScheduler.isIdle():
793 main.eventScheduler.idleCondition.wait()
794 utilities.assert_equals( expect=main.TRUE,
795 actual=main.caseResult,
796 onpass="Balance masters test passed",
797 onfail="Balance masters test failed" )
798 time.sleep( main.caseSleep )
799
You Wang7a27f3a2016-07-05 10:12:27 -0700800 def CASE70( self, main ):
801 """
802 Randomly generate events
803 """
804 import time
805 import random
806 from tests.CHOTestMonkey.dependencies.events.Event import EventType
807 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
808
809 main.log.report( "Randomly generate events" )
810 main.log.report( "__________________________________________________" )
811 main.case( "Randomly generate events" )
812 main.step( "Randomly generate events" )
813 main.caseResult = main.TRUE
814 sleepSec = int( main.params[ 'CASE70' ][ 'sleepSec' ] )
815 hostIntentNum = 0
816 pointIntentNum = 0
817 downDeviceNum = 0
818 downLinkNum = 0
You Wangf6e98a82016-11-14 14:46:49 -0800819 flowObj = False
You Wang7a27f3a2016-07-05 10:12:27 -0700820 upControllers = [ 1, 2, 3 ]
821 while True:
822 events = []
You Wangf6e98a82016-11-14 14:46:49 -0800823 for i in range( int( main.params[ 'CASE70' ][ 'toggleFlowObj' ] ) ):
824 events.append( 'toggle-flowobj' )
You Wang7a27f3a2016-07-05 10:12:27 -0700825 for i in range( int( main.params[ 'CASE70' ][ 'addHostIntentWeight' ] ) ):
826 events.append( 'add-host-intent' )
827 for i in range( int( main.params[ 'CASE70' ][ 'addPointIntentWeight' ] ) ):
828 events.append( 'add-point-intent' )
829 for i in range( int( main.params[ 'CASE70' ][ 'linkDownWeight' ] ) ):
830 events.append( 'link-down' )
831 for i in range( int( main.params[ 'CASE70' ][ 'deviceDownWeight' ] ) ):
832 events.append( 'device-down' )
833 for i in range( int( pow( hostIntentNum, 1.5 ) / 100 ) ):
834 events.append( 'del-host-intent' )
You Wang52163202016-07-14 16:37:15 -0700835 for i in range( int( pow( pointIntentNum, 1.5 ) / 100 ) ):
You Wang7a27f3a2016-07-05 10:12:27 -0700836 events.append( 'del-point-intent' )
837 for i in range( pow( 2, downLinkNum ) - 1 ):
838 events.append( 'link-up' )
839 for i in range( pow( 5, downDeviceNum ) - 1 ):
840 events.append( 'device-up' )
841 main.log.debug( events )
842 event = random.sample( events, 1 )[ 0 ]
843 if event == 'add-host-intent':
844 n = random.randint( 5, 50 )
845 for i in range( n ):
846 cliIndex = random.sample( upControllers, 1 )[ 0 ]
You Wangc848af12016-07-14 09:53:58 -0700847 main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_ADD, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex )
You Wang7a27f3a2016-07-05 10:12:27 -0700848 hostIntentNum += 1
You Wang7a27f3a2016-07-05 10:12:27 -0700849 elif event == 'del-host-intent':
850 n = random.randint( 5, hostIntentNum )
851 for i in range( n ):
852 cliIndex = random.sample( upControllers, 1 )[ 0 ]
You Wangc848af12016-07-14 09:53:58 -0700853 main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_DEL, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex )
You Wang7a27f3a2016-07-05 10:12:27 -0700854 hostIntentNum -= 1
You Wang7a27f3a2016-07-05 10:12:27 -0700855 elif event == 'add-point-intent':
856 n = random.randint( 5, 50 )
857 for i in range( n ):
858 cliIndex = random.sample( upControllers, 1 )[ 0 ]
You Wangc848af12016-07-14 09:53:58 -0700859 main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_ADD, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex, 'bidirectional' )
You Wang52163202016-07-14 16:37:15 -0700860 pointIntentNum += 2
You Wang7a27f3a2016-07-05 10:12:27 -0700861 elif event == 'del-point-intent':
You Wang52163202016-07-14 16:37:15 -0700862 n = random.randint( 5, pointIntentNum / 2 )
You Wang7a27f3a2016-07-05 10:12:27 -0700863 for i in range( n ):
864 cliIndex = random.sample( upControllers, 1 )[ 0 ]
You Wangc848af12016-07-14 09:53:58 -0700865 main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_DEL, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex, 'bidirectional' )
You Wang52163202016-07-14 16:37:15 -0700866 pointIntentNum -= 2
You Wang7a27f3a2016-07-05 10:12:27 -0700867 elif event == 'link-down':
868 main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_DOWN, EventScheduleMethod().RUN_BLOCK, 'random', 'random' )
869 downLinkNum += 1
870 elif event == 'link-up':
871 main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_UP, EventScheduleMethod().RUN_BLOCK, 'random', 'random' )
872 downLinkNum -= 1
873 elif event == 'device-down':
874 main.eventGenerator.triggerEvent( EventType().NETWORK_DEVICE_DOWN, EventScheduleMethod().RUN_BLOCK, 'random' )
875 downDeviceNum += 1
876 elif event == 'device-up':
877 main.eventGenerator.triggerEvent( EventType().NETWORK_DEVICE_UP, EventScheduleMethod().RUN_BLOCK, 'random' )
878 downDeviceNum -= 1
You Wangf6e98a82016-11-14 14:46:49 -0800879 elif event == 'toggle-flowobj':
880 if flowObj == False:
881 main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'true' )
882 else:
883 main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'false' )
884 flowObj = not flowObj
You Wang7a27f3a2016-07-05 10:12:27 -0700885 else:
886 pass
887 main.eventGenerator.triggerEvent( EventType().CHECK_TOPO, EventScheduleMethod().RUN_NON_BLOCK )
888 main.eventGenerator.triggerEvent( EventType().CHECK_ONOS, EventScheduleMethod().RUN_NON_BLOCK )
889 main.eventGenerator.triggerEvent( EventType().CHECK_TRAFFIC, EventScheduleMethod().RUN_NON_BLOCK )
890 main.eventGenerator.triggerEvent( EventType().CHECK_FLOW, EventScheduleMethod().RUN_NON_BLOCK )
891 main.eventGenerator.triggerEvent( EventType().CHECK_INTENT, EventScheduleMethod().RUN_NON_BLOCK )
You Wang7a27f3a2016-07-05 10:12:27 -0700892 with main.eventScheduler.idleCondition:
893 while not main.eventScheduler.isIdle():
894 main.eventScheduler.idleCondition.wait()
You Wang5f4f36e2016-09-21 15:30:30 -0700895 time.sleep( sleepSec )
You Wang7a27f3a2016-07-05 10:12:27 -0700896 utilities.assert_equals( expect=main.TRUE,
897 actual=main.caseResult,
898 onpass="Randomly generate events test passed",
899 onfail="Randomly generate events test failed" )
900 time.sleep( main.caseSleep )
901
You Wang52163202016-07-14 16:37:15 -0700902 def CASE80( self, main ):
903 """
904 Replay events from log file
905 """
906 import time
907 from tests.CHOTestMonkey.dependencies.events.Event import EventType
908 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
909
910 main.log.report( "Replay events from log file" )
911 main.log.report( "__________________________________________________" )
912 main.case( "Replay events from log file" )
913 main.step( "Replay events from log file" )
914 main.caseResult = main.TRUE
915 try:
916 f = open( main.params[ 'CASE80' ][ 'filePath' ], 'r' )
917 for line in f.readlines():
918 if 'CHOTestMonkey' in line and 'Event recorded' in line:
919 line = line.split()
920 eventIndex = int( line[ 9 ] )
921 eventName = line[ 10 ]
922 args = line[ 11: ]
923 assert eventName.startswith( 'CHECK' )\
924 or eventName.startswith( 'NETWORK' )\
925 or eventName.startswith( 'APP' )\
926 or eventName.startswith( 'ONOS' )
927 if main.params[ 'CASE80' ][ 'skipChecks' ] == 'on' and eventName.startswith( 'CHECK' ):
928 continue
929 with main.eventScheduler.idleCondition:
930 while not main.eventScheduler.isIdle():
931 main.eventScheduler.idleCondition.wait()
932 main.eventGenerator.triggerEvent( eventIndex, EventScheduleMethod().RUN_BLOCK, *args )
933 time.sleep( float( main.params[ 'CASE80' ][ 'sleepTime' ] ) )
934 except Exception as e:
935 print e
936 utilities.assert_equals( expect=main.TRUE,
937 actual=main.caseResult,
938 onpass="Replay from log file passed",
939 onfail="Replay from log file failed" )
940
You Wangdb927a52016-02-26 11:03:28 -0800941 def CASE90( self, main ):
942 """
943 Sleep for some time
944 """
945 import time
946 from tests.CHOTestMonkey.dependencies.events.Event import EventType
947 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
948
949 main.log.report( "Sleep for some time" )
950 main.log.report( "__________________________________________________" )
951 main.case( "Sleep for some time" )
952 main.step( "Sleep for some time" )
953 main.caseResult = main.TRUE
954 sleepSec = int( main.params[ 'CASE90' ][ 'sleepSec' ] )
955 main.eventGenerator.triggerEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, sleepSec )
956 with main.eventScheduler.idleCondition:
957 while not main.eventScheduler.isIdle():
958 main.eventScheduler.idleCondition.wait()
959 utilities.assert_equals( expect=main.TRUE,
960 actual=main.caseResult,
961 onpass="Sleep test passed",
962 onfail="Sleep test failed" )
963 time.sleep( main.caseSleep )
964
965 def CASE100( self, main ):
966 """
967 Do something else?
968 """
969 import time
970
971 main.log.report( "Do something else?" )
972 main.log.report( "__________________________________________________" )
973 main.case( "..." )
974
975 main.step( "Wait until the test stops" )
976
977 main.caseResult = main.TRUE
978 utilities.assert_equals( expect=main.TRUE,
979 actual=main.caseResult,
980 onpass="Test PASS",
981 onfail="Test FAIL" )
982
983 testDuration = int( main.params[ 'TEST' ][ 'testDuration' ] )
984 time.sleep( testDuration )