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