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