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