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