You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 1 | """ |
| 2 | CHOTestMonkey class |
| 3 | Author: you@onlab.us |
| 4 | """ |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 5 | import sys |
| 6 | import os |
| 7 | import re |
| 8 | import time |
| 9 | import json |
| 10 | import itertools |
| 11 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 12 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 13 | class 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 |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 23 | onos-package |
| 24 | onos-verify-cell |
| 25 | onos-uninstall |
| 26 | onos-install |
| 27 | onos-start-cli |
| 28 | Set IPv6 cfg parameters for Neighbor Discovery |
| 29 | start event scheduler |
| 30 | start event listener |
| 31 | """ |
| 32 | import time |
| 33 | from threading import Lock, Condition |
You Wang | 221db32 | 2016-06-03 15:45:52 -0700 | [diff] [blame] | 34 | from core.graph import Graph |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 35 | from tests.CHOTestMonkey.dependencies.elements.ONOSElement import Controller |
| 36 | from tests.CHOTestMonkey.dependencies.EventGenerator import EventGenerator |
| 37 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduler |
| 38 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame^] | 39 | try: |
| 40 | from tests.dependencies.ONOSSetup import ONOSSetup |
| 41 | main.testSetUp = ONOSSetup() |
| 42 | except ImportError: |
| 43 | main.log.error( "ONOSSetup not found exiting the test" ) |
| 44 | main.exit() |
| 45 | main.testSetUp.envSetupDescription() |
| 46 | |
| 47 | try: |
| 48 | onosPackage = main.params[ 'TEST' ][ 'package' ] |
| 49 | karafTimeout = main.params[ 'TEST' ][ 'karafCliTimeout' ] |
| 50 | main.enableIPv6 = main.params[ 'TEST' ][ 'IPv6' ] |
| 51 | main.enableIPv6 = True if main.enableIPv6 == "on" else False |
| 52 | main.caseSleep = int( main.params[ 'TEST' ][ 'caseSleep' ] ) |
| 53 | main.numCtrls = int( main.params[ 'TEST' ][ 'numCtrl' ] ) |
| 54 | main.maxNodes = main.numCtrls |
| 55 | main.controllers = [] |
| 56 | |
| 57 | main.devices = [] |
| 58 | main.links = [] |
| 59 | main.hosts = [] |
| 60 | main.intents = [] |
| 61 | main.enabledEvents = {} |
| 62 | for eventName in main.params[ 'EVENT' ].keys(): |
| 63 | if main.params[ 'EVENT' ][ eventName ][ 'status' ] == 'on': |
| 64 | main.enabledEvents[ int( main.params[ 'EVENT' ][ eventName ][ 'typeIndex' ] ) ] = eventName |
| 65 | print main.enabledEvents |
| 66 | main.graph = Graph() |
| 67 | main.eventScheduler = EventScheduler() |
| 68 | main.eventGenerator = EventGenerator() |
| 69 | main.variableLock = Lock() |
| 70 | main.mininetLock = Lock() |
| 71 | main.ONOSbenchLock = Lock() |
| 72 | main.threadID = 0 |
| 73 | main.eventID = 0 |
| 74 | main.caseResult = main.TRUE |
| 75 | stepResult = main.testSetUp.envSetup() |
| 76 | except Exception as e: |
| 77 | main.testSetUp.envSetupException(e) |
| 78 | |
| 79 | main.testSetUp.evnSetupConclusion( stepResult ) |
| 80 | |
| 81 | |
You Wang | 2d32ef4 | 2017-03-03 14:09:44 -0800 | [diff] [blame] | 82 | for i in range( 1, main.numCtrls + 1 ): |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 83 | newController = Controller( i ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame^] | 84 | newController.setCLI( main.CLIs[i - 1] ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 85 | main.controllers.append( newController ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 86 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame^] | 87 | if not main.onoscell : |
| 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>") |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 90 | main.cleanup() |
| 91 | main.exit() |
| 92 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame^] | 93 | setupResult = main.testSetUp.ONOSSetUp( Mininet=main.Mininet1, newCell=False, cellName=main.onoscell ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 94 | |
| 95 | main.step( "Set IPv6 cfg parameters for Neighbor Discovery" ) |
| 96 | setIPv6CfgSleep = int( main.params[ 'TEST' ][ 'setIPv6CfgSleep' ] ) |
| 97 | if main.enableIPv6: |
| 98 | time.sleep( setIPv6CfgSleep ) |
You Wang | 5f4f36e | 2016-09-21 15:30:30 -0700 | [diff] [blame] | 99 | cfgResult1 = main.controllers[ 0 ].CLI.setCfg( "org.onosproject.incubator.net.neighbour.impl.NeighbourResolutionManager", |
| 100 | "ndpEnabled", |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 101 | "true" ) |
| 102 | time.sleep( setIPv6CfgSleep ) |
| 103 | cfgResult2 = main.controllers[ 0 ].CLI.setCfg( "org.onosproject.provider.host.impl.HostLocationProvider", |
You Wang | 092d9b2 | 2016-11-22 13:38:01 -0800 | [diff] [blame] | 104 | "useIpv6ND", |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 105 | "true" ) |
| 106 | else: |
| 107 | main.log.info( "Skipped setting IPv6 cfg parameters as it is disabled in params file" ) |
| 108 | cfgResult1 = main.TRUE |
| 109 | cfgResult2 = main.TRUE |
| 110 | cfgResult = cfgResult1 and cfgResult2 |
| 111 | utilities.assert_equals( expect=main.TRUE, |
| 112 | actual=cfgResult, |
| 113 | onpass="ipv6NeighborDiscovery cfg is set to true", |
| 114 | onfail="Failed to cfg set ipv6NeighborDiscovery" ) |
| 115 | |
| 116 | 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 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame^] | 140 | caseResult = setupResult and cfgResult |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 141 | 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 | """ |
| 148 | Load Mininet topology and balances all switches |
| 149 | """ |
| 150 | import re |
| 151 | import time |
| 152 | import copy |
| 153 | |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 154 | main.topoIndex = "topo" + str( main.params[ 'TEST' ][ 'topo' ] ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 155 | |
| 156 | main.log.report( "Load Mininet topology and Balance all Mininet switches across controllers" ) |
| 157 | main.log.report( "________________________________________________________________________" ) |
| 158 | main.case( "Assign and Balance all Mininet switches across controllers" ) |
| 159 | |
| 160 | main.step( "Start Mininet topology" ) |
| 161 | newTopo = main.params[ 'TOPO' ][ main.topoIndex ][ 'fileName' ] |
| 162 | mininetDir = main.Mininet1.home + "/custom/" |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 163 | topoPath = main.testDir + "/" + main.TEST + "/dependencies/topologies/" + newTopo |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 164 | main.ONOSbench.secureCopy( main.Mininet1.user_name, main.Mininet1.ip_address, topoPath, mininetDir, direction="to" ) |
| 165 | topoPath = mininetDir + newTopo |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 166 | startStatus = main.Mininet1.startNet( topoFile=topoPath ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 167 | main.mininetSwitches = main.Mininet1.getSwitches() |
| 168 | main.mininetHosts = main.Mininet1.getHosts() |
You Wang | 55503a3 | 2016-06-27 15:11:40 -0700 | [diff] [blame] | 169 | main.mininetLinks = main.Mininet1.getLinks( timeout=60 ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 170 | utilities.assert_equals( expect=main.TRUE, |
| 171 | actual=startStatus, |
| 172 | onpass="Start Mininet topology test PASS", |
| 173 | onfail="Start Mininet topology test FAIL" ) |
| 174 | |
| 175 | main.step( "Assign switches to controllers" ) |
| 176 | switchMastership = main.TRUE |
| 177 | for switchName in main.mininetSwitches.keys(): |
You Wang | 2d32ef4 | 2017-03-03 14:09:44 -0800 | [diff] [blame] | 178 | main.Mininet1.assignSwController( sw=switchName, ip=main.ONOSip ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 179 | response = main.Mininet1.getSwController( switchName ) |
| 180 | print( "Response is " + str( response ) ) |
You Wang | 2d32ef4 | 2017-03-03 14:09:44 -0800 | [diff] [blame] | 181 | if re.search( "tcp:" + main.ONOSip[ 0 ], response ): |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 182 | switchMastership = switchMastership and main.TRUE |
| 183 | else: |
| 184 | switchMastership = main.FALSE |
| 185 | utilities.assert_equals( expect=main.TRUE, |
| 186 | actual=switchMastership, |
| 187 | onpass="Assign switches to controllers test PASS", |
| 188 | onfail="Assign switches to controllers test FAIL" ) |
| 189 | # Waiting here to make sure topology converges across all nodes |
| 190 | sleep = int( main.params[ 'TEST' ][ 'loadTopoSleep' ] ) |
| 191 | time.sleep( sleep ) |
| 192 | |
| 193 | main.step( "Balance devices across controllers" ) |
| 194 | balanceResult = main.ONOScli1.balanceMasters() |
| 195 | # giving some breathing time for ONOS to complete re-balance |
| 196 | time.sleep( sleep ) |
| 197 | |
| 198 | caseResult = ( startStatus and switchMastership and balanceResult ) |
| 199 | utilities.assert_equals( expect=main.TRUE, |
| 200 | actual=caseResult, |
| 201 | onpass="Starting new Att topology test PASS", |
| 202 | onfail="Starting new Att topology test FAIL" ) |
| 203 | |
| 204 | def CASE2( self, main ): |
| 205 | """ |
| 206 | Collect and store device and link data from ONOS |
| 207 | """ |
| 208 | import json |
| 209 | from tests.CHOTestMonkey.dependencies.elements.NetworkElement import Device, Link |
| 210 | |
| 211 | main.log.report( "Collect and Store topology details from ONOS" ) |
| 212 | main.log.report( "____________________________________________________________________" ) |
| 213 | main.case( "Collect and Store Topology Details from ONOS" ) |
| 214 | topoResult = main.TRUE |
| 215 | topologyOutput = main.ONOScli1.topology() |
| 216 | topologyResult = main.ONOScli1.getTopology( topologyOutput ) |
| 217 | ONOSDeviceNum = int( topologyResult[ 'devices' ] ) |
| 218 | ONOSLinkNum = int( topologyResult[ 'links' ] ) |
| 219 | mininetSwitchNum = len( main.mininetSwitches ) |
| 220 | mininetLinkNum = ( len( main.mininetLinks ) - len( main.mininetHosts ) ) * 2 |
| 221 | if mininetSwitchNum == ONOSDeviceNum and mininetLinkNum == ONOSLinkNum: |
| 222 | main.step( "Collect and store device data" ) |
| 223 | stepResult = main.TRUE |
| 224 | dpidToName = {} |
| 225 | for key, value in main.mininetSwitches.items(): |
| 226 | dpidToName[ 'of:' + str( value[ 'dpid' ] ) ] = key |
| 227 | devicesRaw = main.ONOScli1.devices() |
| 228 | devices = json.loads( devicesRaw ) |
| 229 | deviceInitIndex = 0 |
| 230 | for device in devices: |
| 231 | name = dpidToName[ device[ 'id' ] ] |
| 232 | newDevice = Device( deviceInitIndex, name, device[ 'id' ] ) |
| 233 | print newDevice |
| 234 | main.devices.append( newDevice ) |
| 235 | deviceInitIndex += 1 |
| 236 | utilities.assert_equals( expect=main.TRUE, |
| 237 | actual=stepResult, |
| 238 | onpass="Successfully collected and stored device data", |
| 239 | onfail="Failed to collect and store device data" ) |
| 240 | |
| 241 | main.step( "Collect and store link data" ) |
| 242 | stepResult = main.TRUE |
| 243 | linksRaw = main.ONOScli1.links() |
| 244 | links = json.loads( linksRaw ) |
| 245 | linkInitIndex = 0 |
| 246 | for link in links: |
| 247 | for device in main.devices: |
| 248 | if device.dpid == link[ 'src' ][ 'device' ]: |
| 249 | deviceA = device |
| 250 | elif device.dpid == link[ 'dst' ][ 'device' ]: |
| 251 | deviceB = device |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 252 | assert deviceA is not None and deviceB is not None |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 253 | newLink = Link( linkInitIndex, deviceA, link[ 'src' ][ 'port' ], deviceB, link[ 'dst' ][ 'port' ] ) |
| 254 | print newLink |
| 255 | main.links.append( newLink ) |
| 256 | linkInitIndex += 1 |
| 257 | # Set backward links and outgoing links of devices |
| 258 | for linkA in main.links: |
| 259 | linkA.deviceA.outgoingLinks.append( linkA ) |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 260 | if linkA.backwardLink is not None: |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 261 | continue |
| 262 | for linkB in main.links: |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 263 | if linkB.backwardLink is not None: |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 264 | continue |
| 265 | if linkA.deviceA == linkB.deviceB and\ |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 266 | linkA.deviceB == linkB.deviceA and\ |
| 267 | linkA.portA == linkB.portB and\ |
| 268 | linkA.portB == linkB.portA: |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 269 | linkA.setBackwardLink( linkB ) |
| 270 | linkB.setBackwardLink( linkA ) |
| 271 | utilities.assert_equals( expect=main.TRUE, |
| 272 | actual=stepResult, |
| 273 | onpass="Successfully collected and stored link data", |
| 274 | onfail="Failed to collect and store link data" ) |
| 275 | else: |
| 276 | main.log.info( "Devices (expected): %s, Links (expected): %s" % ( mininetSwitchNum, mininetLinkNum ) ) |
| 277 | main.log.info( "Devices (actual): %s, Links (actual): %s" % ( ONOSDeviceNum, ONOSLinkNum ) ) |
| 278 | topoResult = main.FALSE |
| 279 | |
| 280 | caseResult = topoResult |
| 281 | utilities.assert_equals( expect=main.TRUE, |
| 282 | actual=caseResult, |
| 283 | onpass="Saving ONOS topology data test PASS", |
| 284 | onfail="Saving ONOS topology data test FAIL" ) |
| 285 | |
| 286 | if not caseResult: |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 287 | main.log.info( "Topology does not match, exiting test..." ) |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 288 | main.cleanup() |
| 289 | main.exit() |
| 290 | |
| 291 | def CASE3( self, main ): |
| 292 | """ |
| 293 | Collect and store host data from ONOS |
| 294 | """ |
| 295 | import json |
| 296 | from tests.CHOTestMonkey.dependencies.elements.NetworkElement import Host |
| 297 | |
| 298 | main.log.report( "Collect and store host adta from ONOS" ) |
| 299 | main.log.report( "______________________________________________" ) |
| 300 | main.case( "Use fwd app and pingall to discover all the hosts, then collect and store host data" ) |
| 301 | |
| 302 | main.step( "Enable Reactive forwarding" ) |
| 303 | appResult = main.controllers[ 0 ].CLI.activateApp( "org.onosproject.fwd" ) |
| 304 | cfgResult1 = main.TRUE |
| 305 | cfgResult2 = main.TRUE |
| 306 | if main.enableIPv6: |
| 307 | cfgResult1 = main.controllers[ 0 ].CLI.setCfg( "org.onosproject.fwd.ReactiveForwarding", "ipv6Forwarding", "true" ) |
| 308 | cfgResult2 = main.controllers[ 0 ].CLI.setCfg( "org.onosproject.fwd.ReactiveForwarding", "matchIpv6Address", "true" ) |
| 309 | stepResult = appResult and cfgResult1 and cfgResult2 |
| 310 | utilities.assert_equals( expect=main.TRUE, |
| 311 | actual=stepResult, |
| 312 | onpass="Successfully enabled reactive forwarding", |
| 313 | onfail="Failed to enable reactive forwarding" ) |
| 314 | |
| 315 | main.step( "Discover hosts using pingall" ) |
| 316 | stepResult = main.TRUE |
| 317 | main.Mininet1.pingall() |
| 318 | if main.enableIPv6: |
| 319 | ping6Result = main.Mininet1.pingall( protocol="IPv6" ) |
| 320 | hosts = main.controllers[ 0 ].CLI.hosts() |
| 321 | hosts = json.loads( hosts ) |
| 322 | if not len( hosts ) == len( main.mininetHosts ): |
| 323 | stepResult = main.FALSE |
| 324 | utilities.assert_equals( expect=main.TRUE, |
| 325 | actual=stepResult, |
| 326 | onpass="Host discovery PASS", |
| 327 | onfail="Host discovery FAIL" ) |
| 328 | if not stepResult: |
| 329 | main.log.debug( hosts ) |
| 330 | main.cleanup() |
| 331 | main.exit() |
| 332 | |
| 333 | main.step( "Disable Reactive forwarding" ) |
| 334 | appResult = main.controllers[ 0 ].CLI.deactivateApp( "org.onosproject.fwd" ) |
| 335 | stepResult = appResult |
| 336 | utilities.assert_equals( expect=main.TRUE, |
| 337 | actual=stepResult, |
| 338 | onpass="Successfully deactivated fwd app", |
| 339 | onfail="Failed to deactivate fwd app" ) |
| 340 | |
| 341 | main.step( "Collect and store host data" ) |
| 342 | stepResult = main.TRUE |
| 343 | macToName = {} |
| 344 | for key, value in main.mininetHosts.items(): |
| 345 | macToName[ value[ 'interfaces' ][ 0 ][ 'mac' ].upper() ] = key |
| 346 | dpidToDevice = {} |
| 347 | for device in main.devices: |
| 348 | dpidToDevice[ device.dpid ] = device |
| 349 | hostInitIndex = 0 |
| 350 | for host in hosts: |
| 351 | name = macToName[ host[ 'mac' ] ] |
Jeremy Ronquillo | 0e538bc | 2017-06-13 15:16:09 -0700 | [diff] [blame] | 352 | dpid = host[ 'locations' ][ 0 ][ 'elementId' ] |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 353 | device = dpidToDevice[ dpid ] |
| 354 | newHost = Host( hostInitIndex, |
| 355 | name, host[ 'id' ], host[ 'mac' ], |
Jeremy Ronquillo | 0e538bc | 2017-06-13 15:16:09 -0700 | [diff] [blame] | 356 | device, host[ 'locations' ][ 0 ][ 'port' ], |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 357 | host[ 'vlan' ], host[ 'ipAddresses' ] ) |
| 358 | print newHost |
| 359 | main.hosts.append( newHost ) |
| 360 | main.devices[ device.index ].hosts.append( newHost ) |
| 361 | hostInitIndex += 1 |
| 362 | utilities.assert_equals( expect=main.TRUE, |
| 363 | actual=stepResult, |
| 364 | onpass="Successfully collected and stored host data", |
| 365 | onfail="Failed to collect and store host data" ) |
| 366 | |
| 367 | main.step( "Create one host component for each host and then start host cli" ) |
| 368 | for host in main.hosts: |
| 369 | main.Mininet1.createHostComponent( host.name ) |
| 370 | hostHandle = getattr( main, host.name ) |
| 371 | main.log.info( "Starting CLI on host " + str( host.name ) ) |
| 372 | startCLIResult = hostHandle.startHostCli() |
| 373 | host.setHandle( hostHandle ) |
| 374 | stepResult = startCLIResult |
| 375 | utilities.assert_equals( expect=main.TRUE, |
| 376 | actual=startCLIResult, |
| 377 | onpass="Host CLI started", |
| 378 | onfail="Failed to start host CLI" ) |
| 379 | |
| 380 | def CASE10( self, main ): |
| 381 | """ |
| 382 | Run all enabled checks |
| 383 | """ |
| 384 | import time |
| 385 | from tests.CHOTestMonkey.dependencies.events.Event import EventType |
| 386 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod |
| 387 | |
| 388 | main.log.report( "Run all enabled checks" ) |
| 389 | main.log.report( "__________________________________________________" ) |
| 390 | main.case( "Run all enabled checks" ) |
| 391 | main.step( "Run all enabled checks" ) |
| 392 | main.caseResult = main.TRUE |
| 393 | main.eventGenerator.triggerEvent( EventType().CHECK_ALL, EventScheduleMethod().RUN_BLOCK ) |
| 394 | # Wait for the scheduler to become idle before going to the next testcase |
| 395 | with main.eventScheduler.idleCondition: |
| 396 | while not main.eventScheduler.isIdle(): |
| 397 | main.eventScheduler.idleCondition.wait() |
| 398 | utilities.assert_equals( expect=main.TRUE, |
| 399 | actual=main.caseResult, |
| 400 | onpass="All enabled checks passed", |
| 401 | onfail="Not all enabled checks passed" ) |
| 402 | time.sleep( main.caseSleep ) |
| 403 | |
| 404 | def CASE20( self, main ): |
| 405 | """ |
| 406 | Bring down/up links and check topology and ping |
| 407 | """ |
| 408 | import time |
| 409 | from tests.CHOTestMonkey.dependencies.events.Event import EventType |
| 410 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod |
| 411 | |
| 412 | main.log.report( "Bring down/up links and check topology and ping" ) |
| 413 | main.log.report( "__________________________________________________" ) |
| 414 | main.case( "Bring down/up links and check topology and ping" ) |
| 415 | main.step( "Bring down/up links and check topology and ping" ) |
| 416 | main.caseResult = main.TRUE |
| 417 | linkToggleNum = int( main.params[ 'CASE20' ][ 'linkToggleNum' ] ) |
| 418 | linkDownUpInterval = int( main.params[ 'CASE20' ][ 'linkDownUpInterval' ] ) |
| 419 | for i in range( 0, linkToggleNum ): |
| 420 | main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_RANDOM_TOGGLE, EventScheduleMethod().RUN_BLOCK, linkDownUpInterval ) |
| 421 | with main.eventScheduler.idleCondition: |
| 422 | while not main.eventScheduler.isIdle(): |
| 423 | main.eventScheduler.idleCondition.wait() |
| 424 | utilities.assert_equals( expect=main.TRUE, |
| 425 | actual=main.caseResult, |
| 426 | onpass="Toggle network links test passed", |
| 427 | onfail="Toggle network links test failed" ) |
| 428 | time.sleep( main.caseSleep ) |
| 429 | |
| 430 | def CASE21( self, main ): |
| 431 | """ |
| 432 | Bring down/up a group of links and check topology and ping |
| 433 | """ |
| 434 | import time |
| 435 | from tests.CHOTestMonkey.dependencies.events.Event import EventType |
| 436 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod |
| 437 | |
| 438 | main.log.report( "Bring down/up a group of links and check topology and ping" ) |
| 439 | main.log.report( "__________________________________________________" ) |
| 440 | main.case( "Bring down/up a group of links and check topology and ping" ) |
| 441 | main.step( "Bring down/up a group of links and check topology and ping" ) |
| 442 | main.caseResult = main.TRUE |
| 443 | linkGroupSize = int( main.params[ 'CASE21' ][ 'linkGroupSize' ] ) |
| 444 | linkDownDownInterval = int( main.params[ 'CASE21' ][ 'linkDownDownInterval' ] ) |
| 445 | linkDownUpInterval = int( main.params[ 'CASE21' ][ 'linkDownUpInterval' ] ) |
| 446 | main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_GROUP_RANDOM_TOGGLE, EventScheduleMethod().RUN_BLOCK, linkGroupSize, linkDownDownInterval, linkDownUpInterval ) |
| 447 | with main.eventScheduler.idleCondition: |
| 448 | while not main.eventScheduler.isIdle(): |
| 449 | main.eventScheduler.idleCondition.wait() |
| 450 | utilities.assert_equals( expect=main.TRUE, |
| 451 | actual=main.caseResult, |
| 452 | onpass="Toggle network link group test passed", |
| 453 | onfail="Toggle network link group test failed" ) |
| 454 | time.sleep( main.caseSleep ) |
| 455 | |
| 456 | def CASE30( self, main ): |
| 457 | """ |
| 458 | Install host intents and check intent states and ping |
| 459 | """ |
| 460 | import time |
| 461 | from tests.CHOTestMonkey.dependencies.events.Event import EventType |
| 462 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod |
| 463 | |
| 464 | main.log.report( "Install host intents and check intent states and ping" ) |
| 465 | main.log.report( "__________________________________________________" ) |
| 466 | main.case( "Install host intents and check intent states and ping" ) |
| 467 | main.step( "Install host intents and check intent states and ping" ) |
| 468 | main.caseResult = main.TRUE |
| 469 | main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_ADD_ALL, EventScheduleMethod().RUN_BLOCK ) |
| 470 | with main.eventScheduler.idleCondition: |
| 471 | while not main.eventScheduler.isIdle(): |
| 472 | main.eventScheduler.idleCondition.wait() |
| 473 | utilities.assert_equals( expect=main.TRUE, |
| 474 | actual=main.caseResult, |
| 475 | onpass="Install host intents test passed", |
| 476 | onfail="Install host intents test failed" ) |
| 477 | time.sleep( main.caseSleep ) |
| 478 | |
| 479 | def CASE31( self, main ): |
| 480 | """ |
| 481 | Uninstall host intents and check intent states and ping |
| 482 | """ |
| 483 | import time |
| 484 | from tests.CHOTestMonkey.dependencies.events.Event import EventType |
| 485 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod |
| 486 | |
| 487 | main.log.report( "Uninstall host intents and check intent states and ping" ) |
| 488 | main.log.report( "__________________________________________________" ) |
| 489 | main.case( "Uninstall host intents and check intent states and ping" ) |
| 490 | main.step( "Uninstall host intents and check intent states and ping" ) |
| 491 | main.caseResult = main.TRUE |
| 492 | main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_DEL_ALL, EventScheduleMethod().RUN_BLOCK ) |
| 493 | with main.eventScheduler.idleCondition: |
| 494 | while not main.eventScheduler.isIdle(): |
| 495 | main.eventScheduler.idleCondition.wait() |
| 496 | utilities.assert_equals( expect=main.TRUE, |
| 497 | actual=main.caseResult, |
| 498 | onpass="Uninstall host intents test passed", |
| 499 | onfail="Uninstall host intents test failed" ) |
| 500 | time.sleep( main.caseSleep ) |
| 501 | |
| 502 | def CASE32( self, main ): |
| 503 | """ |
| 504 | Install point intents and check intent states and ping |
| 505 | """ |
| 506 | import time |
| 507 | from tests.CHOTestMonkey.dependencies.events.Event import EventType |
| 508 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod |
| 509 | |
| 510 | main.log.report( "Install point intents and check intent states and ping" ) |
| 511 | main.log.report( "__________________________________________________" ) |
| 512 | main.case( "Install point intents and check intent states and ping" ) |
| 513 | main.step( "Install point intents and check intent states and ping" ) |
| 514 | main.caseResult = main.TRUE |
| 515 | main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_ADD_ALL, EventScheduleMethod().RUN_BLOCK ) |
| 516 | with main.eventScheduler.idleCondition: |
| 517 | while not main.eventScheduler.isIdle(): |
| 518 | main.eventScheduler.idleCondition.wait() |
| 519 | utilities.assert_equals( expect=main.TRUE, |
| 520 | actual=main.caseResult, |
| 521 | onpass="Install point intents test passed", |
| 522 | onfail="Install point intents test failed" ) |
| 523 | time.sleep( main.caseSleep ) |
| 524 | |
| 525 | def CASE33( self, main ): |
| 526 | """ |
| 527 | Uninstall point intents and check intent states and ping |
| 528 | """ |
| 529 | import time |
| 530 | from tests.CHOTestMonkey.dependencies.events.Event import EventType |
| 531 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod |
| 532 | |
| 533 | main.log.report( "Uninstall point intents and check intent states and ping" ) |
| 534 | main.log.report( "__________________________________________________" ) |
| 535 | main.case( "Uninstall point intents and check intent states and ping" ) |
| 536 | main.step( "Uninstall point intents and check intent states and ping" ) |
| 537 | main.caseResult = main.TRUE |
| 538 | main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_DEL_ALL, EventScheduleMethod().RUN_BLOCK ) |
| 539 | with main.eventScheduler.idleCondition: |
| 540 | while not main.eventScheduler.isIdle(): |
| 541 | main.eventScheduler.idleCondition.wait() |
| 542 | utilities.assert_equals( expect=main.TRUE, |
| 543 | actual=main.caseResult, |
| 544 | onpass="Uninstall point intents test passed", |
| 545 | onfail="Uninstall point intents test failed" ) |
| 546 | time.sleep( main.caseSleep ) |
| 547 | |
| 548 | def CASE40( self, main ): |
| 549 | """ |
| 550 | Randomly bring down one ONOS node |
| 551 | """ |
| 552 | import time |
| 553 | import random |
| 554 | from tests.CHOTestMonkey.dependencies.events.Event import EventType |
| 555 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod |
| 556 | |
| 557 | main.log.report( "Randomly bring down one ONOS node" ) |
| 558 | main.log.report( "__________________________________________________" ) |
| 559 | main.case( "Randomly bring down one ONOS node" ) |
| 560 | main.step( "Randomly bring down one ONOS node" ) |
| 561 | main.caseResult = main.TRUE |
| 562 | availableControllers = [] |
| 563 | for controller in main.controllers: |
| 564 | if controller.isUp(): |
| 565 | availableControllers.append( controller.index ) |
| 566 | if len( availableControllers ) == 0: |
| 567 | main.log.warn( "No available controllers" ) |
| 568 | main.caseResult = main.FALSE |
| 569 | else: |
| 570 | index = random.sample( availableControllers, 1 ) |
| 571 | main.eventGenerator.triggerEvent( EventType().ONOS_ONOS_DOWN, EventScheduleMethod().RUN_BLOCK, index[ 0 ] ) |
| 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="Randomly bring down ONOS test passed", |
| 578 | onfail="Randomly bring down ONOS test failed" ) |
| 579 | time.sleep( main.caseSleep ) |
| 580 | |
| 581 | def CASE41( self, main ): |
| 582 | """ |
| 583 | Randomly bring up one ONOS node that is down |
| 584 | """ |
| 585 | import time |
| 586 | import random |
| 587 | from tests.CHOTestMonkey.dependencies.events.Event import EventType |
| 588 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod |
| 589 | |
| 590 | main.log.report( "Randomly bring up one ONOS node that is down" ) |
| 591 | main.log.report( "__________________________________________________" ) |
| 592 | main.case( "Randomly bring up one ONOS node that is down" ) |
| 593 | main.step( "Randomly bring up one ONOS node that is down" ) |
| 594 | main.caseResult = main.TRUE |
| 595 | targetControllers = [] |
| 596 | for controller in main.controllers: |
| 597 | if not controller.isUp(): |
| 598 | targetControllers.append( controller.index ) |
| 599 | if len( targetControllers ) == 0: |
| 600 | main.log.warn( "All controllers are up" ) |
| 601 | main.caseResult = main.FALSE |
| 602 | else: |
| 603 | index = random.sample( targetControllers, 1 ) |
| 604 | main.eventGenerator.triggerEvent( EventType().ONOS_ONOS_UP, EventScheduleMethod().RUN_BLOCK, index[ 0 ] ) |
| 605 | with main.eventScheduler.idleCondition: |
| 606 | while not main.eventScheduler.isIdle(): |
| 607 | main.eventScheduler.idleCondition.wait() |
| 608 | utilities.assert_equals( expect=main.TRUE, |
| 609 | actual=main.caseResult, |
| 610 | onpass="Randomly bring up ONOS test passed", |
| 611 | onfail="Randomly bring up ONOS test failed" ) |
| 612 | time.sleep( main.caseSleep ) |
| 613 | |
| 614 | def CASE50( self, main ): |
| 615 | """ |
| 616 | Set FlowObjective to True |
| 617 | """ |
| 618 | import time |
| 619 | from tests.CHOTestMonkey.dependencies.events.Event import EventType |
| 620 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod |
| 621 | |
| 622 | main.log.report( "Set FlowObjective to True" ) |
| 623 | main.log.report( "__________________________________________________" ) |
| 624 | main.case( "Set FlowObjective to True" ) |
| 625 | main.step( "Set FlowObjective to True" ) |
| 626 | main.caseResult = main.TRUE |
| 627 | main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'true' ) |
| 628 | with main.eventScheduler.idleCondition: |
| 629 | while not main.eventScheduler.isIdle(): |
| 630 | main.eventScheduler.idleCondition.wait() |
| 631 | utilities.assert_equals( expect=main.TRUE, |
| 632 | actual=main.caseResult, |
| 633 | onpass="Set FlowObjective test passed", |
| 634 | onfail="Set FlowObjective test failed" ) |
| 635 | time.sleep( main.caseSleep ) |
| 636 | |
| 637 | def CASE51( self, main ): |
| 638 | """ |
| 639 | Set FlowObjective to False |
| 640 | """ |
| 641 | import time |
| 642 | from tests.CHOTestMonkey.dependencies.events.Event import EventType |
| 643 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod |
| 644 | |
| 645 | main.log.report( "Set FlowObjective to False" ) |
| 646 | main.log.report( "__________________________________________________" ) |
| 647 | main.case( "Set FlowObjective to False" ) |
| 648 | main.step( "Set FlowObjective to False" ) |
| 649 | main.caseResult = main.TRUE |
| 650 | main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'false' ) |
| 651 | with main.eventScheduler.idleCondition: |
| 652 | while not main.eventScheduler.isIdle(): |
| 653 | main.eventScheduler.idleCondition.wait() |
| 654 | utilities.assert_equals( expect=main.TRUE, |
| 655 | actual=main.caseResult, |
| 656 | onpass="Set FlowObjective test passed", |
| 657 | onfail="Set FlowObjective test failed" ) |
| 658 | time.sleep( main.caseSleep ) |
| 659 | |
| 660 | def CASE60( self, main ): |
| 661 | """ |
| 662 | Balance device masters |
| 663 | """ |
| 664 | import time |
| 665 | from tests.CHOTestMonkey.dependencies.events.Event import EventType |
| 666 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod |
| 667 | |
| 668 | main.log.report( "Balance device masters" ) |
| 669 | main.log.report( "__________________________________________________" ) |
| 670 | main.case( "Balance device masters" ) |
| 671 | main.step( "Balance device masters" ) |
| 672 | main.caseResult = main.TRUE |
| 673 | main.eventGenerator.triggerEvent( EventType().ONOS_BALANCE_MASTERS, EventScheduleMethod().RUN_BLOCK ) |
| 674 | with main.eventScheduler.idleCondition: |
| 675 | while not main.eventScheduler.isIdle(): |
| 676 | main.eventScheduler.idleCondition.wait() |
| 677 | utilities.assert_equals( expect=main.TRUE, |
| 678 | actual=main.caseResult, |
| 679 | onpass="Balance masters test passed", |
| 680 | onfail="Balance masters test failed" ) |
| 681 | time.sleep( main.caseSleep ) |
| 682 | |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 683 | def CASE70( self, main ): |
| 684 | """ |
| 685 | Randomly generate events |
| 686 | """ |
| 687 | import time |
| 688 | import random |
| 689 | from tests.CHOTestMonkey.dependencies.events.Event import EventType |
| 690 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod |
| 691 | |
| 692 | main.log.report( "Randomly generate events" ) |
| 693 | main.log.report( "__________________________________________________" ) |
| 694 | main.case( "Randomly generate events" ) |
| 695 | main.step( "Randomly generate events" ) |
| 696 | main.caseResult = main.TRUE |
| 697 | sleepSec = int( main.params[ 'CASE70' ][ 'sleepSec' ] ) |
| 698 | hostIntentNum = 0 |
| 699 | pointIntentNum = 0 |
| 700 | downDeviceNum = 0 |
| 701 | downLinkNum = 0 |
You Wang | f6e98a8 | 2016-11-14 14:46:49 -0800 | [diff] [blame] | 702 | flowObj = False |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 703 | upControllers = [ 1, 2, 3 ] |
| 704 | while True: |
| 705 | events = [] |
You Wang | f6e98a8 | 2016-11-14 14:46:49 -0800 | [diff] [blame] | 706 | for i in range( int( main.params[ 'CASE70' ][ 'toggleFlowObj' ] ) ): |
| 707 | events.append( 'toggle-flowobj' ) |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 708 | for i in range( int( main.params[ 'CASE70' ][ 'addHostIntentWeight' ] ) ): |
| 709 | events.append( 'add-host-intent' ) |
| 710 | for i in range( int( main.params[ 'CASE70' ][ 'addPointIntentWeight' ] ) ): |
| 711 | events.append( 'add-point-intent' ) |
| 712 | for i in range( int( main.params[ 'CASE70' ][ 'linkDownWeight' ] ) ): |
| 713 | events.append( 'link-down' ) |
| 714 | for i in range( int( main.params[ 'CASE70' ][ 'deviceDownWeight' ] ) ): |
| 715 | events.append( 'device-down' ) |
| 716 | for i in range( int( pow( hostIntentNum, 1.5 ) / 100 ) ): |
| 717 | events.append( 'del-host-intent' ) |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 718 | for i in range( int( pow( pointIntentNum, 1.5 ) / 100 ) ): |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 719 | events.append( 'del-point-intent' ) |
| 720 | for i in range( pow( 2, downLinkNum ) - 1 ): |
| 721 | events.append( 'link-up' ) |
| 722 | for i in range( pow( 5, downDeviceNum ) - 1 ): |
| 723 | events.append( 'device-up' ) |
| 724 | main.log.debug( events ) |
| 725 | event = random.sample( events, 1 )[ 0 ] |
| 726 | if event == 'add-host-intent': |
| 727 | n = random.randint( 5, 50 ) |
| 728 | for i in range( n ): |
| 729 | cliIndex = random.sample( upControllers, 1 )[ 0 ] |
You Wang | c848af1 | 2016-07-14 09:53:58 -0700 | [diff] [blame] | 730 | main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_ADD, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex ) |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 731 | hostIntentNum += 1 |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 732 | elif event == 'del-host-intent': |
| 733 | n = random.randint( 5, hostIntentNum ) |
| 734 | for i in range( n ): |
| 735 | cliIndex = random.sample( upControllers, 1 )[ 0 ] |
You Wang | c848af1 | 2016-07-14 09:53:58 -0700 | [diff] [blame] | 736 | main.eventGenerator.triggerEvent( EventType().APP_INTENT_HOST_DEL, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex ) |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 737 | hostIntentNum -= 1 |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 738 | elif event == 'add-point-intent': |
| 739 | n = random.randint( 5, 50 ) |
| 740 | for i in range( n ): |
| 741 | cliIndex = random.sample( upControllers, 1 )[ 0 ] |
You Wang | c848af1 | 2016-07-14 09:53:58 -0700 | [diff] [blame] | 742 | main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_ADD, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex, 'bidirectional' ) |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 743 | pointIntentNum += 2 |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 744 | elif event == 'del-point-intent': |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 745 | n = random.randint( 5, pointIntentNum / 2 ) |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 746 | for i in range( n ): |
| 747 | cliIndex = random.sample( upControllers, 1 )[ 0 ] |
You Wang | c848af1 | 2016-07-14 09:53:58 -0700 | [diff] [blame] | 748 | main.eventGenerator.triggerEvent( EventType().APP_INTENT_POINT_DEL, EventScheduleMethod().RUN_BLOCK, 'random', 'random', cliIndex, 'bidirectional' ) |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 749 | pointIntentNum -= 2 |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 750 | elif event == 'link-down': |
| 751 | main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_DOWN, EventScheduleMethod().RUN_BLOCK, 'random', 'random' ) |
| 752 | downLinkNum += 1 |
| 753 | elif event == 'link-up': |
| 754 | main.eventGenerator.triggerEvent( EventType().NETWORK_LINK_UP, EventScheduleMethod().RUN_BLOCK, 'random', 'random' ) |
| 755 | downLinkNum -= 1 |
| 756 | elif event == 'device-down': |
| 757 | main.eventGenerator.triggerEvent( EventType().NETWORK_DEVICE_DOWN, EventScheduleMethod().RUN_BLOCK, 'random' ) |
| 758 | downDeviceNum += 1 |
| 759 | elif event == 'device-up': |
| 760 | main.eventGenerator.triggerEvent( EventType().NETWORK_DEVICE_UP, EventScheduleMethod().RUN_BLOCK, 'random' ) |
| 761 | downDeviceNum -= 1 |
You Wang | f6e98a8 | 2016-11-14 14:46:49 -0800 | [diff] [blame] | 762 | elif event == 'toggle-flowobj': |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 763 | if not flowObj: |
You Wang | f6e98a8 | 2016-11-14 14:46:49 -0800 | [diff] [blame] | 764 | main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'true' ) |
| 765 | else: |
| 766 | main.eventGenerator.triggerEvent( EventType().ONOS_SET_FLOWOBJ, EventScheduleMethod().RUN_BLOCK, 'false' ) |
| 767 | flowObj = not flowObj |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 768 | else: |
| 769 | pass |
| 770 | main.eventGenerator.triggerEvent( EventType().CHECK_TOPO, EventScheduleMethod().RUN_NON_BLOCK ) |
| 771 | main.eventGenerator.triggerEvent( EventType().CHECK_ONOS, EventScheduleMethod().RUN_NON_BLOCK ) |
| 772 | main.eventGenerator.triggerEvent( EventType().CHECK_TRAFFIC, EventScheduleMethod().RUN_NON_BLOCK ) |
| 773 | main.eventGenerator.triggerEvent( EventType().CHECK_FLOW, EventScheduleMethod().RUN_NON_BLOCK ) |
| 774 | main.eventGenerator.triggerEvent( EventType().CHECK_INTENT, EventScheduleMethod().RUN_NON_BLOCK ) |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 775 | with main.eventScheduler.idleCondition: |
| 776 | while not main.eventScheduler.isIdle(): |
| 777 | main.eventScheduler.idleCondition.wait() |
You Wang | 5f4f36e | 2016-09-21 15:30:30 -0700 | [diff] [blame] | 778 | time.sleep( sleepSec ) |
You Wang | 7a27f3a | 2016-07-05 10:12:27 -0700 | [diff] [blame] | 779 | utilities.assert_equals( expect=main.TRUE, |
| 780 | actual=main.caseResult, |
| 781 | onpass="Randomly generate events test passed", |
| 782 | onfail="Randomly generate events test failed" ) |
| 783 | time.sleep( main.caseSleep ) |
| 784 | |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 785 | def CASE80( self, main ): |
| 786 | """ |
| 787 | Replay events from log file |
| 788 | """ |
| 789 | import time |
| 790 | from tests.CHOTestMonkey.dependencies.events.Event import EventType |
| 791 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod |
| 792 | |
| 793 | main.log.report( "Replay events from log file" ) |
| 794 | main.log.report( "__________________________________________________" ) |
| 795 | main.case( "Replay events from log file" ) |
| 796 | main.step( "Replay events from log file" ) |
| 797 | main.caseResult = main.TRUE |
| 798 | try: |
| 799 | f = open( main.params[ 'CASE80' ][ 'filePath' ], 'r' ) |
| 800 | for line in f.readlines(): |
| 801 | if 'CHOTestMonkey' in line and 'Event recorded' in line: |
| 802 | line = line.split() |
| 803 | eventIndex = int( line[ 9 ] ) |
| 804 | eventName = line[ 10 ] |
| 805 | args = line[ 11: ] |
| 806 | assert eventName.startswith( 'CHECK' )\ |
Jon Hall | 2bb3e21 | 2017-05-24 17:07:25 -0700 | [diff] [blame] | 807 | or eventName.startswith( 'NETWORK' )\ |
| 808 | or eventName.startswith( 'APP' )\ |
| 809 | or eventName.startswith( 'ONOS' ) |
You Wang | 5216320 | 2016-07-14 16:37:15 -0700 | [diff] [blame] | 810 | if main.params[ 'CASE80' ][ 'skipChecks' ] == 'on' and eventName.startswith( 'CHECK' ): |
| 811 | continue |
| 812 | with main.eventScheduler.idleCondition: |
| 813 | while not main.eventScheduler.isIdle(): |
| 814 | main.eventScheduler.idleCondition.wait() |
| 815 | main.eventGenerator.triggerEvent( eventIndex, EventScheduleMethod().RUN_BLOCK, *args ) |
| 816 | time.sleep( float( main.params[ 'CASE80' ][ 'sleepTime' ] ) ) |
| 817 | except Exception as e: |
| 818 | print e |
| 819 | utilities.assert_equals( expect=main.TRUE, |
| 820 | actual=main.caseResult, |
| 821 | onpass="Replay from log file passed", |
| 822 | onfail="Replay from log file failed" ) |
| 823 | |
You Wang | db927a5 | 2016-02-26 11:03:28 -0800 | [diff] [blame] | 824 | def CASE90( self, main ): |
| 825 | """ |
| 826 | Sleep for some time |
| 827 | """ |
| 828 | import time |
| 829 | from tests.CHOTestMonkey.dependencies.events.Event import EventType |
| 830 | from tests.CHOTestMonkey.dependencies.EventScheduler import EventScheduleMethod |
| 831 | |
| 832 | main.log.report( "Sleep for some time" ) |
| 833 | main.log.report( "__________________________________________________" ) |
| 834 | main.case( "Sleep for some time" ) |
| 835 | main.step( "Sleep for some time" ) |
| 836 | main.caseResult = main.TRUE |
| 837 | sleepSec = int( main.params[ 'CASE90' ][ 'sleepSec' ] ) |
| 838 | main.eventGenerator.triggerEvent( EventType().TEST_SLEEP, EventScheduleMethod().RUN_BLOCK, sleepSec ) |
| 839 | with main.eventScheduler.idleCondition: |
| 840 | while not main.eventScheduler.isIdle(): |
| 841 | main.eventScheduler.idleCondition.wait() |
| 842 | utilities.assert_equals( expect=main.TRUE, |
| 843 | actual=main.caseResult, |
| 844 | onpass="Sleep test passed", |
| 845 | onfail="Sleep test failed" ) |
| 846 | time.sleep( main.caseSleep ) |
| 847 | |
| 848 | def CASE100( self, main ): |
| 849 | """ |
| 850 | Do something else? |
| 851 | """ |
| 852 | import time |
| 853 | |
| 854 | main.log.report( "Do something else?" ) |
| 855 | main.log.report( "__________________________________________________" ) |
| 856 | main.case( "..." ) |
| 857 | |
| 858 | main.step( "Wait until the test stops" ) |
| 859 | |
| 860 | main.caseResult = main.TRUE |
| 861 | utilities.assert_equals( expect=main.TRUE, |
| 862 | actual=main.caseResult, |
| 863 | onpass="Test PASS", |
| 864 | onfail="Test FAIL" ) |
| 865 | |
| 866 | testDuration = int( main.params[ 'TEST' ][ 'testDuration' ] ) |
| 867 | time.sleep( testDuration ) |