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