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