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 2016 Open Networking Foundation ( ONF ) |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 3 | |
| 4 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 5 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>, |
| 6 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 7 | |
| 8 | TestON is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 2 of the License, or |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 11 | ( at your option ) any later version. |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 12 | |
| 13 | TestON is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 20 | """ |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 21 | import os |
| 22 | import imp |
| 23 | import time |
| 24 | import json |
| 25 | import urllib |
| 26 | from core import utilities |
| 27 | |
| 28 | |
| 29 | class Testcaselib: |
Pier | fb719b1 | 2016-09-19 14:51:44 -0700 | [diff] [blame] | 30 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 31 | useSSH = True |
Pier | fb719b1 | 2016-09-19 14:51:44 -0700 | [diff] [blame] | 32 | |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 33 | @staticmethod |
| 34 | def initTest( main ): |
| 35 | """ |
| 36 | - Construct tests variables |
| 37 | - GIT ( optional ) |
| 38 | - Checkout ONOS master branch |
| 39 | - Pull latest ONOS code |
| 40 | - Building ONOS ( optional ) |
| 41 | - Install ONOS package |
| 42 | - Build ONOS package |
| 43 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 44 | try: |
| 45 | from tests.dependencies.ONOSSetup import ONOSSetup |
| 46 | main.testSetUp = ONOSSetup() |
| 47 | except ImportError: |
| 48 | main.log.error( "ONOSSetup not found. exiting the test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 49 | main.cleanAndExit() |
You Wang | d587348 | 2018-01-24 12:30:00 -0800 | [diff] [blame] | 50 | from tests.dependencies.Network import Network |
| 51 | main.Network = Network() |
Devin Lim | 0c972b7 | 2018-02-08 14:53:59 -0800 | [diff] [blame] | 52 | main.testSetUp.envSetupDescription( False ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 53 | stepResult = main.FALSE |
| 54 | try: |
| 55 | main.step( "Constructing test variables" ) |
| 56 | # Test variables |
| 57 | main.cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 58 | main.apps = main.params[ 'ENV' ][ 'cellApps' ] |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 59 | main.path = os.path.dirname( main.testFile ) |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 60 | main.useCommonTopo = main.params[ 'DEPENDENCY' ][ 'useCommonTopo' ] == 'True' |
| 61 | main.topoPath = main.path + ( "/.." if main.useCommonTopo else "" ) + "/dependencies/" |
| 62 | main.useCommonConf = main.params[ 'DEPENDENCY' ][ 'useCommonConf' ] == 'True' |
| 63 | main.configPath = main.path + ( "/.." if main.useCommonConf else "" ) + "/dependencies/" |
| 64 | main.forJson = "json/" |
| 65 | main.forChart = "chart/" |
| 66 | main.forConfig = "conf/" |
| 67 | main.forHost = "host/" |
You Wang | 2731757 | 2018-03-06 12:13:11 -0800 | [diff] [blame] | 68 | main.forSwitchFailure = "switchFailure/" |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 69 | main.forLinkFailure = "linkFailure/" |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 70 | main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ] |
You Wang | d87b231 | 2018-01-30 12:47:17 -0800 | [diff] [blame] | 71 | main.topologyLib = main.params[ 'DEPENDENCY' ][ 'lib' ] if 'lib' in main.params[ 'DEPENDENCY' ] else None |
| 72 | main.topologyConf = main.params[ 'DEPENDENCY' ][ 'conf' ] if 'conf' in main.params[ 'DEPENDENCY' ] else None |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 73 | main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 74 | main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 75 | main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 76 | |
Devin Lim | 0c972b7 | 2018-02-08 14:53:59 -0800 | [diff] [blame] | 77 | stepResult = main.testSetUp.envSetup( False ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 78 | except Exception as e: |
| 79 | main.testSetUp.envSetupException( e ) |
Jonghwan Hyun | 3731d6a | 2017-10-19 11:59:31 -0700 | [diff] [blame] | 80 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 81 | main.testSetUp.evnSetupConclusion( stepResult ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 82 | |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 83 | @staticmethod |
Andreas Pantelopoulos | 90f0b10 | 2018-02-01 13:21:45 -0800 | [diff] [blame] | 84 | def installOnos( main, vlanCfg=True, skipPackage=False, cliSleep=10, |
| 85 | parallel=True ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 86 | """ |
| 87 | - Set up cell |
| 88 | - Create cell file |
| 89 | - Set cell file |
| 90 | - Verify cell file |
| 91 | - Kill ONOS process |
| 92 | - Uninstall ONOS cluster |
| 93 | - Verify ONOS start up |
| 94 | - Install ONOS cluster |
| 95 | - Connect to cli |
| 96 | """ |
| 97 | # main.scale[ 0 ] determines the current number of ONOS controller |
You Wang | d87b231 | 2018-01-30 12:47:17 -0800 | [diff] [blame] | 98 | if not main.apps: |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 99 | main.log.error( "App list is empty" ) |
Jon Hall | 3c91016 | 2018-03-07 14:42:16 -0800 | [diff] [blame] | 100 | main.log.info( "Cluster size: " + str( main.Cluster.numCtrls ) ) |
| 101 | main.log.info( "Cluster ips: " + ', '.join( main.Cluster.getIps() ) ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 102 | main.dynamicHosts = [ 'in1', 'out1' ] |
You Wang | a0f6ff6 | 2018-01-11 15:46:30 -0800 | [diff] [blame] | 103 | main.testSetUp.ONOSSetUp( main.Cluster, newCell=True, cellName=main.cellName, |
Andreas Pantelopoulos | 90f0b10 | 2018-02-01 13:21:45 -0800 | [diff] [blame] | 104 | skipPack=skipPackage, |
| 105 | useSSH=Testcaselib.useSSH, |
Devin Lim | 0c972b7 | 2018-02-08 14:53:59 -0800 | [diff] [blame] | 106 | installParallel=parallel, includeCaseDesc=False ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 107 | ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary, |
| 108 | main.FALSE, |
You Wang | 1cdc5f5 | 2017-12-19 16:47:51 -0800 | [diff] [blame] | 109 | sleep=cliSleep, |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 110 | attempts=10 ) |
| 111 | if ready: |
| 112 | ready = main.TRUE |
| 113 | utilities.assert_equals( expect=main.TRUE, actual=ready, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 114 | onpass="ONOS summary command succeded", |
| 115 | onfail="ONOS summary command failed" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 116 | if not ready: |
| 117 | main.log.error( "ONOS startup failed!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 118 | main.cleanAndExit() |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 119 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 120 | for ctrl in main.Cluster.active(): |
| 121 | ctrl.CLI.logSet( "DEBUG", "org.onosproject.segmentrouting" ) |
| 122 | ctrl.CLI.logSet( "DEBUG", "org.onosproject.driver.pipeline" ) |
| 123 | ctrl.CLI.logSet( "DEBUG", "org.onosproject.store.group.impl" ) |
| 124 | ctrl.CLI.logSet( "DEBUG", "org.onosproject.net.flowobjective.impl" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 125 | |
| 126 | @staticmethod |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 127 | def loadCount( main ): |
| 128 | with open("%s/count/%s.count" % (main.configPath, main.cfgName)) as count: |
| 129 | main.count = json.load(count) |
| 130 | |
| 131 | @staticmethod |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 132 | def loadJson( main ): |
| 133 | with open( "%s%s.json" % ( main.configPath + main.forJson, |
| 134 | main.cfgName ) ) as cfg: |
| 135 | main.Cluster.active( 0 ).REST.setNetCfg( json.load( cfg ) ) |
| 136 | |
| 137 | @staticmethod |
| 138 | def loadChart( main ): |
| 139 | try: |
| 140 | with open( "%s%s.chart" % ( main.configPath + main.forChart, |
| 141 | main.cfgName ) ) as chart: |
| 142 | main.pingChart = json.load(chart) |
| 143 | except IOError: |
| 144 | main.log.warn( "No chart file found." ) |
| 145 | |
| 146 | @staticmethod |
| 147 | def loadHost( main ): |
| 148 | with open( "%s%s.host" % ( main.configPath + main.forHost, |
| 149 | main.cfgName ) ) as host: |
| 150 | main.expectedHosts = json.load( host ) |
| 151 | |
| 152 | @staticmethod |
You Wang | 2731757 | 2018-03-06 12:13:11 -0800 | [diff] [blame] | 153 | def loadSwitchFailureChart( main ): |
| 154 | with open( "%s%s.switchFailureChart" % ( main.configPath + main.forSwitchFailure, |
| 155 | main.cfgName ) ) as sfc: |
| 156 | main.switchFailureChart = json.load( sfc ) |
| 157 | |
| 158 | @staticmethod |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 159 | def loadLinkFailureChart( main ): |
| 160 | with open( "%s%s.linkFailureChart" % ( main.configPath + main.forLinkFailure, |
| 161 | main.cfgName ) ) as sfc: |
| 162 | main.linkFailureChart = json.load( sfc ) |
| 163 | |
| 164 | @staticmethod |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 165 | def startMininet( main, topology, args="" ): |
You Wang | d87b231 | 2018-01-30 12:47:17 -0800 | [diff] [blame] | 166 | copyResult = main.ONOSbench.scp( main.Mininet1, |
| 167 | main.topoPath + main.topology, |
| 168 | main.Mininet1.home, |
| 169 | direction="to" ) |
| 170 | if main.topologyLib: |
| 171 | for lib in main.topologyLib.split(","): |
| 172 | copyResult = copyResult and main.ONOSbench.scp( main.Mininet1, |
| 173 | main.topoPath + lib, |
| 174 | main.Mininet1.home, |
| 175 | direction="to" ) |
| 176 | if main.topologyConf: |
| 177 | for conf in main.topologyConf.split(","): |
| 178 | copyResult = copyResult and main.ONOSbench.scp( main.Mininet1, |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 179 | main.configPath + main.forConfig + conf, |
You Wang | d87b231 | 2018-01-30 12:47:17 -0800 | [diff] [blame] | 180 | "~/", |
| 181 | direction="to" ) |
| 182 | stepResult = copyResult |
| 183 | utilities.assert_equals( expect=main.TRUE, |
| 184 | actual=stepResult, |
| 185 | onpass="Successfully copied topo files", |
| 186 | onfail="Failed to copy topo files" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 187 | main.step( "Starting Mininet Topology" ) |
Jonghwan Hyun | 3731d6a | 2017-10-19 11:59:31 -0700 | [diff] [blame] | 188 | arg = "--onos-ip=%s %s" % (",".join([ctrl.ipAddress for ctrl in main.Cluster.runningNodes]), args) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 189 | main.topology = topology |
| 190 | topoResult = main.Mininet1.startNet( |
| 191 | topoFile=main.Mininet1.home + main.topology, args=arg ) |
| 192 | stepResult = topoResult |
| 193 | utilities.assert_equals( expect=main.TRUE, |
| 194 | actual=stepResult, |
| 195 | onpass="Successfully loaded topology", |
| 196 | onfail="Failed to load topology" ) |
| 197 | # Exit if topology did not load properly |
| 198 | if not topoResult: |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 199 | main.cleanAndExit() |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 200 | |
| 201 | @staticmethod |
You Wang | 84f981d | 2018-01-12 16:11:50 -0800 | [diff] [blame] | 202 | def connectToPhysicalNetwork( main, switchNames ): |
| 203 | main.step( "Connecting to physical netowrk" ) |
| 204 | topoResult = main.NetworkBench.connectToNet() |
| 205 | stepResult = topoResult |
| 206 | utilities.assert_equals( expect=main.TRUE, |
| 207 | actual=stepResult, |
| 208 | onpass="Successfully loaded topology", |
| 209 | onfail="Failed to load topology" ) |
| 210 | # Exit if topology did not load properly |
| 211 | if not topoResult: |
| 212 | main.cleanAndExit() |
| 213 | |
| 214 | main.step( "Assign switches to controllers." ) |
| 215 | assignResult = main.TRUE |
| 216 | for name in switchNames: |
| 217 | assignResult = assignResult & main.NetworkBench.assignSwController( sw=name, |
| 218 | ip=main.Cluster.getIps(), |
| 219 | port='6653' ) |
| 220 | utilities.assert_equals( expect=main.TRUE, |
| 221 | actual=stepResult, |
| 222 | onpass="Successfully assign switches to controllers", |
| 223 | onfail="Failed to assign switches to controllers" ) |
| 224 | |
| 225 | @staticmethod |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 226 | def config( main, cfgName ): |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 227 | main.spines = [] |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 228 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 229 | main.failures = int( main.params[ 'failures' ] ) |
| 230 | main.cfgName = cfgName |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 231 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 232 | if main.cfgName == '2x2': |
| 233 | spine = {} |
| 234 | spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ] |
| 235 | spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ] |
| 236 | main.spines.append( spine ) |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 237 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 238 | spine = {} |
| 239 | spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ] |
| 240 | spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ] |
| 241 | main.spines.append( spine ) |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 242 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 243 | elif main.cfgName == '4x4': |
| 244 | spine = {} |
| 245 | spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ] |
| 246 | spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ] |
| 247 | main.spines.append( spine ) |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 248 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 249 | spine = {} |
| 250 | spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ] |
| 251 | spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ] |
| 252 | main.spines.append( spine ) |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 253 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 254 | spine = {} |
| 255 | spine[ 'name' ] = main.params[ 'switches' ][ 'spine3' ] |
| 256 | spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid3' ] |
| 257 | main.spines.append( spine ) |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 258 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 259 | spine = {} |
| 260 | spine[ 'name' ] = main.params[ 'switches' ][ 'spine4' ] |
| 261 | spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid4' ] |
| 262 | main.spines.append( spine ) |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 263 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 264 | else: |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 265 | main.log.error( "Configuration failed!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 266 | main.cleanAndExit() |
You Wang | 2731757 | 2018-03-06 12:13:11 -0800 | [diff] [blame] | 267 | |
Andreas Pantelopoulos | 2eae324 | 2018-03-06 13:47:20 -0800 | [diff] [blame] | 268 | @staticmethod |
| 269 | def addStaticOnosRoute( main, subnet, intf): |
| 270 | """ |
| 271 | Adds an ONOS static route with the use route-add command. |
| 272 | """ |
| 273 | main.step("Add static route for subnet {0} towards router interface {1}".format(subnet, intf)) |
| 274 | routeResult = main.Cluster.active( 0 ).addStaticRoute(subnet, intf) |
| 275 | |
| 276 | utilities.assert_equals( expect=True, actual=( not routeResult ), |
| 277 | onpass="route-add command succeeded", |
| 278 | onfail="route-add command failed") |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 279 | |
| 280 | @staticmethod |
Jonghwan Hyun | 76a02b7 | 2018-01-30 16:40:48 +0900 | [diff] [blame] | 281 | def checkFlows( main, minFlowCount, tag="", dumpflows=True, sleep=10 ): |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 282 | main.step( |
Jon Hall | 3c91016 | 2018-03-07 14:42:16 -0800 | [diff] [blame] | 283 | "Check whether the flow count is bigger than %s" % minFlowCount ) |
Jonghwan Hyun | 76a02b7 | 2018-01-30 16:40:48 +0900 | [diff] [blame] | 284 | if tag == "": |
| 285 | tag = 'CASE%d' % main.CurrentTestCaseNumber |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 286 | count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowCount, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 287 | main.FALSE, |
| 288 | kwargs={ 'min': minFlowCount }, |
| 289 | attempts=10, |
You Wang | 1cdc5f5 | 2017-12-19 16:47:51 -0800 | [diff] [blame] | 290 | sleep=sleep ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 291 | utilities.assertEquals( |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 292 | expect=True, |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 293 | actual=( count > 0 ), |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 294 | onpass="Flow count looks correct: " + str( count ), |
| 295 | onfail="Flow count looks wrong: " + str( count ) ) |
| 296 | |
| 297 | main.step( "Check whether all flow status are ADDED" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 298 | flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 299 | main.FALSE, |
| 300 | kwargs={ 'isPENDING': False }, |
Jonghwan Hyun | 98fb40a | 2018-01-04 16:16:28 -0800 | [diff] [blame] | 301 | attempts=5, |
You Wang | 1cdc5f5 | 2017-12-19 16:47:51 -0800 | [diff] [blame] | 302 | sleep=sleep ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 303 | utilities.assertEquals( |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 304 | expect=main.TRUE, |
| 305 | actual=flowCheck, |
| 306 | onpass="Flow status is correct!", |
| 307 | onfail="Flow status is wrong!" ) |
| 308 | if dumpflows: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 309 | main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress, |
Pier | 50f0bc6 | 2016-09-07 17:53:40 -0700 | [diff] [blame] | 310 | "flows", |
| 311 | main.logdir, |
Jonghwan Hyun | 76a02b7 | 2018-01-30 16:40:48 +0900 | [diff] [blame] | 312 | tag + "_FlowsBefore" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 313 | main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress, |
Pier | 50f0bc6 | 2016-09-07 17:53:40 -0700 | [diff] [blame] | 314 | "groups", |
| 315 | main.logdir, |
Jonghwan Hyun | 76a02b7 | 2018-01-30 16:40:48 +0900 | [diff] [blame] | 316 | tag + "_GroupsBefore" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 317 | |
| 318 | @staticmethod |
Jonghwan Hyun | 98fb40a | 2018-01-04 16:16:28 -0800 | [diff] [blame] | 319 | def checkFlowsByDpid( main, dpid, minFlowCount, sleep=10 ): |
| 320 | main.step( |
Jonghwan Hyun | cf2345c | 2018-02-26 11:07:54 -0800 | [diff] [blame] | 321 | " Check whether the flow count of device %s is bigger than %s" % ( dpid, minFlowCount ) ) |
| 322 | count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowAddedCount, |
| 323 | main.FALSE, |
| 324 | args=( dpid, minFlowCount ), |
Jonghwan Hyun | 98fb40a | 2018-01-04 16:16:28 -0800 | [diff] [blame] | 325 | attempts=5, |
| 326 | sleep=sleep ) |
| 327 | utilities.assertEquals( |
Jonghwan Hyun | cf2345c | 2018-02-26 11:07:54 -0800 | [diff] [blame] | 328 | expect=True, |
| 329 | actual=( count > minFlowCount ), |
| 330 | onpass="Flow count looks correct: " + str( count ), |
| 331 | onfail="Flow count looks wrong. " ) |
Jonghwan Hyun | 98fb40a | 2018-01-04 16:16:28 -0800 | [diff] [blame] | 332 | |
| 333 | @staticmethod |
Andreas Pantelopoulos | 9173d44 | 2018-03-01 17:07:37 -0800 | [diff] [blame] | 334 | def checkFlowEqualityByDpid( main, dpid, flowCount, sleep=10): |
| 335 | main.step( |
| 336 | " Check whether the flow count of device %s is equal to %s" % ( dpid, flowCount ) ) |
| 337 | count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowAddedCount, |
| 338 | main.FALSE, |
| 339 | args=( dpid, flowCount, False, 1), |
| 340 | attempts=5, |
| 341 | sleep=sleep ) |
| 342 | |
| 343 | utilities.assertEquals( |
| 344 | expect=True, |
| 345 | actual=( int( count ) == flowCount ), |
| 346 | onpass="Flow count looks correct: " + str(count) , |
| 347 | onfail="Flow count looks wrong, should be " + str(flowCount)) |
| 348 | |
| 349 | @staticmethod |
| 350 | def checkGroupEqualityByDpid( main, dpid, groupCount, sleep=10): |
| 351 | main.step( |
| 352 | " Check whether the group count of device %s is equal to %s" % ( dpid, groupCount ) ) |
| 353 | count = utilities.retry( main.Cluster.active( 0 ).CLI.checkGroupAddedCount, |
| 354 | main.FALSE, |
| 355 | args=( dpid, groupCount, False, 1), |
| 356 | attempts=5, |
| 357 | sleep=sleep ) |
| 358 | |
| 359 | utilities.assertEquals( |
| 360 | expect=True, |
| 361 | actual=( count == groupCount ), |
| 362 | onpass="Group count looks correct: " + str(count) , |
| 363 | onfail="Group count looks wrong: should be " + str(groupCount)) |
| 364 | |
| 365 | @staticmethod |
| 366 | def checkFlowsGroupsFromFile(main): |
| 367 | |
| 368 | for dpid, values in main.count.items(): |
| 369 | flowCount = values["flows"] |
| 370 | groupCount = values["groups"] |
| 371 | main.log.report( "Check flow count for dpid " + str(dpid) + |
| 372 | ", should be " + str(flowCount)) |
| 373 | Testcaselib.checkFlowEqualityByDpid(main, dpid, flowCount) |
| 374 | |
| 375 | main.log.report( "Check group count for dpid " + str(dpid) + |
| 376 | ", should be " + str(groupCount)) |
| 377 | Testcaselib.checkGroupEqualityByDpid(main, dpid, groupCount) |
| 378 | |
| 379 | return |
| 380 | |
| 381 | @staticmethod |
Jonghwan Hyun | 812c70f | 2018-02-16 16:33:16 -0800 | [diff] [blame] | 382 | def pingAll( main, tag="", dumpflows=True, acceptableFailed=0, basedOnIp=False, sleep=10, retryAttempts=1 ): |
You Wang | f19d9f4 | 2018-02-23 16:34:19 -0800 | [diff] [blame] | 383 | ''' |
You Wang | ba231e7 | 2018-03-01 13:18:21 -0800 | [diff] [blame] | 384 | Verify connectivity between hosts according to the ping chart |
| 385 | acceptableFailed: max number of acceptable failed pings. |
You Wang | f19d9f4 | 2018-02-23 16:34:19 -0800 | [diff] [blame] | 386 | basedOnIp: if True, run ping or ping6 based on suffix of host names |
Jonghwan Hyun | 812c70f | 2018-02-16 16:33:16 -0800 | [diff] [blame] | 387 | retryAttempts: the number of retry ping. Only works for IPv4 hosts. |
You Wang | f19d9f4 | 2018-02-23 16:34:19 -0800 | [diff] [blame] | 388 | ''' |
You Wang | ba231e7 | 2018-03-01 13:18:21 -0800 | [diff] [blame] | 389 | main.log.report( "Check host connectivity" ) |
| 390 | main.log.debug( "Ping chart: %s" % main.pingChart ) |
Andreas Pantelopoulos | f6ed501 | 2018-02-08 21:26:01 -0800 | [diff] [blame] | 391 | if tag == "": |
| 392 | tag = 'CASE%d' % main.CurrentTestCaseNumber |
| 393 | for entry in main.pingChart.itervalues(): |
You Wang | ba231e7 | 2018-03-01 13:18:21 -0800 | [diff] [blame] | 394 | main.log.debug( "Entry in ping chart: %s" % entry ) |
| 395 | expect = entry[ 'expect' ] |
| 396 | if expect == "Unidirectional": |
| 397 | # Verify ping from each src host to each dst host |
| 398 | src = entry[ 'src' ] |
| 399 | dst = entry[ 'dst' ] |
| 400 | expect = main.TRUE |
| 401 | main.step( "Verify unidirectional connectivity from %s to %s with tag %s" % ( str( src ), str( dst ), tag ) ) |
| 402 | if basedOnIp: |
| 403 | if ("v4" in src[0]): |
| 404 | pa = main.Network.pingallHostsUnidirectional( src, dst, acceptableFailed=acceptableFailed ) |
| 405 | utilities.assert_equals( expect=expect, actual=pa, |
| 406 | onpass="IPv4 connectivity successfully tested", |
| 407 | onfail="IPv4 connectivity failed" ) |
| 408 | if ("v6" in src[0]): |
| 409 | pa = main.Network.pingallHostsUnidirectional( src, dst, ipv6=True, acceptableFailed=acceptableFailed ) |
| 410 | utilities.assert_equals( expect=expect, actual=pa, |
| 411 | onpass="IPv6 connectivity successfully tested", |
| 412 | onfail="IPv6 connectivity failed" ) |
| 413 | else: |
| 414 | pa = main.Network.pingallHostsUnidirectional( src, dst, acceptableFailed=acceptableFailed ) |
| 415 | utilities.assert_equals( expect=expect, actual=pa, |
| 416 | onpass="IP connectivity successfully tested", |
| 417 | onfail="IP connectivity failed" ) |
| 418 | else: |
| 419 | # Verify ping between each host pair |
| 420 | hosts = entry[ 'hosts' ] |
| 421 | try: |
| 422 | expect = main.TRUE if str(expect).lower() == 'true' else main.FALSE |
| 423 | except: |
| 424 | expect = main.FALSE |
| 425 | main.step( "Verify full connectivity for %s with tag %s" % ( str( hosts ), tag ) ) |
| 426 | if basedOnIp: |
| 427 | if ("v4" in hosts[0]): |
Jonghwan Hyun | 812c70f | 2018-02-16 16:33:16 -0800 | [diff] [blame] | 428 | pa = utilities.retry( main.Network.pingallHosts, |
| 429 | main.FALSE if expect else main.TRUE, |
| 430 | args=(hosts,), |
| 431 | attempts=retryAttempts, |
| 432 | sleep=sleep ) |
You Wang | ba231e7 | 2018-03-01 13:18:21 -0800 | [diff] [blame] | 433 | utilities.assert_equals( expect=expect, actual=pa, |
| 434 | onpass="IPv4 connectivity successfully tested", |
| 435 | onfail="IPv4 connectivity failed" ) |
| 436 | if ("v6" in hosts[0]): |
| 437 | pa = main.Network.pingIpv6Hosts( hosts, acceptableFailed=acceptableFailed ) |
| 438 | utilities.assert_equals( expect=expect, actual=pa, |
| 439 | onpass="IPv6 connectivity successfully tested", |
| 440 | onfail="IPv6 connectivity failed" ) |
| 441 | else: |
You Wang | f19d9f4 | 2018-02-23 16:34:19 -0800 | [diff] [blame] | 442 | pa = main.Network.pingallHosts( hosts ) |
| 443 | utilities.assert_equals( expect=expect, actual=pa, |
You Wang | ba231e7 | 2018-03-01 13:18:21 -0800 | [diff] [blame] | 444 | onpass="IP connectivity successfully tested", |
| 445 | onfail="IP connectivity failed" ) |
Andreas Pantelopoulos | f6ed501 | 2018-02-08 21:26:01 -0800 | [diff] [blame] | 446 | |
| 447 | if dumpflows: |
| 448 | main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress, |
| 449 | "flows", |
| 450 | main.logdir, |
| 451 | tag + "_FlowsOn" ) |
| 452 | main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress, |
| 453 | "groups", |
| 454 | main.logdir, |
| 455 | tag + "_GroupsOn" ) |
| 456 | |
| 457 | @staticmethod |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 458 | def killLink( main, end1, end2, switches, links ): |
| 459 | """ |
| 460 | end1,end2: identify the switches, ex.: 'leaf1', 'spine1' |
| 461 | switches, links: number of expected switches and links after linkDown, ex.: '4', '6' |
| 462 | Kill a link and verify ONOS can see the proper link change |
| 463 | """ |
| 464 | main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 465 | main.step( "Kill link between %s and %s" % ( end1, end2 ) ) |
You Wang | d587348 | 2018-01-24 12:30:00 -0800 | [diff] [blame] | 466 | LinkDown = main.Network.link( END1=end1, END2=end2, OPTION="down" ) |
| 467 | LinkDown = main.Network.link( END2=end1, END1=end2, OPTION="down" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 468 | main.log.info( |
| 469 | "Waiting %s seconds for link down to be discovered" % main.linkSleep ) |
| 470 | time.sleep( main.linkSleep ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 471 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 472 | main.FALSE, |
| 473 | kwargs={ 'numoswitch': switches, |
| 474 | 'numolink': links }, |
| 475 | attempts=10, |
| 476 | sleep=main.linkSleep ) |
| 477 | result = topology & LinkDown |
| 478 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 479 | onpass="Link down successful", |
| 480 | onfail="Failed to turn off link?" ) |
| 481 | |
| 482 | @staticmethod |
Andreas Pantelopoulos | fab6bf3 | 2018-03-06 18:56:35 -0800 | [diff] [blame] | 483 | def killLinkBatch( main, links, linksAfter, switches=7): |
| 484 | """ |
| 485 | links = list of links (src, dst) to bring down. |
| 486 | """ |
| 487 | |
| 488 | main.step("Killing a batch of links {0}".format(links)) |
| 489 | |
| 490 | for end1, end2 in links: |
| 491 | main.Network.link( END1=end1, END2=end2, OPTION="down") |
| 492 | main.Network.link( END1=end2, END2=end1, OPTION="down") |
| 493 | |
| 494 | main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
| 495 | main.log.info( |
| 496 | "Waiting %s seconds for links down to be discovered" % main.linkSleep ) |
| 497 | time.sleep( main.linkSleep ) |
| 498 | |
| 499 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
| 500 | main.FALSE, |
| 501 | kwargs={ 'numoswitch': switches, |
| 502 | 'numolink': linksAfter }, |
| 503 | attempts=10, |
| 504 | sleep=main.linkSleep ) |
| 505 | |
| 506 | @staticmethod |
| 507 | def restoreLinkBatch( main, links, linksAfter, switches=7): |
| 508 | """ |
| 509 | links = list of link (src, dst) to bring up again. |
| 510 | """ |
| 511 | |
| 512 | main.step("Restoring a batch of links {0}".format(links)) |
| 513 | |
| 514 | for end1, end2 in links: |
| 515 | main.Network.link( END1=end1, END2=end2, OPTION="up") |
| 516 | main.Network.link( END1=end2, END2=end1, OPTION="up") |
| 517 | |
| 518 | main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
| 519 | main.log.info( |
| 520 | "Waiting %s seconds for links down to be discovered" % main.linkSleep ) |
| 521 | time.sleep( main.linkSleep ) |
| 522 | |
| 523 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
| 524 | main.FALSE, |
| 525 | kwargs={ 'numoswitch': switches, |
| 526 | 'numolink': linksAfter }, |
| 527 | attempts=10, |
| 528 | sleep=main.linkSleep ) |
| 529 | |
| 530 | @staticmethod |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 531 | def restoreLink( main, end1, end2, dpid1, dpid2, port1, port2, switches, |
| 532 | links ): |
| 533 | """ |
| 534 | Params: |
| 535 | end1,end2: identify the end switches, ex.: 'leaf1', 'spine1' |
| 536 | dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002' |
| 537 | port1, port2: respective port of the end switches that connects to the link, ex.:'1' |
| 538 | switches, links: number of expected switches and links after linkDown, ex.: '4', '6' |
| 539 | Kill a link and verify ONOS can see the proper link change |
| 540 | """ |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 541 | main.step( "Restore link between %s and %s" % ( end1, end2 ) ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 542 | result = False |
| 543 | count = 0 |
| 544 | while True: |
| 545 | count += 1 |
You Wang | d587348 | 2018-01-24 12:30:00 -0800 | [diff] [blame] | 546 | main.Network.link( END1=end1, END2=end2, OPTION="up" ) |
| 547 | main.Network.link( END2=end1, END1=end2, OPTION="up" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 548 | main.log.info( |
| 549 | "Waiting %s seconds for link up to be discovered" % main.linkSleep ) |
| 550 | time.sleep( main.linkSleep ) |
Pier | fb719b1 | 2016-09-19 14:51:44 -0700 | [diff] [blame] | 551 | |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 552 | for i in range( 0, main.Cluster.numCtrls ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 553 | ctrl = main.Cluster.runningNodes[ i ] |
| 554 | onosIsUp = main.ONOSbench.isup( ctrl.ipAddress ) |
Pier | fb719b1 | 2016-09-19 14:51:44 -0700 | [diff] [blame] | 555 | if onosIsUp == main.TRUE: |
Jonghwan Hyun | 76a02b7 | 2018-01-30 16:40:48 +0900 | [diff] [blame] | 556 | ctrl.CLI.portstate( dpid=dpid1, port=port1, state='Enable' ) |
| 557 | ctrl.CLI.portstate( dpid=dpid2, port=port2, state='Enable' ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 558 | time.sleep( main.linkSleep ) |
| 559 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 560 | result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches, |
| 561 | numolink=links ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 562 | if count > 5 or result: |
| 563 | break |
| 564 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 565 | onpass="Link up successful", |
| 566 | onfail="Failed to bring link up" ) |
| 567 | |
| 568 | @staticmethod |
| 569 | def killSwitch( main, switch, switches, links ): |
| 570 | """ |
| 571 | Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6' |
| 572 | Completely kill a switch and verify ONOS can see the proper change |
| 573 | """ |
| 574 | main.switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) |
| 575 | main.step( "Kill " + switch ) |
| 576 | main.log.info( "Stopping" + switch ) |
You Wang | d587348 | 2018-01-24 12:30:00 -0800 | [diff] [blame] | 577 | main.Network.switch( SW=switch, OPTION="stop" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 578 | # todo make this repeatable |
| 579 | main.log.info( "Waiting %s seconds for switch down to be discovered" % ( |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 580 | main.switchSleep ) ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 581 | time.sleep( main.switchSleep ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 582 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 583 | main.FALSE, |
| 584 | kwargs={ 'numoswitch': switches, |
| 585 | 'numolink': links }, |
| 586 | attempts=10, |
| 587 | sleep=main.switchSleep ) |
| 588 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 589 | onpass="Kill switch successful", |
| 590 | onfail="Failed to kill switch?" ) |
| 591 | |
| 592 | @staticmethod |
| 593 | def recoverSwitch( main, switch, switches, links ): |
| 594 | """ |
| 595 | Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6' |
| 596 | Recover a switch and verify ONOS can see the proper change |
| 597 | """ |
| 598 | # todo make this repeatable |
| 599 | main.step( "Recovering " + switch ) |
| 600 | main.log.info( "Starting" + switch ) |
You Wang | d587348 | 2018-01-24 12:30:00 -0800 | [diff] [blame] | 601 | main.Network.switch( SW=switch, OPTION="start" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 602 | main.log.info( "Waiting %s seconds for switch up to be discovered" % ( |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 603 | main.switchSleep ) ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 604 | time.sleep( main.switchSleep ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 605 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 606 | main.FALSE, |
| 607 | kwargs={ 'numoswitch': switches, |
| 608 | 'numolink': links }, |
| 609 | attempts=10, |
| 610 | sleep=main.switchSleep ) |
| 611 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 612 | onpass="Switch recovery successful", |
| 613 | onfail="Failed to recover switch?" ) |
| 614 | |
| 615 | @staticmethod |
| 616 | def cleanup( main ): |
| 617 | """ |
| 618 | Stop Onos-cluster. |
| 619 | Stops Mininet |
| 620 | Copies ONOS log |
| 621 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 622 | try: |
| 623 | from tests.dependencies.utils import Utils |
| 624 | except ImportError: |
| 625 | main.log.error( "Utils not found exiting the test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 626 | main.cleanAndExit() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 627 | try: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 628 | main.utils |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 629 | except ( NameError, AttributeError ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 630 | main.utils = Utils() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 631 | |
| 632 | main.utils.mininetCleanup( main.Mininet1 ) |
| 633 | |
Devin Lim | 0c972b7 | 2018-02-08 14:53:59 -0800 | [diff] [blame] | 634 | main.utils.copyKarafLog( "CASE%d" % main.CurrentTestCaseNumber, before=True, includeCaseDesc=False ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 635 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 636 | for ctrl in main.Cluster.active(): |
| 637 | main.ONOSbench.onosStop( ctrl.ipAddress ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 638 | |
| 639 | @staticmethod |
| 640 | def killOnos( main, nodes, switches, links, expNodes ): |
| 641 | """ |
| 642 | Params: nodes, integer array with position of the ONOS nodes in the CLIs array |
| 643 | switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6' |
| 644 | Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change |
| 645 | """ |
Jon Hall | 3c91016 | 2018-03-07 14:42:16 -0800 | [diff] [blame] | 646 | main.step( "Killing ONOS instances with index(es): {}".format( nodes ) ) |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 647 | |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 648 | for i in nodes: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 649 | killResult = main.ONOSbench.onosDie( main.Cluster.runningNodes[ i ].ipAddress ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 650 | utilities.assert_equals( expect=main.TRUE, actual=killResult, |
| 651 | onpass="ONOS instance Killed", |
| 652 | onfail="Error killing ONOS instance" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 653 | main.Cluster.runningNodes[ i ].active = False |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 654 | time.sleep( 12 ) |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 655 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 656 | if len( nodes ) < main.Cluster.numCtrls: |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 657 | |
Jonghwan Hyun | 3731d6a | 2017-10-19 11:59:31 -0700 | [diff] [blame] | 658 | nodeResults = utilities.retry( main.Cluster.nodesCheck, |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 659 | False, |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 660 | attempts=5, |
| 661 | sleep=10 ) |
| 662 | utilities.assert_equals( expect=True, actual=nodeResults, |
| 663 | onpass="Nodes check successful", |
| 664 | onfail="Nodes check NOT successful" ) |
| 665 | |
| 666 | if not nodeResults: |
| 667 | for i in nodes: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 668 | ctrl = main.Cluster.runningNodes[ i ] |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 669 | main.log.debug( "{} components not ACTIVE: \n{}".format( |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 670 | ctrl.name, |
| 671 | ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) ) |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 672 | main.log.error( "Failed to kill ONOS, stopping test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 673 | main.cleanAndExit() |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 674 | |
Jonghwan Hyun | 76a02b7 | 2018-01-30 16:40:48 +0900 | [diff] [blame] | 675 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 676 | main.FALSE, |
| 677 | kwargs={ 'numoswitch': switches, |
| 678 | 'numolink': links, |
| 679 | 'numoctrl': expNodes }, |
| 680 | attempts=10, |
| 681 | sleep=12 ) |
| 682 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 683 | onpass="ONOS Instance down successful", |
| 684 | onfail="Failed to turn off ONOS Instance" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 685 | |
| 686 | @staticmethod |
| 687 | def recoverOnos( main, nodes, switches, links, expNodes ): |
| 688 | """ |
| 689 | Params: nodes, integer array with position of the ONOS nodes in the CLIs array |
| 690 | switches, links, nodes: number of expected switches, links and nodes after recoverOnos, ex.: '4', '6' |
| 691 | Recover an ONOS instance and verify the ONOS cluster can see the proper change |
| 692 | """ |
Jon Hall | 3c91016 | 2018-03-07 14:42:16 -0800 | [diff] [blame] | 693 | main.step( "Recovering ONOS instances with index(es): {}".format( nodes ) ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 694 | [ main.ONOSbench.onosStart( main.Cluster.runningNodes[ i ].ipAddress ) for i in nodes ] |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 695 | for i in nodes: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 696 | isUp = main.ONOSbench.isup( main.Cluster.runningNodes[ i ].ipAddress ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 697 | utilities.assert_equals( expect=main.TRUE, actual=isUp, |
| 698 | onpass="ONOS service is ready", |
| 699 | onfail="ONOS service did not start properly" ) |
| 700 | for i in nodes: |
| 701 | main.step( "Checking if ONOS CLI is ready" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 702 | ctrl = main.Cluster.runningNodes[ i ] |
Jonghwan Hyun | 76a02b7 | 2018-01-30 16:40:48 +0900 | [diff] [blame] | 703 | # ctrl.CLI.startCellCli() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 704 | cliResult = ctrl.CLI.startOnosCli( ctrl.ipAddress, |
| 705 | commandlineTimeout=60, |
| 706 | onosStartTimeout=100 ) |
| 707 | ctrl.active = True |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 708 | utilities.assert_equals( expect=main.TRUE, |
| 709 | actual=cliResult, |
| 710 | onpass="ONOS CLI is ready", |
| 711 | onfail="ONOS CLI is not ready" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 712 | |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 713 | main.step( "Checking ONOS nodes" ) |
Jonghwan Hyun | 3731d6a | 2017-10-19 11:59:31 -0700 | [diff] [blame] | 714 | nodeResults = utilities.retry( main.Cluster.nodesCheck, |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 715 | False, |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 716 | attempts=5, |
| 717 | sleep=10 ) |
| 718 | utilities.assert_equals( expect=True, actual=nodeResults, |
| 719 | onpass="Nodes check successful", |
| 720 | onfail="Nodes check NOT successful" ) |
| 721 | |
| 722 | if not nodeResults: |
| 723 | for i in nodes: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 724 | ctrl = main.Cluster.runningNodes[ i ] |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 725 | main.log.debug( "{} components not ACTIVE: \n{}".format( |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 726 | ctrl.name, |
| 727 | ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) ) |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 728 | main.log.error( "Failed to start ONOS, stopping test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 729 | main.cleanAndExit() |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 730 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 731 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 732 | main.FALSE, |
| 733 | kwargs={ 'numoswitch': switches, |
| 734 | 'numolink': links, |
| 735 | 'numoctrl': expNodes }, |
| 736 | attempts=10, |
| 737 | sleep=12 ) |
| 738 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 739 | onpass="ONOS Instance down successful", |
| 740 | onfail="Failed to turn off ONOS Instance" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 741 | ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary, |
| 742 | main.FALSE, |
| 743 | attempts=10, |
| 744 | sleep=12 ) |
| 745 | if ready: |
| 746 | ready = main.TRUE |
| 747 | utilities.assert_equals( expect=main.TRUE, actual=ready, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 748 | onpass="ONOS summary command succeded", |
| 749 | onfail="ONOS summary command failed" ) |
| 750 | if not ready: |
| 751 | main.log.error( "ONOS startup failed!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame] | 752 | main.cleanAndExit() |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 753 | |
| 754 | @staticmethod |
| 755 | def addHostCfg( main ): |
| 756 | """ |
| 757 | Adds Host Configuration to ONOS |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 758 | Updates expected state of the network ( pingChart ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 759 | """ |
| 760 | import json |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 761 | hostCfg = {} |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 762 | with open( main.configPath + main.forJson + "extra.json" ) as template: |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 763 | hostCfg = json.load( template ) |
| 764 | main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ] |
| 765 | main.step( "Pushing new configuration" ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 766 | mac, cfg = hostCfg[ 'hosts' ].popitem() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 767 | main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ], |
| 768 | subjectClass="hosts", |
| 769 | subjectKey=urllib.quote( mac, |
| 770 | safe='' ), |
| 771 | configKey="basic" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 772 | main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ] |
| 773 | main.step( "Pushing new configuration" ) |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 774 | mac, cfg = hostCfg[ 'hosts' ].popitem() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 775 | main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ], |
| 776 | subjectClass="hosts", |
| 777 | subjectKey=urllib.quote( mac, |
| 778 | safe='' ), |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 779 | configKey="basic" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 780 | main.pingChart.update( { 'vlan1': { "expect": "True", |
| 781 | "hosts": [ "olt1", "vsg1" ] } } ) |
| 782 | main.pingChart[ 'vlan5' ][ 'expect' ] = 0 |
| 783 | main.pingChart[ 'vlan10' ][ 'expect' ] = 0 |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 784 | ports = "[%s,%s]" % ( 5, 6 ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 785 | cfg = '{"of:0000000000000001":[{"vlan":1,"ports":%s,"name":"OLT 1"}]}' % ports |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 786 | main.Cluster.active( 0 ).REST.setNetCfg( json.loads( cfg ), |
| 787 | subjectClass="apps", |
| 788 | subjectKey="org.onosproject.segmentrouting", |
| 789 | configKey="xconnect" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 790 | |
| 791 | @staticmethod |
| 792 | def delHostCfg( main ): |
| 793 | """ |
| 794 | Removest Host Configuration from ONOS |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 795 | Updates expected state of the network ( pingChart ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 796 | """ |
| 797 | import json |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 798 | hostCfg = {} |
Devin Lim | 57221b0 | 2018-02-14 15:45:36 -0800 | [diff] [blame] | 799 | with open( main.configPath + main.forJson + "extra.json" ) as template: |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 800 | hostCfg = json.load( template ) |
| 801 | main.step( "Removing host configuration" ) |
| 802 | main.pingChart[ 'ip' ][ 'expect' ] = 0 |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 803 | mac, cfg = hostCfg[ 'hosts' ].popitem() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 804 | main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts", |
| 805 | subjectKey=urllib.quote( |
| 806 | mac, |
| 807 | safe='' ), |
| 808 | configKey="basic" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 809 | main.step( "Removing configuration" ) |
| 810 | main.pingChart[ 'ip' ][ 'expect' ] = 0 |
Jeremy Ronquillo | 23fb216 | 2017-09-15 14:59:57 -0700 | [diff] [blame] | 811 | mac, cfg = hostCfg[ 'hosts' ].popitem() |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 812 | main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts", |
| 813 | subjectKey=urllib.quote( |
| 814 | mac, |
| 815 | safe='' ), |
| 816 | configKey="basic" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 817 | main.step( "Removing vlan configuration" ) |
| 818 | main.pingChart[ 'vlan1' ][ 'expect' ] = 0 |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 819 | main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="apps", |
| 820 | subjectKey="org.onosproject.segmentrouting", |
| 821 | configKey="xconnect" ) |
You Wang | 53dba1e | 2018-02-02 17:45:44 -0800 | [diff] [blame] | 822 | |
| 823 | @staticmethod |
| 824 | def verifyNetworkHostIp( main, attempts=10, sleep=10 ): |
| 825 | """ |
| 826 | Verifies IP address assignment from the hosts |
| 827 | """ |
| 828 | main.step( "Verify IP address assignment from hosts" ) |
| 829 | ipResult = main.TRUE |
| 830 | for hostName, ip in main.expectedHosts[ "network" ].items(): |
| 831 | ipResult = ipResult and utilities.retry( main.Network.verifyHostIp, |
| 832 | main.FALSE, |
| 833 | kwargs={ 'hostList': [ hostName ], |
| 834 | 'prefix': ip }, |
| 835 | attempts=attempts, |
| 836 | sleep=sleep ) |
| 837 | utilities.assert_equals( expect=main.TRUE, actual=ipResult, |
| 838 | onpass="Verify network host IP succeded", |
| 839 | onfail="Verify network host IP failed" ) |
| 840 | |
| 841 | @staticmethod |
| 842 | def verifyOnosHostIp( main, attempts=10, sleep=10 ): |
| 843 | """ |
| 844 | Verifies host IP address assignment from ONOS |
| 845 | """ |
| 846 | main.step( "Verify host IP address assignment in ONOS" ) |
| 847 | ipResult = main.TRUE |
| 848 | for hostName, ip in main.expectedHosts[ "onos" ].items(): |
| 849 | ipResult = ipResult and utilities.retry( main.Cluster.active( 0 ).verifyHostIp, |
| 850 | main.FALSE, |
| 851 | kwargs={ 'hostList': [ hostName ], |
| 852 | 'prefix': ip }, |
| 853 | attempts=attempts, |
| 854 | sleep=sleep ) |
| 855 | utilities.assert_equals( expect=main.TRUE, actual=ipResult, |
| 856 | onpass="Verify ONOS host IP succeded", |
| 857 | onfail="Verify ONOS host IP failed" ) |
Andreas Pantelopoulos | 2eae324 | 2018-03-06 13:47:20 -0800 | [diff] [blame] | 858 | |
Jonghwan Hyun | 812c70f | 2018-02-16 16:33:16 -0800 | [diff] [blame] | 859 | @staticmethod |
| 860 | def updateIntfCfg( main, connectPoint, ips=[], untagged=0, tagged=[], native=0 ): |
| 861 | """ |
| 862 | Description: |
| 863 | Updates interface configuration in ONOS, with given IP and vlan parameters |
| 864 | Required: |
| 865 | * connectPoint: connect point to update configuration |
| 866 | Optional: |
| 867 | * ips: list of IP addresses, combined with '/xx' subnet representation, |
| 868 | corresponding to 'ips' field in the configuration |
| 869 | * untagged: vlan ID as an integer, corresponding to 'vlan-untagged' field in the configuration |
| 870 | * tagged: integer list of vlan IDs, corresponding to 'vlan-tagged' field in the configuration |
| 871 | * native: vlan ID as an integer, corresponding to 'vlan-native' field in the configuration |
| 872 | """ |
| 873 | cfg = dict() |
| 874 | cfg[ "ports" ] = dict() |
| 875 | cfg[ "ports" ][ connectPoint ] = dict() |
| 876 | cfg[ "ports" ][ connectPoint ][ "interfaces" ] = [ dict() ] |
| 877 | cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "ips" ] = ips |
| 878 | if untagged > 0: |
| 879 | cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-untagged" ] = untagged |
| 880 | else: |
| 881 | cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-tagged" ] = tagged |
| 882 | if native > 0: |
| 883 | cfg[ "ports" ][ connectPoint ][ "interfaces" ][ 0 ][ "vlan-native" ] = native |
| 884 | |
| 885 | main.Cluster.active( 0 ).REST.setNetCfg( json.loads( json.dumps( cfg ) ) ) |