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