Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame] | 1 | """ |
| 2 | Copyright 2016 Open Networking Foundation (ONF) |
| 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 |
| 11 | (at your option) any later version. |
| 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 | """ |
| 21 | |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 22 | import os |
| 23 | import imp |
| 24 | import time |
| 25 | import json |
| 26 | import urllib |
| 27 | from core import utilities |
| 28 | |
| 29 | |
| 30 | class Testcaselib: |
Pier | fb719b1 | 2016-09-19 14:51:44 -0700 | [diff] [blame] | 31 | |
You Wang | f5de25b | 2017-01-06 15:13:01 -0800 | [diff] [blame] | 32 | useSSH=True |
Pier | fb719b1 | 2016-09-19 14:51:44 -0700 | [diff] [blame] | 33 | |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 34 | @staticmethod |
| 35 | def initTest( main ): |
| 36 | """ |
| 37 | - Construct tests variables |
| 38 | - GIT ( optional ) |
| 39 | - Checkout ONOS master branch |
| 40 | - Pull latest ONOS code |
| 41 | - Building ONOS ( optional ) |
| 42 | - Install ONOS package |
| 43 | - Build ONOS package |
| 44 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 45 | try: |
| 46 | from tests.dependencies.ONOSSetup import ONOSSetup |
| 47 | main.testSetUp = ONOSSetup() |
| 48 | except ImportError: |
| 49 | main.log.error( "ONOSSetup not found. exiting the test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame^] | 50 | main.cleanAndExit() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 51 | main.testSetUp.envSetupDescription() |
| 52 | stepResult = main.FALSE |
| 53 | try: |
| 54 | main.step( "Constructing test variables" ) |
| 55 | # Test variables |
| 56 | main.cellName = main.params[ 'ENV' ][ 'cellName' ] |
| 57 | main.apps = main.params[ 'ENV' ][ 'cellApps' ] |
| 58 | main.diff = main.params[ 'ENV' ][ 'diffApps' ] |
| 59 | main.path = os.path.dirname( main.testFile ) |
| 60 | main.dependencyPath = main.path + "/../dependencies/" |
| 61 | main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ] |
| 62 | wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ] |
| 63 | main.scale = (main.params[ 'SCALE' ][ 'size' ]).split( "," ) |
| 64 | main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] ) |
| 65 | # main.ONOSport = main.params[ 'CTRL' ][ 'port' ] |
| 66 | main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] ) |
| 67 | # -- INIT SECTION, ONLY RUNS ONCE -- # |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 68 | |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 69 | copyResult1 = main.ONOSbench.scp( main.Mininet1, |
| 70 | main.dependencyPath + |
| 71 | main.topology, |
| 72 | main.Mininet1.home, |
| 73 | direction="to" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 74 | stepResult = main.testSetUp.envSetup() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 75 | except Exception as e: |
| 76 | main.testSetUp.envSetupException( e ) |
| 77 | main.testSetUp.evnSetupConclusion( stepResult ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 78 | |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 79 | |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 80 | |
| 81 | @staticmethod |
| 82 | def installOnos( main, vlanCfg=True ): |
| 83 | """ |
| 84 | - Set up cell |
| 85 | - Create cell file |
| 86 | - Set cell file |
| 87 | - Verify cell file |
| 88 | - Kill ONOS process |
| 89 | - Uninstall ONOS cluster |
| 90 | - Verify ONOS start up |
| 91 | - Install ONOS cluster |
| 92 | - Connect to cli |
| 93 | """ |
| 94 | # main.scale[ 0 ] determines the current number of ONOS controller |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 95 | if main.diff: |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 96 | main.apps = main.apps + "," + main.diff |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 97 | else: |
| 98 | main.log.error( "App list is empty" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 99 | main.log.info( "NODE COUNT = " + str( main.Cluster.numCtrls ) ) |
| 100 | main.log.info( ''.join( main.Cluster.getIps() ) ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 101 | main.dynamicHosts = [ 'in1', 'out1' ] |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 102 | main.testSetUp.createApplyCell( main.Cluster, newCell=True, cellName=main.cellName, |
| 103 | Mininet=main.Mininet1, useSSH=Testcaselib.useSSH, |
Devin Lim | 6301b74 | 2017-08-07 11:00:21 -0700 | [diff] [blame] | 104 | ips=main.Cluster.getIps() ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 105 | # kill off all onos processes |
| 106 | main.log.info( "Safety check, killing all ONOS processes" + |
| 107 | " before initiating environment setup" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 108 | for ctrl in main.Cluster.runningNodes: |
| 109 | main.ONOSbench.onosDie( ctrl.ipAddress ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 110 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 111 | main.testSetUp.buildOnos( main.Cluster ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 112 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 113 | main.testSetUp.installOnos( main.Cluster, False ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 114 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 115 | main.testSetUp.setupSsh( main.Cluster ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 116 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 117 | main.testSetUp.checkOnosService( main.Cluster ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 118 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 119 | cliResult = main.TRUE |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 120 | main.step( "Checking if ONOS CLI is ready" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 121 | for ctrl in main.Cluster.runningNodes: |
| 122 | ctrl.CLI.startCellCli( ) |
| 123 | cliResult = cliResult and ctrl.CLI.startOnosCli( ctrl.ipAddress, |
| 124 | commandlineTimeout=60, |
| 125 | onosStartTimeout=100 ) |
| 126 | ctrl.active = True |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 127 | utilities.assert_equals( expect=main.TRUE, |
| 128 | actual=cliResult, |
| 129 | onpass="ONOS CLI is ready", |
| 130 | onfail="ONOS CLI is not ready" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 131 | ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary, |
| 132 | main.FALSE, |
| 133 | sleep=10, |
| 134 | attempts=10 ) |
| 135 | if ready: |
| 136 | ready = main.TRUE |
| 137 | utilities.assert_equals( expect=main.TRUE, actual=ready, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 138 | onpass="ONOS summary command succeded", |
| 139 | onfail="ONOS summary command failed" ) |
| 140 | |
| 141 | with open( "%s/json/%s.json" % ( |
| 142 | main.dependencyPath, main.cfgName) ) as cfg: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 143 | main.Cluster.active( 0 ).REST.setNetCfg( json.load( cfg ) ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 144 | with open( "%s/json/%s.chart" % ( |
| 145 | main.dependencyPath, main.cfgName) ) as chart: |
| 146 | main.pingChart = json.load( chart ) |
| 147 | if not ready: |
| 148 | main.log.error( "ONOS startup failed!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame^] | 149 | main.cleanAndExit() |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 150 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 151 | for ctrl in main.Cluster.active(): |
| 152 | ctrl.CLI.logSet( "DEBUG", "org.onosproject.segmentrouting" ) |
| 153 | ctrl.CLI.logSet( "DEBUG", "org.onosproject.driver.pipeline" ) |
| 154 | ctrl.CLI.logSet( "DEBUG", "org.onosproject.store.group.impl" ) |
| 155 | ctrl.CLI.logSet( "DEBUG", "org.onosproject.net.flowobjective.impl" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 156 | |
| 157 | @staticmethod |
| 158 | def startMininet( main, topology, args="" ): |
| 159 | main.step( "Starting Mininet Topology" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 160 | arg = "--onos %d %s" % (main.Cluster.numCtrls, 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 |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 174 | def config( main, cfgName ): |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 175 | main.spines = [] |
| 176 | |
| 177 | main.failures = int(main.params[ 'failures' ]) |
| 178 | main.cfgName = cfgName |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 179 | |
| 180 | if main.cfgName == '2x2' : |
| 181 | spine = {} |
| 182 | spine[ 'name' ] = main.params['switches'][ 'spine1' ] |
| 183 | spine[ 'dpid' ] = main.params['switches'][ 'spinedpid1' ] |
| 184 | main.spines.append(spine) |
| 185 | |
| 186 | spine = {} |
| 187 | spine[ 'name' ] = main.params['switches'][ 'spine2' ] |
| 188 | spine[ 'dpid' ] = main.params['switches'][ 'spinedpid2' ] |
| 189 | main.spines.append(spine) |
| 190 | |
| 191 | elif main.cfgName == '4x4' : |
| 192 | spine = {} |
| 193 | spine[ 'name' ] = main.params['switches'][ 'spine1' ] |
| 194 | spine[ 'dpid' ] = main.params['switches'][ 'spinedpid1' ] |
| 195 | main.spines.append(spine) |
| 196 | |
| 197 | spine = {} |
| 198 | spine[ 'name' ] = main.params['switches'][ 'spine2' ] |
| 199 | spine[ 'dpid' ] = main.params['switches'][ 'spinedpid2' ] |
| 200 | main.spines.append(spine) |
| 201 | |
| 202 | spine = {} |
| 203 | spine[ 'name' ] = main.params['switches'][ 'spine3' ] |
| 204 | spine[ 'dpid' ] = main.params['switches'][ 'spinedpid3' ] |
| 205 | main.spines.append(spine) |
| 206 | |
| 207 | spine = {} |
| 208 | spine[ 'name' ] = main.params['switches'][ 'spine4' ] |
| 209 | spine[ 'dpid' ] = main.params['switches'][ 'spinedpid4' ] |
| 210 | main.spines.append(spine) |
| 211 | |
| 212 | else : |
| 213 | main.log.error( "Configuration failed!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame^] | 214 | main.cleanAndExit() |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 215 | |
| 216 | @staticmethod |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 217 | def checkFlows( main, minFlowCount, dumpflows=True ): |
| 218 | main.step( |
| 219 | " Check whether the flow count is bigger than %s" % minFlowCount ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 220 | count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowCount, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 221 | main.FALSE, |
| 222 | kwargs={ 'min': minFlowCount }, |
| 223 | attempts=10, |
| 224 | sleep=10 ) |
| 225 | utilities.assertEquals( \ |
| 226 | expect=True, |
| 227 | actual=(count > 0), |
| 228 | onpass="Flow count looks correct: " + str( count ), |
| 229 | onfail="Flow count looks wrong: " + str( count ) ) |
| 230 | |
| 231 | main.step( "Check whether all flow status are ADDED" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 232 | flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 233 | main.FALSE, |
| 234 | kwargs={ 'isPENDING': False }, |
| 235 | attempts=2, |
| 236 | sleep=10 ) |
| 237 | utilities.assertEquals( \ |
| 238 | expect=main.TRUE, |
| 239 | actual=flowCheck, |
| 240 | onpass="Flow status is correct!", |
| 241 | onfail="Flow status is wrong!" ) |
| 242 | if dumpflows: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 243 | main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress, |
Pier | 50f0bc6 | 2016-09-07 17:53:40 -0700 | [diff] [blame] | 244 | "flows", |
| 245 | main.logdir, |
| 246 | "flowsBefore" + main.cfgName ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 247 | main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress, |
Pier | 50f0bc6 | 2016-09-07 17:53:40 -0700 | [diff] [blame] | 248 | "groups", |
| 249 | main.logdir, |
| 250 | "groupsBefore" + main.cfgName ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 251 | |
| 252 | @staticmethod |
| 253 | def pingAll( main, tag="", dumpflows=True ): |
| 254 | main.log.report( "Check full connectivity" ) |
| 255 | print main.pingChart |
| 256 | for entry in main.pingChart.itervalues( ): |
| 257 | print entry |
| 258 | hosts, expect = entry[ 'hosts' ], entry[ 'expect' ] |
| 259 | expect = main.TRUE if expect else main.FALSE |
| 260 | main.step( "Connectivity for %s %s" % (str( hosts ), tag) ) |
| 261 | pa = main.Mininet1.pingallHosts( hosts ) |
| 262 | utilities.assert_equals( expect=expect, actual=pa, |
| 263 | onpass="IP connectivity successfully tested", |
| 264 | onfail="IP connectivity failed" ) |
| 265 | if dumpflows: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 266 | main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress, |
Pier | 50f0bc6 | 2016-09-07 17:53:40 -0700 | [diff] [blame] | 267 | "flows", |
| 268 | main.logdir, |
| 269 | "flowsOn" + tag ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 270 | main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress, |
Pier | 50f0bc6 | 2016-09-07 17:53:40 -0700 | [diff] [blame] | 271 | "groups", |
| 272 | main.logdir, |
| 273 | "groupsOn" + tag ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 274 | |
| 275 | @staticmethod |
| 276 | def killLink( main, end1, end2, switches, links ): |
| 277 | """ |
| 278 | end1,end2: identify the switches, ex.: 'leaf1', 'spine1' |
| 279 | switches, links: number of expected switches and links after linkDown, ex.: '4', '6' |
| 280 | Kill a link and verify ONOS can see the proper link change |
| 281 | """ |
| 282 | main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
| 283 | main.step( "Kill link between %s and %s" % (end1, end2) ) |
| 284 | LinkDown = main.Mininet1.link( END1=end1, END2=end2, OPTION="down" ) |
Pier | fb719b1 | 2016-09-19 14:51:44 -0700 | [diff] [blame] | 285 | LinkDown = main.Mininet1.link( END2=end1, END1=end2, OPTION="down" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 286 | main.log.info( |
| 287 | "Waiting %s seconds for link down to be discovered" % main.linkSleep ) |
| 288 | time.sleep( main.linkSleep ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 289 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 290 | main.FALSE, |
| 291 | kwargs={ 'numoswitch': switches, |
| 292 | 'numolink': links }, |
| 293 | attempts=10, |
| 294 | sleep=main.linkSleep ) |
| 295 | result = topology & LinkDown |
| 296 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 297 | onpass="Link down successful", |
| 298 | onfail="Failed to turn off link?" ) |
| 299 | |
| 300 | @staticmethod |
| 301 | def restoreLink( main, end1, end2, dpid1, dpid2, port1, port2, switches, |
| 302 | links ): |
| 303 | """ |
| 304 | Params: |
| 305 | end1,end2: identify the end switches, ex.: 'leaf1', 'spine1' |
| 306 | dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002' |
| 307 | port1, port2: respective port of the end switches that connects to the link, ex.:'1' |
| 308 | switches, links: number of expected switches and links after linkDown, ex.: '4', '6' |
| 309 | Kill a link and verify ONOS can see the proper link change |
| 310 | """ |
| 311 | main.step( "Restore link between %s and %s" % (end1, end2) ) |
| 312 | result = False |
| 313 | count = 0 |
| 314 | while True: |
| 315 | count += 1 |
| 316 | main.Mininet1.link( END1=end1, END2=end2, OPTION="up" ) |
| 317 | main.Mininet1.link( END2=end1, END1=end2, OPTION="up" ) |
| 318 | main.log.info( |
| 319 | "Waiting %s seconds for link up to be discovered" % main.linkSleep ) |
| 320 | time.sleep( main.linkSleep ) |
Pier | fb719b1 | 2016-09-19 14:51:44 -0700 | [diff] [blame] | 321 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 322 | for i in range(0, main.Cluster.numCtrls): |
| 323 | ctrl = main.Cluster.runningNodes[ i ] |
| 324 | onosIsUp = main.ONOSbench.isup( ctrl.ipAddress ) |
Pier | fb719b1 | 2016-09-19 14:51:44 -0700 | [diff] [blame] | 325 | if onosIsUp == main.TRUE: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 326 | ctrl.CLI.portstate( dpid=dpid1, port=port1 ) |
| 327 | ctrl.CLI.portstate( dpid=dpid2, port=port2 ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 328 | time.sleep( main.linkSleep ) |
| 329 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 330 | result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches, |
| 331 | numolink=links ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 332 | if count > 5 or result: |
| 333 | break |
| 334 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 335 | onpass="Link up successful", |
| 336 | onfail="Failed to bring link up" ) |
| 337 | |
| 338 | @staticmethod |
| 339 | def killSwitch( main, switch, switches, links ): |
| 340 | """ |
| 341 | Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6' |
| 342 | Completely kill a switch and verify ONOS can see the proper change |
| 343 | """ |
| 344 | main.switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) |
| 345 | main.step( "Kill " + switch ) |
| 346 | main.log.info( "Stopping" + switch ) |
| 347 | main.Mininet1.switch( SW=switch, OPTION="stop" ) |
| 348 | # todo make this repeatable |
| 349 | main.log.info( "Waiting %s seconds for switch down to be discovered" % ( |
| 350 | main.switchSleep) ) |
| 351 | time.sleep( main.switchSleep ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 352 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 353 | main.FALSE, |
| 354 | kwargs={ 'numoswitch': switches, |
| 355 | 'numolink': links }, |
| 356 | attempts=10, |
| 357 | sleep=main.switchSleep ) |
| 358 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 359 | onpass="Kill switch successful", |
| 360 | onfail="Failed to kill switch?" ) |
| 361 | |
| 362 | @staticmethod |
| 363 | def recoverSwitch( main, switch, switches, links ): |
| 364 | """ |
| 365 | Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6' |
| 366 | Recover a switch and verify ONOS can see the proper change |
| 367 | """ |
| 368 | # todo make this repeatable |
| 369 | main.step( "Recovering " + switch ) |
| 370 | main.log.info( "Starting" + switch ) |
| 371 | main.Mininet1.switch( SW=switch, OPTION="start" ) |
| 372 | main.log.info( "Waiting %s seconds for switch up to be discovered" % ( |
| 373 | main.switchSleep) ) |
| 374 | time.sleep( main.switchSleep ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 375 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 376 | main.FALSE, |
| 377 | kwargs={ 'numoswitch': switches, |
| 378 | 'numolink': links }, |
| 379 | attempts=10, |
| 380 | sleep=main.switchSleep ) |
| 381 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 382 | onpass="Switch recovery successful", |
| 383 | onfail="Failed to recover switch?" ) |
| 384 | |
| 385 | @staticmethod |
| 386 | def cleanup( main ): |
| 387 | """ |
| 388 | Stop Onos-cluster. |
| 389 | Stops Mininet |
| 390 | Copies ONOS log |
| 391 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 392 | try: |
| 393 | from tests.dependencies.utils import Utils |
| 394 | except ImportError: |
| 395 | main.log.error( "Utils not found exiting the test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame^] | 396 | main.cleanAndExit() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 397 | try: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 398 | main.utils |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 399 | except ( NameError, AttributeError ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 400 | main.utils = Utils() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 401 | |
| 402 | main.utils.mininetCleanup( main.Mininet1 ) |
| 403 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 404 | main.utils.copyKarafLog( main.cfgName ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 405 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 406 | for ctrl in main.Cluster.active(): |
| 407 | main.ONOSbench.onosStop( ctrl.ipAddress ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 408 | |
| 409 | @staticmethod |
| 410 | def killOnos( main, nodes, switches, links, expNodes ): |
| 411 | """ |
| 412 | Params: nodes, integer array with position of the ONOS nodes in the CLIs array |
| 413 | switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6' |
| 414 | Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change |
| 415 | """ |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 416 | |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 417 | main.step( "Killing ONOS instance" ) |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 418 | |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 419 | for i in nodes: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 420 | killResult = main.ONOSbench.onosDie( main.Cluster.runningNodes[ i ].ipAddress ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 421 | utilities.assert_equals( expect=main.TRUE, actual=killResult, |
| 422 | onpass="ONOS instance Killed", |
| 423 | onfail="Error killing ONOS instance" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 424 | main.Cluster.runningNodes[ i ].active = False |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 425 | time.sleep( 12 ) |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 426 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 427 | if len( nodes ) < main.Cluster.numCtrls: |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 428 | |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 429 | nodeResults = utilities.retry( Testcaselib.nodesCheck, |
| 430 | False, |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 431 | attempts=5, |
| 432 | sleep=10 ) |
| 433 | utilities.assert_equals( expect=True, actual=nodeResults, |
| 434 | onpass="Nodes check successful", |
| 435 | onfail="Nodes check NOT successful" ) |
| 436 | |
| 437 | if not nodeResults: |
| 438 | for i in nodes: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 439 | ctrl = main.Cluster.runningNodes[ i ] |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 440 | main.log.debug( "{} components not ACTIVE: \n{}".format( |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 441 | ctrl.name, |
| 442 | ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) ) |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 443 | main.log.error( "Failed to kill ONOS, stopping test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame^] | 444 | main.cleanAndExit() |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 445 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 446 | topology = utilities.retry( main.Cluster.active( 0 ).checkStatus, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 447 | main.FALSE, |
| 448 | kwargs={ 'numoswitch': switches, |
| 449 | 'numolink': links, |
| 450 | 'numoctrl': expNodes }, |
| 451 | attempts=10, |
| 452 | sleep=12 ) |
| 453 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 454 | onpass="ONOS Instance down successful", |
| 455 | onfail="Failed to turn off ONOS Instance" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 456 | |
| 457 | @staticmethod |
| 458 | def recoverOnos( main, nodes, switches, links, expNodes ): |
| 459 | """ |
| 460 | Params: nodes, integer array with position of the ONOS nodes in the CLIs array |
| 461 | switches, links, nodes: number of expected switches, links and nodes after recoverOnos, ex.: '4', '6' |
| 462 | Recover an ONOS instance and verify the ONOS cluster can see the proper change |
| 463 | """ |
| 464 | main.step( "Recovering ONOS instance" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 465 | [ main.ONOSbench.onosStart( main.Cluster.runningNodes[ i ].ipAddress ) for i in nodes ] |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 466 | for i in nodes: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 467 | isUp = main.ONOSbench.isup( main.Cluster.runningNodes[ i ].ipAddress ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 468 | utilities.assert_equals( expect=main.TRUE, actual=isUp, |
| 469 | onpass="ONOS service is ready", |
| 470 | onfail="ONOS service did not start properly" ) |
| 471 | for i in nodes: |
| 472 | main.step( "Checking if ONOS CLI is ready" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 473 | ctrl = main.Cluster.runningNodes[ i ] |
| 474 | ctrl.CLI.startCellCli() |
| 475 | cliResult = ctrl.CLI.startOnosCli( ctrl.ipAddress, |
| 476 | commandlineTimeout=60, |
| 477 | onosStartTimeout=100 ) |
| 478 | ctrl.active = True |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 479 | utilities.assert_equals( expect=main.TRUE, |
| 480 | actual=cliResult, |
| 481 | onpass="ONOS CLI is ready", |
| 482 | onfail="ONOS CLI is not ready" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 483 | |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 484 | main.step( "Checking ONOS nodes" ) |
| 485 | nodeResults = utilities.retry( Testcaselib.nodesCheck, |
| 486 | False, |
| 487 | args=[nodes], |
| 488 | attempts=5, |
| 489 | sleep=10 ) |
| 490 | utilities.assert_equals( expect=True, actual=nodeResults, |
| 491 | onpass="Nodes check successful", |
| 492 | onfail="Nodes check NOT successful" ) |
| 493 | |
| 494 | if not nodeResults: |
| 495 | for i in nodes: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 496 | ctrl = main.Cluster.runningNodes[ i ] |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 497 | main.log.debug( "{} components not ACTIVE: \n{}".format( |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 498 | ctrl.name, |
| 499 | ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) ) |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 500 | main.log.error( "Failed to start ONOS, stopping test" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame^] | 501 | main.cleanAndExit() |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 502 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 503 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 504 | main.FALSE, |
| 505 | kwargs={ 'numoswitch': switches, |
| 506 | 'numolink': links, |
| 507 | 'numoctrl': expNodes }, |
| 508 | attempts=10, |
| 509 | sleep=12 ) |
| 510 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 511 | onpass="ONOS Instance down successful", |
| 512 | onfail="Failed to turn off ONOS Instance" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 513 | ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary, |
| 514 | main.FALSE, |
| 515 | attempts=10, |
| 516 | sleep=12 ) |
| 517 | if ready: |
| 518 | ready = main.TRUE |
| 519 | utilities.assert_equals( expect=main.TRUE, actual=ready, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 520 | onpass="ONOS summary command succeded", |
| 521 | onfail="ONOS summary command failed" ) |
| 522 | if not ready: |
| 523 | main.log.error( "ONOS startup failed!" ) |
Devin Lim | 4407596 | 2017-08-11 10:56:37 -0700 | [diff] [blame^] | 524 | main.cleanAndExit() |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 525 | |
| 526 | @staticmethod |
| 527 | def addHostCfg( main ): |
| 528 | """ |
| 529 | Adds Host Configuration to ONOS |
| 530 | Updates expected state of the network (pingChart) |
| 531 | """ |
| 532 | import json |
| 533 | hostCfg = { } |
| 534 | with open( main.dependencyPath + "/json/extra.json" ) as template: |
| 535 | hostCfg = json.load( template ) |
| 536 | main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ] |
| 537 | main.step( "Pushing new configuration" ) |
| 538 | mac, cfg = hostCfg[ 'hosts' ].popitem( ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 539 | main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ], |
| 540 | subjectClass="hosts", |
| 541 | subjectKey=urllib.quote( mac, |
| 542 | safe='' ), |
| 543 | configKey="basic" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 544 | main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ] |
| 545 | main.step( "Pushing new configuration" ) |
| 546 | mac, cfg = hostCfg[ 'hosts' ].popitem( ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 547 | main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ], |
| 548 | subjectClass="hosts", |
| 549 | subjectKey=urllib.quote( mac, |
| 550 | safe='' ), |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 551 | configKey="basic" ) |
| 552 | main.pingChart.update( { 'vlan1': { "expect": "True", |
| 553 | "hosts": [ "olt1", "vsg1" ] } } ) |
| 554 | main.pingChart[ 'vlan5' ][ 'expect' ] = 0 |
| 555 | main.pingChart[ 'vlan10' ][ 'expect' ] = 0 |
| 556 | ports = "[%s,%s]" % (5, 6) |
| 557 | cfg = '{"of:0000000000000001":[{"vlan":1,"ports":%s,"name":"OLT 1"}]}' % ports |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 558 | main.Cluster.active( 0 ).REST.setNetCfg( json.loads( cfg ), |
| 559 | subjectClass="apps", |
| 560 | subjectKey="org.onosproject.segmentrouting", |
| 561 | configKey="xconnect" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 562 | |
| 563 | @staticmethod |
| 564 | def delHostCfg( main ): |
| 565 | """ |
| 566 | Removest Host Configuration from ONOS |
| 567 | Updates expected state of the network (pingChart) |
| 568 | """ |
| 569 | import json |
| 570 | hostCfg = { } |
| 571 | with open( main.dependencyPath + "/json/extra.json" ) as template: |
| 572 | hostCfg = json.load( template ) |
| 573 | main.step( "Removing host configuration" ) |
| 574 | main.pingChart[ 'ip' ][ 'expect' ] = 0 |
| 575 | mac, cfg = hostCfg[ 'hosts' ].popitem( ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 576 | main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts", |
| 577 | subjectKey=urllib.quote( |
| 578 | mac, |
| 579 | safe='' ), |
| 580 | configKey="basic" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 581 | main.step( "Removing configuration" ) |
| 582 | main.pingChart[ 'ip' ][ 'expect' ] = 0 |
| 583 | mac, cfg = hostCfg[ 'hosts' ].popitem( ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 584 | main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts", |
| 585 | subjectKey=urllib.quote( |
| 586 | mac, |
| 587 | safe='' ), |
| 588 | configKey="basic" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 589 | main.step( "Removing vlan configuration" ) |
| 590 | main.pingChart[ 'vlan1' ][ 'expect' ] = 0 |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 591 | main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="apps", |
| 592 | subjectKey="org.onosproject.segmentrouting", |
| 593 | configKey="xconnect" ) |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 594 | @staticmethod |
| 595 | def nodesCheck( nodes ): |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 596 | results = True |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 597 | nodesOutput = main.Cluster.command( "nodes", specificDriver=2 ) |
| 598 | ips = main.Cluster.getIps( activeOnly=True ) |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 599 | ips.sort() |
| 600 | for i in nodesOutput: |
| 601 | try: |
| 602 | current = json.loads( i ) |
| 603 | activeIps = [] |
| 604 | currentResult = False |
| 605 | for node in current: |
| 606 | if node['state'] == 'READY': |
| 607 | activeIps.append( node['ip'] ) |
| 608 | currentResult = True |
| 609 | for ip in ips: |
| 610 | if ip not in activeIps: |
| 611 | currentResult = False |
| 612 | break |
| 613 | except ( ValueError, TypeError ): |
| 614 | main.log.error( "Error parsing nodes output" ) |
| 615 | main.log.warn( repr( i ) ) |
| 616 | currentResult = False |
| 617 | results = results and currentResult |
| 618 | return results |