blob: 2a0dc55ac7850287c5f0bacd466d232c97cd26c6 [file] [log] [blame]
You Wangdb927a52016-02-26 11:03:28 -08001"""
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07002Copyright 2016 Open Networking Foundation (ONF)
3
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
7
8 TestON is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
12
13 TestON is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with TestON. If not, see <http://www.gnu.org/licenses/>.
20"""
21
22"""
You Wangdb927a52016-02-26 11:03:28 -080023CHOTestMonkey class
24Author: you@onlab.us
25"""
You Wangdb927a52016-02-26 11:03:28 -080026import sys
27import os
28import re
29import time
30import json
31import itertools
32
Jon Hall2bb3e212017-05-24 17:07:25 -070033
You Wangdb927a52016-02-26 11:03:28 -080034class CHOTestMonkey:
35
36 def __init__( self ):
37 self.default = ''
38
39 def CASE0( self, main ):
40 """
41 Startup sequence:
42 apply cell <name>
43 git pull
You Wangdb927a52016-02-26 11:03:28 -080044 onos-package
45 onos-verify-cell
46 onos-uninstall
47 onos-install
48 onos-start-cli
49 Set IPv6 cfg parameters for Neighbor Discovery
50 start event scheduler
51 start event listener
52 """
53 import time
54 from threading import Lock, Condition
You Wang221db322016-06-03 15:45:52 -070055 from core.graph import Graph
You Wangdb927a52016-02-26 11:03:28 -080056 from tests.CHOTestMonkey.dependencies.elements.ONOSElement import Controller
57 from tests.CHOTestMonkey.dependencies.EventGenerator import EventGenerator
58 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduler
59
Devin Lim58046fa2017-07-05 16:55:00 -070060 try:
61 from tests.dependencies.ONOSSetup import ONOSSetup
62 main.testSetUp = ONOSSetup()
63 except ImportError:
64 main.log.error( "ONOSSetup not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070065 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070066 main.testSetUp.envSetupDescription()
67
68 try:
69 onosPackage = main.params[ 'TEST' ][ 'package' ]
70 karafTimeout = main.params[ 'TEST' ][ 'karafCliTimeout' ]
71 main.enableIPv6 = main.params[ 'TEST' ][ 'IPv6' ]
72 main.enableIPv6 = True if main.enableIPv6 == "on" else False
73 main.caseSleep = int( main.params[ 'TEST' ][ 'caseSleep' ] )
Devin Limc5c9e112017-08-17 15:16:05 -070074 main.onosCell = main.params[ 'ENV' ][ 'cellName' ]
75 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
Devin Lim58046fa2017-07-05 16:55:00 -070076 main.controllers = []
77
78 main.devices = []
79 main.links = []
80 main.hosts = []
81 main.intents = []
82 main.enabledEvents = {}
83 for eventName in main.params[ 'EVENT' ].keys():
84 if main.params[ 'EVENT' ][ eventName ][ 'status' ] == 'on':
85 main.enabledEvents[ int( main.params[ 'EVENT' ][ eventName ][ 'typeIndex' ] ) ] = eventName
86 print main.enabledEvents
87 main.graph = Graph()
88 main.eventScheduler = EventScheduler()
89 main.eventGenerator = EventGenerator()
90 main.variableLock = Lock()
91 main.mininetLock = Lock()
92 main.ONOSbenchLock = Lock()
93 main.threadID = 0
94 main.eventID = 0
95 main.caseResult = main.TRUE
96 stepResult = main.testSetUp.envSetup()
97 except Exception as e:
98 main.testSetUp.envSetupException(e)
99
100 main.testSetUp.evnSetupConclusion( stepResult )
101
Devin Lim142b5342017-07-20 15:22:39 -0700102 setupResult = main.testSetUp.ONOSSetUp( main.Mininet1, main.Cluster,
Devin Limc5c9e112017-08-17 15:16:05 -0700103 cellName=main.onosCell )
Devin Lim142b5342017-07-20 15:22:39 -0700104 for i in range( 1, main.Cluster.numCtrls + 1 ):
105 newController = Controller( i )
106 newController.setCLI( main.Cluster.active( i - 1 ).CLI )
107 main.controllers.append( newController )
You Wangdb927a52016-02-26 11:03:28 -0800108
109 main.step( "Set IPv6 cfg parameters for Neighbor Discovery" )
110 setIPv6CfgSleep = int( main.params[ 'TEST' ][ 'setIPv6CfgSleep' ] )
111 if main.enableIPv6:
112 time.sleep( setIPv6CfgSleep )
You Wang6ce33b02017-08-08 13:05:09 -0700113 cfgResult1 = main.controllers[ 0 ].CLI.setCfg( "org.onosproject.net.neighbour.impl.NeighbourResolutionManager",
You Wang5f4f36e2016-09-21 15:30:30 -0700114 "ndpEnabled",
You Wangdb927a52016-02-26 11:03:28 -0800115 "true" )
116 time.sleep( setIPv6CfgSleep )
117 cfgResult2 = main.controllers[ 0 ].CLI.setCfg( "org.onosproject.provider.host.impl.HostLocationProvider",
You Wang6ce33b02017-08-08 13:05:09 -0700118 "requestIpv6ND",
You Wangdb927a52016-02-26 11:03:28 -0800119 "true" )
120 else:
121 main.log.info( "Skipped setting IPv6 cfg parameters as it is disabled in params file" )
122 cfgResult1 = main.TRUE
123 cfgResult2 = main.TRUE
124 cfgResult = cfgResult1 and cfgResult2
125 utilities.assert_equals( expect=main.TRUE,
126 actual=cfgResult,
127 onpass="ipv6NeighborDiscovery cfg is set to true",
128 onfail="Failed to cfg set ipv6NeighborDiscovery" )
129
130 main.step( "Start a thread for the scheduler" )
131 t = main.Thread( target=main.eventScheduler.startScheduler,
132 threadID=main.threadID,
133 name="startScheduler",
134 args=[] )
135 t.start()
136 stepResult = main.TRUE
137 with main.variableLock:
138 main.threadID = main.threadID + 1
139
140 utilities.assert_equals( expect=main.TRUE,
141 actual=stepResult,
142 onpass="Test step PASS",
143 onfail="Test step FAIL" )
144
145 main.step( "Start a thread to listen to and handle network, ONOS and application events" )
146 t = main.Thread( target=main.eventGenerator.startListener,
147 threadID=main.threadID,
148 name="startListener",
149 args=[] )
150 t.start()
151 with main.variableLock:
152 main.threadID = main.threadID + 1
153
Devin Lim58046fa2017-07-05 16:55:00 -0700154 caseResult = setupResult and cfgResult
You Wangdb927a52016-02-26 11:03:28 -0800155 utilities.assert_equals( expect=main.TRUE,
156 actual=caseResult,
157 onpass="Set up test environment PASS",
158 onfail="Set up test environment FAIL" )
159
160 def CASE1( self, main ):
161 """
162 Load Mininet topology and balances all switches
163 """
164 import re
165 import time
166 import copy
167
Jon Hall2bb3e212017-05-24 17:07:25 -0700168 main.topoIndex = "topo" + str( main.params[ 'TEST' ][ 'topo' ] )
You Wangdb927a52016-02-26 11:03:28 -0800169
170 main.log.report( "Load Mininet topology and Balance all Mininet switches across controllers" )
171 main.log.report( "________________________________________________________________________" )
172 main.case( "Assign and Balance all Mininet switches across controllers" )
173
174 main.step( "Start Mininet topology" )
175 newTopo = main.params[ 'TOPO' ][ main.topoIndex ][ 'fileName' ]
176 mininetDir = main.Mininet1.home + "/custom/"
Jon Hall2bb3e212017-05-24 17:07:25 -0700177 topoPath = main.testDir + "/" + main.TEST + "/dependencies/topologies/" + newTopo
You Wangdb927a52016-02-26 11:03:28 -0800178 main.ONOSbench.secureCopy( main.Mininet1.user_name, main.Mininet1.ip_address, topoPath, mininetDir, direction="to" )
179 topoPath = mininetDir + newTopo
Jon Hall2bb3e212017-05-24 17:07:25 -0700180 startStatus = main.Mininet1.startNet( topoFile=topoPath )
You Wangdb927a52016-02-26 11:03:28 -0800181 main.mininetSwitches = main.Mininet1.getSwitches()
182 main.mininetHosts = main.Mininet1.getHosts()
You Wang55503a32016-06-27 15:11:40 -0700183 main.mininetLinks = main.Mininet1.getLinks( timeout=60 )
You Wangdb927a52016-02-26 11:03:28 -0800184 utilities.assert_equals( expect=main.TRUE,
185 actual=startStatus,
186 onpass="Start Mininet topology test PASS",
187 onfail="Start Mininet topology test FAIL" )
188
189 main.step( "Assign switches to controllers" )
190 switchMastership = main.TRUE
191 for switchName in main.mininetSwitches.keys():
Devin Lim142b5342017-07-20 15:22:39 -0700192 ips = main.Cluster.getIps()
193 main.Mininet1.assignSwController( sw=switchName, ip=ips )
You Wangdb927a52016-02-26 11:03:28 -0800194 response = main.Mininet1.getSwController( switchName )
195 print( "Response is " + str( response ) )
Devin Lim142b5342017-07-20 15:22:39 -0700196 if re.search( "tcp:" + main.Cluster.active( 0 ).ipAddress, response ):
You Wangdb927a52016-02-26 11:03:28 -0800197 switchMastership = switchMastership and main.TRUE
198 else:
199 switchMastership = main.FALSE
200 utilities.assert_equals( expect=main.TRUE,
201 actual=switchMastership,
202 onpass="Assign switches to controllers test PASS",
203 onfail="Assign switches to controllers test FAIL" )
204 # Waiting here to make sure topology converges across all nodes
205 sleep = int( main.params[ 'TEST' ][ 'loadTopoSleep' ] )
206 time.sleep( sleep )
207
208 main.step( "Balance devices across controllers" )
Devin Lim142b5342017-07-20 15:22:39 -0700209 balanceResult = main.Cluster.active( 0 ).CLI.balanceMasters()
You Wangdb927a52016-02-26 11:03:28 -0800210 # giving some breathing time for ONOS to complete re-balance
211 time.sleep( sleep )
212
213 caseResult = ( startStatus and switchMastership and balanceResult )
214 utilities.assert_equals( expect=main.TRUE,
215 actual=caseResult,
216 onpass="Starting new Att topology test PASS",
217 onfail="Starting new Att topology test FAIL" )
218
219 def CASE2( self, main ):
220 """
221 Collect and store device and link data from ONOS
222 """
223 import json
224 from tests.CHOTestMonkey.dependencies.elements.NetworkElement import Device, Link
225
226 main.log.report( "Collect and Store topology details from ONOS" )
227 main.log.report( "____________________________________________________________________" )
228 main.case( "Collect and Store Topology Details from ONOS" )
229 topoResult = main.TRUE
Devin Lim142b5342017-07-20 15:22:39 -0700230 topologyOutput = main.Cluster.active( 0 ).CLI.topology()
231 topologyResult = main.Cluster.active( 0 ).CLI.getTopology( topologyOutput )
You Wangdb927a52016-02-26 11:03:28 -0800232 ONOSDeviceNum = int( topologyResult[ 'devices' ] )
233 ONOSLinkNum = int( topologyResult[ 'links' ] )
234 mininetSwitchNum = len( main.mininetSwitches )
235 mininetLinkNum = ( len( main.mininetLinks ) - len( main.mininetHosts ) ) * 2
236 if mininetSwitchNum == ONOSDeviceNum and mininetLinkNum == ONOSLinkNum:
237 main.step( "Collect and store device data" )
238 stepResult = main.TRUE
239 dpidToName = {}
240 for key, value in main.mininetSwitches.items():
241 dpidToName[ 'of:' + str( value[ 'dpid' ] ) ] = key
Devin Lim142b5342017-07-20 15:22:39 -0700242 devicesRaw = main.Cluster.active( 0 ).CLI.devices()
You Wangdb927a52016-02-26 11:03:28 -0800243 devices = json.loads( devicesRaw )
244 deviceInitIndex = 0
245 for device in devices:
246 name = dpidToName[ device[ 'id' ] ]
247 newDevice = Device( deviceInitIndex, name, device[ 'id' ] )
248 print newDevice
249 main.devices.append( newDevice )
250 deviceInitIndex += 1
251 utilities.assert_equals( expect=main.TRUE,
252 actual=stepResult,
253 onpass="Successfully collected and stored device data",
254 onfail="Failed to collect and store device data" )
255
256 main.step( "Collect and store link data" )
257 stepResult = main.TRUE
Devin Lim142b5342017-07-20 15:22:39 -0700258 linksRaw = main.Cluster.active( 0 ).CLI.links()
You Wangdb927a52016-02-26 11:03:28 -0800259 links = json.loads( linksRaw )
260 linkInitIndex = 0
261 for link in links:
262 for device in main.devices:
263 if device.dpid == link[ 'src' ][ 'device' ]:
264 deviceA = device
265 elif device.dpid == link[ 'dst' ][ 'device' ]:
266 deviceB = device
Jon Hall2bb3e212017-05-24 17:07:25 -0700267 assert deviceA is not None and deviceB is not None
You Wangdb927a52016-02-26 11:03:28 -0800268 newLink = Link( linkInitIndex, deviceA, link[ 'src' ][ 'port' ], deviceB, link[ 'dst' ][ 'port' ] )
269 print newLink
270 main.links.append( newLink )
271 linkInitIndex += 1
272 # Set backward links and outgoing links of devices
273 for linkA in main.links:
274 linkA.deviceA.outgoingLinks.append( linkA )
Jon Hall2bb3e212017-05-24 17:07:25 -0700275 if linkA.backwardLink is not None:
You Wangdb927a52016-02-26 11:03:28 -0800276 continue
277 for linkB in main.links:
Jon Hall2bb3e212017-05-24 17:07:25 -0700278 if linkB.backwardLink is not None:
You Wangdb927a52016-02-26 11:03:28 -0800279 continue
280 if linkA.deviceA == linkB.deviceB and\
Jon Hall2bb3e212017-05-24 17:07:25 -0700281 linkA.deviceB == linkB.deviceA and\
282 linkA.portA == linkB.portB and\
283 linkA.portB == linkB.portA:
You Wangdb927a52016-02-26 11:03:28 -0800284 linkA.setBackwardLink( linkB )
285 linkB.setBackwardLink( linkA )
286 utilities.assert_equals( expect=main.TRUE,
287 actual=stepResult,
288 onpass="Successfully collected and stored link data",
289 onfail="Failed to collect and store link data" )
290 else:
291 main.log.info( "Devices (expected): %s, Links (expected): %s" % ( mininetSwitchNum, mininetLinkNum ) )
292 main.log.info( "Devices (actual): %s, Links (actual): %s" % ( ONOSDeviceNum, ONOSLinkNum ) )
293 topoResult = main.FALSE
294
295 caseResult = topoResult
296 utilities.assert_equals( expect=main.TRUE,
297 actual=caseResult,
298 onpass="Saving ONOS topology data test PASS",
299 onfail="Saving ONOS topology data test FAIL" )
300
301 if not caseResult:
Jon Hall2bb3e212017-05-24 17:07:25 -0700302 main.log.info( "Topology does not match, exiting test..." )
Devin Lim44075962017-08-11 10:56:37 -0700303 main.cleanAndExit()
You Wangdb927a52016-02-26 11:03:28 -0800304
305 def CASE3( self, main ):
306 """
307 Collect and store host data from ONOS
308 """
309 import json
310 from tests.CHOTestMonkey.dependencies.elements.NetworkElement import Host
311
312 main.log.report( "Collect and store host adta from ONOS" )
313 main.log.report( "______________________________________________" )
314 main.case( "Use fwd app and pingall to discover all the hosts, then collect and store host data" )
315
316 main.step( "Enable Reactive forwarding" )
317 appResult = main.controllers[ 0 ].CLI.activateApp( "org.onosproject.fwd" )
318 cfgResult1 = main.TRUE
319 cfgResult2 = main.TRUE
320 if main.enableIPv6:
321 cfgResult1 = main.controllers[ 0 ].CLI.setCfg( "org.onosproject.fwd.ReactiveForwarding", "ipv6Forwarding", "true" )
322 cfgResult2 = main.controllers[ 0 ].CLI.setCfg( "org.onosproject.fwd.ReactiveForwarding", "matchIpv6Address", "true" )
323 stepResult = appResult and cfgResult1 and cfgResult2
324 utilities.assert_equals( expect=main.TRUE,
325 actual=stepResult,
326 onpass="Successfully enabled reactive forwarding",
327 onfail="Failed to enable reactive forwarding" )
328
329 main.step( "Discover hosts using pingall" )
330 stepResult = main.TRUE
331 main.Mininet1.pingall()
332 if main.enableIPv6:
333 ping6Result = main.Mininet1.pingall( protocol="IPv6" )
334 hosts = main.controllers[ 0 ].CLI.hosts()
335 hosts = json.loads( hosts )
336 if not len( hosts ) == len( main.mininetHosts ):
337 stepResult = main.FALSE
338 utilities.assert_equals( expect=main.TRUE,
339 actual=stepResult,
340 onpass="Host discovery PASS",
341 onfail="Host discovery FAIL" )
342 if not stepResult:
343 main.log.debug( hosts )
Devin Lim44075962017-08-11 10:56:37 -0700344 main.cleanAndExit()
You Wangdb927a52016-02-26 11:03:28 -0800345
346 main.step( "Disable Reactive forwarding" )
347 appResult = main.controllers[ 0 ].CLI.deactivateApp( "org.onosproject.fwd" )
348 stepResult = appResult
349 utilities.assert_equals( expect=main.TRUE,
350 actual=stepResult,
351 onpass="Successfully deactivated fwd app",
352 onfail="Failed to deactivate fwd app" )
353
354 main.step( "Collect and store host data" )
355 stepResult = main.TRUE
356 macToName = {}
357 for key, value in main.mininetHosts.items():
358 macToName[ value[ 'interfaces' ][ 0 ][ 'mac' ].upper() ] = key
359 dpidToDevice = {}
360 for device in main.devices:
361 dpidToDevice[ device.dpid ] = device
362 hostInitIndex = 0
363 for host in hosts:
364 name = macToName[ host[ 'mac' ] ]
Jeremy Ronquillo0e538bc2017-06-13 15:16:09 -0700365 dpid = host[ 'locations' ][ 0 ][ 'elementId' ]
You Wangdb927a52016-02-26 11:03:28 -0800366 device = dpidToDevice[ dpid ]
367 newHost = Host( hostInitIndex,
368 name, host[ 'id' ], host[ 'mac' ],
Jeremy Ronquillo0e538bc2017-06-13 15:16:09 -0700369 device, host[ 'locations' ][ 0 ][ 'port' ],
You Wangdb927a52016-02-26 11:03:28 -0800370 host[ 'vlan' ], host[ 'ipAddresses' ] )
371 print newHost
372 main.hosts.append( newHost )
373 main.devices[ device.index ].hosts.append( newHost )
374 hostInitIndex += 1
375 utilities.assert_equals( expect=main.TRUE,
376 actual=stepResult,
377 onpass="Successfully collected and stored host data",
378 onfail="Failed to collect and store host data" )
379
380 main.step( "Create one host component for each host and then start host cli" )
381 for host in main.hosts:
382 main.Mininet1.createHostComponent( host.name )
383 hostHandle = getattr( main, host.name )
384 main.log.info( "Starting CLI on host " + str( host.name ) )
385 startCLIResult = hostHandle.startHostCli()
386 host.setHandle( hostHandle )
387 stepResult = startCLIResult
388 utilities.assert_equals( expect=main.TRUE,
389 actual=startCLIResult,
390 onpass="Host CLI started",
391 onfail="Failed to start host CLI" )
392
393 def CASE10( self, main ):
394 """
395 Run all enabled checks
396 """
397 import time
398 from tests.CHOTestMonkey.dependencies.events.Event import EventType
399 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
400
401 main.log.report( "Run all enabled checks" )
402 main.log.report( "__________________________________________________" )
403 main.case( "Run all enabled checks" )
404 main.step( "Run all enabled checks" )
405 main.caseResult = main.TRUE
406 main.eventGenerator.triggerEvent( EventType().CHECK_ALL, EventScheduleMethod().RUN_BLOCK )
407 # Wait for the scheduler to become idle before going to the next testcase
408 with main.eventScheduler.idleCondition:
409 while not main.eventScheduler.isIdle():
410 main.eventScheduler.idleCondition.wait()
411 utilities.assert_equals( expect=main.TRUE,
412 actual=main.caseResult,
413 onpass="All enabled checks passed",
414 onfail="Not all enabled checks passed" )
415 time.sleep( main.caseSleep )
416
417 def CASE20( self, main ):
418 """
419 Bring down/up links and check topology and ping
420 """
421 import time
422 from tests.CHOTestMonkey.dependencies.events.Event import EventType
423 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
424
425 main.log.report( "Bring down/up links and check topology and ping" )
426 main.log.report( "__________________________________________________" )
427 main.case( "Bring down/up links and check topology and ping" )
428 main.step( "Bring down/up links and check topology and ping" )
429 main.caseResult = main.TRUE
430 linkToggleNum = int( main.params[ 'CASE20' ][ 'linkToggleNum' ] )
431 linkDownUpInterval = int( main.params[ 'CASE20' ][ 'linkDownUpInterval' ] )
432 for i in range( 0, linkToggleNum ):
433 main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_RANDOM_TOGGLE, EventScheduleMethod().RUN_BLOCK, linkDownUpInterval )
434 with main.eventScheduler.idleCondition:
435 while not main.eventScheduler.isIdle():
436 main.eventScheduler.idleCondition.wait()
437 utilities.assert_equals( expect=main.TRUE,
438 actual=main.caseResult,
439 onpass="Toggle network links test passed",
440 onfail="Toggle network links test failed" )
441 time.sleep( main.caseSleep )
442
443 def CASE21( self, main ):
444 """
445 Bring down/up a group of links and check topology and ping
446 """
447 import time
448 from tests.CHOTestMonkey.dependencies.events.Event import EventType
449 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
450
451 main.log.report( "Bring down/up a group of links and check topology and ping" )
452 main.log.report( "__________________________________________________" )
453 main.case( "Bring down/up a group of links and check topology and ping" )
454 main.step( "Bring down/up a group of links and check topology and ping" )
455 main.caseResult = main.TRUE
456 linkGroupSize = int( main.params[ 'CASE21' ][ 'linkGroupSize' ] )
457 linkDownDownInterval = int( main.params[ 'CASE21' ][ 'linkDownDownInterval' ] )
458 linkDownUpInterval = int( main.params[ 'CASE21' ][ 'linkDownUpInterval' ] )
459 main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_GROUP_RANDOM_TOGGLE, EventScheduleMethod().RUN_BLOCK, linkGroupSize, linkDownDownInterval, linkDownUpInterval )
460 with main.eventScheduler.idleCondition:
461 while not main.eventScheduler.isIdle():
462 main.eventScheduler.idleCondition.wait()
463 utilities.assert_equals( expect=main.TRUE,
464 actual=main.caseResult,
465 onpass="Toggle network link group test passed",
466 onfail="Toggle network link group test failed" )
467 time.sleep( main.caseSleep )
468
469 def CASE30( self, main ):
470 """
471 Install host intents and check intent states and ping
472 """
473 import time
474 from tests.CHOTestMonkey.dependencies.events.Event import EventType
475 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
476
477 main.log.report( "Install host intents and check intent states and ping" )
478 main.log.report( "__________________________________________________" )
479 main.case( "Install host intents and check intent states and ping" )
480 main.step( "Install host intents and check intent states and ping" )
481 main.caseResult = main.TRUE
482 main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_ADD_ALL, EventScheduleMethod().RUN_BLOCK )
483 with main.eventScheduler.idleCondition:
484 while not main.eventScheduler.isIdle():
485 main.eventScheduler.idleCondition.wait()
486 utilities.assert_equals( expect=main.TRUE,
487 actual=main.caseResult,
488 onpass="Install host intents test passed",
489 onfail="Install host intents test failed" )
490 time.sleep( main.caseSleep )
491
492 def CASE31( self, main ):
493 """
494 Uninstall host intents and check intent states and ping
495 """
496 import time
497 from tests.CHOTestMonkey.dependencies.events.Event import EventType
498 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
499
500 main.log.report( "Uninstall host intents and check intent states and ping" )
501 main.log.report( "__________________________________________________" )
502 main.case( "Uninstall host intents and check intent states and ping" )
503 main.step( "Uninstall host intents and check intent states and ping" )
504 main.caseResult = main.TRUE
505 main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_DEL_ALL, EventScheduleMethod().RUN_BLOCK )
506 with main.eventScheduler.idleCondition:
507 while not main.eventScheduler.isIdle():
508 main.eventScheduler.idleCondition.wait()
509 utilities.assert_equals( expect=main.TRUE,
510 actual=main.caseResult,
511 onpass="Uninstall host intents test passed",
512 onfail="Uninstall host intents test failed" )
513 time.sleep( main.caseSleep )
514
515 def CASE32( self, main ):
516 """
517 Install point intents and check intent states and ping
518 """
519 import time
520 from tests.CHOTestMonkey.dependencies.events.Event import EventType
521 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
522
523 main.log.report( "Install point intents and check intent states and ping" )
524 main.log.report( "__________________________________________________" )
525 main.case( "Install point intents and check intent states and ping" )
526 main.step( "Install point intents and check intent states and ping" )
527 main.caseResult = main.TRUE
528 main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_ADD_ALL, EventScheduleMethod().RUN_BLOCK )
529 with main.eventScheduler.idleCondition:
530 while not main.eventScheduler.isIdle():
531 main.eventScheduler.idleCondition.wait()
532 utilities.assert_equals( expect=main.TRUE,
533 actual=main.caseResult,
534 onpass="Install point intents test passed",
535 onfail="Install point intents test failed" )
536 time.sleep( main.caseSleep )
537
538 def CASE33( self, main ):
539 """
540 Uninstall point intents and check intent states and ping
541 """
542 import time
543 from tests.CHOTestMonkey.dependencies.events.Event import EventType
544 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
545
546 main.log.report( "Uninstall point intents and check intent states and ping" )
547 main.log.report( "__________________________________________________" )
548 main.case( "Uninstall point intents and check intent states and ping" )
549 main.step( "Uninstall point intents and check intent states and ping" )
550 main.caseResult = main.TRUE
551 main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_DEL_ALL, EventScheduleMethod().RUN_BLOCK )
552 with main.eventScheduler.idleCondition:
553 while not main.eventScheduler.isIdle():
554 main.eventScheduler.idleCondition.wait()
555 utilities.assert_equals( expect=main.TRUE,
556 actual=main.caseResult,
557 onpass="Uninstall point intents test passed",
558 onfail="Uninstall point intents test failed" )
559 time.sleep( main.caseSleep )
560
561 def CASE40( self, main ):
562 """
563 Randomly bring down one ONOS node
564 """
565 import time
566 import random
567 from tests.CHOTestMonkey.dependencies.events.Event import EventType
568 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
569
570 main.log.report( "Randomly bring down one ONOS node" )
571 main.log.report( "__________________________________________________" )
572 main.case( "Randomly bring down one ONOS node" )
573 main.step( "Randomly bring down one ONOS node" )
574 main.caseResult = main.TRUE
575 availableControllers = []
576 for controller in main.controllers:
577 if controller.isUp():
578 availableControllers.append( controller.index )
579 if len( availableControllers ) == 0:
580 main.log.warn( "No available controllers" )
581 main.caseResult = main.FALSE
582 else:
583 index = random.sample( availableControllers, 1 )
584 main.eventGenerator.triggerEvent( EventType().ONOS_ONOS_DOWN, EventScheduleMethod().RUN_BLOCK, index[ 0 ] )
585 with main.eventScheduler.idleCondition:
586 while not main.eventScheduler.isIdle():
587 main.eventScheduler.idleCondition.wait()
588 utilities.assert_equals( expect=main.TRUE,
589 actual=main.caseResult,
590 onpass="Randomly bring down ONOS test passed",
591 onfail="Randomly bring down ONOS test failed" )
592 time.sleep( main.caseSleep )
593
594 def CASE41( self, main ):
595 """
596 Randomly bring up one ONOS node that is down
597 """
598 import time
599 import random
600 from tests.CHOTestMonkey.dependencies.events.Event import EventType
601 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
602
603 main.log.report( "Randomly bring up one ONOS node that is down" )
604 main.log.report( "__________________________________________________" )
605 main.case( "Randomly bring up one ONOS node that is down" )
606 main.step( "Randomly bring up one ONOS node that is down" )
607 main.caseResult = main.TRUE
608 targetControllers = []
609 for controller in main.controllers:
610 if not controller.isUp():
611 targetControllers.append( controller.index )
612 if len( targetControllers ) == 0:
613 main.log.warn( "All controllers are up" )
614 main.caseResult = main.FALSE
615 else:
616 index = random.sample( targetControllers, 1 )
617 main.eventGenerator.triggerEvent( EventType().ONOS_ONOS_UP, EventScheduleMethod().RUN_BLOCK, index[ 0 ] )
618 with main.eventScheduler.idleCondition:
619 while not main.eventScheduler.isIdle():
620 main.eventScheduler.idleCondition.wait()
621 utilities.assert_equals( expect=main.TRUE,
622 actual=main.caseResult,
623 onpass="Randomly bring up ONOS test passed",
624 onfail="Randomly bring up ONOS test failed" )
625 time.sleep( main.caseSleep )
626
627 def CASE50( self, main ):
628 """
629 Set FlowObjective to True
630 """
631 import time
632 from tests.CHOTestMonkey.dependencies.events.Event import EventType
633 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
634
635 main.log.report( "Set FlowObjective to True" )
636 main.log.report( "__________________________________________________" )
637 main.case( "Set FlowObjective to True" )
638 main.step( "Set FlowObjective to True" )
639 main.caseResult = main.TRUE
640 main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'true' )
641 with main.eventScheduler.idleCondition:
642 while not main.eventScheduler.isIdle():
643 main.eventScheduler.idleCondition.wait()
644 utilities.assert_equals( expect=main.TRUE,
645 actual=main.caseResult,
646 onpass="Set FlowObjective test passed",
647 onfail="Set FlowObjective test failed" )
648 time.sleep( main.caseSleep )
649
650 def CASE51( self, main ):
651 """
652 Set FlowObjective to False
653 """
654 import time
655 from tests.CHOTestMonkey.dependencies.events.Event import EventType
656 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
657
658 main.log.report( "Set FlowObjective to False" )
659 main.log.report( "__________________________________________________" )
660 main.case( "Set FlowObjective to False" )
661 main.step( "Set FlowObjective to False" )
662 main.caseResult = main.TRUE
663 main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'false' )
664 with main.eventScheduler.idleCondition:
665 while not main.eventScheduler.isIdle():
666 main.eventScheduler.idleCondition.wait()
667 utilities.assert_equals( expect=main.TRUE,
668 actual=main.caseResult,
669 onpass="Set FlowObjective test passed",
670 onfail="Set FlowObjective test failed" )
671 time.sleep( main.caseSleep )
672
673 def CASE60( self, main ):
674 """
675 Balance device masters
676 """
677 import time
678 from tests.CHOTestMonkey.dependencies.events.Event import EventType
679 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
680
681 main.log.report( "Balance device masters" )
682 main.log.report( "__________________________________________________" )
683 main.case( "Balance device masters" )
684 main.step( "Balance device masters" )
685 main.caseResult = main.TRUE
686 main.eventGenerator.triggerEvent( EventType().ONOS_BALANCE_MASTERS, EventScheduleMethod().RUN_BLOCK )
687 with main.eventScheduler.idleCondition:
688 while not main.eventScheduler.isIdle():
689 main.eventScheduler.idleCondition.wait()
690 utilities.assert_equals( expect=main.TRUE,
691 actual=main.caseResult,
692 onpass="Balance masters test passed",
693 onfail="Balance masters test failed" )
694 time.sleep( main.caseSleep )
695
You Wang7a27f3a2016-07-05 10:12:27 -0700696 def CASE70( self, main ):
697 """
698 Randomly generate events
699 """
700 import time
701 import random
702 from tests.CHOTestMonkey.dependencies.events.Event import EventType
703 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
704
705 main.log.report( "Randomly generate events" )
706 main.log.report( "__________________________________________________" )
707 main.case( "Randomly generate events" )
708 main.step( "Randomly generate events" )
709 main.caseResult = main.TRUE
710 sleepSec = int( main.params[ 'CASE70' ][ 'sleepSec' ] )
711 hostIntentNum = 0
712 pointIntentNum = 0
713 downDeviceNum = 0
714 downLinkNum = 0
You Wangf6e98a82016-11-14 14:46:49 -0800715 flowObj = False
You Wang7a27f3a2016-07-05 10:12:27 -0700716 upControllers = [ 1, 2, 3 ]
717 while True:
718 events = []
You Wangf6e98a82016-11-14 14:46:49 -0800719 for i in range( int( main.params[ 'CASE70' ][ 'toggleFlowObj' ] ) ):
720 events.append( 'toggle-flowobj' )
You Wang7a27f3a2016-07-05 10:12:27 -0700721 for i in range( int( main.params[ 'CASE70' ][ 'addHostIntentWeight' ] ) ):
722 events.append( 'add-host-intent' )
723 for i in range( int( main.params[ 'CASE70' ][ 'addPointIntentWeight' ] ) ):
724 events.append( 'add-point-intent' )
725 for i in range( int( main.params[ 'CASE70' ][ 'linkDownWeight' ] ) ):
726 events.append( 'link-down' )
727 for i in range( int( main.params[ 'CASE70' ][ 'deviceDownWeight' ] ) ):
728 events.append( 'device-down' )
729 for i in range( int( pow( hostIntentNum, 1.5 ) / 100 ) ):
730 events.append( 'del-host-intent' )
You Wang52163202016-07-14 16:37:15 -0700731 for i in range( int( pow( pointIntentNum, 1.5 ) / 100 ) ):
You Wang7a27f3a2016-07-05 10:12:27 -0700732 events.append( 'del-point-intent' )
733 for i in range( pow( 2, downLinkNum ) - 1 ):
734 events.append( 'link-up' )
735 for i in range( pow( 5, downDeviceNum ) - 1 ):
736 events.append( 'device-up' )
737 main.log.debug( events )
738 event = random.sample( events, 1 )[ 0 ]
739 if event == 'add-host-intent':
740 n = random.randint( 5, 50 )
741 for i in range( n ):
742 cliIndex = random.sample( upControllers, 1 )[ 0 ]
You Wangc848af12016-07-14 09:53:58 -0700743 main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_ADD, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex )
You Wang7a27f3a2016-07-05 10:12:27 -0700744 hostIntentNum += 1
You Wang7a27f3a2016-07-05 10:12:27 -0700745 elif event == 'del-host-intent':
746 n = random.randint( 5, hostIntentNum )
747 for i in range( n ):
748 cliIndex = random.sample( upControllers, 1 )[ 0 ]
You Wangc848af12016-07-14 09:53:58 -0700749 main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_DEL, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex )
You Wang7a27f3a2016-07-05 10:12:27 -0700750 hostIntentNum -= 1
You Wang7a27f3a2016-07-05 10:12:27 -0700751 elif event == 'add-point-intent':
752 n = random.randint( 5, 50 )
753 for i in range( n ):
754 cliIndex = random.sample( upControllers, 1 )[ 0 ]
You Wangc848af12016-07-14 09:53:58 -0700755 main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_ADD, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex, 'bidirectional' )
You Wang52163202016-07-14 16:37:15 -0700756 pointIntentNum += 2
You Wang7a27f3a2016-07-05 10:12:27 -0700757 elif event == 'del-point-intent':
You Wang52163202016-07-14 16:37:15 -0700758 n = random.randint( 5, pointIntentNum / 2 )
You Wang7a27f3a2016-07-05 10:12:27 -0700759 for i in range( n ):
760 cliIndex = random.sample( upControllers, 1 )[ 0 ]
You Wangc848af12016-07-14 09:53:58 -0700761 main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_DEL, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex, 'bidirectional' )
You Wang52163202016-07-14 16:37:15 -0700762 pointIntentNum -= 2
You Wang7a27f3a2016-07-05 10:12:27 -0700763 elif event == 'link-down':
764 main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_DOWN, EventScheduleMethod().RUN_BLOCK, 'random', 'random' )
765 downLinkNum += 1
766 elif event == 'link-up':
767 main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_UP, EventScheduleMethod().RUN_BLOCK, 'random', 'random' )
768 downLinkNum -= 1
769 elif event == 'device-down':
770 main.eventGenerator.triggerEvent( EventType().NETWORK_DEVICE_DOWN, EventScheduleMethod().RUN_BLOCK, 'random' )
771 downDeviceNum += 1
772 elif event == 'device-up':
773 main.eventGenerator.triggerEvent( EventType().NETWORK_DEVICE_UP, EventScheduleMethod().RUN_BLOCK, 'random' )
774 downDeviceNum -= 1
You Wangf6e98a82016-11-14 14:46:49 -0800775 elif event == 'toggle-flowobj':
Jon Hall2bb3e212017-05-24 17:07:25 -0700776 if not flowObj:
You Wangf6e98a82016-11-14 14:46:49 -0800777 main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'true' )
778 else:
779 main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'false' )
780 flowObj = not flowObj
You Wang7a27f3a2016-07-05 10:12:27 -0700781 else:
782 pass
783 main.eventGenerator.triggerEvent( EventType().CHECK_TOPO, EventScheduleMethod().RUN_NON_BLOCK )
784 main.eventGenerator.triggerEvent( EventType().CHECK_ONOS, EventScheduleMethod().RUN_NON_BLOCK )
785 main.eventGenerator.triggerEvent( EventType().CHECK_TRAFFIC, EventScheduleMethod().RUN_NON_BLOCK )
786 main.eventGenerator.triggerEvent( EventType().CHECK_FLOW, EventScheduleMethod().RUN_NON_BLOCK )
787 main.eventGenerator.triggerEvent( EventType().CHECK_INTENT, EventScheduleMethod().RUN_NON_BLOCK )
You Wang7a27f3a2016-07-05 10:12:27 -0700788 with main.eventScheduler.idleCondition:
789 while not main.eventScheduler.isIdle():
790 main.eventScheduler.idleCondition.wait()
You Wang5f4f36e2016-09-21 15:30:30 -0700791 time.sleep( sleepSec )
You Wang7a27f3a2016-07-05 10:12:27 -0700792 utilities.assert_equals( expect=main.TRUE,
793 actual=main.caseResult,
794 onpass="Randomly generate events test passed",
795 onfail="Randomly generate events test failed" )
796 time.sleep( main.caseSleep )
797
You Wang52163202016-07-14 16:37:15 -0700798 def CASE80( self, main ):
799 """
800 Replay events from log file
801 """
802 import time
803 from tests.CHOTestMonkey.dependencies.events.Event import EventType
804 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
805
806 main.log.report( "Replay events from log file" )
807 main.log.report( "__________________________________________________" )
808 main.case( "Replay events from log file" )
809 main.step( "Replay events from log file" )
810 main.caseResult = main.TRUE
811 try:
812 f = open( main.params[ 'CASE80' ][ 'filePath' ], 'r' )
813 for line in f.readlines():
814 if 'CHOTestMonkey' in line and 'Event recorded' in line:
815 line = line.split()
816 eventIndex = int( line[ 9 ] )
817 eventName = line[ 10 ]
818 args = line[ 11: ]
819 assert eventName.startswith( 'CHECK' )\
Jon Hall2bb3e212017-05-24 17:07:25 -0700820 or eventName.startswith( 'NETWORK' )\
821 or eventName.startswith( 'APP' )\
822 or eventName.startswith( 'ONOS' )
You Wang52163202016-07-14 16:37:15 -0700823 if main.params[ 'CASE80' ][ 'skipChecks' ] == 'on' and eventName.startswith( 'CHECK' ):
824 continue
825 with main.eventScheduler.idleCondition:
826 while not main.eventScheduler.isIdle():
827 main.eventScheduler.idleCondition.wait()
828 main.eventGenerator.triggerEvent( eventIndex, EventScheduleMethod().RUN_BLOCK, *args )
829 time.sleep( float( main.params[ 'CASE80' ][ 'sleepTime' ] ) )
830 except Exception as e:
831 print e
832 utilities.assert_equals( expect=main.TRUE,
833 actual=main.caseResult,
834 onpass="Replay from log file passed",
835 onfail="Replay from log file failed" )
836
You Wangdb927a52016-02-26 11:03:28 -0800837 def CASE90( self, main ):
838 """
839 Sleep for some time
840 """
841 import time
842 from tests.CHOTestMonkey.dependencies.events.Event import EventType
843 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
844
845 main.log.report( "Sleep for some time" )
846 main.log.report( "__________________________________________________" )
847 main.case( "Sleep for some time" )
848 main.step( "Sleep for some time" )
849 main.caseResult = main.TRUE
850 sleepSec = int( main.params[ 'CASE90' ][ 'sleepSec' ] )
851 main.eventGenerator.triggerEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, sleepSec )
852 with main.eventScheduler.idleCondition:
853 while not main.eventScheduler.isIdle():
854 main.eventScheduler.idleCondition.wait()
855 utilities.assert_equals( expect=main.TRUE,
856 actual=main.caseResult,
857 onpass="Sleep test passed",
858 onfail="Sleep test failed" )
859 time.sleep( main.caseSleep )
860
861 def CASE100( self, main ):
862 """
863 Do something else?
864 """
865 import time
866
867 main.log.report( "Do something else?" )
868 main.log.report( "__________________________________________________" )
869 main.case( "..." )
870
871 main.step( "Wait until the test stops" )
872
873 main.caseResult = main.TRUE
874 utilities.assert_equals( expect=main.TRUE,
875 actual=main.caseResult,
876 onpass="Test PASS",
877 onfail="Test FAIL" )
878
879 testDuration = int( main.params[ 'TEST' ][ 'testDuration' ] )
880 time.sleep( testDuration )