blob: 38e013eaadd4bb373ac94c81d3e46c2bf9ace4c9 [file] [log] [blame]
Flavio Castro0a05b8d2016-06-16 17:26:51 -07001import os
2import imp
3import time
Flavio Castro49c218d2016-06-21 16:55:57 -07004import json
Flavio Castroab163ca2016-07-07 14:05:00 -07005import urllib
Flavio Castro0a05b8d2016-06-16 17:26:51 -07006from core import utilities
7
8
9class 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 Castro0a05b8d2016-06-16 17:26:51 -070021 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 Castro5608a392016-06-22 17:02:35 -070028 main.dependencyPath = main.path + "/../dependencies/"
Flavio Castro0a05b8d2016-06-16 17:26:51 -070029 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
30 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
Flavio Castro5608a392016-06-22 17:02:35 -070031 main.scale = (main.params[ 'SCALE' ][ 'size' ]).split( "," )
Flavio Castro0a05b8d2016-06-16 17:26:51 -070032 main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
Flavio Castro5608a392016-06-22 17:02:35 -070033 # main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
Flavio Castro0a05b8d2016-06-16 17:26:51 -070034 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
Flavio Castro5608a392016-06-22 17:02:35 -070035 main.cellData = { } # for creating cell file
36 main.CLIs = [ ]
37 main.ONOSip = [ ]
38 main.RESTs = [ ]
Flavio Castro0a05b8d2016-06-16 17:26:51 -070039
40 # Assigning ONOS cli handles to a list
Flavio Castro5608a392016-06-22 17:02:35 -070041 for i in range( 1, main.maxNodes + 1 ):
Flavio Castro0a05b8d2016-06-16 17:26:51 -070042 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
Flavio Castro49c218d2016-06-21 16:55:57 -070043 main.RESTs.append( getattr( main, 'ONOSrest' + str( i ) ) )
Flavio Castro5608a392016-06-22 17:02:35 -070044 main.ONOSip.append( main.CLIs[ i - 1 ].ip_address )
Flavio Castro0a05b8d2016-06-16 17:26:51 -070045 # -- 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 Castroab163ca2016-07-07 14:05:00 -070069 def installOnos( main, vlanCfg=True ):
Flavio Castro0a05b8d2016-06-16 17:26:51 -070070 """
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 Castro5608a392016-06-22 17:02:35 -070082 apps = main.apps
Flavio Castro0a05b8d2016-06-16 17:26:51 -070083 if main.diff:
84 apps = main.apps + "," + main.diff
Flavio Castro5608a392016-06-22 17:02:35 -070085 else:
86 main.log.error( "App list is empty" )
Flavio Castro0a05b8d2016-06-16 17:26:51 -070087 print "NODE COUNT = ", main.numCtrls
88 print main.ONOSip
Flavio Castro5608a392016-06-22 17:02:35 -070089 tempOnosIp = [ ]
Flavio Castroab163ca2016-07-07 14:05:00 -070090 main.dynamicHosts = [ 'in1', 'out1' ]
Flavio Castro0a05b8d2016-06-16 17:26:51 -070091 for i in range( main.numCtrls ):
Flavio Castro5608a392016-06-22 17:02:35 -070092 tempOnosIp.append( main.ONOSip[ i ] )
Flavio Castro0a05b8d2016-06-16 17:26:51 -070093 onosUser = main.params[ 'ENV' ][ 'cellUser' ]
Flavio Castro5608a392016-06-22 17:02:35 -070094 main.step( "Create and Apply cell file" )
Flavio Castro0a05b8d2016-06-16 17:26:51 -070095 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 Castro5608a392016-06-22 17:02:35 -0700102 verifyResult = main.ONOSbench.verifyCell( )
Flavio Castro0a05b8d2016-06-16 17:26:51 -0700103 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 Castro5608a392016-06-22 17:02:35 -0700109 # kill off all onos processes
Flavio Castro0a05b8d2016-06-16 17:26:51 -0700110 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 Castro5608a392016-06-22 17:02:35 -0700115 packageResult = main.ONOSbench.onosPackage( )
Flavio Castro0a05b8d2016-06-16 17:26:51 -0700116
117 onosInstallResult = main.TRUE
118 for i in range( main.numCtrls ):
119 onosInstallResult = onosInstallResult and \
Flavio Castro5608a392016-06-22 17:02:35 -0700120 main.ONOSbench.onosInstall(
Flavio Castro519072e2016-06-23 13:30:48 -0700121 node=main.ONOSip[ i ] )
Flavio Castro0a05b8d2016-06-16 17:26:51 -0700122 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 Castro5608a392016-06-22 17:02:35 -0700128 stopResult, startResult, onosIsUp = main.TRUE, main.TRUE, main.TRUE,
Flavio Castro0a05b8d2016-06-16 17:26:51 -0700129 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 Castro5608a392016-06-22 17:02:35 -0700150 main.CLIs[ i ].startCellCli( )
151 cliResult = main.CLIs[ i ].startOnosCli( main.ONOSip[ i ],
152 commandlineTimeout=60,
153 onosStartTimeout=100 )
Flavio Castro0a05b8d2016-06-16 17:26:51 -0700154 utilities.assert_equals( expect=main.TRUE,
155 actual=cliResult,
156 onpass="ONOS CLI is ready",
157 onfail="ONOS CLI is not ready" )
Flavio Castro5608a392016-06-22 17:02:35 -0700158 main.active = 0
Flavio Castro0a05b8d2016-06-16 17:26:51 -0700159 for i in range( 10 ):
160 ready = True
Flavio Castro5608a392016-06-22 17:02:35 -0700161 output = main.CLIs[ main.active ].summary( )
Flavio Castro0a05b8d2016-06-16 17:26:51 -0700162 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 Castroab163ca2016-07-07 14:05:00 -0700171 with open( "%s/json/%s.json" % (
172 main.dependencyPath, main.cfgName) ) as cfg:
Flavio Castro5608a392016-06-22 17:02:35 -0700173 main.RESTs[ main.active ].setNetCfg( json.load( cfg ) )
Flavio Castroab163ca2016-07-07 14:05:00 -0700174 with open( "%s/json/%s.chart" % (
175 main.dependencyPath, main.cfgName) ) as chart:
176 main.pingChart = json.load( chart )
Flavio Castro0a05b8d2016-06-16 17:26:51 -0700177 if not ready:
178 main.log.error( "ONOS startup failed!" )
Flavio Castro5608a392016-06-22 17:02:35 -0700179 main.cleanup( )
180 main.exit( )
Flavio Castro0a05b8d2016-06-16 17:26:51 -0700181
182 for i in range( main.numCtrls ):
Flavio Castro5608a392016-06-22 17:02:35 -0700183 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 Castro0a05b8d2016-06-16 17:26:51 -0700188
189 @staticmethod
190 def startMininet( main, topology, args="" ):
191 main.step( "Starting Mininet Topology" )
192 arg = "--onos %d %s" % (main.numCtrls, args)
Flavio Castro5608a392016-06-22 17:02:35 -0700193 main.topology = topology
194 topoResult = main.Mininet1.startNet(
Flavio Castro519072e2016-06-23 13:30:48 -0700195 topoFile=main.dependencyPath + main.topology, args=arg )
Flavio Castro0a05b8d2016-06-16 17:26:51 -0700196 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 Castro5608a392016-06-22 17:02:35 -0700203 main.cleanup( )
204 main.exit( )
Flavio Castro0a05b8d2016-06-16 17:26:51 -0700205
206 @staticmethod
Flavio Castroab163ca2016-07-07 14:05:00 -0700207 def checkFlows( main, minFlowCount, dumpflows=True ):
Flavio Castro5608a392016-06-22 17:02:35 -0700208 main.step(
Flavio Castro519072e2016-06-23 13:30:48 -0700209 " Check whether the flow count is bigger than %s" % minFlowCount )
Flavio Castro5608a392016-06-22 17:02:35 -0700210 count = utilities.retry( main.CLIs[ main.active ].checkFlowCount,
Flavio Castro02b43632016-06-20 17:07:27 -0700211 main.FALSE,
Flavio Castro5608a392016-06-22 17:02:35 -0700212 kwargs={ 'min': minFlowCount },
Flavio Castro02b43632016-06-20 17:07:27 -0700213 attempts=10,
Flavio Castro5608a392016-06-22 17:02:35 -0700214 sleep=10 )
Flavio Castro0a05b8d2016-06-16 17:26:51 -0700215 utilities.assertEquals( \
216 expect=True,
Flavio Castro5608a392016-06-22 17:02:35 -0700217 actual=(count > 0),
218 onpass="Flow count looks correct: " + str( count ),
219 onfail="Flow count looks wrong: " + str( count ) )
Flavio Castro0a05b8d2016-06-16 17:26:51 -0700220
221 main.step( "Check whether all flow status are ADDED" )
Flavio Castro5608a392016-06-22 17:02:35 -0700222 flowCheck = utilities.retry( main.CLIs[ main.active ].checkFlowsState,
Flavio Castro0a05b8d2016-06-16 17:26:51 -0700223 main.FALSE,
Flavio Castro5608a392016-06-22 17:02:35 -0700224 kwargs={ 'isPENDING': False },
Flavio Castroab163ca2016-07-07 14:05:00 -0700225 attempts=2,
Flavio Castro5608a392016-06-22 17:02:35 -0700226 sleep=10 )
Flavio Castro0a05b8d2016-06-16 17:26:51 -0700227 utilities.assertEquals( \
228 expect=main.TRUE,
229 actual=flowCheck,
230 onpass="Flow status is correct!",
231 onfail="Flow status is wrong!" )
Flavio Castroab163ca2016-07-07 14:05:00 -0700232 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 Castro0a05b8d2016-06-16 17:26:51 -0700239
240 @staticmethod
Flavio Castro519072e2016-06-23 13:30:48 -0700241 def pingAll( main, tag="", dumpflows=True ):
Flavio Castro0a05b8d2016-06-16 17:26:51 -0700242 main.log.report( "Check full connectivity" )
Flavio Castroab163ca2016-07-07 14:05:00 -0700243 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 Castro519072e2016-06-23 13:30:48 -0700253 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 Castro0a05b8d2016-06-16 17:26:51 -0700258
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 Castro5608a392016-06-22 17:02:35 -0700267 main.step( "Kill link between %s and %s" % (end1, end2) )
Flavio Castro0a05b8d2016-06-16 17:26:51 -0700268 LinkDown = main.Mininet1.link( END1=end1, END2=end2, OPTION="down" )
Flavio Castro5608a392016-06-22 17:02:35 -0700269 main.log.info(
Flavio Castro519072e2016-06-23 13:30:48 -0700270 "Waiting %s seconds for link down to be discovered" % main.linkSleep )
Flavio Castro0a05b8d2016-06-16 17:26:51 -0700271 time.sleep( main.linkSleep )
Flavio Castro5608a392016-06-22 17:02:35 -0700272 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 Castro0a05b8d2016-06-16 17:26:51 -0700278 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 Castro5608a392016-06-22 17:02:35 -0700284 def restoreLink( main, end1, end2, dpid1, dpid2, port1, port2, switches,
285 links ):
Flavio Castro0a05b8d2016-06-16 17:26:51 -0700286 """
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 Castro02b43632016-06-20 17:07:27 -0700290 port1, port2: respective port of the end switches that connects to the link, ex.:'1'
Flavio Castro0a05b8d2016-06-16 17:26:51 -0700291 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 Castro5608a392016-06-22 17:02:35 -0700294 main.step( "Restore link between %s and %s" % (end1, end2) )
Flavio Castro0a05b8d2016-06-16 17:26:51 -0700295 result = False
Flavio Castro5608a392016-06-22 17:02:35 -0700296 count = 0
Flavio Castro0a05b8d2016-06-16 17:26:51 -0700297 while True:
Flavio Castrod1f36892016-07-06 11:49:11 -0700298 count += 1
Flavio Castro0a05b8d2016-06-16 17:26:51 -0700299 main.Mininet1.link( END1=end1, END2=end2, OPTION="up" )
300 main.Mininet1.link( END2=end1, END1=end2, OPTION="up" )
Flavio Castro5608a392016-06-22 17:02:35 -0700301 main.log.info(
Flavio Castro519072e2016-06-23 13:30:48 -0700302 "Waiting %s seconds for link up to be discovered" % main.linkSleep )
Flavio Castro0a05b8d2016-06-16 17:26:51 -0700303 time.sleep( main.linkSleep )
Flavio Castro5608a392016-06-22 17:02:35 -0700304 main.CLIs[ main.active ].portstate( dpid=dpid1, port=port1 )
305 main.CLIs[ main.active ].portstate( dpid=dpid2, port=port2 )
Flavio Castro0a05b8d2016-06-16 17:26:51 -0700306 time.sleep( main.linkSleep )
307
Flavio Castro5608a392016-06-22 17:02:35 -0700308 result = main.CLIs[ main.active ].checkStatus( numoswitch=switches,
309 numolink=links )
310 if count > 5 or result:
Flavio Castro0a05b8d2016-06-16 17:26:51 -0700311 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 Castro02b43632016-06-20 17:07:27 -0700320 Completely kill a switch and verify ONOS can see the proper change
Flavio Castro0a05b8d2016-06-16 17:26:51 -0700321 """
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 Castro5608a392016-06-22 17:02:35 -0700326 # todo make this repeatable
327 main.log.info( "Waiting %s seconds for switch down to be discovered" % (
Flavio Castro519072e2016-06-23 13:30:48 -0700328 main.switchSleep) )
Flavio Castro0a05b8d2016-06-16 17:26:51 -0700329 time.sleep( main.switchSleep )
Flavio Castro5608a392016-06-22 17:02:35 -0700330 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 Castro0a05b8d2016-06-16 17:26:51 -0700336 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 Castro5608a392016-06-22 17:02:35 -0700346 # todo make this repeatable
Flavio Castro0a05b8d2016-06-16 17:26:51 -0700347 main.step( "Recovering " + switch )
348 main.log.info( "Starting" + switch )
Flavio Castro5608a392016-06-22 17:02:35 -0700349 main.Mininet1.switch( SW=switch, OPTION="start" )
350 main.log.info( "Waiting %s seconds for switch up to be discovered" % (
Flavio Castro519072e2016-06-23 13:30:48 -0700351 main.switchSleep) )
Flavio Castro0a05b8d2016-06-16 17:26:51 -0700352 time.sleep( main.switchSleep )
Flavio Castro5608a392016-06-22 17:02:35 -0700353 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 Castro0a05b8d2016-06-16 17:26:51 -0700359 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 Castro5608a392016-06-22 17:02:35 -0700370 main.Mininet1.stopNet( )
Flavio Castro49c218d2016-06-21 16:55:57 -0700371 main.ONOSbench.scp( main.ONOScli1, "/opt/onos/log/karaf.log",
Flavio Castro5608a392016-06-22 17:02:35 -0700372 "/tmp/karaf.log", direction="from" )
Flavio Castro49c218d2016-06-21 16:55:57 -0700373 main.ONOSbench.cpLogsToDir( "/tmp/karaf.log", main.logdir,
Flavio Castro5608a392016-06-22 17:02:35 -0700374 copyFileName="karaf.log." + main.cfgName )
Flavio Castro49c218d2016-06-21 16:55:57 -0700375 for i in range( main.numCtrls ):
Flavio Castro5608a392016-06-22 17:02:35 -0700376 main.ONOSbench.onosStop( main.ONOSip[ i ] )
Flavio Castro519072e2016-06-23 13:30:48 -0700377
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 Castro519072e2016-06-23 13:30:48 -0700444 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 Castroab163ca2016-07-07 14:05:00 -0700459
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" )