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