Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 1 | import os
|
| 2 | import imp
|
| 3 | import time
|
Flavio Castro | 49c218d | 2016-06-21 16:55:57 -0700 | [diff] [blame] | 4 | import json
|
Flavio Castro | ab163ca | 2016-07-07 14:05:00 -0700 | [diff] [blame] | 5 | import urllib
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 6 | from core import utilities
|
| 7 |
|
| 8 |
|
| 9 | class Testcaselib:
|
| 10 | @staticmethod
|
| 11 | def initTest( main ):
|
| 12 | """
|
| 13 | - Construct tests variables
|
| 14 | - GIT ( optional )
|
| 15 | - Checkout ONOS master branch
|
| 16 | - Pull latest ONOS code
|
| 17 | - Building ONOS ( optional )
|
| 18 | - Install ONOS package
|
| 19 | - Build ONOS package
|
| 20 | """
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 21 | main.step( "Constructing test variables" )
|
| 22 | # Test variables
|
| 23 | main.cellName = main.params[ 'ENV' ][ 'cellName' ]
|
| 24 | main.apps = main.params[ 'ENV' ][ 'cellApps' ]
|
| 25 | main.diff = main.params[ 'ENV' ][ 'diffApps' ]
|
| 26 | gitBranch = main.params[ 'GIT' ][ 'branch' ]
|
| 27 | main.path = os.path.dirname( main.testFile )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 28 | main.dependencyPath = main.path + "/../dependencies/"
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 29 | main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
|
| 30 | wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 31 | main.scale = (main.params[ 'SCALE' ][ 'size' ]).split( "," )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 32 | main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 33 | # main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 34 | main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 35 | main.cellData = { } # for creating cell file
|
| 36 | main.CLIs = [ ]
|
| 37 | main.ONOSip = [ ]
|
| 38 | main.RESTs = [ ]
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 39 |
|
| 40 | # Assigning ONOS cli handles to a list
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 41 | for i in range( 1, main.maxNodes + 1 ):
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 42 | main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
|
Flavio Castro | 49c218d | 2016-06-21 16:55:57 -0700 | [diff] [blame] | 43 | main.RESTs.append( getattr( main, 'ONOSrest' + str( i ) ) )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 44 | main.ONOSip.append( main.CLIs[ i - 1 ].ip_address )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 45 | # -- INIT SECTION, ONLY RUNS ONCE -- #
|
| 46 | main.startUp = imp.load_source( wrapperFile1,
|
| 47 | main.dependencyPath +
|
| 48 | wrapperFile1 +
|
| 49 | ".py" )
|
| 50 |
|
| 51 | copyResult1 = main.ONOSbench.scp( main.Mininet1,
|
| 52 | main.dependencyPath +
|
| 53 | main.topology,
|
| 54 | main.Mininet1.home,
|
| 55 | direction="to" )
|
| 56 | if main.CLIs:
|
| 57 | stepResult = main.TRUE
|
| 58 | else:
|
| 59 | main.log.error( "Did not properly created list of ONOS CLI handle" )
|
| 60 | stepResult = main.FALSE
|
| 61 |
|
| 62 | utilities.assert_equals( expect=main.TRUE,
|
| 63 | actual=stepResult,
|
| 64 | onpass="Successfully construct " +
|
| 65 | "test variables ",
|
| 66 | onfail="Failed to construct test variables" )
|
| 67 |
|
| 68 | @staticmethod
|
Flavio Castro | ab163ca | 2016-07-07 14:05:00 -0700 | [diff] [blame] | 69 | def installOnos( main, vlanCfg=True ):
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 70 | """
|
| 71 | - Set up cell
|
| 72 | - Create cell file
|
| 73 | - Set cell file
|
| 74 | - Verify cell file
|
| 75 | - Kill ONOS process
|
| 76 | - Uninstall ONOS cluster
|
| 77 | - Verify ONOS start up
|
| 78 | - Install ONOS cluster
|
| 79 | - Connect to cli
|
| 80 | """
|
| 81 | # main.scale[ 0 ] determines the current number of ONOS controller
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 82 | apps = main.apps
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 83 | if main.diff:
|
| 84 | apps = main.apps + "," + main.diff
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 85 | else:
|
| 86 | main.log.error( "App list is empty" )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 87 | print "NODE COUNT = ", main.numCtrls
|
| 88 | print main.ONOSip
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 89 | tempOnosIp = [ ]
|
Flavio Castro | ab163ca | 2016-07-07 14:05:00 -0700 | [diff] [blame] | 90 | main.dynamicHosts = [ 'in1', 'out1' ]
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 91 | for i in range( main.numCtrls ):
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 92 | tempOnosIp.append( main.ONOSip[ i ] )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 93 | onosUser = main.params[ 'ENV' ][ 'cellUser' ]
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 94 | main.step( "Create and Apply cell file" )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 95 | main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
|
| 96 | "temp",
|
| 97 | main.Mininet1.ip_address,
|
| 98 | apps,
|
| 99 | tempOnosIp,
|
| 100 | onosUser )
|
| 101 | cellResult = main.ONOSbench.setCell( "temp" )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 102 | verifyResult = main.ONOSbench.verifyCell( )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 103 | stepResult = cellResult and verifyResult
|
| 104 | utilities.assert_equals( expect=main.TRUE,
|
| 105 | actual=stepResult,
|
| 106 | onpass="Successfully applied cell to " + \
|
| 107 | "environment",
|
| 108 | onfail="Failed to apply cell to environment " )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 109 | # kill off all onos processes
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 110 | main.log.info( "Safety check, killing all ONOS processes" +
|
| 111 | " before initiating environment setup" )
|
| 112 | for i in range( main.maxNodes ):
|
| 113 | main.ONOSbench.onosDie( main.ONOSip[ i ] )
|
| 114 | main.step( "Create and Install ONOS package" )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 115 | packageResult = main.ONOSbench.onosPackage( )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 116 |
|
| 117 | onosInstallResult = main.TRUE
|
| 118 | for i in range( main.numCtrls ):
|
| 119 | onosInstallResult = onosInstallResult and \
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 120 | main.ONOSbench.onosInstall(
|
Flavio Castro | 519072e | 2016-06-23 13:30:48 -0700 | [diff] [blame] | 121 | node=main.ONOSip[ i ] )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 122 | stepResult = onosInstallResult
|
| 123 | utilities.assert_equals( expect=main.TRUE,
|
| 124 | actual=stepResult,
|
| 125 | onpass="Successfully installed ONOS package",
|
| 126 | onfail="Failed to install ONOS package" )
|
| 127 | main.step( "Starting ONOS service" )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 128 | stopResult, startResult, onosIsUp = main.TRUE, main.TRUE, main.TRUE,
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 129 | for i in range( main.numCtrls ):
|
| 130 | onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
|
| 131 | if onosIsUp == main.TRUE:
|
| 132 | main.log.report( "ONOS instance is up and ready" )
|
| 133 | else:
|
| 134 | main.log.report( "ONOS instance may not be up, stop and " +
|
| 135 | "start ONOS again " )
|
| 136 | for i in range( main.numCtrls ):
|
| 137 | stopResult = stopResult and \
|
| 138 | main.ONOSbench.onosStop( main.ONOSip[ i ] )
|
| 139 | for i in range( main.numCtrls ):
|
| 140 | startResult = startResult and \
|
| 141 | main.ONOSbench.onosStart( main.ONOSip[ i ] )
|
| 142 | stepResult = onosIsUp and stopResult and startResult
|
| 143 |
|
| 144 | utilities.assert_equals( expect=main.TRUE,
|
| 145 | actual=stepResult,
|
| 146 | onpass="ONOS service is ready",
|
| 147 | onfail="ONOS service did not start properly" )
|
| 148 | main.step( "Checking if ONOS CLI is ready" )
|
| 149 | for i in range( main.numCtrls ):
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 150 | main.CLIs[ i ].startCellCli( )
|
| 151 | cliResult = main.CLIs[ i ].startOnosCli( main.ONOSip[ i ],
|
| 152 | commandlineTimeout=60,
|
| 153 | onosStartTimeout=100 )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 154 | utilities.assert_equals( expect=main.TRUE,
|
| 155 | actual=cliResult,
|
| 156 | onpass="ONOS CLI is ready",
|
| 157 | onfail="ONOS CLI is not ready" )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 158 | main.active = 0
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 159 | for i in range( 10 ):
|
| 160 | ready = True
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 161 | output = main.CLIs[ main.active ].summary( )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 162 | if not output:
|
| 163 | ready = False
|
| 164 | if ready:
|
| 165 | break
|
| 166 | time.sleep( 10 )
|
| 167 | utilities.assert_equals( expect=True, actual=ready,
|
| 168 | onpass="ONOS summary command succeded",
|
| 169 | onfail="ONOS summary command failed" )
|
| 170 |
|
Flavio Castro | ab163ca | 2016-07-07 14:05:00 -0700 | [diff] [blame] | 171 | with open( "%s/json/%s.json" % (
|
| 172 | main.dependencyPath, main.cfgName) ) as cfg:
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 173 | main.RESTs[ main.active ].setNetCfg( json.load( cfg ) )
|
Flavio Castro | ab163ca | 2016-07-07 14:05:00 -0700 | [diff] [blame] | 174 | with open( "%s/json/%s.chart" % (
|
| 175 | main.dependencyPath, main.cfgName) ) as chart:
|
| 176 | main.pingChart = json.load( chart )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 177 | if not ready:
|
| 178 | main.log.error( "ONOS startup failed!" )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 179 | main.cleanup( )
|
| 180 | main.exit( )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 181 |
|
| 182 | for i in range( main.numCtrls ):
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 183 | main.CLIs[ i ].logSet( "DEBUG", "org.onosproject.segmentrouting" )
|
| 184 | main.CLIs[ i ].logSet( "DEBUG", "org.onosproject.driver.pipeline" )
|
| 185 | main.CLIs[ i ].logSet( "DEBUG", "org.onosproject.store.group.impl" )
|
| 186 | main.CLIs[ i ].logSet( "DEBUG",
|
| 187 | "org.onosproject.net.flowobjective.impl" )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 188 |
|
| 189 | @staticmethod
|
| 190 | def startMininet( main, topology, args="" ):
|
| 191 | main.step( "Starting Mininet Topology" )
|
| 192 | arg = "--onos %d %s" % (main.numCtrls, args)
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 193 | main.topology = topology
|
| 194 | topoResult = main.Mininet1.startNet(
|
Flavio Castro | 519072e | 2016-06-23 13:30:48 -0700 | [diff] [blame] | 195 | topoFile=main.dependencyPath + main.topology, args=arg )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 196 | stepResult = topoResult
|
| 197 | utilities.assert_equals( expect=main.TRUE,
|
| 198 | actual=stepResult,
|
| 199 | onpass="Successfully loaded topology",
|
| 200 | onfail="Failed to load topology" )
|
| 201 | # Exit if topology did not load properly
|
| 202 | if not topoResult:
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 203 | main.cleanup( )
|
| 204 | main.exit( )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 205 |
|
| 206 | @staticmethod
|
Flavio Castro | ab163ca | 2016-07-07 14:05:00 -0700 | [diff] [blame] | 207 | def checkFlows( main, minFlowCount, dumpflows=True ):
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 208 | main.step(
|
Flavio Castro | 519072e | 2016-06-23 13:30:48 -0700 | [diff] [blame] | 209 | " Check whether the flow count is bigger than %s" % minFlowCount )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 210 | count = utilities.retry( main.CLIs[ main.active ].checkFlowCount,
|
Flavio Castro | 02b4363 | 2016-06-20 17:07:27 -0700 | [diff] [blame] | 211 | main.FALSE,
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 212 | kwargs={ 'min': minFlowCount },
|
Flavio Castro | 02b4363 | 2016-06-20 17:07:27 -0700 | [diff] [blame] | 213 | attempts=10,
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 214 | sleep=10 )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 215 | utilities.assertEquals( \
|
| 216 | expect=True,
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 217 | actual=(count > 0),
|
| 218 | onpass="Flow count looks correct: " + str( count ),
|
| 219 | onfail="Flow count looks wrong: " + str( count ) )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 220 |
|
| 221 | main.step( "Check whether all flow status are ADDED" )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 222 | flowCheck = utilities.retry( main.CLIs[ main.active ].checkFlowsState,
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 223 | main.FALSE,
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 224 | kwargs={ 'isPENDING': False },
|
Flavio Castro | ab163ca | 2016-07-07 14:05:00 -0700 | [diff] [blame] | 225 | attempts=2,
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 226 | sleep=10 )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 227 | utilities.assertEquals( \
|
| 228 | expect=main.TRUE,
|
| 229 | actual=flowCheck,
|
| 230 | onpass="Flow status is correct!",
|
| 231 | onfail="Flow status is wrong!" )
|
Flavio Castro | ab163ca | 2016-07-07 14:05:00 -0700 | [diff] [blame] | 232 | if dumpflows:
|
| 233 | main.ONOSbench.dumpFlows( main.ONOSip[ main.active ],
|
| 234 | main.logdir,
|
| 235 | "flowsBefore" + main.cfgName )
|
| 236 | main.ONOSbench.dumpGroups( main.ONOSip[ main.active ],
|
| 237 | main.logdir,
|
| 238 | "groupsBefore" + main.cfgName )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 239 |
|
| 240 | @staticmethod
|
Flavio Castro | 519072e | 2016-06-23 13:30:48 -0700 | [diff] [blame] | 241 | def pingAll( main, tag="", dumpflows=True ):
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 242 | main.log.report( "Check full connectivity" )
|
Flavio Castro | ab163ca | 2016-07-07 14:05:00 -0700 | [diff] [blame] | 243 | print main.pingChart
|
| 244 | for entry in main.pingChart.itervalues( ):
|
| 245 | print entry
|
| 246 | hosts, expect = entry[ 'hosts' ], entry[ 'expect' ]
|
| 247 | expect = main.TRUE if expect else main.FALSE
|
| 248 | main.step( "Connectivity for %s %s" % (str( hosts ), tag) )
|
| 249 | pa = main.Mininet1.pingallHosts( hosts )
|
| 250 | utilities.assert_equals( expect=expect, actual=pa,
|
| 251 | onpass="IP connectivity successfully tested",
|
| 252 | onfail="IP connectivity failed" )
|
Flavio Castro | 519072e | 2016-06-23 13:30:48 -0700 | [diff] [blame] | 253 | if dumpflows:
|
| 254 | main.ONOSbench.dumpFlows( main.ONOSip[ main.active ],
|
| 255 | main.logdir, "flowsOn" + tag )
|
| 256 | main.ONOSbench.dumpGroups( main.ONOSip[ main.active ],
|
| 257 | main.logdir, "groupsOn" + tag )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 258 |
|
| 259 | @staticmethod
|
| 260 | def killLink( main, end1, end2, switches, links ):
|
| 261 | """
|
| 262 | end1,end2: identify the switches, ex.: 'leaf1', 'spine1'
|
| 263 | switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
|
| 264 | Kill a link and verify ONOS can see the proper link change
|
| 265 | """
|
| 266 | main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 267 | main.step( "Kill link between %s and %s" % (end1, end2) )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 268 | LinkDown = main.Mininet1.link( END1=end1, END2=end2, OPTION="down" )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 269 | main.log.info(
|
Flavio Castro | 519072e | 2016-06-23 13:30:48 -0700 | [diff] [blame] | 270 | "Waiting %s seconds for link down to be discovered" % main.linkSleep )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 271 | time.sleep( main.linkSleep )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 272 | topology = utilities.retry( main.CLIs[ main.active ].checkStatus,
|
| 273 | main.FALSE,
|
| 274 | kwargs={ 'numoswitch': switches,
|
| 275 | 'numolink': links },
|
| 276 | attempts=10,
|
| 277 | sleep=main.linkSleep )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 278 | result = topology & LinkDown
|
| 279 | utilities.assert_equals( expect=main.TRUE, actual=result,
|
| 280 | onpass="Link down successful",
|
| 281 | onfail="Failed to turn off link?" )
|
| 282 |
|
| 283 | @staticmethod
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 284 | def restoreLink( main, end1, end2, dpid1, dpid2, port1, port2, switches,
|
| 285 | links ):
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 286 | """
|
| 287 | Params:
|
| 288 | end1,end2: identify the end switches, ex.: 'leaf1', 'spine1'
|
| 289 | dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002'
|
Flavio Castro | 02b4363 | 2016-06-20 17:07:27 -0700 | [diff] [blame] | 290 | port1, port2: respective port of the end switches that connects to the link, ex.:'1'
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 291 | switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
|
| 292 | Kill a link and verify ONOS can see the proper link change
|
| 293 | """
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 294 | main.step( "Restore link between %s and %s" % (end1, end2) )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 295 | result = False
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 296 | count = 0
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 297 | while True:
|
Flavio Castro | d1f3689 | 2016-07-06 11:49:11 -0700 | [diff] [blame] | 298 | count += 1
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 299 | main.Mininet1.link( END1=end1, END2=end2, OPTION="up" )
|
| 300 | main.Mininet1.link( END2=end1, END1=end2, OPTION="up" )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 301 | main.log.info(
|
Flavio Castro | 519072e | 2016-06-23 13:30:48 -0700 | [diff] [blame] | 302 | "Waiting %s seconds for link up to be discovered" % main.linkSleep )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 303 | time.sleep( main.linkSleep )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 304 | main.CLIs[ main.active ].portstate( dpid=dpid1, port=port1 )
|
| 305 | main.CLIs[ main.active ].portstate( dpid=dpid2, port=port2 )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 306 | time.sleep( main.linkSleep )
|
| 307 |
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 308 | result = main.CLIs[ main.active ].checkStatus( numoswitch=switches,
|
| 309 | numolink=links )
|
| 310 | if count > 5 or result:
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 311 | break
|
| 312 | utilities.assert_equals( expect=main.TRUE, actual=result,
|
| 313 | onpass="Link up successful",
|
| 314 | onfail="Failed to bring link up" )
|
| 315 |
|
| 316 | @staticmethod
|
| 317 | def killSwitch( main, switch, switches, links ):
|
| 318 | """
|
| 319 | Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6'
|
Flavio Castro | 02b4363 | 2016-06-20 17:07:27 -0700 | [diff] [blame] | 320 | Completely kill a switch and verify ONOS can see the proper change
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 321 | """
|
| 322 | main.switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
|
| 323 | main.step( "Kill " + switch )
|
| 324 | main.log.info( "Stopping" + switch )
|
| 325 | main.Mininet1.switch( SW=switch, OPTION="stop" )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 326 | # todo make this repeatable
|
| 327 | main.log.info( "Waiting %s seconds for switch down to be discovered" % (
|
Flavio Castro | 519072e | 2016-06-23 13:30:48 -0700 | [diff] [blame] | 328 | main.switchSleep) )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 329 | time.sleep( main.switchSleep )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 330 | topology = utilities.retry( main.CLIs[ main.active ].checkStatus,
|
| 331 | main.FALSE,
|
| 332 | kwargs={ 'numoswitch': switches,
|
| 333 | 'numolink': links },
|
| 334 | attempts=10,
|
| 335 | sleep=main.switchSleep )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 336 | utilities.assert_equals( expect=main.TRUE, actual=topology,
|
| 337 | onpass="Kill switch successful",
|
| 338 | onfail="Failed to kill switch?" )
|
| 339 |
|
| 340 | @staticmethod
|
| 341 | def recoverSwitch( main, switch, switches, links ):
|
| 342 | """
|
| 343 | Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6'
|
| 344 | Recover a switch and verify ONOS can see the proper change
|
| 345 | """
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 346 | # todo make this repeatable
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 347 | main.step( "Recovering " + switch )
|
| 348 | main.log.info( "Starting" + switch )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 349 | main.Mininet1.switch( SW=switch, OPTION="start" )
|
| 350 | main.log.info( "Waiting %s seconds for switch up to be discovered" % (
|
Flavio Castro | 519072e | 2016-06-23 13:30:48 -0700 | [diff] [blame] | 351 | main.switchSleep) )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 352 | time.sleep( main.switchSleep )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 353 | topology = utilities.retry( main.CLIs[ main.active ].checkStatus,
|
| 354 | main.FALSE,
|
| 355 | kwargs={ 'numoswitch': switches,
|
| 356 | 'numolink': links },
|
| 357 | attempts=10,
|
| 358 | sleep=main.switchSleep )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 359 | utilities.assert_equals( expect=main.TRUE, actual=topology,
|
| 360 | onpass="Switch recovery successful",
|
| 361 | onfail="Failed to recover switch?" )
|
| 362 |
|
| 363 | @staticmethod
|
| 364 | def cleanup( main ):
|
| 365 | """
|
| 366 | Stop Onos-cluster.
|
| 367 | Stops Mininet
|
| 368 | Copies ONOS log
|
| 369 | """
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 370 | main.Mininet1.stopNet( )
|
Flavio Castro | 49c218d | 2016-06-21 16:55:57 -0700 | [diff] [blame] | 371 | main.ONOSbench.scp( main.ONOScli1, "/opt/onos/log/karaf.log",
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 372 | "/tmp/karaf.log", direction="from" )
|
Flavio Castro | 49c218d | 2016-06-21 16:55:57 -0700 | [diff] [blame] | 373 | main.ONOSbench.cpLogsToDir( "/tmp/karaf.log", main.logdir,
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 374 | copyFileName="karaf.log." + main.cfgName )
|
Flavio Castro | 49c218d | 2016-06-21 16:55:57 -0700 | [diff] [blame] | 375 | for i in range( main.numCtrls ):
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 376 | main.ONOSbench.onosStop( main.ONOSip[ i ] )
|
Flavio Castro | 519072e | 2016-06-23 13:30:48 -0700 | [diff] [blame] | 377 |
|
| 378 | @staticmethod
|
| 379 | def killOnos( main, nodes, switches, links, expNodes ):
|
| 380 | """
|
| 381 | Params: nodes, integer array with position of the ONOS nodes in the CLIs array
|
| 382 | switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6'
|
| 383 | Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change
|
| 384 | """
|
| 385 | main.step( "Killing ONOS instance" )
|
| 386 | for i in nodes:
|
| 387 | killResult = main.ONOSbench.onosDie( main.CLIs[ i ].ip_address )
|
| 388 | utilities.assert_equals( expect=main.TRUE, actual=killResult,
|
| 389 | onpass="ONOS instance Killed",
|
| 390 | onfail="Error killing ONOS instance" )
|
| 391 | if i == main.active:
|
| 392 | main.active = (i + 1) % main.numCtrls
|
| 393 | time.sleep( 12 )
|
| 394 | if len( nodes ) < main.numCtrls:
|
| 395 | topology = utilities.retry( main.CLIs[ main.active ].checkStatus,
|
| 396 | main.FALSE,
|
| 397 | kwargs={ 'numoswitch': switches,
|
| 398 | 'numolink': links,
|
| 399 | 'numoctrl': expNodes },
|
| 400 | attempts=10,
|
| 401 | sleep=12 )
|
| 402 | utilities.assert_equals( expect=main.TRUE, actual=topology,
|
| 403 | onpass="ONOS Instance down successful",
|
| 404 | onfail="Failed to turn off ONOS Instance" )
|
| 405 | else:
|
| 406 | main.active = -1
|
| 407 |
|
| 408 | @staticmethod
|
| 409 | def recoverOnos( main, nodes, switches, links, expNodes ):
|
| 410 | """
|
| 411 | Params: nodes, integer array with position of the ONOS nodes in the CLIs array
|
| 412 | switches, links, nodes: number of expected switches, links and nodes after recoverOnos, ex.: '4', '6'
|
| 413 | Recover an ONOS instance and verify the ONOS cluster can see the proper change
|
| 414 | """
|
| 415 | main.step( "Recovering ONOS instance" )
|
| 416 | [ main.ONOSbench.onosStart( main.CLIs[ i ].ip_address ) for i in nodes ]
|
| 417 | for i in nodes:
|
| 418 | isUp = main.ONOSbench.isup( main.ONOSip[ i ] )
|
| 419 | utilities.assert_equals( expect=main.TRUE, actual=isUp,
|
| 420 | onpass="ONOS service is ready",
|
| 421 | onfail="ONOS service did not start properly" )
|
| 422 | for i in nodes:
|
| 423 | main.step( "Checking if ONOS CLI is ready" )
|
| 424 | main.CLIs[ i ].startCellCli( )
|
| 425 | cliResult = main.CLIs[ i ].startOnosCli( main.ONOSip[ i ],
|
| 426 | commandlineTimeout=60,
|
| 427 | onosStartTimeout=100 )
|
| 428 | utilities.assert_equals( expect=main.TRUE,
|
| 429 | actual=cliResult,
|
| 430 | onpass="ONOS CLI is ready",
|
| 431 | onfail="ONOS CLI is not ready" )
|
| 432 | main.active = i if main.active == -1 else main.active
|
| 433 |
|
| 434 | topology = utilities.retry( main.CLIs[ main.active ].checkStatus,
|
| 435 | main.FALSE,
|
| 436 | kwargs={ 'numoswitch': switches,
|
| 437 | 'numolink': links,
|
| 438 | 'numoctrl': expNodes },
|
| 439 | attempts=10,
|
| 440 | sleep=12 )
|
| 441 | utilities.assert_equals( expect=main.TRUE, actual=topology,
|
| 442 | onpass="ONOS Instance down successful",
|
| 443 | onfail="Failed to turn off ONOS Instance" )
|
Flavio Castro | 519072e | 2016-06-23 13:30:48 -0700 | [diff] [blame] | 444 | for i in range( 10 ):
|
| 445 | ready = True
|
| 446 | output = main.CLIs[ main.active ].summary( )
|
| 447 | if not output:
|
| 448 | ready = False
|
| 449 | if ready:
|
| 450 | break
|
| 451 | time.sleep( 10 )
|
| 452 | utilities.assert_equals( expect=True, actual=ready,
|
| 453 | onpass="ONOS summary command succeded",
|
| 454 | onfail="ONOS summary command failed" )
|
| 455 | if not ready:
|
| 456 | main.log.error( "ONOS startup failed!" )
|
| 457 | main.cleanup( )
|
| 458 | main.exit( )
|
Flavio Castro | ab163ca | 2016-07-07 14:05:00 -0700 | [diff] [blame] | 459 |
|
| 460 | @staticmethod
|
| 461 | def addHostCfg( main ):
|
| 462 | """
|
| 463 | Adds Host Configuration to ONOS
|
| 464 | Updates expected state of the network (pingChart)
|
| 465 | """
|
| 466 | import json
|
| 467 | hostCfg = { }
|
| 468 | with open( main.dependencyPath + "/json/extra.json" ) as template:
|
| 469 | hostCfg = json.load( template )
|
| 470 | main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ]
|
| 471 | main.step( "Pushing new configuration" )
|
| 472 | mac, cfg = hostCfg[ 'hosts' ].popitem( )
|
| 473 | main.RESTs[ main.active ].setNetCfg( cfg[ 'basic' ],
|
| 474 | subjectClass="hosts",
|
| 475 | subjectKey=urllib.quote( mac,
|
| 476 | safe='' ),
|
| 477 | configKey="basic" )
|
| 478 | main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ]
|
| 479 | main.step( "Pushing new configuration" )
|
| 480 | mac, cfg = hostCfg[ 'hosts' ].popitem( )
|
| 481 | main.RESTs[ main.active ].setNetCfg( cfg[ 'basic' ],
|
| 482 | subjectClass="hosts",
|
| 483 | subjectKey=urllib.quote( mac,
|
| 484 | safe='' ),
|
| 485 | configKey="basic" )
|
| 486 | main.pingChart.update( { 'vlan1': { "expect": "True",
|
| 487 | "hosts": [ "olt1", "vsg1" ] } } )
|
| 488 | main.pingChart[ 'vlan5' ][ 'expect' ] = 0
|
| 489 | main.pingChart[ 'vlan10' ][ 'expect' ] = 0
|
| 490 | ports = "[%s,%s]" % (5, 6)
|
| 491 | cfg = '{"of:0000000000000001":[{"vlan":1,"ports":%s,"name":"OLT 1"}]}' % ports
|
| 492 | main.RESTs[ main.active ].setNetCfg( json.loads( cfg ),
|
| 493 | subjectClass="apps",
|
| 494 | subjectKey="org.onosproject.segmentrouting",
|
| 495 | configKey="xconnect" )
|
| 496 |
|
| 497 | @staticmethod
|
| 498 | def delHostCfg( main ):
|
| 499 | """
|
| 500 | Removest Host Configuration from ONOS
|
| 501 | Updates expected state of the network (pingChart)
|
| 502 | """
|
| 503 | import json
|
| 504 | hostCfg = { }
|
| 505 | with open( main.dependencyPath + "/json/extra.json" ) as template:
|
| 506 | hostCfg = json.load( template )
|
| 507 | main.step( "Removing host configuration" )
|
| 508 | main.pingChart[ 'ip' ][ 'expect' ] = 0
|
| 509 | mac, cfg = hostCfg[ 'hosts' ].popitem( )
|
| 510 | main.RESTs[ main.active ].removeNetCfg( subjectClass="hosts",
|
| 511 | subjectKey=urllib.quote(
|
| 512 | mac,
|
| 513 | safe='' ),
|
| 514 | configKey="basic" )
|
| 515 | main.step( "Removing configuration" )
|
| 516 | main.pingChart[ 'ip' ][ 'expect' ] = 0
|
| 517 | mac, cfg = hostCfg[ 'hosts' ].popitem( )
|
| 518 | main.RESTs[ main.active ].removeNetCfg( subjectClass="hosts",
|
| 519 | subjectKey=urllib.quote(
|
| 520 | mac,
|
| 521 | safe='' ),
|
| 522 | configKey="basic" )
|
| 523 | main.step( "Removing vlan configuration" )
|
| 524 | main.pingChart[ 'vlan1' ][ 'expect' ] = 0
|
| 525 | main.RESTs[ main.active ].removeNetCfg( subjectClass="apps",
|
| 526 | subjectKey="org.onosproject.segmentrouting",
|
| 527 | configKey="xconnect" )
|