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