acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 1 | # Testing the basic intent functionality of ONOS |
| 2 | |
| 3 | class FUNCoptical: |
| 4 | |
| 5 | def __init__( self ): |
| 6 | self.default = '' |
| 7 | |
| 8 | def CASE1( self, main ): |
| 9 | import time |
| 10 | import imp |
| 11 | import re |
| 12 | |
| 13 | """ |
| 14 | - Construct tests variables |
| 15 | - GIT ( optional ) |
| 16 | - Checkout ONOS master branch |
| 17 | - Pull latest ONOS code |
| 18 | - Building ONOS ( optional ) |
| 19 | - Install ONOS package |
| 20 | - Build ONOS package |
| 21 | """ |
| 22 | |
| 23 | main.case( "Constructing test variables and building ONOS package" ) |
| 24 | main.step( "Constructing test variables" ) |
| 25 | main.caseExplanation = "This test case is mainly for loading " +\ |
| 26 | "from params file, and pull and build the " +\ |
| 27 | " latest ONOS package" |
| 28 | stepResult = main.FALSE |
| 29 | |
| 30 | # Test variables |
| 31 | try: |
| 32 | main.testOnDirectory = re.sub( "(/tests)$", "", main.testDir ) |
| 33 | main.apps = main.params[ 'ENV' ][ 'cellApps' ] |
| 34 | gitBranch = main.params[ 'GIT' ][ 'branch' ] |
| 35 | main.dependencyPath = main.testOnDirectory + \ |
| 36 | main.params[ 'DEPENDENCY' ][ 'path' ] |
| 37 | main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," ) |
| 38 | if main.ONOSbench.maxNodes: |
| 39 | main.maxNodes = int( main.ONOSbench.maxNodes ) |
| 40 | else: |
| 41 | main.maxNodes = 0 |
| 42 | wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ] |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 43 | main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] ) |
| 44 | main.checkIntentSleep = int( main.params[ 'SLEEP' ][ 'checkintent' ] ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 45 | main.checkTopoAttempts = int( main.params[ 'SLEEP' ][ 'topoAttempts' ] ) |
| 46 | gitPull = main.params[ 'GIT' ][ 'pull' ] |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 47 | main.switches = int( main.params[ 'MININET' ][ 'switch' ] ) |
| 48 | main.links = int( main.params[ 'MININET' ][ 'links' ] ) |
| 49 | main.hosts = int( main.params[ 'MININET' ][ 'hosts' ] ) |
| 50 | main.opticalTopo = main.params[ 'MININET' ][ 'toponame' ] |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 51 | main.cellData = {} # For creating cell file |
| 52 | main.hostsData = {} |
| 53 | main.CLIs = [] |
| 54 | main.ONOSip = [] # List of IPs of active ONOS nodes. CASE 2 |
| 55 | main.activeONOSip = [] |
| 56 | main.assertReturnString = '' # Assembled assert return string |
Jeremy Songster | 17147f2 | 2016-05-31 18:30:52 -0700 | [diff] [blame] | 57 | main.cycle = 0 # How many times FUNCintent has run through its tests |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 58 | |
| 59 | main.ONOSip = main.ONOSbench.getOnosIps() |
| 60 | |
| 61 | # Assigning ONOS cli handles to a list |
| 62 | for i in range( 1, main.maxNodes + 1 ): |
| 63 | main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) ) |
| 64 | |
| 65 | # -- INIT SECTION, ONLY RUNS ONCE -- # |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 66 | main.topo = imp.load_source( wrapperFile1, |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 67 | main.dependencyPath + |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 68 | wrapperFile1 + |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 69 | ".py" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 70 | if main.CLIs: |
| 71 | stepResult = main.TRUE |
| 72 | else: |
| 73 | main.log.error( "Did not properly created list of ONOS CLI handle" ) |
| 74 | stepResult = main.FALSE |
| 75 | except Exception as e: |
| 76 | main.log.exception(e) |
| 77 | main.cleanup() |
| 78 | main.exit() |
| 79 | |
| 80 | utilities.assert_equals( expect=main.TRUE, |
| 81 | actual=stepResult, |
| 82 | onpass="Successfully construct " + |
| 83 | "test variables ", |
| 84 | onfail="Failed to construct test variables" ) |
| 85 | |
| 86 | if gitPull == 'True': |
| 87 | main.step( "Building ONOS in " + gitBranch + " branch" ) |
| 88 | onosBuildResult = main.startUp.onosBuild( main, gitBranch ) |
| 89 | stepResult = onosBuildResult |
| 90 | utilities.assert_equals( expect=main.TRUE, |
| 91 | actual=stepResult, |
| 92 | onpass="Successfully compiled " + |
| 93 | "latest ONOS", |
| 94 | onfail="Failed to compile " + |
| 95 | "latest ONOS" ) |
| 96 | else: |
| 97 | main.log.warn( "Did not pull new code so skipping mvn " + |
| 98 | "clean install" ) |
| 99 | main.ONOSbench.getVersion( report=True ) |
| 100 | |
| 101 | def CASE2( self, main ): |
| 102 | """ |
| 103 | - Set up cell |
| 104 | - Create cell file |
| 105 | - Set cell file |
| 106 | - Verify cell file |
| 107 | - Kill ONOS process |
| 108 | - Uninstall ONOS cluster |
| 109 | - Verify ONOS start up |
| 110 | - Install ONOS cluster |
| 111 | - Connect to cli |
| 112 | """ |
| 113 | |
Jeremy Songster | 17147f2 | 2016-05-31 18:30:52 -0700 | [diff] [blame] | 114 | main.cycle += 1 |
| 115 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 116 | # main.scale[ 0 ] determines the current number of ONOS controller |
| 117 | main.numCtrls = int( main.scale[ 0 ] ) |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 118 | main.flowCompiler = "Flow Rules" |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 119 | |
| 120 | main.case( "Starting up " + str( main.numCtrls ) + |
| 121 | " node(s) ONOS cluster" ) |
| 122 | main.caseExplanation = "Set up ONOS with " + str( main.numCtrls ) +\ |
| 123 | " node(s) ONOS cluster" |
| 124 | |
| 125 | |
| 126 | |
| 127 | #kill off all onos processes |
| 128 | main.log.info( "Safety check, killing all ONOS processes" + |
Jon Hall | 70b2ff4 | 2015-11-17 15:49:44 -0800 | [diff] [blame] | 129 | " before initiating environment setup" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 130 | |
| 131 | for i in range( main.maxNodes ): |
| 132 | main.ONOSbench.onosDie( main.ONOSip[ i ] ) |
| 133 | |
| 134 | print "NODE COUNT = ", main.numCtrls |
| 135 | |
| 136 | tempOnosIp = [] |
| 137 | for i in range( main.numCtrls ): |
| 138 | tempOnosIp.append( main.ONOSip[i] ) |
| 139 | |
| 140 | main.ONOSbench.createCellFile( main.ONOSbench.ip_address, |
| 141 | "temp", main.Mininet1.ip_address, |
| 142 | main.apps, tempOnosIp ) |
| 143 | |
| 144 | main.step( "Apply cell to environment" ) |
| 145 | cellResult = main.ONOSbench.setCell( "temp" ) |
| 146 | verifyResult = main.ONOSbench.verifyCell() |
| 147 | stepResult = cellResult and verifyResult |
| 148 | utilities.assert_equals( expect=main.TRUE, |
| 149 | actual=stepResult, |
| 150 | onpass="Successfully applied cell to " + \ |
| 151 | "environment", |
| 152 | onfail="Failed to apply cell to environment " ) |
| 153 | |
| 154 | main.step( "Creating ONOS package" ) |
| 155 | packageResult = main.ONOSbench.onosPackage() |
| 156 | stepResult = packageResult |
| 157 | utilities.assert_equals( expect=main.TRUE, |
| 158 | actual=stepResult, |
| 159 | onpass="Successfully created ONOS package", |
| 160 | onfail="Failed to create ONOS package" ) |
| 161 | |
| 162 | time.sleep( main.startUpSleep ) |
| 163 | main.step( "Uninstalling ONOS package" ) |
| 164 | onosUninstallResult = main.TRUE |
| 165 | for ip in main.ONOSip: |
| 166 | onosUninstallResult = onosUninstallResult and \ |
| 167 | main.ONOSbench.onosUninstall( nodeIp=ip ) |
| 168 | stepResult = onosUninstallResult |
| 169 | utilities.assert_equals( expect=main.TRUE, |
| 170 | actual=stepResult, |
| 171 | onpass="Successfully uninstalled ONOS package", |
| 172 | onfail="Failed to uninstall ONOS package" ) |
| 173 | |
| 174 | time.sleep( main.startUpSleep ) |
| 175 | main.step( "Installing ONOS package" ) |
| 176 | onosInstallResult = main.TRUE |
| 177 | for i in range( main.numCtrls ): |
| 178 | onosInstallResult = onosInstallResult and \ |
| 179 | main.ONOSbench.onosInstall( node=main.ONOSip[ i ] ) |
| 180 | # Populate activeONOSip |
| 181 | main.activeONOSip.append( main.ONOSip[ i ] ) |
| 182 | stepResult = onosInstallResult |
| 183 | utilities.assert_equals( expect=main.TRUE, |
| 184 | actual=stepResult, |
| 185 | onpass="Successfully installed ONOS package", |
| 186 | onfail="Failed to install ONOS package" ) |
| 187 | |
| 188 | time.sleep( main.startUpSleep ) |
| 189 | main.step( "Starting ONOS service" ) |
| 190 | stopResult = main.TRUE |
| 191 | startResult = main.TRUE |
| 192 | onosIsUp = main.TRUE |
| 193 | |
| 194 | for i in range( main.numCtrls ): |
Jeremy Songster | 7edb663 | 2016-04-28 15:44:28 -0700 | [diff] [blame] | 195 | isUp = main.ONOSbench.isup( main.ONOSip[ i ] ) |
| 196 | onosIsUp = onosIsUp and isUp |
| 197 | if isUp == main.TRUE: |
| 198 | main.log.report( "ONOS instance {0} is up and ready".format( i + 1 ) ) |
| 199 | else: |
| 200 | main.log.report( "ONOS instance {0} may not be up, stop and ".format( i + 1 ) + |
| 201 | "start ONOS again " ) |
| 202 | stopResult = stopResult and main.ONOSbench.onosStop( main.ONOSip[ i ] ) |
| 203 | startResult = startResult and main.ONOSbench.onosStart( main.ONOSip[ i ] ) |
| 204 | if not startResult or stopResult: |
| 205 | main.log.report( "ONOS instance {0} did not start correctly.".format( i + 1) ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 206 | stepResult = onosIsUp and stopResult and startResult |
| 207 | utilities.assert_equals( expect=main.TRUE, |
| 208 | actual=stepResult, |
Jeremy Songster | 7edb663 | 2016-04-28 15:44:28 -0700 | [diff] [blame] | 209 | onpass="ONOS service is ready on all nodes", |
| 210 | onfail="ONOS service did not start properly on all nodes" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 211 | |
| 212 | main.step( "Start ONOS cli" ) |
| 213 | cliResult = main.TRUE |
| 214 | for i in range( main.numCtrls ): |
| 215 | cliResult = cliResult and \ |
| 216 | main.CLIs[ i ].startOnosCli( main.ONOSip[ i ] ) |
| 217 | stepResult = cliResult |
| 218 | utilities.assert_equals( expect=main.TRUE, |
| 219 | actual=stepResult, |
| 220 | onpass="Successfully start ONOS cli", |
| 221 | onfail="Failed to start ONOS cli" ) |
| 222 | |
| 223 | # Remove the first element in main.scale list |
| 224 | main.scale.remove( main.scale[ 0 ] ) |
| 225 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 226 | def CASE10( self, main ): |
| 227 | """ |
| 228 | Start Mininet opticalTest Topology |
| 229 | """ |
| 230 | main.case( "Mininet with Linc-OE startup") |
| 231 | main.caseExplanation = "Start opticalTest.py topology included with ONOS" |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 232 | if main.opticalTopo: |
| 233 | main.step( "Copying optical topology to $ONOS_ROOT/tools/test/topos/" ) |
| 234 | main.ONOSbench.scp( main.ONOSbench, |
| 235 | "{0}{1}.py".format( main.dependencyPath, main.opticalTopo ), |
| 236 | "~/onos/tools/test/topos/{0}.py".format( main.opticalTopo ) ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 237 | main.step( "Starting mininet and LINC-OE" ) |
| 238 | topoResult = main.TRUE |
| 239 | time.sleep( 10 ) |
| 240 | controllerIPs = ' '.join( main.activeONOSip ) |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 241 | opticalMnScript = main.LincOE.runOpticalMnScript(ctrllerIP = controllerIPs, topology=main.opticalTopo ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 242 | topoResult = opticalMnScript |
| 243 | utilities.assert_equals( |
| 244 | expect=main.TRUE, |
| 245 | actual=topoResult, |
| 246 | onpass="Started the topology successfully ", |
| 247 | onfail="Failed to start the topology") |
| 248 | |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 249 | main.step( "Push Topology.json to ONOS through onos-netcfg" ) |
| 250 | pushResult = main.TRUE |
| 251 | time.sleep( 20 ) |
| 252 | main.ONOSbench.onosNetCfg( controllerIps=controllerIPs, path=main.dependencyPath, fileName="Topology" ) |
| 253 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 254 | # Exit if topology did not load properly |
| 255 | if not topoResult: |
| 256 | main.cleanup() |
| 257 | main.exit() |
| 258 | |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 259 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 260 | |
| 261 | |
| 262 | def CASE14( self, main ): |
| 263 | """ |
| 264 | Stop mininet |
| 265 | """ |
| 266 | main.log.report( "Stop Mininet topology" ) |
| 267 | main.case( "Stop Mininet topology" ) |
| 268 | main.caseExplanation = "Stopping the current mininet topology " +\ |
| 269 | "to start up fresh" |
| 270 | |
| 271 | main.step( "Stopping Mininet Topology" ) |
| 272 | topoResult = main.LincOE.stopNet( timeout=180 ) |
| 273 | utilities.assert_equals( expect=main.TRUE, |
| 274 | actual=topoResult, |
| 275 | onpass="Successfully stopped mininet", |
| 276 | onfail="Failed to stopped mininet" ) |
| 277 | # Exit if topology did not load properly |
| 278 | if not topoResult: |
| 279 | main.cleanup() |
| 280 | main.exit() |
| 281 | |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 282 | def CASE16( self, main ): |
| 283 | """ |
| 284 | Balance Masters |
| 285 | """ |
| 286 | main.case( "Balance mastership of switches" ) |
| 287 | main.step( "Balancing mastership of switches" ) |
| 288 | |
| 289 | balanceResult = main.FALSE |
| 290 | balanceResult = utilities.retry( f=main.CLIs[ 0 ].balanceMasters, retValue=main.FALSE, args=[] ) |
| 291 | |
| 292 | utilities.assert_equals( expect=main.TRUE, |
| 293 | actual=balanceResult, |
| 294 | onpass="Successfully balanced mastership of switches", |
| 295 | onfail="Failed to balance mastership of switches" ) |
| 296 | if not balanceResult: |
| 297 | main.initialized = main.FALSE |
| 298 | |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 299 | def CASE17( self, main ): |
| 300 | """ |
| 301 | Use Flow Objectives |
| 302 | """ |
| 303 | main.case( "Enable intent compilation using Flow Objectives" ) |
| 304 | main.step( "Enabling Flow Objectives" ) |
| 305 | |
| 306 | main.flowCompiler = "Flow Objectives" |
| 307 | |
| 308 | cmd = "org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator" |
| 309 | |
| 310 | stepResult = main.CLIs[ 0 ].setCfg( component=cmd, |
| 311 | propName="useFlowObjectives", value="true" ) |
| 312 | |
| 313 | utilities.assert_equals( expect=main.TRUE, |
| 314 | actual=stepResult, |
| 315 | onpass="Successfully activated Flow Objectives", |
| 316 | onfail="Failed to activate Flow Objectives" ) |
| 317 | |
Jeremy Songster | 17147f2 | 2016-05-31 18:30:52 -0700 | [diff] [blame] | 318 | def CASE19( self, main ): |
| 319 | """ |
| 320 | Copy the karaf.log files after each testcase cycle |
| 321 | """ |
| 322 | main.log.report( "Copy karaf logs" ) |
| 323 | main.case( "Copy karaf logs" ) |
| 324 | main.caseExplanation = "Copying the karaf logs to preserve them through" +\ |
| 325 | "reinstalling ONOS" |
| 326 | main.step( "Copying karaf logs" ) |
Jeremy Songster | 31aad31 | 2016-06-13 16:32:11 -0700 | [diff] [blame] | 327 | stepResult = main.TRUE |
| 328 | scpResult = main.TRUE |
| 329 | copyResult = main.TRUE |
Jeremy Songster | 17147f2 | 2016-05-31 18:30:52 -0700 | [diff] [blame] | 330 | i = 0 |
| 331 | for cli in main.CLIs: |
| 332 | main.node = cli |
| 333 | ip = main.ONOSip[ i ] |
| 334 | main.node.ip_address = ip |
Jeremy Songster | 31aad31 | 2016-06-13 16:32:11 -0700 | [diff] [blame] | 335 | scpResult = scpResult and main.ONOSbench.scp( main.node , |
| 336 | "/opt/onos/log/karaf.log", |
| 337 | "/tmp/karaf.log", |
| 338 | direction="from" ) |
| 339 | copyResult = copyResult and main.ONOSbench.cpLogsToDir( "/tmp/karaf.log", main.logdir, |
| 340 | copyFileName=( "karaf.log.node{0}.cycle{1}".format( str( i + 1 ), str( main.cycle ) ) ) ) |
| 341 | if scpResult and copyResult: |
| 342 | stepResult = main.TRUE and stepResult |
| 343 | else: |
| 344 | stepResult = main.FALSE and stepResult |
Jeremy Songster | 17147f2 | 2016-05-31 18:30:52 -0700 | [diff] [blame] | 345 | i += 1 |
Jeremy Songster | 31aad31 | 2016-06-13 16:32:11 -0700 | [diff] [blame] | 346 | utilities.assert_equals( expect=main.TRUE, |
| 347 | actual=stepResult, |
| 348 | onpass="Successfully copied remote ONOS logs", |
| 349 | onfail="Failed to copy remote ONOS logs" ) |
Jeremy Songster | 17147f2 | 2016-05-31 18:30:52 -0700 | [diff] [blame] | 350 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 351 | def CASE21( self,main ): |
| 352 | """ |
| 353 | Run pingall to discover all hosts |
| 354 | """ |
| 355 | main.case( "Running Pingall" ) |
| 356 | main.caseExplanation = "Use pingall to discover all hosts. Pingall is expected to fail." |
| 357 | main.step( "Discover Hosts through Pingall" ) |
Jeremy Songster | 7edb663 | 2016-04-28 15:44:28 -0700 | [diff] [blame] | 358 | pingResult = main.LincOE.pingall( timeout = 120 ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 359 | |
| 360 | utilities.assert_equals( expect=main.FALSE, |
| 361 | actual=pingResult, |
| 362 | onpass="Pingall Completed", |
| 363 | onfail="Pingall did not complete or did not return fales" ) |
| 364 | |
| 365 | def CASE22( self,main ): |
| 366 | """ |
| 367 | Send arpings to discover all hosts |
| 368 | """ |
| 369 | main.case( "Discover Hosts with arping" ) |
| 370 | main.caseExplanation = "Send arpings between all the hosts to discover and verify them" |
| 371 | |
| 372 | main.step( "Send arping between all hosts" ) |
| 373 | |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 374 | hosts = [] |
| 375 | for i in range( main.hosts ): |
| 376 | hosts.append( 'h{}'.format( i + 1 ) ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 377 | |
| 378 | arpingHostResults = main.TRUE |
| 379 | for host in hosts: |
| 380 | if main.LincOE.arping( host ): |
| 381 | main.log.info( "Successfully reached host {} with arping".format( host ) ) |
| 382 | else: |
| 383 | main.log.error( "Could not reach host {} with arping".format( host ) ) |
| 384 | arpingHostResults = main.FALSE |
| 385 | |
| 386 | utilities.assert_equals( expect=main.TRUE, |
| 387 | actual=arpingHostResults, |
| 388 | onpass="Successfully discovered all hosts", |
| 389 | onfail="Could not descover some hosts" ) |
| 390 | |
| 391 | def CASE23( self, main ): |
| 392 | """ |
| 393 | Compare ONOS Topology to Mininet Topology |
| 394 | """ |
| 395 | import json |
| 396 | |
| 397 | main.case( "Compare ONOS Topology view to Mininet topology" ) |
| 398 | main.caseExplanation = "Compare topology elements between Mininet" +\ |
| 399 | " and ONOS" |
| 400 | |
| 401 | main.log.info( "Gathering topology information from Mininet" ) |
| 402 | devicesResults = main.FALSE # Overall Boolean for device correctness |
| 403 | linksResults = main.FALSE # Overall Boolean for link correctness |
| 404 | hostsResults = main.FALSE # Overall Boolean for host correctness |
| 405 | deviceFails = [] # Nodes where devices are incorrect |
| 406 | linkFails = [] # Nodes where links are incorrect |
| 407 | hostFails = [] # Nodes where hosts are incorrect |
| 408 | attempts = main.checkTopoAttempts # Remaining Attempts |
| 409 | |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 410 | mnSwitches = main.switches |
| 411 | mnLinks = main.links |
| 412 | mnHosts = main.hosts |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 413 | |
Jon Hall | 70b2ff4 | 2015-11-17 15:49:44 -0800 | [diff] [blame] | 414 | main.step( "Comparing Mininet topology to ONOS topology" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 415 | |
| 416 | while ( attempts >= 0 ) and\ |
| 417 | ( not devicesResults or not linksResults or not hostsResults ): |
| 418 | time.sleep( 2 ) |
| 419 | if not devicesResults: |
| 420 | devices = main.topo.getAllDevices( main ) |
| 421 | ports = main.topo.getAllPorts( main ) |
| 422 | devicesResults = main.TRUE |
| 423 | deviceFails = [] # Reset for each attempt |
| 424 | if not linksResults: |
| 425 | links = main.topo.getAllLinks( main ) |
| 426 | linksResults = main.TRUE |
| 427 | linkFails = [] # Reset for each attempt |
| 428 | if not hostsResults: |
| 429 | hosts = main.topo.getAllHosts( main ) |
| 430 | hostsResults = main.TRUE |
| 431 | hostFails = [] # Reset for each attempt |
| 432 | |
| 433 | # Check for matching topology on each node |
| 434 | for controller in range( main.numCtrls ): |
| 435 | controllerStr = str( controller + 1 ) # ONOS node number |
| 436 | # Compare Devices |
| 437 | if devices[ controller ] and ports[ controller ] and\ |
| 438 | "Error" not in devices[ controller ] and\ |
| 439 | "Error" not in ports[ controller ]: |
| 440 | |
| 441 | try: |
| 442 | deviceData = json.loads( devices[ controller ] ) |
| 443 | portData = json.loads( ports[ controller ] ) |
| 444 | except (TypeError,ValueError): |
| 445 | main.log.error("Could not load json:" + str( devices[ controller ] ) + ' or ' + str( ports[ controller ] )) |
| 446 | currentDevicesResult = main.FALSE |
| 447 | else: |
| 448 | if mnSwitches == len( deviceData ): |
| 449 | currentDevicesResult = main.TRUE |
| 450 | else: |
| 451 | currentDevicesResult = main.FALSE |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 452 | main.log.error( "Node {} only sees {} device(s) but {} exist".format( |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 453 | controllerStr,len( deviceData ),mnSwitches ) ) |
| 454 | else: |
| 455 | currentDevicesResult = main.FALSE |
| 456 | if not currentDevicesResult: |
| 457 | deviceFails.append( controllerStr ) |
| 458 | devicesResults = devicesResults and currentDevicesResult |
| 459 | # Compare Links |
| 460 | if links[ controller ] and "Error" not in links[ controller ]: |
| 461 | try: |
| 462 | linkData = json.loads( links[ controller ] ) |
| 463 | except (TypeError,ValueError): |
| 464 | main.log.error("Could not load json:" + str( links[ controller ] ) ) |
| 465 | currentLinksResult = main.FALSE |
| 466 | else: |
| 467 | if mnLinks == len( linkData ): |
| 468 | currentLinksResult = main.TRUE |
| 469 | else: |
| 470 | currentLinksResult = main.FALSE |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 471 | main.log.error( "Node {} only sees {} link(s) but {} exist".format( |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 472 | controllerStr,len( linkData ),mnLinks ) ) |
| 473 | else: |
| 474 | currentLinksResult = main.FALSE |
| 475 | if not currentLinksResult: |
| 476 | linkFails.append( controllerStr ) |
| 477 | linksResults = linksResults and currentLinksResult |
| 478 | # Compare Hosts |
| 479 | if hosts[ controller ] and "Error" not in hosts[ controller ]: |
| 480 | try: |
| 481 | hostData = json.loads( hosts[ controller ] ) |
| 482 | except (TypeError,ValueError): |
| 483 | main.log.error("Could not load json:" + str( hosts[ controller ] ) ) |
| 484 | currentHostsResult = main.FALSE |
| 485 | else: |
| 486 | if mnHosts == len( hostData ): |
| 487 | currentHostsResult = main.TRUE |
| 488 | else: |
| 489 | currentHostsResult = main.FALSE |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 490 | main.log.error( "Node {} only sees {} host(s) but {} exist".format( |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 491 | controllerStr,len( hostData ),mnHosts ) ) |
| 492 | else: |
| 493 | currentHostsResult = main.FALSE |
| 494 | if not currentHostsResult: |
| 495 | hostFails.append( controllerStr ) |
| 496 | hostsResults = hostsResults and currentHostsResult |
| 497 | # Decrement Attempts Remaining |
| 498 | attempts -= 1 |
| 499 | |
| 500 | utilities.assert_equals( expect=[], |
| 501 | actual=deviceFails, |
| 502 | onpass="ONOS correctly discovered all devices", |
| 503 | onfail="ONOS incorrectly discovered devices on nodes: " + |
| 504 | str( deviceFails ) ) |
| 505 | utilities.assert_equals( expect=[], |
| 506 | actual=linkFails, |
| 507 | onpass="ONOS correctly discovered all links", |
| 508 | onfail="ONOS incorrectly discovered links on nodes: " + |
| 509 | str( linkFails ) ) |
| 510 | utilities.assert_equals( expect=[], |
| 511 | actual=hostFails, |
| 512 | onpass="ONOS correctly discovered all hosts", |
| 513 | onfail="ONOS incorrectly discovered hosts on nodes: " + |
| 514 | str( hostFails ) ) |
| 515 | if hostsResults and linksResults and devicesResults: |
| 516 | topoResults = main.TRUE |
| 517 | else: |
| 518 | topoResults = main.FALSE |
| 519 | utilities.assert_equals( expect=main.TRUE, |
| 520 | actual=topoResults, |
| 521 | onpass="ONOS correctly discovered the topology", |
| 522 | onfail="ONOS incorrectly discovered the topology" ) |
| 523 | |
| 524 | |
| 525 | def CASE31( self, main ): |
| 526 | import time |
| 527 | """ |
| 528 | Add bidirectional point intents between 2 packet layer( mininet ) |
| 529 | devices and ping mininet hosts |
| 530 | """ |
| 531 | main.log.report( |
| 532 | "This testcase adds bidirectional point intents between 2 " + |
| 533 | "packet layer( mininet ) devices and ping mininet hosts" ) |
| 534 | main.case( "Install point intents between 2 packet layer device and " + |
| 535 | "ping the hosts" ) |
| 536 | main.caseExplanation = "This testcase adds bidirectional point intents between 2 " +\ |
| 537 | "packet layer( mininet ) devices and ping mininet hosts" |
| 538 | |
| 539 | main.step( "Adding point intents" ) |
| 540 | checkFlowResult = main.TRUE |
| 541 | main.pIntentsId = [] |
| 542 | pIntent1 = main.CLIs[ 0 ].addPointIntent( |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 543 | "of:0000000000000001/1", |
| 544 | "of:0000000000000002/1" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 545 | time.sleep( 10 ) |
| 546 | pIntent2 = main.CLIs[ 0 ].addPointIntent( |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 547 | "of:0000000000000002/1", |
| 548 | "of:0000000000000001/1" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 549 | main.pIntentsId.append( pIntent1 ) |
| 550 | main.pIntentsId.append( pIntent2 ) |
| 551 | time.sleep( 10 ) |
| 552 | main.log.info( "Checking intents state") |
| 553 | checkStateResult = main.CLIs[ 0 ].checkIntentState( |
| 554 | intentsId = main.pIntentsId ) |
| 555 | time.sleep( 10 ) |
| 556 | main.log.info( "Checking flows state") |
| 557 | checkFlowResult = main.CLIs[ 0 ].checkFlowsState() |
| 558 | # Sleep for 10 seconds to provide time for the intent state to change |
| 559 | time.sleep( 10 ) |
| 560 | main.log.info( "Checking intents state one more time") |
| 561 | checkStateResult = main.CLIs[ 0 ].checkIntentState( |
| 562 | intentsId = main.pIntentsId ) |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 563 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 564 | if checkStateResult and checkFlowResult: |
| 565 | addIntentsResult = main.TRUE |
| 566 | else: |
| 567 | addIntentsResult = main.FALSE |
| 568 | utilities.assert_equals( |
| 569 | expect=main.TRUE, |
| 570 | actual=addIntentsResult, |
| 571 | onpass="Successfully added point intents", |
| 572 | onfail="Failed to add point intents") |
| 573 | |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 574 | pingResult = main.FALSE |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 575 | |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 576 | if not addIntentsResult: |
| 577 | main.log.error( "Intents were not properly installed. Skipping ping." ) |
| 578 | |
| 579 | else: |
| 580 | main.step( "Ping h1 and h2" ) |
| 581 | pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 582 | utilities.assert_equals( |
| 583 | expect=main.TRUE, |
| 584 | actual=pingResult, |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 585 | onpass="Successfully pinged h1 and h2", |
| 586 | onfail="Failed to ping between h1 and h2") |
| 587 | |
| 588 | main.step( "Remove Point to Point intents" ) |
| 589 | removeResult = main.FALSE |
| 590 | # Check remaining intents |
| 591 | try: |
| 592 | intentsJson = json.loads( main.CLIs[ 0 ].intents() ) |
| 593 | main.log.debug( intentsJson ) |
| 594 | main.CLIs[ 0 ].removeIntent( intentId=pIntent1, purge=True ) |
| 595 | main.CLIs[ 0 ].removeIntent( intentId=pIntent2, purge=True ) |
| 596 | for intents in intentsJson: |
| 597 | main.CLIs[ 0 ].removeIntent( intentId=intents.get( 'id' ), |
| 598 | app='org.onosproject.cli', |
| 599 | purge=True ) |
| 600 | time.sleep( 15 ) |
| 601 | |
| 602 | for i in range( main.numCtrls ): |
| 603 | if len( json.loads( main.CLIs[ i ].intents() ) ): |
| 604 | print json.loads( main.CLIs[ i ].intents() ) |
| 605 | removeResult = main.FALSE |
| 606 | else: |
| 607 | removeResult = main.TRUE |
| 608 | except ( TypeError, ValueError ): |
| 609 | main.log.error( "Cannot see intents on Node " + str( main.CLIs[ 0 ] ) +\ |
| 610 | ". Removing all intents.") |
| 611 | main.CLIs[ 0 ].removeAllIntents( purge=True ) |
| 612 | main.CLIs[ 0 ].removeAllIntents( purge=True, app='org.onosproject.cli') |
| 613 | |
| 614 | utilities.assert_equals( expect=main.TRUE, |
| 615 | actual=removeResult, |
| 616 | onpass="Successfully removed host intents", |
| 617 | onfail="Failed to remove host intents" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 618 | |
| 619 | def CASE32( self ): |
| 620 | """ |
| 621 | Add host intents between 2 packet layer host |
| 622 | """ |
| 623 | import time |
| 624 | import json |
| 625 | main.log.report( "Adding host intents between 2 optical layer host" ) |
| 626 | main.case( "Test add host intents between optical layer host" ) |
| 627 | main.caseExplanation = "Test host intents between 2 optical layer host" |
| 628 | |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 629 | main.step( "Creating list of hosts" ) |
| 630 | hostnum = 0 |
| 631 | try: |
| 632 | hostData = json.loads( hosts[ controller ] ) |
| 633 | except( TypeError, ValueError ): |
| 634 | main.log.error("Could not load json:" + str( hosts[ controller ] ) ) |
| 635 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 636 | main.step( "Adding host intents to h1 and h2" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 637 | hostId = [] |
| 638 | # Listing host MAC addresses |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 639 | for host in hostData: |
| 640 | hostId.append( host.get("id") ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 641 | host1 = hostId[ 0 ] |
| 642 | host2 = hostId[ 1 ] |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 643 | main.log.debug( host1 ) |
| 644 | main.log.debug( host2 ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 645 | |
| 646 | intentsId = [] |
| 647 | intent1 = main.CLIs[ 0 ].addHostIntent( hostIdOne = host1, |
| 648 | hostIdTwo = host2 ) |
| 649 | intentsId.append( intent1 ) |
| 650 | # Checking intents state before pinging |
| 651 | main.log.info( "Checking intents state" ) |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 652 | intentResult = utilities.retry( f=main.CLIs[ 0 ].checkIntentState, |
| 653 | retValue=main.FALSE, args=intentsId, |
| 654 | sleep=main.checkIntentSleep, attempts=10 ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 655 | |
| 656 | # If intent state is still wrong, display intent states |
| 657 | if not intentResult: |
| 658 | main.log.error( main.CLIs[ 0 ].intents() ) |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 659 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 660 | utilities.assert_equals( expect=main.TRUE, |
| 661 | actual=intentResult, |
| 662 | onpass="All intents are in INSTALLED state ", |
| 663 | onfail="Some of the intents are not in " + |
| 664 | "INSTALLED state " ) |
| 665 | |
| 666 | if not intentResult: |
| 667 | main.log.error( "Intents were not properly installed. Skipping Ping" ) |
| 668 | else: |
| 669 | # Pinging h1 to h2 and then ping h2 to h1 |
| 670 | main.step( "Pinging h1 and h2" ) |
| 671 | pingResult = main.TRUE |
| 672 | pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" ) \ |
| 673 | and main.LincOE.pingHostOptical( src="h2",target="h1" ) |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 674 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 675 | utilities.assert_equals( expect=main.TRUE, |
| 676 | actual=pingResult, |
| 677 | onpass="Pinged successfully between h1 and h2", |
| 678 | onfail="Pinged failed between h1 and h2" ) |
| 679 | |
| 680 | # Removed all added host intents |
| 681 | main.step( "Removing host intents" ) |
| 682 | removeResult = main.TRUE |
| 683 | # Check remaining intents |
Jeremy | 7134f5b | 2016-04-05 13:50:21 -0700 | [diff] [blame] | 684 | try: |
| 685 | intentsJson = json.loads( main.CLIs[ 0 ].intents() ) |
| 686 | main.CLIs[ 0 ].removeIntent( intentId=intent1, purge=True ) |
| 687 | #main.CLIs[ 0 ].removeIntent( intentId=intent2, purge=True ) |
| 688 | main.log.debug(intentsJson) |
| 689 | for intents in intentsJson: |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 690 | main.CLIs[ 0 ].removeIntent( intentId=intents.get( 'id' ), |
| 691 | app='org.onosproject.optical', |
| 692 | purge=True ) |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 693 | time.sleep( 15 ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 694 | |
Jeremy | 7134f5b | 2016-04-05 13:50:21 -0700 | [diff] [blame] | 695 | for i in range( main.numCtrls ): |
| 696 | if len( json.loads( main.CLIs[ i ].intents() ) ): |
| 697 | print json.loads( main.CLIs[ i ].intents() ) |
| 698 | removeResult = main.FALSE |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 699 | else: |
| 700 | removeResult = main.TRUE |
Jeremy | 7134f5b | 2016-04-05 13:50:21 -0700 | [diff] [blame] | 701 | except ( TypeError, ValueError ): |
| 702 | main.log.error( "Cannot see intents on Node " + str( main.CLIs[ 0 ] ) +\ |
| 703 | ". Removing all intents.") |
| 704 | main.CLIs[ 0 ].removeAllIntents( purge=True ) |
| 705 | main.CLIs[ 0 ].removeAllIntents( purge=True, app='org.onosproject.optical') |
| 706 | |
| 707 | utilities.assert_equals( expect=main.TRUE, |
| 708 | actual=removeResult, |
| 709 | onpass="Successfully removed host intents", |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 710 | onfail="Failed to remove host intents" ) |