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 | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 5 |
|
| 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
|
| 69 | def installOnos( main ):
|
| 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 | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 90 | for i in range( main.numCtrls ):
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 91 | tempOnosIp.append( main.ONOSip[ i ] )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 92 | onosUser = main.params[ 'ENV' ][ 'cellUser' ]
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 93 | main.step( "Create and Apply cell file" )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 94 | main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
|
| 95 | "temp",
|
| 96 | main.Mininet1.ip_address,
|
| 97 | apps,
|
| 98 | tempOnosIp,
|
| 99 | onosUser )
|
| 100 | cellResult = main.ONOSbench.setCell( "temp" )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 101 | verifyResult = main.ONOSbench.verifyCell( )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 102 | stepResult = cellResult and verifyResult
|
| 103 | utilities.assert_equals( expect=main.TRUE,
|
| 104 | actual=stepResult,
|
| 105 | onpass="Successfully applied cell to " + \
|
| 106 | "environment",
|
| 107 | onfail="Failed to apply cell to environment " )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 108 | # kill off all onos processes
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 109 | main.log.info( "Safety check, killing all ONOS processes" +
|
| 110 | " before initiating environment setup" )
|
| 111 | for i in range( main.maxNodes ):
|
| 112 | main.ONOSbench.onosDie( main.ONOSip[ i ] )
|
| 113 | main.step( "Create and Install ONOS package" )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 114 | packageResult = main.ONOSbench.onosPackage( )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 115 |
|
| 116 | onosInstallResult = main.TRUE
|
| 117 | for i in range( main.numCtrls ):
|
| 118 | onosInstallResult = onosInstallResult and \
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 119 | main.ONOSbench.onosInstall(
|
Flavio Castro | 519072e | 2016-06-23 13:30:48 -0700 | [diff] [blame] | 120 | node=main.ONOSip[ i ] )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 121 | stepResult = onosInstallResult
|
| 122 | utilities.assert_equals( expect=main.TRUE,
|
| 123 | actual=stepResult,
|
| 124 | onpass="Successfully installed ONOS package",
|
| 125 | onfail="Failed to install ONOS package" )
|
| 126 | main.step( "Starting ONOS service" )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 127 | stopResult, startResult, onosIsUp = main.TRUE, main.TRUE, main.TRUE,
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 128 | for i in range( main.numCtrls ):
|
| 129 | onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
|
| 130 | if onosIsUp == main.TRUE:
|
| 131 | main.log.report( "ONOS instance is up and ready" )
|
| 132 | else:
|
| 133 | main.log.report( "ONOS instance may not be up, stop and " +
|
| 134 | "start ONOS again " )
|
| 135 | for i in range( main.numCtrls ):
|
| 136 | stopResult = stopResult and \
|
| 137 | main.ONOSbench.onosStop( main.ONOSip[ i ] )
|
| 138 | for i in range( main.numCtrls ):
|
| 139 | startResult = startResult and \
|
| 140 | main.ONOSbench.onosStart( main.ONOSip[ i ] )
|
| 141 | stepResult = onosIsUp and stopResult and startResult
|
| 142 |
|
| 143 | utilities.assert_equals( expect=main.TRUE,
|
| 144 | actual=stepResult,
|
| 145 | onpass="ONOS service is ready",
|
| 146 | onfail="ONOS service did not start properly" )
|
| 147 | main.step( "Checking if ONOS CLI is ready" )
|
| 148 | for i in range( main.numCtrls ):
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 149 | main.CLIs[ i ].startCellCli( )
|
| 150 | cliResult = main.CLIs[ i ].startOnosCli( main.ONOSip[ i ],
|
| 151 | commandlineTimeout=60,
|
| 152 | onosStartTimeout=100 )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 153 | utilities.assert_equals( expect=main.TRUE,
|
| 154 | actual=cliResult,
|
| 155 | onpass="ONOS CLI is ready",
|
| 156 | onfail="ONOS CLI is not ready" )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 157 | main.active = 0
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 158 | for i in range( 10 ):
|
| 159 | ready = True
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 160 | output = main.CLIs[ main.active ].summary( )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 161 | if not output:
|
| 162 | ready = False
|
| 163 | if ready:
|
| 164 | break
|
| 165 | time.sleep( 10 )
|
| 166 | utilities.assert_equals( expect=True, actual=ready,
|
| 167 | onpass="ONOS summary command succeded",
|
| 168 | onfail="ONOS summary command failed" )
|
| 169 |
|
Flavio Castro | 49c218d | 2016-06-21 16:55:57 -0700 | [diff] [blame] | 170 | with open( main.dependencyPath + "/" + main.cfgName + ".json" ) as cfg:
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 171 | main.RESTs[ main.active ].setNetCfg( json.load( cfg ) )
|
Flavio Castro | 49c218d | 2016-06-21 16:55:57 -0700 | [diff] [blame] | 172 |
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 173 | if not ready:
|
| 174 | main.log.error( "ONOS startup failed!" )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 175 | main.cleanup( )
|
| 176 | main.exit( )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 177 |
|
| 178 | for i in range( main.numCtrls ):
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 179 | main.CLIs[ i ].logSet( "DEBUG", "org.onosproject.segmentrouting" )
|
| 180 | main.CLIs[ i ].logSet( "DEBUG", "org.onosproject.driver.pipeline" )
|
| 181 | main.CLIs[ i ].logSet( "DEBUG", "org.onosproject.store.group.impl" )
|
| 182 | main.CLIs[ i ].logSet( "DEBUG",
|
| 183 | "org.onosproject.net.flowobjective.impl" )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 184 |
|
| 185 | @staticmethod
|
| 186 | def startMininet( main, topology, args="" ):
|
| 187 | main.step( "Starting Mininet Topology" )
|
| 188 | arg = "--onos %d %s" % (main.numCtrls, args)
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 189 | main.topology = topology
|
| 190 | topoResult = main.Mininet1.startNet(
|
Flavio Castro | 519072e | 2016-06-23 13:30:48 -0700 | [diff] [blame] | 191 | topoFile=main.dependencyPath + main.topology, args=arg )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 192 | stepResult = topoResult
|
| 193 | utilities.assert_equals( expect=main.TRUE,
|
| 194 | actual=stepResult,
|
| 195 | onpass="Successfully loaded topology",
|
| 196 | onfail="Failed to load topology" )
|
| 197 | # Exit if topology did not load properly
|
| 198 | if not topoResult:
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 199 | main.cleanup( )
|
| 200 | main.exit( )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 201 |
|
| 202 | @staticmethod
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 203 | def checkFlows( main, minFlowCount ):
|
| 204 | main.step(
|
Flavio Castro | 519072e | 2016-06-23 13:30:48 -0700 | [diff] [blame] | 205 | " Check whether the flow count is bigger than %s" % minFlowCount )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 206 | count = utilities.retry( main.CLIs[ main.active ].checkFlowCount,
|
Flavio Castro | 02b4363 | 2016-06-20 17:07:27 -0700 | [diff] [blame] | 207 | main.FALSE,
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 208 | kwargs={ 'min': minFlowCount },
|
Flavio Castro | 02b4363 | 2016-06-20 17:07:27 -0700 | [diff] [blame] | 209 | attempts=10,
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 210 | sleep=10 )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 211 | utilities.assertEquals( \
|
| 212 | expect=True,
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 213 | actual=(count > 0),
|
| 214 | onpass="Flow count looks correct: " + str( count ),
|
| 215 | onfail="Flow count looks wrong: " + str( count ) )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 216 |
|
| 217 | main.step( "Check whether all flow status are ADDED" )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 218 | flowCheck = utilities.retry( main.CLIs[ main.active ].checkFlowsState,
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 219 | main.FALSE,
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 220 | kwargs={ 'isPENDING': False },
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 221 | attempts=10,
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 222 | sleep=10 )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 223 | utilities.assertEquals( \
|
| 224 | expect=main.TRUE,
|
| 225 | actual=flowCheck,
|
| 226 | onpass="Flow status is correct!",
|
| 227 | onfail="Flow status is wrong!" )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 228 | main.ONOSbench.dumpFlows( main.ONOSip[ main.active ],
|
| 229 | main.logdir, "flowsBefore" + main.cfgName )
|
| 230 | main.ONOSbench.dumpGroups( main.ONOSip[ 0 ],
|
| 231 | main.logdir, "groupsBefore" + main.cfgName )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 232 |
|
| 233 | @staticmethod
|
Flavio Castro | 519072e | 2016-06-23 13:30:48 -0700 | [diff] [blame] | 234 | def pingAll( main, tag="", dumpflows=True ):
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 235 | main.log.report( "Check full connectivity" )
|
Flavio Castro | e168f7f | 2016-06-24 15:53:12 -0700 | [diff] [blame] | 236 | main.step("Check IP connectivity %s" %tag)
|
| 237 | hosts = main.Mininet1.getHosts().keys()
|
| 238 | vlan10 = [ '%s10' % s for s in [ 'olt', 'vsg' ] ]
|
| 239 | vlan5 = [ '%s5' % s for s in [ 'olt', 'vsg' ] ]
|
| 240 | IPHosts = [ host for host in hosts if host not in ( vlan10 + vlan5 ) ]
|
| 241 | pa = main.Mininet1.pingallHosts(IPHosts)
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 242 | utilities.assert_equals( expect=main.TRUE, actual=pa,
|
Flavio Castro | e168f7f | 2016-06-24 15:53:12 -0700 | [diff] [blame] | 243 | onpass="IP connectivity successfully tested",
|
| 244 | onfail="IP connectivity failed" )
|
| 245 | main.step("Check VLAN connectivity %s" %tag)
|
| 246 | p1 = main.Mininet1.pingallHosts(vlan5)
|
| 247 | p2 = main.Mininet1.pingallHosts(vlan10)
|
| 248 | utilities.assert_equals( expect=main.TRUE, actual=p1&p2,
|
| 249 | onpass="Vlan connectivity successfully tested",
|
| 250 | onfail="Vlan connectivity failed" )
|
Flavio Castro | 519072e | 2016-06-23 13:30:48 -0700 | [diff] [blame] | 251 | if dumpflows:
|
| 252 | main.ONOSbench.dumpFlows( main.ONOSip[ main.active ],
|
| 253 | main.logdir, "flowsOn" + tag )
|
| 254 | main.ONOSbench.dumpGroups( main.ONOSip[ main.active ],
|
| 255 | main.logdir, "groupsOn" + tag )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 256 |
|
| 257 | @staticmethod
|
| 258 | def killLink( main, end1, end2, switches, links ):
|
| 259 | """
|
| 260 | end1,end2: identify the switches, ex.: 'leaf1', 'spine1'
|
| 261 | switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
|
| 262 | Kill a link and verify ONOS can see the proper link change
|
| 263 | """
|
| 264 | main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 265 | main.step( "Kill link between %s and %s" % (end1, end2) )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 266 | LinkDown = main.Mininet1.link( END1=end1, END2=end2, OPTION="down" )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 267 | main.log.info(
|
Flavio Castro | 519072e | 2016-06-23 13:30:48 -0700 | [diff] [blame] | 268 | "Waiting %s seconds for link down to be discovered" % main.linkSleep )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 269 | time.sleep( main.linkSleep )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 270 | topology = utilities.retry( main.CLIs[ main.active ].checkStatus,
|
| 271 | main.FALSE,
|
| 272 | kwargs={ 'numoswitch': switches,
|
| 273 | 'numolink': links },
|
| 274 | attempts=10,
|
| 275 | sleep=main.linkSleep )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 276 | result = topology & LinkDown
|
| 277 | utilities.assert_equals( expect=main.TRUE, actual=result,
|
| 278 | onpass="Link down successful",
|
| 279 | onfail="Failed to turn off link?" )
|
| 280 |
|
| 281 | @staticmethod
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 282 | def restoreLink( main, end1, end2, dpid1, dpid2, port1, port2, switches,
|
| 283 | links ):
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 284 | """
|
| 285 | Params:
|
| 286 | end1,end2: identify the end switches, ex.: 'leaf1', 'spine1'
|
| 287 | dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002'
|
Flavio Castro | 02b4363 | 2016-06-20 17:07:27 -0700 | [diff] [blame] | 288 | 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] | 289 | switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
|
| 290 | Kill a link and verify ONOS can see the proper link change
|
| 291 | """
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 292 | main.step( "Restore link between %s and %s" % (end1, end2) )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 293 | result = False
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 294 | count = 0
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 295 | while True:
|
Flavio Castro | d1f3689 | 2016-07-06 11:49:11 -0700 | [diff] [blame] | 296 | count += 1
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 297 | main.Mininet1.link( END1=end1, END2=end2, OPTION="up" )
|
| 298 | main.Mininet1.link( END2=end1, END1=end2, OPTION="up" )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 299 | main.log.info(
|
Flavio Castro | 519072e | 2016-06-23 13:30:48 -0700 | [diff] [blame] | 300 | "Waiting %s seconds for link up to be discovered" % main.linkSleep )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 301 | time.sleep( main.linkSleep )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 302 | main.CLIs[ main.active ].portstate( dpid=dpid1, port=port1 )
|
| 303 | main.CLIs[ main.active ].portstate( dpid=dpid2, port=port2 )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 304 | time.sleep( main.linkSleep )
|
| 305 |
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 306 | result = main.CLIs[ main.active ].checkStatus( numoswitch=switches,
|
| 307 | numolink=links )
|
| 308 | if count > 5 or result:
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 309 | break
|
| 310 | utilities.assert_equals( expect=main.TRUE, actual=result,
|
| 311 | onpass="Link up successful",
|
| 312 | onfail="Failed to bring link up" )
|
| 313 |
|
| 314 | @staticmethod
|
| 315 | def killSwitch( main, switch, switches, links ):
|
| 316 | """
|
| 317 | 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] | 318 | Completely kill a switch and verify ONOS can see the proper change
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 319 | """
|
| 320 | main.switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
|
| 321 | main.step( "Kill " + switch )
|
| 322 | main.log.info( "Stopping" + switch )
|
| 323 | main.Mininet1.switch( SW=switch, OPTION="stop" )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 324 | # todo make this repeatable
|
| 325 | main.log.info( "Waiting %s seconds for switch down to be discovered" % (
|
Flavio Castro | 519072e | 2016-06-23 13:30:48 -0700 | [diff] [blame] | 326 | main.switchSleep) )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 327 | time.sleep( main.switchSleep )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 328 | topology = utilities.retry( main.CLIs[ main.active ].checkStatus,
|
| 329 | main.FALSE,
|
| 330 | kwargs={ 'numoswitch': switches,
|
| 331 | 'numolink': links },
|
| 332 | attempts=10,
|
| 333 | sleep=main.switchSleep )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 334 | utilities.assert_equals( expect=main.TRUE, actual=topology,
|
| 335 | onpass="Kill switch successful",
|
| 336 | onfail="Failed to kill switch?" )
|
| 337 |
|
| 338 | @staticmethod
|
| 339 | def recoverSwitch( main, switch, switches, links ):
|
| 340 | """
|
| 341 | Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6'
|
| 342 | Recover a switch and verify ONOS can see the proper change
|
| 343 | """
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 344 | # todo make this repeatable
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 345 | main.step( "Recovering " + switch )
|
| 346 | main.log.info( "Starting" + switch )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 347 | main.Mininet1.switch( SW=switch, OPTION="start" )
|
| 348 | main.log.info( "Waiting %s seconds for switch up to be discovered" % (
|
Flavio Castro | 519072e | 2016-06-23 13:30:48 -0700 | [diff] [blame] | 349 | main.switchSleep) )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 350 | time.sleep( main.switchSleep )
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 351 | topology = utilities.retry( main.CLIs[ main.active ].checkStatus,
|
| 352 | main.FALSE,
|
| 353 | kwargs={ 'numoswitch': switches,
|
| 354 | 'numolink': links },
|
| 355 | attempts=10,
|
| 356 | sleep=main.switchSleep )
|
Flavio Castro | 0a05b8d | 2016-06-16 17:26:51 -0700 | [diff] [blame] | 357 | utilities.assert_equals( expect=main.TRUE, actual=topology,
|
| 358 | onpass="Switch recovery successful",
|
| 359 | onfail="Failed to recover switch?" )
|
| 360 |
|
| 361 | @staticmethod
|
| 362 | def cleanup( main ):
|
| 363 | """
|
| 364 | Stop Onos-cluster.
|
| 365 | Stops Mininet
|
| 366 | Copies ONOS log
|
| 367 | """
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 368 | main.Mininet1.stopNet( )
|
Flavio Castro | 49c218d | 2016-06-21 16:55:57 -0700 | [diff] [blame] | 369 | main.ONOSbench.scp( main.ONOScli1, "/opt/onos/log/karaf.log",
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 370 | "/tmp/karaf.log", direction="from" )
|
Flavio Castro | 49c218d | 2016-06-21 16:55:57 -0700 | [diff] [blame] | 371 | main.ONOSbench.cpLogsToDir( "/tmp/karaf.log", main.logdir,
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 372 | copyFileName="karaf.log." + main.cfgName )
|
Flavio Castro | 49c218d | 2016-06-21 16:55:57 -0700 | [diff] [blame] | 373 | for i in range( main.numCtrls ):
|
Flavio Castro | 5608a39 | 2016-06-22 17:02:35 -0700 | [diff] [blame] | 374 | main.ONOSbench.onosStop( main.ONOSip[ i ] )
|
Flavio Castro | 519072e | 2016-06-23 13:30:48 -0700 | [diff] [blame] | 375 |
|
| 376 | @staticmethod
|
| 377 | def killOnos( main, nodes, switches, links, expNodes ):
|
| 378 | """
|
| 379 | Params: nodes, integer array with position of the ONOS nodes in the CLIs array
|
| 380 | switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6'
|
| 381 | Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change
|
| 382 | """
|
| 383 | main.step( "Killing ONOS instance" )
|
| 384 | for i in nodes:
|
| 385 | killResult = main.ONOSbench.onosDie( main.CLIs[ i ].ip_address )
|
| 386 | utilities.assert_equals( expect=main.TRUE, actual=killResult,
|
| 387 | onpass="ONOS instance Killed",
|
| 388 | onfail="Error killing ONOS instance" )
|
| 389 | if i == main.active:
|
| 390 | main.active = (i + 1) % main.numCtrls
|
| 391 | time.sleep( 12 )
|
| 392 | if len( nodes ) < main.numCtrls:
|
| 393 | topology = utilities.retry( main.CLIs[ main.active ].checkStatus,
|
| 394 | main.FALSE,
|
| 395 | kwargs={ 'numoswitch': switches,
|
| 396 | 'numolink': links,
|
| 397 | 'numoctrl': expNodes },
|
| 398 | attempts=10,
|
| 399 | sleep=12 )
|
| 400 | utilities.assert_equals( expect=main.TRUE, actual=topology,
|
| 401 | onpass="ONOS Instance down successful",
|
| 402 | onfail="Failed to turn off ONOS Instance" )
|
| 403 | else:
|
| 404 | main.active = -1
|
| 405 |
|
| 406 | @staticmethod
|
| 407 | def recoverOnos( 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 recoverOnos, ex.: '4', '6'
|
| 411 | Recover an ONOS instance and verify the ONOS cluster can see the proper change
|
| 412 | """
|
| 413 | main.step( "Recovering ONOS instance" )
|
| 414 | [ main.ONOSbench.onosStart( main.CLIs[ i ].ip_address ) for i in nodes ]
|
| 415 | for i in nodes:
|
| 416 | isUp = main.ONOSbench.isup( main.ONOSip[ i ] )
|
| 417 | utilities.assert_equals( expect=main.TRUE, actual=isUp,
|
| 418 | onpass="ONOS service is ready",
|
| 419 | onfail="ONOS service did not start properly" )
|
| 420 | for i in nodes:
|
| 421 | main.step( "Checking if ONOS CLI is ready" )
|
| 422 | main.CLIs[ i ].startCellCli( )
|
| 423 | cliResult = main.CLIs[ i ].startOnosCli( main.ONOSip[ i ],
|
| 424 | commandlineTimeout=60,
|
| 425 | onosStartTimeout=100 )
|
| 426 | utilities.assert_equals( expect=main.TRUE,
|
| 427 | actual=cliResult,
|
| 428 | onpass="ONOS CLI is ready",
|
| 429 | onfail="ONOS CLI is not ready" )
|
| 430 | main.active = i if main.active == -1 else main.active
|
| 431 |
|
| 432 | topology = utilities.retry( main.CLIs[ main.active ].checkStatus,
|
| 433 | main.FALSE,
|
| 434 | kwargs={ 'numoswitch': switches,
|
| 435 | 'numolink': links,
|
| 436 | 'numoctrl': expNodes },
|
| 437 | attempts=10,
|
| 438 | sleep=12 )
|
| 439 | utilities.assert_equals( expect=main.TRUE, actual=topology,
|
| 440 | onpass="ONOS Instance down successful",
|
| 441 | onfail="Failed to turn off ONOS Instance" )
|
| 442 |
|
| 443 | for i in range( 10 ):
|
| 444 | ready = True
|
| 445 | output = main.CLIs[ main.active ].summary( )
|
| 446 | if not output:
|
| 447 | ready = False
|
| 448 | if ready:
|
| 449 | break
|
| 450 | time.sleep( 10 )
|
| 451 | utilities.assert_equals( expect=True, actual=ready,
|
| 452 | onpass="ONOS summary command succeded",
|
| 453 | onfail="ONOS summary command failed" )
|
| 454 | if not ready:
|
| 455 | main.log.error( "ONOS startup failed!" )
|
| 456 | main.cleanup( )
|
| 457 | main.exit( )
|