blob: bc6f249d2b8064249c1c202b7ed217cc521480c2 [file] [log] [blame]
You Wangdb927a52016-02-26 11:03:28 -08001"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002Copyright 2016 Open Networking Foundation ( ONF )
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07003
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
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070011 ( at your option ) any later version.
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070012
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"""
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070021"""
You Wangdb927a52016-02-26 11:03:28 -080022CHOTestMonkey class
23Author: you@onlab.us
24"""
You Wangdb927a52016-02-26 11:03:28 -080025import sys
26import os
27import re
28import time
29import json
30import itertools
31
Jon Hall2bb3e212017-05-24 17:07:25 -070032
You Wangdb927a52016-02-26 11:03:28 -080033class CHOTestMonkey:
34
35 def __init__( self ):
36 self.default = ''
37
38 def CASE0( self, main ):
39 """
40 Startup sequence:
41 apply cell <name>
42 git pull
You Wangdb927a52016-02-26 11:03:28 -080043 onos-package
44 onos-verify-cell
45 onos-uninstall
46 onos-install
47 onos-start-cli
You Wangdb927a52016-02-26 11:03:28 -080048 start event scheduler
49 start event listener
50 """
51 import time
52 from threading import Lock, Condition
You Wang221db322016-06-03 15:45:52 -070053 from core.graph import Graph
You Wangdb927a52016-02-26 11:03:28 -080054 from tests.CHOTestMonkey.dependencies.elements.ONOSElement import Controller
55 from tests.CHOTestMonkey.dependencies.EventGenerator import EventGenerator
56 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduler
57
Devin Lim58046fa2017-07-05 16:55:00 -070058 try:
59 from tests.dependencies.ONOSSetup import ONOSSetup
60 main.testSetUp = ONOSSetup()
61 except ImportError:
62 main.log.error( "ONOSSetup not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070063 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070064 main.testSetUp.envSetupDescription()
65
You Wangc61aaa22019-02-01 15:49:48 -080066 from tests.dependencies.Network import Network
67 main.Network = Network()
68
Devin Lim58046fa2017-07-05 16:55:00 -070069 try:
70 onosPackage = main.params[ 'TEST' ][ 'package' ]
71 karafTimeout = main.params[ 'TEST' ][ 'karafCliTimeout' ]
You Wang9fc5ce42019-01-23 15:10:08 -080072 main.enableIPv6 = main.params[ 'TEST' ][ 'IPv6' ].lower() == "on"
Devin Lim58046fa2017-07-05 16:55:00 -070073 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' ]
You Wangc61aaa22019-02-01 15:49:48 -080076 main.restartCluster = main.params[ 'TEST' ][ 'restartCluster' ] == "True"
77 main.excludeNodes = main.params[ 'TOPO' ][ 'excludeNodes' ].split( ',' ) \
78 if main.params[ 'TOPO' ][ 'excludeNodes' ] else []
79 main.skipSwitches = main.params[ 'CASE70' ][ 'skipSwitches' ].split( ',' ) \
80 if main.params[ 'CASE70' ][ 'skipSwitches' ] else []
81 main.skipLinks = main.params[ 'CASE70' ][ 'skipLinks' ].split( ',' ) \
82 if main.params[ 'CASE70' ][ 'skipLinks' ] else []
Devin Lim58046fa2017-07-05 16:55:00 -070083 main.controllers = []
Devin Lim58046fa2017-07-05 16:55:00 -070084 main.devices = []
85 main.links = []
86 main.hosts = []
87 main.intents = []
You Wangc61aaa22019-02-01 15:49:48 -080088 main.flowObj = False
Devin Lim58046fa2017-07-05 16:55:00 -070089 main.enabledEvents = {}
90 for eventName in main.params[ 'EVENT' ].keys():
91 if main.params[ 'EVENT' ][ eventName ][ 'status' ] == 'on':
92 main.enabledEvents[ int( main.params[ 'EVENT' ][ eventName ][ 'typeIndex' ] ) ] = eventName
Devin Lim58046fa2017-07-05 16:55:00 -070093 main.graph = Graph()
94 main.eventScheduler = EventScheduler()
95 main.eventGenerator = EventGenerator()
96 main.variableLock = Lock()
You Wangc61aaa22019-02-01 15:49:48 -080097 main.networkLock = Lock()
Devin Lim58046fa2017-07-05 16:55:00 -070098 main.ONOSbenchLock = Lock()
99 main.threadID = 0
100 main.eventID = 0
101 main.caseResult = main.TRUE
102 stepResult = main.testSetUp.envSetup()
103 except Exception as e:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700104 main.testSetUp.envSetupException( e )
Devin Lim58046fa2017-07-05 16:55:00 -0700105
106 main.testSetUp.evnSetupConclusion( stepResult )
107
You Wanga0f6ff62018-01-11 15:46:30 -0800108 setupResult = main.testSetUp.ONOSSetUp( main.Cluster,
You Wangc61aaa22019-02-01 15:49:48 -0800109 cellName=main.onosCell,
110 restartCluster=main.restartCluster )
Devin Lim142b5342017-07-20 15:22:39 -0700111 for i in range( 1, main.Cluster.numCtrls + 1 ):
112 newController = Controller( i )
You Wang9fc5ce42019-01-23 15:10:08 -0800113 newController.setCLI( main.Cluster.runningNodes[ i - 1 ].CLI )
Devin Lim142b5342017-07-20 15:22:39 -0700114 main.controllers.append( newController )
You Wangdb927a52016-02-26 11:03:28 -0800115
You Wangdb927a52016-02-26 11:03:28 -0800116 main.step( "Start a thread for the scheduler" )
117 t = main.Thread( target=main.eventScheduler.startScheduler,
118 threadID=main.threadID,
119 name="startScheduler",
120 args=[] )
121 t.start()
122 stepResult = main.TRUE
123 with main.variableLock:
124 main.threadID = main.threadID + 1
125
126 utilities.assert_equals( expect=main.TRUE,
127 actual=stepResult,
128 onpass="Test step PASS",
129 onfail="Test step FAIL" )
130
131 main.step( "Start a thread to listen to and handle network, ONOS and application events" )
132 t = main.Thread( target=main.eventGenerator.startListener,
133 threadID=main.threadID,
134 name="startListener",
135 args=[] )
136 t.start()
137 with main.variableLock:
138 main.threadID = main.threadID + 1
139
You Wang9fc5ce42019-01-23 15:10:08 -0800140 caseResult = setupResult
You Wangdb927a52016-02-26 11:03:28 -0800141 utilities.assert_equals( expect=main.TRUE,
142 actual=caseResult,
143 onpass="Set up test environment PASS",
144 onfail="Set up test environment FAIL" )
145
146 def CASE1( self, main ):
147 """
You Wang9fc5ce42019-01-23 15:10:08 -0800148 Set IPv6 cfg parameters for Neighbor Discovery
149 """
150 main.step( "Set IPv6 cfg parameters for Neighbor Discovery" )
151 setIPv6CfgSleep = int( main.params[ 'CASE1' ][ 'setIPv6CfgSleep' ] )
152 if main.enableIPv6:
153 time.sleep( setIPv6CfgSleep )
154 cfgResult1 = main.Cluster.active( 0 ).CLI.setCfg( "org.onosproject.net.neighbour.impl.NeighbourResolutionManager",
155 "ndpEnabled",
156 "true" )
157 time.sleep( setIPv6CfgSleep )
158 cfgResult2 = main.Cluster.active( 0 ).CLI.setCfg( "org.onosproject.provider.host.impl.HostLocationProvider",
159 "requestIpv6ND",
160 "true" )
161 else:
162 main.log.info( "Skipped setting IPv6 cfg parameters as it is disabled in params file" )
163 cfgResult1 = main.TRUE
164 cfgResult2 = main.TRUE
165 cfgResult = cfgResult1 and cfgResult2
166 utilities.assert_equals( expect=main.TRUE,
167 actual=cfgResult,
168 onpass="ipv6NeighborDiscovery cfg is set to true",
169 onfail="Failed to cfg set ipv6NeighborDiscovery" )
170
171 def CASE2( self, main ):
172 """
173 Load network configuration files
174 """
175 import json
176 main.case( "Load json files for configuring the network" )
177
178 main.step( "Load json files for configuring the network" )
179 cfgResult = main.TRUE
180 jsonFileName = main.params[ 'CASE2' ][ 'fileName' ]
181 jsonFile = main.testDir + "/dependencies/topologies/json/" + jsonFileName
182 with open( jsonFile ) as cfg:
183 main.Cluster.active( 0 ).REST.setNetCfg( json.load( cfg ) )
184
185 main.step( "Load host files" )
186 hostFileName = main.params[ 'CASE2' ][ 'hostFileName' ]
187 hostFile = main.testDir + "/dependencies/topologies/host/" + hostFileName
188 with open( hostFile ) as cfg:
189 main.expectedHosts = json.load( cfg )
190
191 utilities.assert_equals( expect=main.TRUE,
192 actual=cfgResult,
193 onpass="Correctly loaded network configurations",
194 onfail="Failed to load network configurations" )
195
196 def CASE4( self, main ):
197 """
198 Copy topology lib and config files to Mininet node
You Wangdb927a52016-02-26 11:03:28 -0800199 """
200 import re
You Wang9fc5ce42019-01-23 15:10:08 -0800201 main.case( "Copy topology lib and config files to Mininet node" )
202
203 copyResult = main.TRUE
204 main.step( "Copy topology lib files to Mininet node" )
205 for libFileName in main.params[ 'CASE4' ][ 'lib' ].split(","):
206 libFile = main.testDir + "/dependencies/topologies/lib/" + libFileName
207 copyResult = copyResult and main.ONOSbench.scp( main.Mininet1,
208 libFile,
209 main.Mininet1.home + "/custom",
210 direction="to" )
211
212 main.step( "Copy topology config files to Mininet node" )
213 controllerIPs = [ ctrl.ipAddress for ctrl in main.Cluster.runningNodes ]
214 index = 0
215 for confFileName in main.params[ 'CASE4' ][ 'conf' ].split(","):
216 confFile = main.testDir + "/dependencies/topologies/conf/" + confFileName
217 # Update zebra configurations with correct ONOS instance IP
218 if confFileName in [ "zebradbgp1.conf", "zebradbgp2.conf" ]:
219 ip = controllerIPs[ index ]
220 index = ( index + 1 ) % len( controllerIPs )
221 with open( confFile ) as f:
222 s = f.read()
223 s = re.sub( r"(fpm connection ip).*(port 2620)", r"\1 " + ip + r" \2", s )
224 with open( confFile, "w" ) as f:
225 f.write( s )
226 copyResult = copyResult and main.ONOSbench.scp( main.Mininet1,
227 confFile,
228 "~/",
229 direction="to" )
230
231 utilities.assert_equals( expect=main.TRUE,
232 actual=copyResult,
233 onpass="Successfully copied topo lib/conf files",
234 onfail="Failed to copy topo lib/conf files" )
235
236 def CASE5( self, main ):
237 """
You Wangc61aaa22019-02-01 15:49:48 -0800238 Load Mininet or physical network topology and balances switch mastership
You Wang9fc5ce42019-01-23 15:10:08 -0800239 """
You Wangdb927a52016-02-26 11:03:28 -0800240 import time
You Wang9fc5ce42019-01-23 15:10:08 -0800241 import re
You Wangc61aaa22019-02-01 15:49:48 -0800242 main.log.report( "Load Mininet or physical network topology and Balance switch mastership" )
You Wangdb927a52016-02-26 11:03:28 -0800243 main.log.report( "________________________________________________________________________" )
You Wangc61aaa22019-02-01 15:49:48 -0800244 main.case( "Load Mininet or physical network topology and Balance switch mastership" )
You Wangdb927a52016-02-26 11:03:28 -0800245
You Wangc61aaa22019-02-01 15:49:48 -0800246 if hasattr( main, 'Mininet1' ):
247 main.step( "Copy Mininet topology files" )
248 main.topoIndex = "topo" + str( main.params[ 'TEST' ][ 'topo' ] )
249 topoFileName = main.params[ 'TOPO' ][ main.topoIndex ][ 'fileName' ]
250 topoFile = main.testDir + "/dependencies/topologies/" + topoFileName
251 copyResult = main.ONOSbench.scp( main.Mininet1, topoFile, main.Mininet1.home + "/custom", direction="to" )
252 utilities.assert_equals( expect=main.TRUE,
253 actual=copyResult,
254 onpass="Successfully copied topo files",
255 onfail="Failed to copy topo files" )
You Wang9fc5ce42019-01-23 15:10:08 -0800256
You Wangc61aaa22019-02-01 15:49:48 -0800257 main.step( "Load topology" )
258 if hasattr( main, 'Mininet1' ):
259 topoResult = main.Mininet1.startNet( topoFile=main.Mininet1.home + "/custom/" + topoFileName,
260 args=main.params[ 'TOPO' ][ 'mininetArgs' ] )
261 else:
262 topoResult = main.NetworkBench.connectToNet()
You Wangdb927a52016-02-26 11:03:28 -0800263 utilities.assert_equals( expect=main.TRUE,
You Wangc61aaa22019-02-01 15:49:48 -0800264 actual=topoResult,
265 onpass="Successfully loaded topology",
266 onfail="Failed to load topology" )
267 # Exit if topology did not load properly
268 if not topoResult:
269 main.cleanAndExit()
You Wangdb927a52016-02-26 11:03:28 -0800270
271 main.step( "Assign switches to controllers" )
You Wangc61aaa22019-02-01 15:49:48 -0800272 if hasattr( main, 'Mininet1' ):
273 main.networkSwitches = main.Network.getSwitches( excludeNodes=main.excludeNodes )
274 else:
275 main.networkSwitches = main.Network.getSwitches( excludeNodes=main.excludeNodes,
276 includeStopped=True )
277 assignResult = main.TRUE
278 for name in main.networkSwitches.keys():
Devin Lim142b5342017-07-20 15:22:39 -0700279 ips = main.Cluster.getIps()
You Wangc61aaa22019-02-01 15:49:48 -0800280 assignResult = assignResult and main.Network.assignSwController( sw=name, ip=ips )
You Wangdb927a52016-02-26 11:03:28 -0800281 utilities.assert_equals( expect=main.TRUE,
You Wangc61aaa22019-02-01 15:49:48 -0800282 actual=assignResult,
283 onpass="Successfully assign switches to controllers",
284 onfail="Failed to assign switches to controllers" )
285
You Wangdb927a52016-02-26 11:03:28 -0800286 # Waiting here to make sure topology converges across all nodes
You Wang9fc5ce42019-01-23 15:10:08 -0800287 sleep = int( main.params[ 'TOPO' ][ 'loadTopoSleep' ] )
You Wangdb927a52016-02-26 11:03:28 -0800288 time.sleep( sleep )
289
290 main.step( "Balance devices across controllers" )
Devin Lim142b5342017-07-20 15:22:39 -0700291 balanceResult = main.Cluster.active( 0 ).CLI.balanceMasters()
You Wangc61aaa22019-02-01 15:49:48 -0800292 utilities.assert_equals( expect=main.TRUE,
293 actual=balanceResult,
294 onpass="Successfully balanced mastership",
295 onfail="Faild to balance mastership" )
You Wangdb927a52016-02-26 11:03:28 -0800296 # giving some breathing time for ONOS to complete re-balance
You Wang9fc5ce42019-01-23 15:10:08 -0800297 time.sleep( 5 )
298
You Wangc61aaa22019-02-01 15:49:48 -0800299 # Connecting to hosts that only have data plane connectivity
300 if hasattr( main, 'NetworkBench' ):
301 main.step( "Connecting inband hosts" )
302 hostResult = main.NetworkBench.connectInbandHosts()
303 utilities.assert_equals( expect=main.TRUE,
304 actual=hostResult,
305 onpass="Successfully connected inband hosts",
306 onfail="Failed to connect inband hosts" )
307 else:
308 hostResult = main.TRUE
You Wangdb927a52016-02-26 11:03:28 -0800309
You Wangc61aaa22019-02-01 15:49:48 -0800310 # Get network hosts and links
311 main.networkHosts = main.Network.getHosts()
312 if hasattr( main, "expectedHosts" ):
313 main.networkHosts = { key: value for key, value in main.networkHosts.items() if key in main.expectedHosts[ "network" ].keys() }
314 main.networkLinks = main.Network.getLinks()
315 main.networkLinks = [ link for link in main.networkLinks if
316 link[ 'node1' ] in main.networkHosts.keys() + main.networkSwitches.keys() and
317 link[ 'node2' ] in main.networkHosts.keys() + main.networkSwitches.keys() ]
318
319 caseResult = ( topoResult and assignResult and balanceResult and hostResult )
You Wangdb927a52016-02-26 11:03:28 -0800320 utilities.assert_equals( expect=main.TRUE,
321 actual=caseResult,
You Wangc61aaa22019-02-01 15:49:48 -0800322 onpass="Starting new topology test PASS",
323 onfail="Starting new topology test FAIL" )
You Wangdb927a52016-02-26 11:03:28 -0800324
You Wang9fc5ce42019-01-23 15:10:08 -0800325 def CASE6( self, main ):
You Wangdb927a52016-02-26 11:03:28 -0800326 """
327 Collect and store device and link data from ONOS
328 """
329 import json
330 from tests.CHOTestMonkey.dependencies.elements.NetworkElement import Device, Link
331
332 main.log.report( "Collect and Store topology details from ONOS" )
333 main.log.report( "____________________________________________________________________" )
334 main.case( "Collect and Store Topology Details from ONOS" )
You Wang9fc5ce42019-01-23 15:10:08 -0800335
You Wangdb927a52016-02-26 11:03:28 -0800336 topoResult = main.TRUE
Devin Lim142b5342017-07-20 15:22:39 -0700337 topologyOutput = main.Cluster.active( 0 ).CLI.topology()
338 topologyResult = main.Cluster.active( 0 ).CLI.getTopology( topologyOutput )
You Wangdb927a52016-02-26 11:03:28 -0800339 ONOSDeviceNum = int( topologyResult[ 'devices' ] )
340 ONOSLinkNum = int( topologyResult[ 'links' ] )
You Wangc61aaa22019-02-01 15:49:48 -0800341 networkSwitchNum = len( main.networkSwitches )
342 if hasattr( main, 'Mininet1' ):
343 networkLinkNum = ( len( main.networkLinks ) - len( main.networkHosts ) ) * 2
344 else:
345 networkLinkNum = len( main.networkLinks ) * 2
346 if networkSwitchNum == ONOSDeviceNum and networkLinkNum == ONOSLinkNum:
You Wangdb927a52016-02-26 11:03:28 -0800347 main.step( "Collect and store device data" )
348 stepResult = main.TRUE
349 dpidToName = {}
You Wangc61aaa22019-02-01 15:49:48 -0800350 for key, value in main.networkSwitches.items():
You Wangdb927a52016-02-26 11:03:28 -0800351 dpidToName[ 'of:' + str( value[ 'dpid' ] ) ] = key
You Wang9fc5ce42019-01-23 15:10:08 -0800352 main.devicesRaw = main.Cluster.active( 0 ).CLI.devices()
353 devices = json.loads( main.devicesRaw )
You Wangdb927a52016-02-26 11:03:28 -0800354 deviceInitIndex = 0
355 for device in devices:
356 name = dpidToName[ device[ 'id' ] ]
357 newDevice = Device( deviceInitIndex, name, device[ 'id' ] )
You Wang9fc5ce42019-01-23 15:10:08 -0800358 main.log.info( 'New device: {}'.format( newDevice ) )
You Wangdb927a52016-02-26 11:03:28 -0800359 main.devices.append( newDevice )
360 deviceInitIndex += 1
361 utilities.assert_equals( expect=main.TRUE,
362 actual=stepResult,
363 onpass="Successfully collected and stored device data",
364 onfail="Failed to collect and store device data" )
365
366 main.step( "Collect and store link data" )
367 stepResult = main.TRUE
You Wang9fc5ce42019-01-23 15:10:08 -0800368 main.linksRaw = main.Cluster.active( 0 ).CLI.links()
369 links = json.loads( main.linksRaw )
You Wangdb927a52016-02-26 11:03:28 -0800370 linkInitIndex = 0
371 for link in links:
372 for device in main.devices:
373 if device.dpid == link[ 'src' ][ 'device' ]:
374 deviceA = device
375 elif device.dpid == link[ 'dst' ][ 'device' ]:
376 deviceB = device
Jon Hall2bb3e212017-05-24 17:07:25 -0700377 assert deviceA is not None and deviceB is not None
You Wangdb927a52016-02-26 11:03:28 -0800378 newLink = Link( linkInitIndex, deviceA, link[ 'src' ][ 'port' ], deviceB, link[ 'dst' ][ 'port' ] )
You Wang9fc5ce42019-01-23 15:10:08 -0800379 main.log.info( 'New link: {}'.format( newLink ) )
You Wangdb927a52016-02-26 11:03:28 -0800380 main.links.append( newLink )
381 linkInitIndex += 1
382 # Set backward links and outgoing links of devices
383 for linkA in main.links:
384 linkA.deviceA.outgoingLinks.append( linkA )
Jon Hall2bb3e212017-05-24 17:07:25 -0700385 if linkA.backwardLink is not None:
You Wangdb927a52016-02-26 11:03:28 -0800386 continue
387 for linkB in main.links:
Jon Hall2bb3e212017-05-24 17:07:25 -0700388 if linkB.backwardLink is not None:
You Wangdb927a52016-02-26 11:03:28 -0800389 continue
390 if linkA.deviceA == linkB.deviceB and\
Jon Hall2bb3e212017-05-24 17:07:25 -0700391 linkA.deviceB == linkB.deviceA and\
392 linkA.portA == linkB.portB and\
393 linkA.portB == linkB.portA:
You Wangdb927a52016-02-26 11:03:28 -0800394 linkA.setBackwardLink( linkB )
395 linkB.setBackwardLink( linkA )
396 utilities.assert_equals( expect=main.TRUE,
397 actual=stepResult,
398 onpass="Successfully collected and stored link data",
399 onfail="Failed to collect and store link data" )
400 else:
You Wangc61aaa22019-02-01 15:49:48 -0800401 main.log.info( "Devices (expected): %s, Links (expected): %s" % ( networkSwitchNum, networkLinkNum ) )
You Wangdb927a52016-02-26 11:03:28 -0800402 main.log.info( "Devices (actual): %s, Links (actual): %s" % ( ONOSDeviceNum, ONOSLinkNum ) )
403 topoResult = main.FALSE
404
405 caseResult = topoResult
406 utilities.assert_equals( expect=main.TRUE,
407 actual=caseResult,
408 onpass="Saving ONOS topology data test PASS",
409 onfail="Saving ONOS topology data test FAIL" )
410
411 if not caseResult:
Jon Hall2bb3e212017-05-24 17:07:25 -0700412 main.log.info( "Topology does not match, exiting test..." )
Devin Lim44075962017-08-11 10:56:37 -0700413 main.cleanAndExit()
You Wangdb927a52016-02-26 11:03:28 -0800414
You Wang9fc5ce42019-01-23 15:10:08 -0800415 def CASE7( self, main ):
You Wangdb927a52016-02-26 11:03:28 -0800416 """
417 Collect and store host data from ONOS
418 """
419 import json
420 from tests.CHOTestMonkey.dependencies.elements.NetworkElement import Host
421
422 main.log.report( "Collect and store host adta from ONOS" )
423 main.log.report( "______________________________________________" )
You Wang9fc5ce42019-01-23 15:10:08 -0800424 main.case( "Use fwd app and pingall to discover all the hosts if necessary, then collect and store host data" )
You Wangdb927a52016-02-26 11:03:28 -0800425
You Wang9fc5ce42019-01-23 15:10:08 -0800426 if main.params[ 'TEST' ][ 'dataPlaneConnectivity' ] == 'False':
427 main.step( "Enable Reactive forwarding" )
428 appResult = main.Cluster.active( 0 ).CLI.activateApp( "org.onosproject.fwd" )
429 cfgResult1 = main.TRUE
430 cfgResult2 = main.TRUE
431 if main.enableIPv6:
432 cfgResult1 = main.Cluster.active( 0 ).CLI.setCfg( "org.onosproject.fwd.ReactiveForwarding", "ipv6Forwarding", "true" )
433 cfgResult2 = main.Cluster.active( 0 ).CLI.setCfg( "org.onosproject.fwd.ReactiveForwarding", "matchIpv6Address", "true" )
434 stepResult = appResult and cfgResult1 and cfgResult2
435 utilities.assert_equals( expect=main.TRUE,
436 actual=stepResult,
437 onpass="Successfully enabled reactive forwarding",
438 onfail="Failed to enable reactive forwarding" )
You Wangdb927a52016-02-26 11:03:28 -0800439
You Wang9fc5ce42019-01-23 15:10:08 -0800440 main.step( "Discover hosts using pingall" )
You Wangc61aaa22019-02-01 15:49:48 -0800441 main.Network.pingall()
You Wang9fc5ce42019-01-23 15:10:08 -0800442 if main.enableIPv6:
You Wangc61aaa22019-02-01 15:49:48 -0800443 ping6Result = main.Network.pingall( protocol="IPv6" )
You Wang9fc5ce42019-01-23 15:10:08 -0800444
445 main.step( "Disable Reactive forwarding" )
446 appResult = main.Cluster.active( 0 ).CLI.deactivateApp( "org.onosproject.fwd" )
447 stepResult = appResult
448 utilities.assert_equals( expect=main.TRUE,
449 actual=stepResult,
450 onpass="Successfully deactivated fwd app",
451 onfail="Failed to deactivate fwd app" )
452
453 main.step( "Verify host discovery" )
You Wangdb927a52016-02-26 11:03:28 -0800454 stepResult = main.TRUE
You Wang9fc5ce42019-01-23 15:10:08 -0800455 main.hostsRaw = main.Cluster.active( 0 ).CLI.hosts()
456 hosts = json.loads( main.hostsRaw )
457 if hasattr( main, "expectedHosts" ):
458 hosts = [ host for host in hosts if host[ 'id' ] in main.expectedHosts[ 'onos' ].keys() ]
You Wangc61aaa22019-02-01 15:49:48 -0800459 if not len( hosts ) == len( main.networkHosts ):
You Wangdb927a52016-02-26 11:03:28 -0800460 stepResult = main.FALSE
461 utilities.assert_equals( expect=main.TRUE,
462 actual=stepResult,
463 onpass="Host discovery PASS",
464 onfail="Host discovery FAIL" )
465 if not stepResult:
466 main.log.debug( hosts )
Devin Lim44075962017-08-11 10:56:37 -0700467 main.cleanAndExit()
You Wangdb927a52016-02-26 11:03:28 -0800468
You Wangdb927a52016-02-26 11:03:28 -0800469 main.step( "Collect and store host data" )
470 stepResult = main.TRUE
471 macToName = {}
You Wangc61aaa22019-02-01 15:49:48 -0800472 for key, value in main.networkHosts.items():
You Wangdb927a52016-02-26 11:03:28 -0800473 macToName[ value[ 'interfaces' ][ 0 ][ 'mac' ].upper() ] = key
474 dpidToDevice = {}
475 for device in main.devices:
476 dpidToDevice[ device.dpid ] = device
477 hostInitIndex = 0
478 for host in hosts:
479 name = macToName[ host[ 'mac' ] ]
You Wang9fc5ce42019-01-23 15:10:08 -0800480 devices = {}
481 for location in host[ 'locations' ]:
482 device = dpidToDevice[ location[ 'elementId' ] ]
483 devices[ device ] = location[ 'port' ]
You Wangdb927a52016-02-26 11:03:28 -0800484 newHost = Host( hostInitIndex,
485 name, host[ 'id' ], host[ 'mac' ],
You Wang9fc5ce42019-01-23 15:10:08 -0800486 devices,
You Wangdb927a52016-02-26 11:03:28 -0800487 host[ 'vlan' ], host[ 'ipAddresses' ] )
You Wang9fc5ce42019-01-23 15:10:08 -0800488 main.log.info( 'New host: {}'.format( newHost ) )
You Wangdb927a52016-02-26 11:03:28 -0800489 main.hosts.append( newHost )
You Wangdb927a52016-02-26 11:03:28 -0800490 hostInitIndex += 1
You Wang9fc5ce42019-01-23 15:10:08 -0800491 for location in host[ 'locations' ]:
492 device = dpidToDevice[ location[ 'elementId' ] ]
493 main.devices[ device.index ].hosts[ newHost ] = location[ 'port' ]
494
495 # Collect IPv4 and IPv6 hosts
496 main.ipv4Hosts = []
497 main.ipv6Hosts = []
498 for host in main.hosts:
499 if any( re.match( str( main.params[ 'TEST' ][ 'ipv6Regex' ] ), ipAddress ) for ipAddress in host.ipAddresses ):
500 main.ipv6Hosts.append( host )
501 if any( re.match( str( main.params[ 'TEST' ][ 'ipv4Regex' ] ), ipAddress ) for ipAddress in host.ipAddresses ):
502 main.ipv4Hosts.append( host )
You Wangdb927a52016-02-26 11:03:28 -0800503 utilities.assert_equals( expect=main.TRUE,
504 actual=stepResult,
505 onpass="Successfully collected and stored host data",
506 onfail="Failed to collect and store host data" )
507
508 main.step( "Create one host component for each host and then start host cli" )
You Wangc61aaa22019-02-01 15:49:48 -0800509 hostResult = main.TRUE
You Wangdb927a52016-02-26 11:03:28 -0800510 for host in main.hosts:
You Wangc61aaa22019-02-01 15:49:48 -0800511 main.Network.createHostComponent( host.name )
You Wangdb927a52016-02-26 11:03:28 -0800512 hostHandle = getattr( main, host.name )
You Wangc61aaa22019-02-01 15:49:48 -0800513 if hasattr( main, "Mininet1" ):
514 main.log.info( "Starting CLI on host " + str( host.name ) )
515 hostResult = hostResult and hostHandle.startHostCli()
516 else:
517 main.log.info( "Connecting inband host " + str( host.name ) )
518 hostResult = hostResult and hostHandle.connectInband()
You Wangdb927a52016-02-26 11:03:28 -0800519 host.setHandle( hostHandle )
You Wang9fc5ce42019-01-23 15:10:08 -0800520 if main.params[ 'TEST' ][ 'dataPlaneConnectivity' ] == 'True':
521 # Hosts should already be able to ping each other
522 if host in main.ipv4Hosts:
523 host.correspondents += main.ipv4Hosts
524 if host in main.ipv6Hosts:
525 host.correspondents += main.ipv6Hosts
526 utilities.assert_equals( expect=main.TRUE,
You Wangc61aaa22019-02-01 15:49:48 -0800527 actual=hostResult,
528 onpass="Host components created",
529 onfail="Failed to create host components" )
You Wangdb927a52016-02-26 11:03:28 -0800530
531 def CASE10( self, main ):
532 """
533 Run all enabled checks
534 """
535 import time
536 from tests.CHOTestMonkey.dependencies.events.Event import EventType
537 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
538
539 main.log.report( "Run all enabled checks" )
540 main.log.report( "__________________________________________________" )
541 main.case( "Run all enabled checks" )
542 main.step( "Run all enabled checks" )
543 main.caseResult = main.TRUE
544 main.eventGenerator.triggerEvent( EventType().CHECK_ALL, EventScheduleMethod().RUN_BLOCK )
545 # Wait for the scheduler to become idle before going to the next testcase
546 with main.eventScheduler.idleCondition:
547 while not main.eventScheduler.isIdle():
548 main.eventScheduler.idleCondition.wait()
549 utilities.assert_equals( expect=main.TRUE,
550 actual=main.caseResult,
551 onpass="All enabled checks passed",
552 onfail="Not all enabled checks passed" )
553 time.sleep( main.caseSleep )
554
555 def CASE20( self, main ):
556 """
557 Bring down/up links and check topology and ping
558 """
559 import time
560 from tests.CHOTestMonkey.dependencies.events.Event import EventType
561 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
562
563 main.log.report( "Bring down/up links and check topology and ping" )
564 main.log.report( "__________________________________________________" )
565 main.case( "Bring down/up links and check topology and ping" )
566 main.step( "Bring down/up links and check topology and ping" )
567 main.caseResult = main.TRUE
568 linkToggleNum = int( main.params[ 'CASE20' ][ 'linkToggleNum' ] )
569 linkDownUpInterval = int( main.params[ 'CASE20' ][ 'linkDownUpInterval' ] )
570 for i in range( 0, linkToggleNum ):
571 main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_RANDOM_TOGGLE, EventScheduleMethod().RUN_BLOCK, linkDownUpInterval )
572 with main.eventScheduler.idleCondition:
573 while not main.eventScheduler.isIdle():
574 main.eventScheduler.idleCondition.wait()
575 utilities.assert_equals( expect=main.TRUE,
576 actual=main.caseResult,
577 onpass="Toggle network links test passed",
578 onfail="Toggle network links test failed" )
579 time.sleep( main.caseSleep )
580
581 def CASE21( self, main ):
582 """
583 Bring down/up a group of links and check topology and ping
584 """
585 import time
586 from tests.CHOTestMonkey.dependencies.events.Event import EventType
587 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
588
589 main.log.report( "Bring down/up a group of links and check topology and ping" )
590 main.log.report( "__________________________________________________" )
591 main.case( "Bring down/up a group of links and check topology and ping" )
592 main.step( "Bring down/up a group of links and check topology and ping" )
593 main.caseResult = main.TRUE
594 linkGroupSize = int( main.params[ 'CASE21' ][ 'linkGroupSize' ] )
595 linkDownDownInterval = int( main.params[ 'CASE21' ][ 'linkDownDownInterval' ] )
596 linkDownUpInterval = int( main.params[ 'CASE21' ][ 'linkDownUpInterval' ] )
597 main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_GROUP_RANDOM_TOGGLE, EventScheduleMethod().RUN_BLOCK, linkGroupSize, linkDownDownInterval, linkDownUpInterval )
598 with main.eventScheduler.idleCondition:
599 while not main.eventScheduler.isIdle():
600 main.eventScheduler.idleCondition.wait()
601 utilities.assert_equals( expect=main.TRUE,
602 actual=main.caseResult,
603 onpass="Toggle network link group test passed",
604 onfail="Toggle network link group test failed" )
605 time.sleep( main.caseSleep )
606
607 def CASE30( self, main ):
608 """
609 Install host intents and check intent states and ping
610 """
611 import time
612 from tests.CHOTestMonkey.dependencies.events.Event import EventType
613 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
614
615 main.log.report( "Install host intents and check intent states and ping" )
616 main.log.report( "__________________________________________________" )
617 main.case( "Install host intents and check intent states and ping" )
618 main.step( "Install host intents and check intent states and ping" )
619 main.caseResult = main.TRUE
620 main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_ADD_ALL, EventScheduleMethod().RUN_BLOCK )
621 with main.eventScheduler.idleCondition:
622 while not main.eventScheduler.isIdle():
623 main.eventScheduler.idleCondition.wait()
624 utilities.assert_equals( expect=main.TRUE,
625 actual=main.caseResult,
626 onpass="Install host intents test passed",
627 onfail="Install host intents test failed" )
628 time.sleep( main.caseSleep )
629
630 def CASE31( self, main ):
631 """
632 Uninstall host intents and check intent states and ping
633 """
634 import time
635 from tests.CHOTestMonkey.dependencies.events.Event import EventType
636 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
637
638 main.log.report( "Uninstall host intents and check intent states and ping" )
639 main.log.report( "__________________________________________________" )
640 main.case( "Uninstall host intents and check intent states and ping" )
641 main.step( "Uninstall host intents and check intent states and ping" )
642 main.caseResult = main.TRUE
643 main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_DEL_ALL, EventScheduleMethod().RUN_BLOCK )
644 with main.eventScheduler.idleCondition:
645 while not main.eventScheduler.isIdle():
646 main.eventScheduler.idleCondition.wait()
647 utilities.assert_equals( expect=main.TRUE,
648 actual=main.caseResult,
649 onpass="Uninstall host intents test passed",
650 onfail="Uninstall host intents test failed" )
651 time.sleep( main.caseSleep )
652
653 def CASE32( self, main ):
654 """
655 Install point intents and check intent states and ping
656 """
657 import time
658 from tests.CHOTestMonkey.dependencies.events.Event import EventType
659 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
660
661 main.log.report( "Install point intents and check intent states and ping" )
662 main.log.report( "__________________________________________________" )
663 main.case( "Install point intents and check intent states and ping" )
664 main.step( "Install point intents and check intent states and ping" )
665 main.caseResult = main.TRUE
666 main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_ADD_ALL, EventScheduleMethod().RUN_BLOCK )
667 with main.eventScheduler.idleCondition:
668 while not main.eventScheduler.isIdle():
669 main.eventScheduler.idleCondition.wait()
670 utilities.assert_equals( expect=main.TRUE,
671 actual=main.caseResult,
672 onpass="Install point intents test passed",
673 onfail="Install point intents test failed" )
674 time.sleep( main.caseSleep )
675
676 def CASE33( self, main ):
677 """
678 Uninstall point intents and check intent states and ping
679 """
680 import time
681 from tests.CHOTestMonkey.dependencies.events.Event import EventType
682 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
683
684 main.log.report( "Uninstall point intents and check intent states and ping" )
685 main.log.report( "__________________________________________________" )
686 main.case( "Uninstall point intents and check intent states and ping" )
687 main.step( "Uninstall point intents and check intent states and ping" )
688 main.caseResult = main.TRUE
689 main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_DEL_ALL, EventScheduleMethod().RUN_BLOCK )
690 with main.eventScheduler.idleCondition:
691 while not main.eventScheduler.isIdle():
692 main.eventScheduler.idleCondition.wait()
693 utilities.assert_equals( expect=main.TRUE,
694 actual=main.caseResult,
695 onpass="Uninstall point intents test passed",
696 onfail="Uninstall point intents test failed" )
697 time.sleep( main.caseSleep )
698
699 def CASE40( self, main ):
700 """
701 Randomly bring down one ONOS node
702 """
703 import time
704 import random
705 from tests.CHOTestMonkey.dependencies.events.Event import EventType
706 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
707
708 main.log.report( "Randomly bring down one ONOS node" )
709 main.log.report( "__________________________________________________" )
710 main.case( "Randomly bring down one ONOS node" )
711 main.step( "Randomly bring down one ONOS node" )
712 main.caseResult = main.TRUE
713 availableControllers = []
714 for controller in main.controllers:
715 if controller.isUp():
716 availableControllers.append( controller.index )
717 if len( availableControllers ) == 0:
718 main.log.warn( "No available controllers" )
719 main.caseResult = main.FALSE
720 else:
721 index = random.sample( availableControllers, 1 )
722 main.eventGenerator.triggerEvent( EventType().ONOS_ONOS_DOWN, EventScheduleMethod().RUN_BLOCK, index[ 0 ] )
723 with main.eventScheduler.idleCondition:
724 while not main.eventScheduler.isIdle():
725 main.eventScheduler.idleCondition.wait()
726 utilities.assert_equals( expect=main.TRUE,
727 actual=main.caseResult,
728 onpass="Randomly bring down ONOS test passed",
729 onfail="Randomly bring down ONOS test failed" )
You Wang817990a2019-01-22 15:07:25 -0800730 time.sleep( int( main.params[ 'CASE40' ][ 'sleepSec' ] ) )
You Wangdb927a52016-02-26 11:03:28 -0800731
732 def CASE41( self, main ):
733 """
734 Randomly bring up one ONOS node that is down
735 """
736 import time
737 import random
738 from tests.CHOTestMonkey.dependencies.events.Event import EventType
739 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
740
741 main.log.report( "Randomly bring up one ONOS node that is down" )
742 main.log.report( "__________________________________________________" )
743 main.case( "Randomly bring up one ONOS node that is down" )
744 main.step( "Randomly bring up one ONOS node that is down" )
745 main.caseResult = main.TRUE
746 targetControllers = []
747 for controller in main.controllers:
748 if not controller.isUp():
749 targetControllers.append( controller.index )
750 if len( targetControllers ) == 0:
751 main.log.warn( "All controllers are up" )
752 main.caseResult = main.FALSE
753 else:
754 index = random.sample( targetControllers, 1 )
755 main.eventGenerator.triggerEvent( EventType().ONOS_ONOS_UP, EventScheduleMethod().RUN_BLOCK, index[ 0 ] )
756 with main.eventScheduler.idleCondition:
757 while not main.eventScheduler.isIdle():
758 main.eventScheduler.idleCondition.wait()
759 utilities.assert_equals( expect=main.TRUE,
760 actual=main.caseResult,
761 onpass="Randomly bring up ONOS test passed",
762 onfail="Randomly bring up ONOS test failed" )
You Wang817990a2019-01-22 15:07:25 -0800763 time.sleep( int( main.params[ 'CASE41' ][ 'sleepSec' ] ) )
You Wangdb927a52016-02-26 11:03:28 -0800764
765 def CASE50( self, main ):
766 """
767 Set FlowObjective to True
768 """
769 import time
770 from tests.CHOTestMonkey.dependencies.events.Event import EventType
771 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
772
773 main.log.report( "Set FlowObjective to True" )
774 main.log.report( "__________________________________________________" )
775 main.case( "Set FlowObjective to True" )
776 main.step( "Set FlowObjective to True" )
777 main.caseResult = main.TRUE
778 main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'true' )
779 with main.eventScheduler.idleCondition:
780 while not main.eventScheduler.isIdle():
781 main.eventScheduler.idleCondition.wait()
782 utilities.assert_equals( expect=main.TRUE,
783 actual=main.caseResult,
784 onpass="Set FlowObjective test passed",
785 onfail="Set FlowObjective test failed" )
786 time.sleep( main.caseSleep )
787
788 def CASE51( self, main ):
789 """
790 Set FlowObjective to False
791 """
792 import time
793 from tests.CHOTestMonkey.dependencies.events.Event import EventType
794 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
795
796 main.log.report( "Set FlowObjective to False" )
797 main.log.report( "__________________________________________________" )
798 main.case( "Set FlowObjective to False" )
799 main.step( "Set FlowObjective to False" )
800 main.caseResult = main.TRUE
801 main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'false' )
802 with main.eventScheduler.idleCondition:
803 while not main.eventScheduler.isIdle():
804 main.eventScheduler.idleCondition.wait()
805 utilities.assert_equals( expect=main.TRUE,
806 actual=main.caseResult,
807 onpass="Set FlowObjective test passed",
808 onfail="Set FlowObjective test failed" )
809 time.sleep( main.caseSleep )
810
811 def CASE60( self, main ):
812 """
813 Balance device masters
814 """
815 import time
816 from tests.CHOTestMonkey.dependencies.events.Event import EventType
817 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
818
819 main.log.report( "Balance device masters" )
820 main.log.report( "__________________________________________________" )
821 main.case( "Balance device masters" )
822 main.step( "Balance device masters" )
823 main.caseResult = main.TRUE
824 main.eventGenerator.triggerEvent( EventType().ONOS_BALANCE_MASTERS, EventScheduleMethod().RUN_BLOCK )
825 with main.eventScheduler.idleCondition:
826 while not main.eventScheduler.isIdle():
827 main.eventScheduler.idleCondition.wait()
828 utilities.assert_equals( expect=main.TRUE,
829 actual=main.caseResult,
830 onpass="Balance masters test passed",
831 onfail="Balance masters test failed" )
832 time.sleep( main.caseSleep )
833
You Wang7a27f3a2016-07-05 10:12:27 -0700834 def CASE70( self, main ):
835 """
836 Randomly generate events
837 """
838 import time
839 import random
840 from tests.CHOTestMonkey.dependencies.events.Event import EventType
841 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
842
843 main.log.report( "Randomly generate events" )
844 main.log.report( "__________________________________________________" )
845 main.case( "Randomly generate events" )
846 main.step( "Randomly generate events" )
847 main.caseResult = main.TRUE
848 sleepSec = int( main.params[ 'CASE70' ][ 'sleepSec' ] )
You Wangc61aaa22019-02-01 15:49:48 -0800849 allControllers = range( 1, int( main.params[ 'TEST' ][ 'numCtrl' ] ) + 1 )
You Wang7a27f3a2016-07-05 10:12:27 -0700850 while True:
You Wangc61aaa22019-02-01 15:49:48 -0800851 upControllers = [ i for i in allControllers if main.controllers[ i - 1 ].isUp() ]
852 downOnosNum = len( allControllers ) - len( upControllers )
853 hostIntentNum = len( [ intent for intent in main.intents if intent.type == 'INTENT_HOST' ] )
854 pointIntentNum = len( [ intent for intent in main.intents if intent.type == 'INTENT_POINT' ] )
855 downDeviceNum = len( [ device for device in main.devices if device.isDown() or device.isRemoved() ] )
856 downLinkNum = len( [ link for link in main.links if link.isDown() ] ) / 2
857 downPortNum = sum( [ len( device.downPorts ) for device in main.devices ] )
You Wang7a27f3a2016-07-05 10:12:27 -0700858 events = []
You Wangc61aaa22019-02-01 15:49:48 -0800859 for event, weight in main.params[ 'CASE70' ][ 'eventWeight' ].items():
860 events += [ event ] * int( weight )
861 events += [ 'del-host-intent' ] * int( pow( hostIntentNum, 1.5 ) / 100 )
862 events += [ 'del-point-intent' ] * int( pow( pointIntentNum, 1.5 ) / 100 )
863 events += [ 'device-up' ] * int( pow( 4, downDeviceNum ) - 1 )
864 if 'link-down' in main.params[ 'CASE70' ][ 'eventWeight' ].keys():
865 events += [ 'link-up' ] * int( pow( 4, downLinkNum ) - 1 )
866 if 'port-down' in main.params[ 'CASE70' ][ 'eventWeight' ].keys():
867 events += [ 'port-up' ] * int( pow( 4, downPortNum ) - 1 )
868 events += [ 'onos-up' ] * int( pow( 4, downOnosNum ) - 1 )
You Wang7a27f3a2016-07-05 10:12:27 -0700869 main.log.debug( events )
870 event = random.sample( events, 1 )[ 0 ]
871 if event == 'add-host-intent':
872 n = random.randint( 5, 50 )
873 for i in range( n ):
874 cliIndex = random.sample( upControllers, 1 )[ 0 ]
You Wangc848af12016-07-14 09:53:58 -0700875 main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_ADD, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex )
You Wang7a27f3a2016-07-05 10:12:27 -0700876 elif event == 'del-host-intent':
877 n = random.randint( 5, hostIntentNum )
878 for i in range( n ):
879 cliIndex = random.sample( upControllers, 1 )[ 0 ]
You Wangc848af12016-07-14 09:53:58 -0700880 main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_DEL, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex )
You Wang7a27f3a2016-07-05 10:12:27 -0700881 elif event == 'add-point-intent':
882 n = random.randint( 5, 50 )
883 for i in range( n ):
884 cliIndex = random.sample( upControllers, 1 )[ 0 ]
You Wangc848af12016-07-14 09:53:58 -0700885 main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_ADD, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex, 'bidirectional' )
You Wang7a27f3a2016-07-05 10:12:27 -0700886 elif event == 'del-point-intent':
You Wang52163202016-07-14 16:37:15 -0700887 n = random.randint( 5, pointIntentNum / 2 )
You Wang7a27f3a2016-07-05 10:12:27 -0700888 for i in range( n ):
889 cliIndex = random.sample( upControllers, 1 )[ 0 ]
You Wangc848af12016-07-14 09:53:58 -0700890 main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_DEL, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex, 'bidirectional' )
You Wang7a27f3a2016-07-05 10:12:27 -0700891 elif event == 'link-down':
892 main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_DOWN, EventScheduleMethod().RUN_BLOCK, 'random', 'random' )
You Wang7a27f3a2016-07-05 10:12:27 -0700893 elif event == 'link-up':
894 main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_UP, EventScheduleMethod().RUN_BLOCK, 'random', 'random' )
You Wang7a27f3a2016-07-05 10:12:27 -0700895 elif event == 'device-down':
896 main.eventGenerator.triggerEvent( EventType().NETWORK_DEVICE_DOWN, EventScheduleMethod().RUN_BLOCK, 'random' )
You Wang7a27f3a2016-07-05 10:12:27 -0700897 elif event == 'device-up':
898 main.eventGenerator.triggerEvent( EventType().NETWORK_DEVICE_UP, EventScheduleMethod().RUN_BLOCK, 'random' )
You Wang9fc5ce42019-01-23 15:10:08 -0800899 elif event == 'port-down':
900 main.eventGenerator.triggerEvent( EventType().NETWORK_PORT_DOWN, EventScheduleMethod().RUN_BLOCK, 'random', 'random' )
You Wang9fc5ce42019-01-23 15:10:08 -0800901 elif event == 'port-up':
902 main.eventGenerator.triggerEvent( EventType().NETWORK_PORT_UP, EventScheduleMethod().RUN_BLOCK, 'random', 'random' )
You Wangc61aaa22019-02-01 15:49:48 -0800903 elif event == 'onos-down' and downOnosNum == 0:
You Wang9fc5ce42019-01-23 15:10:08 -0800904 main.eventGenerator.triggerEvent( EventType().ONOS_ONOS_DOWN, EventScheduleMethod().RUN_BLOCK, 1 )
You Wang9fc5ce42019-01-23 15:10:08 -0800905 elif event == 'onos-up':
906 main.eventGenerator.triggerEvent( EventType().ONOS_ONOS_UP, EventScheduleMethod().RUN_BLOCK, 1 )
You Wang9fc5ce42019-01-23 15:10:08 -0800907 main.eventGenerator.triggerEvent( EventType().ONOS_BALANCE_MASTERS, EventScheduleMethod().RUN_BLOCK )
You Wangf6e98a82016-11-14 14:46:49 -0800908 elif event == 'toggle-flowobj':
You Wangc61aaa22019-02-01 15:49:48 -0800909 main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'false' if main.flowObj else 'true' )
You Wang7a27f3a2016-07-05 10:12:27 -0700910 else:
911 pass
You Wangc61aaa22019-02-01 15:49:48 -0800912 main.eventGenerator.triggerEvent( EventType().CHECK_ALL, EventScheduleMethod().RUN_NON_BLOCK )
You Wang7a27f3a2016-07-05 10:12:27 -0700913 with main.eventScheduler.idleCondition:
914 while not main.eventScheduler.isIdle():
915 main.eventScheduler.idleCondition.wait()
You Wang5f4f36e2016-09-21 15:30:30 -0700916 time.sleep( sleepSec )
You Wang7a27f3a2016-07-05 10:12:27 -0700917 utilities.assert_equals( expect=main.TRUE,
918 actual=main.caseResult,
919 onpass="Randomly generate events test passed",
920 onfail="Randomly generate events test failed" )
921 time.sleep( main.caseSleep )
922
You Wang52163202016-07-14 16:37:15 -0700923 def CASE80( self, main ):
924 """
925 Replay events from log file
926 """
927 import time
928 from tests.CHOTestMonkey.dependencies.events.Event import EventType
929 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
930
931 main.log.report( "Replay events from log file" )
932 main.log.report( "__________________________________________________" )
933 main.case( "Replay events from log file" )
934 main.step( "Replay events from log file" )
935 main.caseResult = main.TRUE
936 try:
937 f = open( main.params[ 'CASE80' ][ 'filePath' ], 'r' )
938 for line in f.readlines():
939 if 'CHOTestMonkey' in line and 'Event recorded' in line:
940 line = line.split()
941 eventIndex = int( line[ 9 ] )
942 eventName = line[ 10 ]
943 args = line[ 11: ]
944 assert eventName.startswith( 'CHECK' )\
Jon Hall2bb3e212017-05-24 17:07:25 -0700945 or eventName.startswith( 'NETWORK' )\
946 or eventName.startswith( 'APP' )\
947 or eventName.startswith( 'ONOS' )
You Wang52163202016-07-14 16:37:15 -0700948 if main.params[ 'CASE80' ][ 'skipChecks' ] == 'on' and eventName.startswith( 'CHECK' ):
949 continue
950 with main.eventScheduler.idleCondition:
951 while not main.eventScheduler.isIdle():
952 main.eventScheduler.idleCondition.wait()
953 main.eventGenerator.triggerEvent( eventIndex, EventScheduleMethod().RUN_BLOCK, *args )
954 time.sleep( float( main.params[ 'CASE80' ][ 'sleepTime' ] ) )
955 except Exception as e:
You Wang9fc5ce42019-01-23 15:10:08 -0800956 main.log.error( "Uncaught exception: {}".format( e ) )
You Wang52163202016-07-14 16:37:15 -0700957 utilities.assert_equals( expect=main.TRUE,
958 actual=main.caseResult,
959 onpass="Replay from log file passed",
960 onfail="Replay from log file failed" )
961
You Wangdb927a52016-02-26 11:03:28 -0800962 def CASE90( self, main ):
963 """
964 Sleep for some time
965 """
966 import time
967 from tests.CHOTestMonkey.dependencies.events.Event import EventType
968 from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod
969
970 main.log.report( "Sleep for some time" )
971 main.log.report( "__________________________________________________" )
972 main.case( "Sleep for some time" )
973 main.step( "Sleep for some time" )
974 main.caseResult = main.TRUE
975 sleepSec = int( main.params[ 'CASE90' ][ 'sleepSec' ] )
976 main.eventGenerator.triggerEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, sleepSec )
977 with main.eventScheduler.idleCondition:
978 while not main.eventScheduler.isIdle():
979 main.eventScheduler.idleCondition.wait()
980 utilities.assert_equals( expect=main.TRUE,
981 actual=main.caseResult,
982 onpass="Sleep test passed",
983 onfail="Sleep test failed" )
984 time.sleep( main.caseSleep )
985
986 def CASE100( self, main ):
987 """
988 Do something else?
989 """
990 import time
991
992 main.log.report( "Do something else?" )
993 main.log.report( "__________________________________________________" )
994 main.case( "..." )
995
996 main.step( "Wait until the test stops" )
997
998 main.caseResult = main.TRUE
999 utilities.assert_equals( expect=main.TRUE,
1000 actual=main.caseResult,
1001 onpass="Test PASS",
1002 onfail="Test FAIL" )
1003
1004 testDuration = int( main.params[ 'TEST' ][ 'testDuration' ] )
1005 time.sleep( testDuration )