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" ) |
| 50 | main.exit() |
| 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, |
| 104 | ip=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!" ) |
| 149 | main.cleanup( ) |
| 150 | main.exit( ) |
| 151 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 152 | for ctrl in main.Cluster.active(): |
| 153 | ctrl.CLI.logSet( "DEBUG", "org.onosproject.segmentrouting" ) |
| 154 | ctrl.CLI.logSet( "DEBUG", "org.onosproject.driver.pipeline" ) |
| 155 | ctrl.CLI.logSet( "DEBUG", "org.onosproject.store.group.impl" ) |
| 156 | ctrl.CLI.logSet( "DEBUG", "org.onosproject.net.flowobjective.impl" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 157 | |
| 158 | @staticmethod |
| 159 | def startMininet( main, topology, args="" ): |
| 160 | main.step( "Starting Mininet Topology" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 161 | arg = "--onos %d %s" % (main.Cluster.numCtrls, args) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 162 | main.topology = topology |
| 163 | topoResult = main.Mininet1.startNet( |
| 164 | topoFile=main.Mininet1.home + main.topology, args=arg ) |
| 165 | stepResult = topoResult |
| 166 | utilities.assert_equals( expect=main.TRUE, |
| 167 | actual=stepResult, |
| 168 | onpass="Successfully loaded topology", |
| 169 | onfail="Failed to load topology" ) |
| 170 | # Exit if topology did not load properly |
| 171 | if not topoResult: |
| 172 | main.cleanup( ) |
| 173 | main.exit( ) |
| 174 | |
| 175 | @staticmethod |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 176 | def config( main, cfgName ): |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 177 | main.spines = [] |
| 178 | |
| 179 | main.failures = int(main.params[ 'failures' ]) |
| 180 | main.cfgName = cfgName |
Pier | a2a7e1b | 2016-10-04 11:51:43 -0700 | [diff] [blame] | 181 | |
| 182 | if main.cfgName == '2x2' : |
| 183 | spine = {} |
| 184 | spine[ 'name' ] = main.params['switches'][ 'spine1' ] |
| 185 | spine[ 'dpid' ] = main.params['switches'][ 'spinedpid1' ] |
| 186 | main.spines.append(spine) |
| 187 | |
| 188 | spine = {} |
| 189 | spine[ 'name' ] = main.params['switches'][ 'spine2' ] |
| 190 | spine[ 'dpid' ] = main.params['switches'][ 'spinedpid2' ] |
| 191 | main.spines.append(spine) |
| 192 | |
| 193 | elif main.cfgName == '4x4' : |
| 194 | spine = {} |
| 195 | spine[ 'name' ] = main.params['switches'][ 'spine1' ] |
| 196 | spine[ 'dpid' ] = main.params['switches'][ 'spinedpid1' ] |
| 197 | main.spines.append(spine) |
| 198 | |
| 199 | spine = {} |
| 200 | spine[ 'name' ] = main.params['switches'][ 'spine2' ] |
| 201 | spine[ 'dpid' ] = main.params['switches'][ 'spinedpid2' ] |
| 202 | main.spines.append(spine) |
| 203 | |
| 204 | spine = {} |
| 205 | spine[ 'name' ] = main.params['switches'][ 'spine3' ] |
| 206 | spine[ 'dpid' ] = main.params['switches'][ 'spinedpid3' ] |
| 207 | main.spines.append(spine) |
| 208 | |
| 209 | spine = {} |
| 210 | spine[ 'name' ] = main.params['switches'][ 'spine4' ] |
| 211 | spine[ 'dpid' ] = main.params['switches'][ 'spinedpid4' ] |
| 212 | main.spines.append(spine) |
| 213 | |
| 214 | else : |
| 215 | main.log.error( "Configuration failed!" ) |
| 216 | main.cleanup( ) |
| 217 | main.exit( ) |
| 218 | |
| 219 | @staticmethod |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 220 | def checkFlows( main, minFlowCount, dumpflows=True ): |
| 221 | main.step( |
| 222 | " Check whether the flow count is bigger than %s" % minFlowCount ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 223 | count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowCount, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 224 | main.FALSE, |
| 225 | kwargs={ 'min': minFlowCount }, |
| 226 | attempts=10, |
| 227 | sleep=10 ) |
| 228 | utilities.assertEquals( \ |
| 229 | expect=True, |
| 230 | actual=(count > 0), |
| 231 | onpass="Flow count looks correct: " + str( count ), |
| 232 | onfail="Flow count looks wrong: " + str( count ) ) |
| 233 | |
| 234 | main.step( "Check whether all flow status are ADDED" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 235 | flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 236 | main.FALSE, |
| 237 | kwargs={ 'isPENDING': False }, |
| 238 | attempts=2, |
| 239 | sleep=10 ) |
| 240 | utilities.assertEquals( \ |
| 241 | expect=main.TRUE, |
| 242 | actual=flowCheck, |
| 243 | onpass="Flow status is correct!", |
| 244 | onfail="Flow status is wrong!" ) |
| 245 | if dumpflows: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 246 | main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress, |
Pier | 50f0bc6 | 2016-09-07 17:53:40 -0700 | [diff] [blame] | 247 | "flows", |
| 248 | main.logdir, |
| 249 | "flowsBefore" + main.cfgName ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 250 | main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress, |
Pier | 50f0bc6 | 2016-09-07 17:53:40 -0700 | [diff] [blame] | 251 | "groups", |
| 252 | main.logdir, |
| 253 | "groupsBefore" + main.cfgName ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 254 | |
| 255 | @staticmethod |
| 256 | def pingAll( main, tag="", dumpflows=True ): |
| 257 | main.log.report( "Check full connectivity" ) |
| 258 | print main.pingChart |
| 259 | for entry in main.pingChart.itervalues( ): |
| 260 | print entry |
| 261 | hosts, expect = entry[ 'hosts' ], entry[ 'expect' ] |
| 262 | expect = main.TRUE if expect else main.FALSE |
| 263 | main.step( "Connectivity for %s %s" % (str( hosts ), tag) ) |
| 264 | pa = main.Mininet1.pingallHosts( hosts ) |
| 265 | utilities.assert_equals( expect=expect, actual=pa, |
| 266 | onpass="IP connectivity successfully tested", |
| 267 | onfail="IP connectivity failed" ) |
| 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, |
| 272 | "flowsOn" + tag ) |
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, |
| 276 | "groupsOn" + tag ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 277 | |
| 278 | @staticmethod |
| 279 | def killLink( main, end1, end2, switches, links ): |
| 280 | """ |
| 281 | end1,end2: identify the switches, ex.: 'leaf1', 'spine1' |
| 282 | switches, links: number of expected switches and links after linkDown, ex.: '4', '6' |
| 283 | Kill a link and verify ONOS can see the proper link change |
| 284 | """ |
| 285 | main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] ) |
| 286 | main.step( "Kill link between %s and %s" % (end1, end2) ) |
| 287 | LinkDown = main.Mininet1.link( END1=end1, END2=end2, OPTION="down" ) |
Pier | fb719b1 | 2016-09-19 14:51:44 -0700 | [diff] [blame] | 288 | LinkDown = main.Mininet1.link( END2=end1, END1=end2, OPTION="down" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 289 | main.log.info( |
| 290 | "Waiting %s seconds for link down to be discovered" % main.linkSleep ) |
| 291 | time.sleep( main.linkSleep ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 292 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 293 | main.FALSE, |
| 294 | kwargs={ 'numoswitch': switches, |
| 295 | 'numolink': links }, |
| 296 | attempts=10, |
| 297 | sleep=main.linkSleep ) |
| 298 | result = topology & LinkDown |
| 299 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 300 | onpass="Link down successful", |
| 301 | onfail="Failed to turn off link?" ) |
| 302 | |
| 303 | @staticmethod |
| 304 | def restoreLink( main, end1, end2, dpid1, dpid2, port1, port2, switches, |
| 305 | links ): |
| 306 | """ |
| 307 | Params: |
| 308 | end1,end2: identify the end switches, ex.: 'leaf1', 'spine1' |
| 309 | dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002' |
| 310 | port1, port2: respective port of the end switches that connects to the link, ex.:'1' |
| 311 | switches, links: number of expected switches and links after linkDown, ex.: '4', '6' |
| 312 | Kill a link and verify ONOS can see the proper link change |
| 313 | """ |
| 314 | main.step( "Restore link between %s and %s" % (end1, end2) ) |
| 315 | result = False |
| 316 | count = 0 |
| 317 | while True: |
| 318 | count += 1 |
| 319 | main.Mininet1.link( END1=end1, END2=end2, OPTION="up" ) |
| 320 | main.Mininet1.link( END2=end1, END1=end2, OPTION="up" ) |
| 321 | main.log.info( |
| 322 | "Waiting %s seconds for link up to be discovered" % main.linkSleep ) |
| 323 | time.sleep( main.linkSleep ) |
Pier | fb719b1 | 2016-09-19 14:51:44 -0700 | [diff] [blame] | 324 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 325 | for i in range(0, main.Cluster.numCtrls): |
| 326 | ctrl = main.Cluster.runningNodes[ i ] |
| 327 | onosIsUp = main.ONOSbench.isup( ctrl.ipAddress ) |
Pier | fb719b1 | 2016-09-19 14:51:44 -0700 | [diff] [blame] | 328 | if onosIsUp == main.TRUE: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 329 | ctrl.CLI.portstate( dpid=dpid1, port=port1 ) |
| 330 | ctrl.CLI.portstate( dpid=dpid2, port=port2 ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 331 | time.sleep( main.linkSleep ) |
| 332 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 333 | result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches, |
| 334 | numolink=links ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 335 | if count > 5 or result: |
| 336 | break |
| 337 | utilities.assert_equals( expect=main.TRUE, actual=result, |
| 338 | onpass="Link up successful", |
| 339 | onfail="Failed to bring link up" ) |
| 340 | |
| 341 | @staticmethod |
| 342 | def killSwitch( main, switch, switches, links ): |
| 343 | """ |
| 344 | Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6' |
| 345 | Completely kill a switch and verify ONOS can see the proper change |
| 346 | """ |
| 347 | main.switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] ) |
| 348 | main.step( "Kill " + switch ) |
| 349 | main.log.info( "Stopping" + switch ) |
| 350 | main.Mininet1.switch( SW=switch, OPTION="stop" ) |
| 351 | # todo make this repeatable |
| 352 | main.log.info( "Waiting %s seconds for switch down to be discovered" % ( |
| 353 | main.switchSleep) ) |
| 354 | time.sleep( main.switchSleep ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 355 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 356 | main.FALSE, |
| 357 | kwargs={ 'numoswitch': switches, |
| 358 | 'numolink': links }, |
| 359 | attempts=10, |
| 360 | sleep=main.switchSleep ) |
| 361 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 362 | onpass="Kill switch successful", |
| 363 | onfail="Failed to kill switch?" ) |
| 364 | |
| 365 | @staticmethod |
| 366 | def recoverSwitch( main, switch, switches, links ): |
| 367 | """ |
| 368 | Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6' |
| 369 | Recover a switch and verify ONOS can see the proper change |
| 370 | """ |
| 371 | # todo make this repeatable |
| 372 | main.step( "Recovering " + switch ) |
| 373 | main.log.info( "Starting" + switch ) |
| 374 | main.Mininet1.switch( SW=switch, OPTION="start" ) |
| 375 | main.log.info( "Waiting %s seconds for switch up to be discovered" % ( |
| 376 | main.switchSleep) ) |
| 377 | time.sleep( main.switchSleep ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 378 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 379 | main.FALSE, |
| 380 | kwargs={ 'numoswitch': switches, |
| 381 | 'numolink': links }, |
| 382 | attempts=10, |
| 383 | sleep=main.switchSleep ) |
| 384 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 385 | onpass="Switch recovery successful", |
| 386 | onfail="Failed to recover switch?" ) |
| 387 | |
| 388 | @staticmethod |
| 389 | def cleanup( main ): |
| 390 | """ |
| 391 | Stop Onos-cluster. |
| 392 | Stops Mininet |
| 393 | Copies ONOS log |
| 394 | """ |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 395 | try: |
| 396 | from tests.dependencies.utils import Utils |
| 397 | except ImportError: |
| 398 | main.log.error( "Utils not found exiting the test" ) |
| 399 | main.exit() |
| 400 | try: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 401 | main.utils |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 402 | except ( NameError, AttributeError ): |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 403 | main.utils = Utils() |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 404 | |
| 405 | main.utils.mininetCleanup( main.Mininet1 ) |
| 406 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 407 | main.utils.copyKarafLog( main.cfgName ) |
Devin Lim | 58046fa | 2017-07-05 16:55:00 -0700 | [diff] [blame] | 408 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 409 | for ctrl in main.Cluster.active(): |
| 410 | main.ONOSbench.onosStop( ctrl.ipAddress ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 411 | |
| 412 | @staticmethod |
| 413 | def killOnos( main, nodes, switches, links, expNodes ): |
| 414 | """ |
| 415 | Params: nodes, integer array with position of the ONOS nodes in the CLIs array |
| 416 | switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6' |
| 417 | Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change |
| 418 | """ |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 419 | |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 420 | main.step( "Killing ONOS instance" ) |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 421 | |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 422 | for i in nodes: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 423 | killResult = main.ONOSbench.onosDie( main.Cluster.runningNodes[ i ].ipAddress ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 424 | utilities.assert_equals( expect=main.TRUE, actual=killResult, |
| 425 | onpass="ONOS instance Killed", |
| 426 | onfail="Error killing ONOS instance" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 427 | main.Cluster.runningNodes[ i ].active = False |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 428 | time.sleep( 12 ) |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 429 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 430 | if len( nodes ) < main.Cluster.numCtrls: |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 431 | |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 432 | nodeResults = utilities.retry( Testcaselib.nodesCheck, |
| 433 | False, |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 434 | attempts=5, |
| 435 | sleep=10 ) |
| 436 | utilities.assert_equals( expect=True, actual=nodeResults, |
| 437 | onpass="Nodes check successful", |
| 438 | onfail="Nodes check NOT successful" ) |
| 439 | |
| 440 | if not nodeResults: |
| 441 | for i in nodes: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 442 | ctrl = main.Cluster.runningNodes[ i ] |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 443 | main.log.debug( "{} components not ACTIVE: \n{}".format( |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 444 | ctrl.name, |
| 445 | ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) ) |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 446 | main.log.error( "Failed to kill ONOS, stopping test" ) |
| 447 | main.cleanup() |
| 448 | main.exit() |
| 449 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 450 | topology = utilities.retry( main.Cluster.active( 0 ).checkStatus, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 451 | main.FALSE, |
| 452 | kwargs={ 'numoswitch': switches, |
| 453 | 'numolink': links, |
| 454 | 'numoctrl': expNodes }, |
| 455 | attempts=10, |
| 456 | sleep=12 ) |
| 457 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 458 | onpass="ONOS Instance down successful", |
| 459 | onfail="Failed to turn off ONOS Instance" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 460 | |
| 461 | @staticmethod |
| 462 | def recoverOnos( main, nodes, switches, links, expNodes ): |
| 463 | """ |
| 464 | Params: nodes, integer array with position of the ONOS nodes in the CLIs array |
| 465 | switches, links, nodes: number of expected switches, links and nodes after recoverOnos, ex.: '4', '6' |
| 466 | Recover an ONOS instance and verify the ONOS cluster can see the proper change |
| 467 | """ |
| 468 | main.step( "Recovering ONOS instance" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 469 | [ main.ONOSbench.onosStart( main.Cluster.runningNodes[ i ].ipAddress ) for i in nodes ] |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 470 | for i in nodes: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 471 | isUp = main.ONOSbench.isup( main.Cluster.runningNodes[ i ].ipAddress ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 472 | utilities.assert_equals( expect=main.TRUE, actual=isUp, |
| 473 | onpass="ONOS service is ready", |
| 474 | onfail="ONOS service did not start properly" ) |
| 475 | for i in nodes: |
| 476 | main.step( "Checking if ONOS CLI is ready" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 477 | ctrl = main.Cluster.runningNodes[ i ] |
| 478 | ctrl.CLI.startCellCli() |
| 479 | cliResult = ctrl.CLI.startOnosCli( ctrl.ipAddress, |
| 480 | commandlineTimeout=60, |
| 481 | onosStartTimeout=100 ) |
| 482 | ctrl.active = True |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 483 | utilities.assert_equals( expect=main.TRUE, |
| 484 | actual=cliResult, |
| 485 | onpass="ONOS CLI is ready", |
| 486 | onfail="ONOS CLI is not ready" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 487 | |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 488 | main.step( "Checking ONOS nodes" ) |
| 489 | nodeResults = utilities.retry( Testcaselib.nodesCheck, |
| 490 | False, |
| 491 | args=[nodes], |
| 492 | attempts=5, |
| 493 | sleep=10 ) |
| 494 | utilities.assert_equals( expect=True, actual=nodeResults, |
| 495 | onpass="Nodes check successful", |
| 496 | onfail="Nodes check NOT successful" ) |
| 497 | |
| 498 | if not nodeResults: |
| 499 | for i in nodes: |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 500 | ctrl = main.Cluster.runningNodes[ i ] |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 501 | main.log.debug( "{} components not ACTIVE: \n{}".format( |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 502 | ctrl.name, |
| 503 | ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) ) |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 504 | main.log.error( "Failed to start ONOS, stopping test" ) |
| 505 | main.cleanup() |
| 506 | main.exit() |
| 507 | |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 508 | topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 509 | main.FALSE, |
| 510 | kwargs={ 'numoswitch': switches, |
| 511 | 'numolink': links, |
| 512 | 'numoctrl': expNodes }, |
| 513 | attempts=10, |
| 514 | sleep=12 ) |
| 515 | utilities.assert_equals( expect=main.TRUE, actual=topology, |
| 516 | onpass="ONOS Instance down successful", |
| 517 | onfail="Failed to turn off ONOS Instance" ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 518 | ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary, |
| 519 | main.FALSE, |
| 520 | attempts=10, |
| 521 | sleep=12 ) |
| 522 | if ready: |
| 523 | ready = main.TRUE |
| 524 | utilities.assert_equals( expect=main.TRUE, actual=ready, |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 525 | onpass="ONOS summary command succeded", |
| 526 | onfail="ONOS summary command failed" ) |
| 527 | if not ready: |
| 528 | main.log.error( "ONOS startup failed!" ) |
| 529 | main.cleanup( ) |
| 530 | main.exit( ) |
| 531 | |
| 532 | @staticmethod |
| 533 | def addHostCfg( main ): |
| 534 | """ |
| 535 | Adds Host Configuration to ONOS |
| 536 | Updates expected state of the network (pingChart) |
| 537 | """ |
| 538 | import json |
| 539 | hostCfg = { } |
| 540 | with open( main.dependencyPath + "/json/extra.json" ) as template: |
| 541 | hostCfg = json.load( template ) |
| 542 | main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ] |
| 543 | main.step( "Pushing new configuration" ) |
| 544 | mac, cfg = hostCfg[ 'hosts' ].popitem( ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 545 | main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ], |
| 546 | subjectClass="hosts", |
| 547 | subjectKey=urllib.quote( mac, |
| 548 | safe='' ), |
| 549 | configKey="basic" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 550 | main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ] |
| 551 | main.step( "Pushing new configuration" ) |
| 552 | mac, cfg = hostCfg[ 'hosts' ].popitem( ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 553 | main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ], |
| 554 | subjectClass="hosts", |
| 555 | subjectKey=urllib.quote( mac, |
| 556 | safe='' ), |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 557 | configKey="basic" ) |
| 558 | main.pingChart.update( { 'vlan1': { "expect": "True", |
| 559 | "hosts": [ "olt1", "vsg1" ] } } ) |
| 560 | main.pingChart[ 'vlan5' ][ 'expect' ] = 0 |
| 561 | main.pingChart[ 'vlan10' ][ 'expect' ] = 0 |
| 562 | ports = "[%s,%s]" % (5, 6) |
| 563 | cfg = '{"of:0000000000000001":[{"vlan":1,"ports":%s,"name":"OLT 1"}]}' % ports |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 564 | main.Cluster.active( 0 ).REST.setNetCfg( json.loads( cfg ), |
| 565 | subjectClass="apps", |
| 566 | subjectKey="org.onosproject.segmentrouting", |
| 567 | configKey="xconnect" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 568 | |
| 569 | @staticmethod |
| 570 | def delHostCfg( main ): |
| 571 | """ |
| 572 | Removest Host Configuration from ONOS |
| 573 | Updates expected state of the network (pingChart) |
| 574 | """ |
| 575 | import json |
| 576 | hostCfg = { } |
| 577 | with open( main.dependencyPath + "/json/extra.json" ) as template: |
| 578 | hostCfg = json.load( template ) |
| 579 | main.step( "Removing host configuration" ) |
| 580 | main.pingChart[ 'ip' ][ 'expect' ] = 0 |
| 581 | mac, cfg = hostCfg[ 'hosts' ].popitem( ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 582 | main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts", |
| 583 | subjectKey=urllib.quote( |
| 584 | mac, |
| 585 | safe='' ), |
| 586 | configKey="basic" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 587 | main.step( "Removing configuration" ) |
| 588 | main.pingChart[ 'ip' ][ 'expect' ] = 0 |
| 589 | mac, cfg = hostCfg[ 'hosts' ].popitem( ) |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 590 | main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts", |
| 591 | subjectKey=urllib.quote( |
| 592 | mac, |
| 593 | safe='' ), |
| 594 | configKey="basic" ) |
Jon Hall | 1efcb3f | 2016-08-23 13:42:15 -0700 | [diff] [blame] | 595 | main.step( "Removing vlan configuration" ) |
| 596 | main.pingChart[ 'vlan1' ][ 'expect' ] = 0 |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 597 | main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="apps", |
| 598 | subjectKey="org.onosproject.segmentrouting", |
| 599 | configKey="xconnect" ) |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 600 | @staticmethod |
| 601 | def nodesCheck( nodes ): |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 602 | results = True |
Devin Lim | 142b534 | 2017-07-20 15:22:39 -0700 | [diff] [blame] | 603 | nodesOutput = main.Cluster.command( "nodes", specificDriver=2 ) |
| 604 | ips = main.Cluster.getIps( activeOnly=True ) |
Pier | 3b58c65 | 2016-09-26 12:03:31 -0700 | [diff] [blame] | 605 | ips.sort() |
| 606 | for i in nodesOutput: |
| 607 | try: |
| 608 | current = json.loads( i ) |
| 609 | activeIps = [] |
| 610 | currentResult = False |
| 611 | for node in current: |
| 612 | if node['state'] == 'READY': |
| 613 | activeIps.append( node['ip'] ) |
| 614 | currentResult = True |
| 615 | for ip in ips: |
| 616 | if ip not in activeIps: |
| 617 | currentResult = False |
| 618 | break |
| 619 | except ( ValueError, TypeError ): |
| 620 | main.log.error( "Error parsing nodes output" ) |
| 621 | main.log.warn( repr( i ) ) |
| 622 | currentResult = False |
| 623 | results = results and currentResult |
| 624 | return results |