Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 1 | """ |
| 2 | Copyright 2015 Open Networking Foundation (ONF) |
| 3 | |
| 4 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 5 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 6 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 7 | |
| 8 | TestON is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 2 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | TestON is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 20 | """ |
| 21 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 22 | # Testing the basic intent functionality of ONOS |
| 23 | |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 24 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 25 | class FUNCoptical: |
| 26 | |
| 27 | def __init__( self ): |
| 28 | self.default = '' |
| 29 | |
| 30 | def CASE1( self, main ): |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 31 | import imp |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 32 | import time |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 33 | import re |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 34 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 35 | - Construct tests variables |
| 36 | - GIT ( optional ) |
| 37 | - Checkout ONOS master branch |
| 38 | - Pull latest ONOS code |
| 39 | - Building ONOS ( optional ) |
| 40 | - Install ONOS package |
| 41 | - Build ONOS package |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 42 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 43 | try: |
| 44 | from tests.dependencies.ONOSSetup import ONOSSetup |
| 45 | main.testSetUp = ONOSSetup() |
| 46 | except ImportError: |
| 47 | main.log.error( "ONOSSetup not found. exiting the test" ) |
| 48 | main.exit() |
| 49 | main.testSetUp.envSetupDescription() |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 50 | stepResult = main.FALSE |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 51 | # Test variables |
| 52 | try: |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 53 | main.apps = main.params[ 'ENV' ][ 'cellApps' ] |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 54 | main.dependencyPath = main.testOnDirectory + \ |
| 55 | main.params[ 'DEPENDENCY' ][ 'path' ] |
| 56 | main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 57 | wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ] |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 58 | main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] ) |
| 59 | main.checkIntentSleep = int( main.params[ 'SLEEP' ][ 'checkintent' ] ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 60 | main.checkTopoAttempts = int( main.params[ 'SLEEP' ][ 'topoAttempts' ] ) |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 61 | main.switches = int( main.params[ 'MININET' ][ 'switch' ] ) |
| 62 | main.links = int( main.params[ 'MININET' ][ 'links' ] ) |
| 63 | main.hosts = int( main.params[ 'MININET' ][ 'hosts' ] ) |
| 64 | main.opticalTopo = main.params[ 'MININET' ][ 'toponame' ] |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 65 | main.hostsData = {} |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 66 | main.activeONOSip = [] |
| 67 | main.assertReturnString = '' # Assembled assert return string |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 68 | main.cycle = 0 # How many times FUNCintent has run through its tests |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 69 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 70 | # -- INIT SECTION, ONLY RUNS ONCE -- # |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 71 | stepResult = main.testSetUp.envSetup( True ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 72 | except Exception as e: |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 73 | main.testSetUp.envSetupException( e ) |
| 74 | main.testSetUp.evnSetupConclusion( stepResult ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 75 | |
| 76 | def CASE2( self, main ): |
| 77 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 78 | - Set up cell |
| 79 | - Create cell file |
| 80 | - Set cell file |
| 81 | - Verify cell file |
| 82 | - Kill ONOS process |
| 83 | - Uninstall ONOS cluster |
| 84 | - Verify ONOS start up |
| 85 | - Install ONOS cluster |
| 86 | - Connect to cli |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 87 | """ |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 88 | main.flowCompiler = "Flow Rules" |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 89 | main.testSetUp.ONOSSetUp( main.LincOE, True ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 90 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 91 | def CASE10( self, main ): |
| 92 | """ |
| 93 | Start Mininet opticalTest Topology |
| 94 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 95 | del main.activeONOSip[:] |
| 96 | for i in range( main.numCtrls ): |
| 97 | # Populate activeONOSip |
| 98 | main.activeONOSip.append( main.ONOSip[ i ] ) |
| 99 | |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 100 | main.case( "Mininet with Linc-OE startup" ) |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 101 | main.step( "Push TopoDDriver.json to ONOS through onos-netcfg" ) |
Devin Lim | 0207527 | 2017-07-10 15:33:21 -0700 | [diff] [blame] | 102 | topoResult = True |
| 103 | for ip in main.activeONOSip: |
| 104 | topoResult = topoResult and \ |
| 105 | main.ONOSbench.onosNetCfg(controllerIp=ip, path=main.dependencyPath, |
| 106 | fileName="TopoDDriver.json") |
| 107 | |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 108 | #Exit if topology did not load properly |
| 109 | if not topoResult: |
| 110 | main.cleanup() |
| 111 | main.exit() |
| 112 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 113 | main.caseExplanation = "Start opticalTest.py topology included with ONOS" |
| 114 | main.step( "Starting mininet and LINC-OE" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 115 | time.sleep( 10 ) |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 116 | controllerIPs = ','.join( main.activeONOSip ) |
| 117 | cIps = "" |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 118 | for i in range( 0, 4 ): |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 119 | cIps += controllerIPs + ' ' |
| 120 | opticalMnScript = main.LincOE.runOpticalMnScript( ctrllerIP=cIps, topology=main.opticalTopo ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 121 | topoResult = opticalMnScript |
| 122 | utilities.assert_equals( |
| 123 | expect=main.TRUE, |
| 124 | actual=topoResult, |
| 125 | onpass="Started the topology successfully ", |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 126 | onfail="Failed to start the topology" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 127 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 128 | def CASE14( self, main ): |
| 129 | """ |
| 130 | Stop mininet |
| 131 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 132 | try: |
| 133 | from tests.dependencies.utils import Utils |
| 134 | except ImportError: |
| 135 | main.log.error( "Utils not found exiting the test" ) |
| 136 | main.exit() |
| 137 | try: |
| 138 | main.Utils |
| 139 | except ( NameError, AttributeError ): |
| 140 | main.Utils = Utils() |
| 141 | main.Utils.mininetCleanIntro() |
| 142 | topoResult = main.Utils.mininetCleanup( main.LincOE, timeout=180 ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 143 | # Exit if topology did not load properly |
| 144 | if not topoResult: |
| 145 | main.cleanup() |
| 146 | main.exit() |
| 147 | |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 148 | def CASE16( self, main ): |
| 149 | """ |
| 150 | Balance Masters |
| 151 | """ |
| 152 | main.case( "Balance mastership of switches" ) |
| 153 | main.step( "Balancing mastership of switches" ) |
| 154 | |
| 155 | balanceResult = main.FALSE |
| 156 | balanceResult = utilities.retry( f=main.CLIs[ 0 ].balanceMasters, retValue=main.FALSE, args=[] ) |
| 157 | |
| 158 | utilities.assert_equals( expect=main.TRUE, |
| 159 | actual=balanceResult, |
| 160 | onpass="Successfully balanced mastership of switches", |
| 161 | onfail="Failed to balance mastership of switches" ) |
| 162 | if not balanceResult: |
| 163 | main.initialized = main.FALSE |
| 164 | |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 165 | def CASE17( self, main ): |
| 166 | """ |
| 167 | Use Flow Objectives |
| 168 | """ |
| 169 | main.case( "Enable intent compilation using Flow Objectives" ) |
| 170 | main.step( "Enabling Flow Objectives" ) |
| 171 | |
| 172 | main.flowCompiler = "Flow Objectives" |
| 173 | |
| 174 | cmd = "org.onosproject.net.intent.impl.compiler.IntentConfigurableRegistrator" |
| 175 | |
| 176 | stepResult = main.CLIs[ 0 ].setCfg( component=cmd, |
| 177 | propName="useFlowObjectives", value="true" ) |
You Wang | 106d0fa | 2017-05-15 17:22:15 -0700 | [diff] [blame] | 178 | stepResult &= main.CLIs[ 0 ].setCfg( component=cmd, |
| 179 | propName="defaultFlowObjectiveCompiler", |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 180 | value='org.onosproject.net.intent.impl.compiler.LinkCollectionIntentObjectiveCompiler' ) |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 181 | |
| 182 | utilities.assert_equals( expect=main.TRUE, |
| 183 | actual=stepResult, |
| 184 | onpass="Successfully activated Flow Objectives", |
| 185 | onfail="Failed to activate Flow Objectives" ) |
| 186 | |
Jeremy Songster | 17147f2 | 2016-05-31 18:30:52 -0700 | [diff] [blame] | 187 | def CASE19( self, main ): |
| 188 | """ |
| 189 | Copy the karaf.log files after each testcase cycle |
| 190 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 191 | try: |
| 192 | from tests.dependencies.utils import Utils |
| 193 | except ImportError: |
| 194 | main.log.error( "Utils not found exiting the test" ) |
| 195 | main.exit() |
| 196 | try: |
| 197 | main.Utils |
| 198 | except ( NameError, AttributeError ): |
| 199 | main.Utils = Utils() |
| 200 | main.Utils.copyKarafLog() |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 201 | def CASE21( self, main ): |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 202 | """ |
| 203 | Run pingall to discover all hosts |
| 204 | """ |
| 205 | main.case( "Running Pingall" ) |
| 206 | main.caseExplanation = "Use pingall to discover all hosts. Pingall is expected to fail." |
| 207 | main.step( "Discover Hosts through Pingall" ) |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 208 | pingResult = main.LincOE.pingall( timeout=120 ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 209 | |
| 210 | utilities.assert_equals( expect=main.FALSE, |
| 211 | actual=pingResult, |
| 212 | onpass="Pingall Completed", |
| 213 | onfail="Pingall did not complete or did not return fales" ) |
| 214 | |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 215 | def CASE22( self, main ): |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 216 | """ |
| 217 | Send arpings to discover all hosts |
| 218 | """ |
| 219 | main.case( "Discover Hosts with arping" ) |
| 220 | main.caseExplanation = "Send arpings between all the hosts to discover and verify them" |
| 221 | |
| 222 | main.step( "Send arping between all hosts" ) |
| 223 | |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 224 | hosts = [] |
| 225 | for i in range( main.hosts ): |
| 226 | hosts.append( 'h{}'.format( i + 1 ) ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 227 | |
| 228 | arpingHostResults = main.TRUE |
| 229 | for host in hosts: |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 230 | if main.LincOE.arping( host, ethDevice=host+"-eth0" ): |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 231 | main.log.info( "Successfully reached host {} with arping".format( host ) ) |
| 232 | else: |
| 233 | main.log.error( "Could not reach host {} with arping".format( host ) ) |
| 234 | arpingHostResults = main.FALSE |
| 235 | |
| 236 | utilities.assert_equals( expect=main.TRUE, |
| 237 | actual=arpingHostResults, |
| 238 | onpass="Successfully discovered all hosts", |
| 239 | onfail="Could not descover some hosts" ) |
| 240 | |
| 241 | def CASE23( self, main ): |
| 242 | """ |
| 243 | Compare ONOS Topology to Mininet Topology |
| 244 | """ |
| 245 | import json |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 246 | try: |
| 247 | from tests.dependencies.topology import Topology |
| 248 | except ImportError: |
| 249 | main.log.error( "Topology not found exiting the test" ) |
| 250 | main.exit() |
| 251 | try: |
| 252 | main.topoRelated |
| 253 | except ( NameError, AttributeError ): |
| 254 | main.topoRelated = Topology() |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 255 | main.case( "Compare ONOS Topology view to Mininet topology" ) |
| 256 | main.caseExplanation = "Compare topology elements between Mininet" +\ |
| 257 | " and ONOS" |
| 258 | |
| 259 | main.log.info( "Gathering topology information from Mininet" ) |
| 260 | devicesResults = main.FALSE # Overall Boolean for device correctness |
| 261 | linksResults = main.FALSE # Overall Boolean for link correctness |
| 262 | hostsResults = main.FALSE # Overall Boolean for host correctness |
| 263 | deviceFails = [] # Nodes where devices are incorrect |
| 264 | linkFails = [] # Nodes where links are incorrect |
| 265 | hostFails = [] # Nodes where hosts are incorrect |
| 266 | attempts = main.checkTopoAttempts # Remaining Attempts |
| 267 | |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 268 | mnSwitches = main.switches |
| 269 | mnLinks = main.links |
| 270 | mnHosts = main.hosts |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 271 | |
Jon Hall | 70b2ff4 | 2015-11-17 15:49:44 -0800 | [diff] [blame] | 272 | main.step( "Comparing Mininet topology to ONOS topology" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 273 | |
| 274 | while ( attempts >= 0 ) and\ |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 275 | ( not devicesResults or not linksResults or not hostsResults ): |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 276 | time.sleep( 2 ) |
| 277 | if not devicesResults: |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 278 | devices = main.topoRelated.getAllDevices( main.numCtrls, False ) |
| 279 | ports = main.topoRelated.getAllPorts( main.numCtrls, False ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 280 | devicesResults = main.TRUE |
| 281 | deviceFails = [] # Reset for each attempt |
| 282 | if not linksResults: |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 283 | links = main.topoRelated.getAllLinks( main.numCtrls, False ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 284 | linksResults = main.TRUE |
| 285 | linkFails = [] # Reset for each attempt |
| 286 | if not hostsResults: |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 287 | hosts = main.topoRelated.getAllHosts( main.numCtrls, False ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 288 | hostsResults = main.TRUE |
| 289 | hostFails = [] # Reset for each attempt |
| 290 | |
| 291 | # Check for matching topology on each node |
| 292 | for controller in range( main.numCtrls ): |
| 293 | controllerStr = str( controller + 1 ) # ONOS node number |
| 294 | # Compare Devices |
| 295 | if devices[ controller ] and ports[ controller ] and\ |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 296 | "Error" not in devices[ controller ] and\ |
| 297 | "Error" not in ports[ controller ]: |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 298 | |
| 299 | try: |
| 300 | deviceData = json.loads( devices[ controller ] ) |
| 301 | portData = json.loads( ports[ controller ] ) |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 302 | except ( TypeError, ValueError ): |
| 303 | main.log.error( "Could not load json:" + str( devices[ controller ] ) + ' or ' + str( ports[ controller ] ) ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 304 | currentDevicesResult = main.FALSE |
| 305 | else: |
| 306 | if mnSwitches == len( deviceData ): |
| 307 | currentDevicesResult = main.TRUE |
| 308 | else: |
| 309 | currentDevicesResult = main.FALSE |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 310 | main.log.error( "Node {} only sees {} device(s) but {} exist".format( |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 311 | controllerStr, len( deviceData ), mnSwitches ) ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 312 | else: |
| 313 | currentDevicesResult = main.FALSE |
| 314 | if not currentDevicesResult: |
| 315 | deviceFails.append( controllerStr ) |
| 316 | devicesResults = devicesResults and currentDevicesResult |
| 317 | # Compare Links |
| 318 | if links[ controller ] and "Error" not in links[ controller ]: |
| 319 | try: |
| 320 | linkData = json.loads( links[ controller ] ) |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 321 | except ( TypeError, ValueError ): |
| 322 | main.log.error( "Could not load json:" + str( links[ controller ] ) ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 323 | currentLinksResult = main.FALSE |
| 324 | else: |
| 325 | if mnLinks == len( linkData ): |
| 326 | currentLinksResult = main.TRUE |
| 327 | else: |
| 328 | currentLinksResult = main.FALSE |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 329 | main.log.error( "Node {} only sees {} link(s) but {} exist".format( |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 330 | controllerStr, len( linkData ), mnLinks ) ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 331 | else: |
| 332 | currentLinksResult = main.FALSE |
| 333 | if not currentLinksResult: |
| 334 | linkFails.append( controllerStr ) |
| 335 | linksResults = linksResults and currentLinksResult |
| 336 | # Compare Hosts |
| 337 | if hosts[ controller ] and "Error" not in hosts[ controller ]: |
| 338 | try: |
| 339 | hostData = json.loads( hosts[ controller ] ) |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 340 | except ( TypeError, ValueError ): |
| 341 | main.log.error( "Could not load json:" + str( hosts[ controller ] ) ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 342 | currentHostsResult = main.FALSE |
| 343 | else: |
| 344 | if mnHosts == len( hostData ): |
| 345 | currentHostsResult = main.TRUE |
| 346 | else: |
| 347 | currentHostsResult = main.FALSE |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 348 | main.log.error( "Node {} only sees {} host(s) but {} exist".format( |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 349 | controllerStr, len( hostData ), mnHosts ) ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 350 | else: |
| 351 | currentHostsResult = main.FALSE |
| 352 | if not currentHostsResult: |
| 353 | hostFails.append( controllerStr ) |
| 354 | hostsResults = hostsResults and currentHostsResult |
| 355 | # Decrement Attempts Remaining |
| 356 | attempts -= 1 |
| 357 | |
| 358 | utilities.assert_equals( expect=[], |
| 359 | actual=deviceFails, |
| 360 | onpass="ONOS correctly discovered all devices", |
| 361 | onfail="ONOS incorrectly discovered devices on nodes: " + |
| 362 | str( deviceFails ) ) |
| 363 | utilities.assert_equals( expect=[], |
| 364 | actual=linkFails, |
| 365 | onpass="ONOS correctly discovered all links", |
| 366 | onfail="ONOS incorrectly discovered links on nodes: " + |
| 367 | str( linkFails ) ) |
| 368 | utilities.assert_equals( expect=[], |
| 369 | actual=hostFails, |
| 370 | onpass="ONOS correctly discovered all hosts", |
| 371 | onfail="ONOS incorrectly discovered hosts on nodes: " + |
| 372 | str( hostFails ) ) |
| 373 | if hostsResults and linksResults and devicesResults: |
| 374 | topoResults = main.TRUE |
| 375 | else: |
| 376 | topoResults = main.FALSE |
| 377 | utilities.assert_equals( expect=main.TRUE, |
| 378 | actual=topoResults, |
| 379 | onpass="ONOS correctly discovered the topology", |
| 380 | onfail="ONOS incorrectly discovered the topology" ) |
| 381 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 382 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 383 | def CASE31( self, main ): |
| 384 | import time |
| 385 | """ |
| 386 | Add bidirectional point intents between 2 packet layer( mininet ) |
| 387 | devices and ping mininet hosts |
| 388 | """ |
| 389 | main.log.report( |
| 390 | "This testcase adds bidirectional point intents between 2 " + |
| 391 | "packet layer( mininet ) devices and ping mininet hosts" ) |
| 392 | main.case( "Install point intents between 2 packet layer device and " + |
| 393 | "ping the hosts" ) |
| 394 | main.caseExplanation = "This testcase adds bidirectional point intents between 2 " +\ |
| 395 | "packet layer( mininet ) devices and ping mininet hosts" |
| 396 | |
| 397 | main.step( "Adding point intents" ) |
| 398 | checkFlowResult = main.TRUE |
| 399 | main.pIntentsId = [] |
| 400 | pIntent1 = main.CLIs[ 0 ].addPointIntent( |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 401 | "of:0000000000000015/1", |
| 402 | "of:000000000000000b/2" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 403 | time.sleep( 10 ) |
| 404 | pIntent2 = main.CLIs[ 0 ].addPointIntent( |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 405 | "of:000000000000000b/2", |
| 406 | "of:0000000000000015/1" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 407 | main.pIntentsId.append( pIntent1 ) |
| 408 | main.pIntentsId.append( pIntent2 ) |
| 409 | time.sleep( 10 ) |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 410 | main.log.info( "Checking intents state" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 411 | checkStateResult = main.CLIs[ 0 ].checkIntentState( |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 412 | intentsId=main.pIntentsId ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 413 | time.sleep( 10 ) |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 414 | checkStateResult = utilities.retry( f=main.CLIs[0].checkIntentState, |
| 415 | retValue=main.FALSE, args=( main.pIntentsId, "INSTALLED" ), |
| 416 | sleep=main.checkIntentSleep, attempts=10 ) |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 417 | main.log.info( "Checking flows state" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 418 | checkFlowResult = main.CLIs[ 0 ].checkFlowsState() |
| 419 | # Sleep for 10 seconds to provide time for the intent state to change |
| 420 | time.sleep( 10 ) |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 421 | main.log.info( "Checking intents state one more time" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 422 | checkStateResult = main.CLIs[ 0 ].checkIntentState( |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 423 | intentsId=main.pIntentsId ) |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 424 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 425 | if checkStateResult and checkFlowResult: |
| 426 | addIntentsResult = main.TRUE |
| 427 | else: |
| 428 | addIntentsResult = main.FALSE |
| 429 | utilities.assert_equals( |
| 430 | expect=main.TRUE, |
| 431 | actual=addIntentsResult, |
| 432 | onpass="Successfully added point intents", |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 433 | onfail="Failed to add point intents" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 434 | |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 435 | pingResult = main.FALSE |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 436 | |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 437 | if not addIntentsResult: |
| 438 | main.log.error( "Intents were not properly installed. Skipping ping." ) |
| 439 | |
| 440 | else: |
| 441 | main.step( "Ping h1 and h2" ) |
| 442 | pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 443 | utilities.assert_equals( |
| 444 | expect=main.TRUE, |
| 445 | actual=pingResult, |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 446 | onpass="Successfully pinged h1 and h2", |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 447 | onfail="Failed to ping between h1 and h2" ) |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 448 | |
| 449 | main.step( "Remove Point to Point intents" ) |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 450 | removeResult = main.TRUE |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 451 | # Check remaining intents |
| 452 | try: |
| 453 | intentsJson = json.loads( main.CLIs[ 0 ].intents() ) |
| 454 | main.log.debug( intentsJson ) |
| 455 | main.CLIs[ 0 ].removeIntent( intentId=pIntent1, purge=True ) |
| 456 | main.CLIs[ 0 ].removeIntent( intentId=pIntent2, purge=True ) |
| 457 | for intents in intentsJson: |
| 458 | main.CLIs[ 0 ].removeIntent( intentId=intents.get( 'id' ), |
| 459 | app='org.onosproject.cli', |
| 460 | purge=True ) |
| 461 | time.sleep( 15 ) |
| 462 | |
| 463 | for i in range( main.numCtrls ): |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 464 | if not any ( intent.get('state') == 'WITHDRAWING' for intent |
| 465 | in json.loads( main.CLIs[i].intents() ) ): |
| 466 | main.log.debug( json.loads( main.CLIs[i].intents ) ) |
| 467 | removeResult = main.FALSE |
| 468 | break |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 469 | else: |
| 470 | removeResult = main.TRUE |
| 471 | except ( TypeError, ValueError ): |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 472 | main.log.error( "Cannot see intents on Node " + str( main.CLIs[ 0 ] ) + |
| 473 | ". Removing all intents." ) |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 474 | main.CLIs[ 0 ].removeAllIntents( purge=True ) |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 475 | main.CLIs[ 0 ].removeAllIntents( purge=True, app='org.onosproject.cli' ) |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 476 | |
| 477 | utilities.assert_equals( expect=main.TRUE, |
| 478 | actual=removeResult, |
| 479 | onpass="Successfully removed host intents", |
| 480 | onfail="Failed to remove host intents" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 481 | |
| 482 | def CASE32( self ): |
| 483 | """ |
| 484 | Add host intents between 2 packet layer host |
| 485 | """ |
| 486 | import time |
| 487 | import json |
| 488 | main.log.report( "Adding host intents between 2 optical layer host" ) |
| 489 | main.case( "Test add host intents between optical layer host" ) |
| 490 | main.caseExplanation = "Test host intents between 2 optical layer host" |
| 491 | |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 492 | main.step( "Creating list of hosts" ) |
| 493 | hostnum = 0 |
| 494 | try: |
| 495 | hostData = json.loads( hosts[ controller ] ) |
| 496 | except( TypeError, ValueError ): |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 497 | main.log.error( "Could not load json:" + str( hosts[ controller ] ) ) |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 498 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 499 | main.step( "Adding host intents to h1 and h2" ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 500 | hostId = [] |
| 501 | # Listing host MAC addresses |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 502 | for host in hostData: |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 503 | hostId.append( host.get( "id" ) ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 504 | host1 = hostId[ 0 ] |
| 505 | host2 = hostId[ 1 ] |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 506 | main.log.debug( host1 ) |
| 507 | main.log.debug( host2 ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 508 | |
| 509 | intentsId = [] |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 510 | intent1 = main.CLIs[ 0 ].addHostIntent( hostIdOne=host1, |
| 511 | hostIdTwo=host2 ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 512 | intentsId.append( intent1 ) |
| 513 | # Checking intents state before pinging |
| 514 | main.log.info( "Checking intents state" ) |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 515 | intentResult = utilities.retry( f=main.CLIs[ 0 ].checkIntentState, |
| 516 | retValue=main.FALSE, args=intentsId, |
| 517 | sleep=main.checkIntentSleep, attempts=10 ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 518 | |
| 519 | # If intent state is still wrong, display intent states |
| 520 | if not intentResult: |
| 521 | main.log.error( main.CLIs[ 0 ].intents() ) |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 522 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 523 | utilities.assert_equals( expect=main.TRUE, |
| 524 | actual=intentResult, |
| 525 | onpass="All intents are in INSTALLED state ", |
| 526 | onfail="Some of the intents are not in " + |
| 527 | "INSTALLED state " ) |
| 528 | |
| 529 | if not intentResult: |
| 530 | main.log.error( "Intents were not properly installed. Skipping Ping" ) |
| 531 | else: |
| 532 | # Pinging h1 to h2 and then ping h2 to h1 |
| 533 | main.step( "Pinging h1 and h2" ) |
| 534 | pingResult = main.TRUE |
| 535 | pingResult = main.LincOE.pingHostOptical( src="h1", target="h2" ) \ |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 536 | and main.LincOE.pingHostOptical( src="h2", target="h1" ) |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 537 | |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 538 | utilities.assert_equals( expect=main.TRUE, |
| 539 | actual=pingResult, |
| 540 | onpass="Pinged successfully between h1 and h2", |
| 541 | onfail="Pinged failed between h1 and h2" ) |
| 542 | |
| 543 | # Removed all added host intents |
| 544 | main.step( "Removing host intents" ) |
| 545 | removeResult = main.TRUE |
| 546 | # Check remaining intents |
Jeremy | 7134f5b | 2016-04-05 13:50:21 -0700 | [diff] [blame] | 547 | try: |
| 548 | intentsJson = json.loads( main.CLIs[ 0 ].intents() ) |
| 549 | main.CLIs[ 0 ].removeIntent( intentId=intent1, purge=True ) |
| 550 | #main.CLIs[ 0 ].removeIntent( intentId=intent2, purge=True ) |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 551 | main.log.debug( intentsJson ) |
Jeremy | 7134f5b | 2016-04-05 13:50:21 -0700 | [diff] [blame] | 552 | for intents in intentsJson: |
Jeremy | e4bc713 | 2016-03-30 14:04:01 -0700 | [diff] [blame] | 553 | main.CLIs[ 0 ].removeIntent( intentId=intents.get( 'id' ), |
| 554 | app='org.onosproject.optical', |
| 555 | purge=True ) |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 556 | time.sleep( 15 ) |
acsmars | 51a7fe0 | 2015-10-29 18:33:32 -0700 | [diff] [blame] | 557 | |
Jeremy | 7134f5b | 2016-04-05 13:50:21 -0700 | [diff] [blame] | 558 | for i in range( main.numCtrls ): |
Devin Lim | 752dd7b | 2017-06-27 14:40:03 -0700 | [diff] [blame] | 559 | if not any ( intent.get('state') == 'WITHDRAWING' for intent |
| 560 | in json.loads( main.CLIs[i].intents() ) ): |
| 561 | main.log.debug( json.loads( main.CLIs[i].intents ) ) |
| 562 | removeResult = main.FALSE |
| 563 | break |
Jeremy Songster | 5665f1b | 2016-06-20 14:38:22 -0700 | [diff] [blame] | 564 | else: |
| 565 | removeResult = main.TRUE |
Jeremy | 7134f5b | 2016-04-05 13:50:21 -0700 | [diff] [blame] | 566 | except ( TypeError, ValueError ): |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 567 | main.log.error( "Cannot see intents on Node " + str( main.CLIs[ 0 ] ) + |
| 568 | ". Removing all intents." ) |
Jeremy | 7134f5b | 2016-04-05 13:50:21 -0700 | [diff] [blame] | 569 | main.CLIs[ 0 ].removeAllIntents( purge=True ) |
Jon Hall | e02505a | 2017-05-24 16:36:43 -0700 | [diff] [blame] | 570 | main.CLIs[ 0 ].removeAllIntents( purge=True, app='org.onosproject.optical' ) |
Jeremy | 7134f5b | 2016-04-05 13:50:21 -0700 | [diff] [blame] | 571 | |
| 572 | utilities.assert_equals( expect=main.TRUE, |
| 573 | actual=removeResult, |
| 574 | onpass="Successfully removed host intents", |
Chiyu Cheng | ef10950 | 2016-11-21 15:51:38 -0800 | [diff] [blame] | 575 | onfail="Failed to remove host intents" ) |