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