blob: 7ef28e6ad836690e8d2d9df2fdf569de0cac8dba [file] [log] [blame]
Jon Hall1efcb3f2016-08-23 13:42:15 -07001import os
2import imp
3import time
4import json
5import urllib
6from core import utilities
7
8
9class Testcaselib:
Pierfb719b12016-09-19 14:51:44 -070010
11 useSSH=False
12
Jon Hall1efcb3f2016-08-23 13:42:15 -070013 @staticmethod
14 def initTest( main ):
15 """
16 - Construct tests variables
17 - GIT ( optional )
18 - Checkout ONOS master branch
19 - Pull latest ONOS code
20 - Building ONOS ( optional )
21 - Install ONOS package
22 - Build ONOS package
23 """
24 main.step( "Constructing test variables" )
25 # Test variables
26 main.cellName = main.params[ 'ENV' ][ 'cellName' ]
27 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
28 main.diff = main.params[ 'ENV' ][ 'diffApps' ]
29 gitBranch = main.params[ 'GIT' ][ 'branch' ]
30 main.path = os.path.dirname( main.testFile )
31 main.dependencyPath = main.path + "/../dependencies/"
32 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
33 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
34 main.scale = (main.params[ 'SCALE' ][ 'size' ]).split( "," )
35 main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
36 # main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
37 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
38 main.cellData = { } # for creating cell file
39 main.CLIs = [ ]
40 main.ONOSip = [ ]
41 main.RESTs = [ ]
42
43 # Assigning ONOS cli handles to a list
44 for i in range( 1, main.maxNodes + 1 ):
45 main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) )
46 main.RESTs.append( getattr( main, 'ONOSrest' + str( i ) ) )
47 main.ONOSip.append( main.CLIs[ i - 1 ].ip_address )
48 # -- INIT SECTION, ONLY RUNS ONCE -- #
49 main.startUp = imp.load_source( wrapperFile1,
50 main.dependencyPath +
51 wrapperFile1 +
52 ".py" )
53
54 copyResult1 = main.ONOSbench.scp( main.Mininet1,
55 main.dependencyPath +
56 main.topology,
57 main.Mininet1.home,
58 direction="to" )
59 if main.CLIs:
60 stepResult = main.TRUE
61 else:
62 main.log.error( "Did not properly created list of ONOS CLI handle" )
63 stepResult = main.FALSE
64
65 utilities.assert_equals( expect=main.TRUE,
66 actual=stepResult,
67 onpass="Successfully construct " +
68 "test variables ",
69 onfail="Failed to construct test variables" )
70
71 @staticmethod
72 def installOnos( main, vlanCfg=True ):
73 """
74 - Set up cell
75 - Create cell file
76 - Set cell file
77 - Verify cell file
78 - Kill ONOS process
79 - Uninstall ONOS cluster
80 - Verify ONOS start up
81 - Install ONOS cluster
82 - Connect to cli
83 """
84 # main.scale[ 0 ] determines the current number of ONOS controller
85 apps = main.apps
86 if main.diff:
87 apps = main.apps + "," + main.diff
88 else:
89 main.log.error( "App list is empty" )
90 print "NODE COUNT = ", main.numCtrls
91 print main.ONOSip
92 tempOnosIp = [ ]
93 main.dynamicHosts = [ 'in1', 'out1' ]
94 for i in range( main.numCtrls ):
95 tempOnosIp.append( main.ONOSip[ i ] )
96 onosUser = main.params[ 'ENV' ][ 'cellUser' ]
97 main.step( "Create and Apply cell file" )
98 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
99 "temp",
100 main.Mininet1.ip_address,
101 apps,
102 tempOnosIp,
103 onosUser,
Pierfb719b12016-09-19 14:51:44 -0700104 useSSH=Testcaselib.useSSH )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700105 cellResult = main.ONOSbench.setCell( "temp" )
106 verifyResult = main.ONOSbench.verifyCell( )
107 stepResult = cellResult and verifyResult
108 utilities.assert_equals( expect=main.TRUE,
109 actual=stepResult,
110 onpass="Successfully applied cell to " + \
111 "environment",
112 onfail="Failed to apply cell to environment " )
113 # kill off all onos processes
114 main.log.info( "Safety check, killing all ONOS processes" +
115 " before initiating environment setup" )
116 for i in range( main.maxNodes ):
117 main.ONOSbench.onosDie( main.ONOSip[ i ] )
118 main.step( "Create and Install ONOS package" )
Jon Hallbd60ea02016-08-23 10:03:59 -0700119 packageResult = main.ONOSbench.buckBuild()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700120
121 onosInstallResult = main.TRUE
122 for i in range( main.numCtrls ):
123 onosInstallResult = onosInstallResult and \
124 main.ONOSbench.onosInstall(
125 node=main.ONOSip[ i ] )
126 stepResult = onosInstallResult
127 utilities.assert_equals( expect=main.TRUE,
128 actual=stepResult,
129 onpass="Successfully installed ONOS package",
130 onfail="Failed to install ONOS package" )
Pierfb719b12016-09-19 14:51:44 -0700131 if Testcaselib.useSSH:
132 for i in range( main.numCtrls ):
133 onosInstallResult = onosInstallResult and \
134 main.ONOSbench.onosSecureSSH(
135 node=main.ONOSip[ i ] )
136 stepResult = onosInstallResult
137 utilities.assert_equals( expect=main.TRUE,
138 actual=stepResult,
139 onpass="Successfully secure SSH",
140 onfail="Failed to secure SSH" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700141 main.step( "Starting ONOS service" )
142 stopResult, startResult, onosIsUp = main.TRUE, main.TRUE, main.TRUE,
143 for i in range( main.numCtrls ):
144 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
145 if onosIsUp == main.TRUE:
146 main.log.report( "ONOS instance is up and ready" )
147 else:
148 main.log.report( "ONOS instance may not be up, stop and " +
149 "start ONOS again " )
150 for i in range( main.numCtrls ):
151 stopResult = stopResult and \
152 main.ONOSbench.onosStop( main.ONOSip[ i ] )
153 for i in range( main.numCtrls ):
154 startResult = startResult and \
155 main.ONOSbench.onosStart( main.ONOSip[ i ] )
156 stepResult = onosIsUp and stopResult and startResult
157
158 utilities.assert_equals( expect=main.TRUE,
159 actual=stepResult,
160 onpass="ONOS service is ready",
161 onfail="ONOS service did not start properly" )
162 main.step( "Checking if ONOS CLI is ready" )
163 for i in range( main.numCtrls ):
164 main.CLIs[ i ].startCellCli( )
165 cliResult = main.CLIs[ i ].startOnosCli( main.ONOSip[ i ],
166 commandlineTimeout=60,
167 onosStartTimeout=100 )
168 utilities.assert_equals( expect=main.TRUE,
169 actual=cliResult,
170 onpass="ONOS CLI is ready",
171 onfail="ONOS CLI is not ready" )
172 main.active = 0
173 for i in range( 10 ):
174 ready = True
175 output = main.CLIs[ main.active ].summary( )
176 if not output:
177 ready = False
178 if ready:
179 break
180 time.sleep( 10 )
181 utilities.assert_equals( expect=True, actual=ready,
182 onpass="ONOS summary command succeded",
183 onfail="ONOS summary command failed" )
184
185 with open( "%s/json/%s.json" % (
186 main.dependencyPath, main.cfgName) ) as cfg:
187 main.RESTs[ main.active ].setNetCfg( json.load( cfg ) )
188 with open( "%s/json/%s.chart" % (
189 main.dependencyPath, main.cfgName) ) as chart:
190 main.pingChart = json.load( chart )
191 if not ready:
192 main.log.error( "ONOS startup failed!" )
193 main.cleanup( )
194 main.exit( )
195
196 for i in range( main.numCtrls ):
197 main.CLIs[ i ].logSet( "DEBUG", "org.onosproject.segmentrouting" )
198 main.CLIs[ i ].logSet( "DEBUG", "org.onosproject.driver.pipeline" )
199 main.CLIs[ i ].logSet( "DEBUG", "org.onosproject.store.group.impl" )
200 main.CLIs[ i ].logSet( "DEBUG",
201 "org.onosproject.net.flowobjective.impl" )
202
203 @staticmethod
204 def startMininet( main, topology, args="" ):
205 main.step( "Starting Mininet Topology" )
206 arg = "--onos %d %s" % (main.numCtrls, args)
207 main.topology = topology
208 topoResult = main.Mininet1.startNet(
209 topoFile=main.Mininet1.home + main.topology, args=arg )
210 stepResult = topoResult
211 utilities.assert_equals( expect=main.TRUE,
212 actual=stepResult,
213 onpass="Successfully loaded topology",
214 onfail="Failed to load topology" )
215 # Exit if topology did not load properly
216 if not topoResult:
217 main.cleanup( )
218 main.exit( )
219
220 @staticmethod
Piera2a7e1b2016-10-04 11:51:43 -0700221 def config(main, cfgName, numCtrls):
222 main.spines = []
223
224 main.failures = int(main.params[ 'failures' ])
225 main.cfgName = cfgName
226 main.numCtrls = numCtrls
227
228 if main.cfgName == '2x2' :
229 spine = {}
230 spine[ 'name' ] = main.params['switches'][ 'spine1' ]
231 spine[ 'dpid' ] = main.params['switches'][ 'spinedpid1' ]
232 main.spines.append(spine)
233
234 spine = {}
235 spine[ 'name' ] = main.params['switches'][ 'spine2' ]
236 spine[ 'dpid' ] = main.params['switches'][ 'spinedpid2' ]
237 main.spines.append(spine)
238
239 elif main.cfgName == '4x4' :
240 spine = {}
241 spine[ 'name' ] = main.params['switches'][ 'spine1' ]
242 spine[ 'dpid' ] = main.params['switches'][ 'spinedpid1' ]
243 main.spines.append(spine)
244
245 spine = {}
246 spine[ 'name' ] = main.params['switches'][ 'spine2' ]
247 spine[ 'dpid' ] = main.params['switches'][ 'spinedpid2' ]
248 main.spines.append(spine)
249
250 spine = {}
251 spine[ 'name' ] = main.params['switches'][ 'spine3' ]
252 spine[ 'dpid' ] = main.params['switches'][ 'spinedpid3' ]
253 main.spines.append(spine)
254
255 spine = {}
256 spine[ 'name' ] = main.params['switches'][ 'spine4' ]
257 spine[ 'dpid' ] = main.params['switches'][ 'spinedpid4' ]
258 main.spines.append(spine)
259
260 else :
261 main.log.error( "Configuration failed!" )
262 main.cleanup( )
263 main.exit( )
264
265 @staticmethod
Jon Hall1efcb3f2016-08-23 13:42:15 -0700266 def checkFlows( main, minFlowCount, dumpflows=True ):
267 main.step(
268 " Check whether the flow count is bigger than %s" % minFlowCount )
269 count = utilities.retry( main.CLIs[ main.active ].checkFlowCount,
270 main.FALSE,
271 kwargs={ 'min': minFlowCount },
272 attempts=10,
273 sleep=10 )
274 utilities.assertEquals( \
275 expect=True,
276 actual=(count > 0),
277 onpass="Flow count looks correct: " + str( count ),
278 onfail="Flow count looks wrong: " + str( count ) )
279
280 main.step( "Check whether all flow status are ADDED" )
281 flowCheck = utilities.retry( main.CLIs[ main.active ].checkFlowsState,
282 main.FALSE,
283 kwargs={ 'isPENDING': False },
284 attempts=2,
285 sleep=10 )
286 utilities.assertEquals( \
287 expect=main.TRUE,
288 actual=flowCheck,
289 onpass="Flow status is correct!",
290 onfail="Flow status is wrong!" )
291 if dumpflows:
Pier50f0bc62016-09-07 17:53:40 -0700292 main.ONOSbench.dumpONOSCmd( main.ONOSip[ main.active ],
293 "flows",
294 main.logdir,
295 "flowsBefore" + main.cfgName )
296 main.ONOSbench.dumpONOSCmd( main.ONOSip[ main.active ],
297 "groups",
298 main.logdir,
299 "groupsBefore" + main.cfgName )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700300
301 @staticmethod
302 def pingAll( main, tag="", dumpflows=True ):
303 main.log.report( "Check full connectivity" )
304 print main.pingChart
305 for entry in main.pingChart.itervalues( ):
306 print entry
307 hosts, expect = entry[ 'hosts' ], entry[ 'expect' ]
308 expect = main.TRUE if expect else main.FALSE
309 main.step( "Connectivity for %s %s" % (str( hosts ), tag) )
310 pa = main.Mininet1.pingallHosts( hosts )
311 utilities.assert_equals( expect=expect, actual=pa,
312 onpass="IP connectivity successfully tested",
313 onfail="IP connectivity failed" )
314 if dumpflows:
Pier50f0bc62016-09-07 17:53:40 -0700315 main.ONOSbench.dumpONOSCmd( main.ONOSip[ main.active ],
316 "flows",
317 main.logdir,
318 "flowsOn" + tag )
319 main.ONOSbench.dumpONOSCmd( main.ONOSip[ main.active ],
320 "groups",
321 main.logdir,
322 "groupsOn" + tag )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700323
324 @staticmethod
325 def killLink( main, end1, end2, switches, links ):
326 """
327 end1,end2: identify the switches, ex.: 'leaf1', 'spine1'
328 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
329 Kill a link and verify ONOS can see the proper link change
330 """
331 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
332 main.step( "Kill link between %s and %s" % (end1, end2) )
333 LinkDown = main.Mininet1.link( END1=end1, END2=end2, OPTION="down" )
Pierfb719b12016-09-19 14:51:44 -0700334 LinkDown = main.Mininet1.link( END2=end1, END1=end2, OPTION="down" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700335 main.log.info(
336 "Waiting %s seconds for link down to be discovered" % main.linkSleep )
337 time.sleep( main.linkSleep )
338 topology = utilities.retry( main.CLIs[ main.active ].checkStatus,
339 main.FALSE,
340 kwargs={ 'numoswitch': switches,
341 'numolink': links },
342 attempts=10,
343 sleep=main.linkSleep )
344 result = topology & LinkDown
345 utilities.assert_equals( expect=main.TRUE, actual=result,
346 onpass="Link down successful",
347 onfail="Failed to turn off link?" )
348
349 @staticmethod
350 def restoreLink( main, end1, end2, dpid1, dpid2, port1, port2, switches,
351 links ):
352 """
353 Params:
354 end1,end2: identify the end switches, ex.: 'leaf1', 'spine1'
355 dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002'
356 port1, port2: respective port of the end switches that connects to the link, ex.:'1'
357 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
358 Kill a link and verify ONOS can see the proper link change
359 """
360 main.step( "Restore link between %s and %s" % (end1, end2) )
361 result = False
362 count = 0
363 while True:
364 count += 1
365 main.Mininet1.link( END1=end1, END2=end2, OPTION="up" )
366 main.Mininet1.link( END2=end1, END1=end2, OPTION="up" )
367 main.log.info(
368 "Waiting %s seconds for link up to be discovered" % main.linkSleep )
369 time.sleep( main.linkSleep )
Pierfb719b12016-09-19 14:51:44 -0700370
371 for i in range(0, main.numCtrls):
372 onosIsUp = main.ONOSbench.isup( main.ONOSip[ i ] )
373 if onosIsUp == main.TRUE:
374 main.CLIs[ i ].portstate( dpid=dpid1, port=port1 )
375 main.CLIs[ i ].portstate( dpid=dpid2, port=port2 )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700376 time.sleep( main.linkSleep )
377
378 result = main.CLIs[ main.active ].checkStatus( numoswitch=switches,
379 numolink=links )
380 if count > 5 or result:
381 break
382 utilities.assert_equals( expect=main.TRUE, actual=result,
383 onpass="Link up successful",
384 onfail="Failed to bring link up" )
385
386 @staticmethod
387 def killSwitch( main, switch, switches, links ):
388 """
389 Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6'
390 Completely kill a switch and verify ONOS can see the proper change
391 """
392 main.switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
393 main.step( "Kill " + switch )
394 main.log.info( "Stopping" + switch )
395 main.Mininet1.switch( SW=switch, OPTION="stop" )
396 # todo make this repeatable
397 main.log.info( "Waiting %s seconds for switch down to be discovered" % (
398 main.switchSleep) )
399 time.sleep( main.switchSleep )
400 topology = utilities.retry( main.CLIs[ main.active ].checkStatus,
401 main.FALSE,
402 kwargs={ 'numoswitch': switches,
403 'numolink': links },
404 attempts=10,
405 sleep=main.switchSleep )
406 utilities.assert_equals( expect=main.TRUE, actual=topology,
407 onpass="Kill switch successful",
408 onfail="Failed to kill switch?" )
409
410 @staticmethod
411 def recoverSwitch( main, switch, switches, links ):
412 """
413 Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6'
414 Recover a switch and verify ONOS can see the proper change
415 """
416 # todo make this repeatable
417 main.step( "Recovering " + switch )
418 main.log.info( "Starting" + switch )
419 main.Mininet1.switch( SW=switch, OPTION="start" )
420 main.log.info( "Waiting %s seconds for switch up to be discovered" % (
421 main.switchSleep) )
422 time.sleep( main.switchSleep )
423 topology = utilities.retry( main.CLIs[ main.active ].checkStatus,
424 main.FALSE,
425 kwargs={ 'numoswitch': switches,
426 'numolink': links },
427 attempts=10,
428 sleep=main.switchSleep )
429 utilities.assert_equals( expect=main.TRUE, actual=topology,
430 onpass="Switch recovery successful",
431 onfail="Failed to recover switch?" )
432
433 @staticmethod
434 def cleanup( main ):
435 """
436 Stop Onos-cluster.
437 Stops Mininet
438 Copies ONOS log
439 """
440 main.Mininet1.stopNet( )
441 main.ONOSbench.scp( main.ONOScli1, "/opt/onos/log/karaf.log",
442 "/tmp/karaf.log", direction="from" )
443 main.ONOSbench.cpLogsToDir( "/tmp/karaf.log", main.logdir,
444 copyFileName="karaf.log." + main.cfgName )
445 for i in range( main.numCtrls ):
446 main.ONOSbench.onosStop( main.ONOSip[ i ] )
447
448 @staticmethod
449 def killOnos( main, nodes, switches, links, expNodes ):
450 """
451 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
452 switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6'
453 Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change
454 """
Pier3b58c652016-09-26 12:03:31 -0700455
Jon Hall1efcb3f2016-08-23 13:42:15 -0700456 main.step( "Killing ONOS instance" )
Pier3b58c652016-09-26 12:03:31 -0700457
Jon Hall1efcb3f2016-08-23 13:42:15 -0700458 for i in nodes:
459 killResult = main.ONOSbench.onosDie( main.CLIs[ i ].ip_address )
460 utilities.assert_equals( expect=main.TRUE, actual=killResult,
461 onpass="ONOS instance Killed",
462 onfail="Error killing ONOS instance" )
463 if i == main.active:
464 main.active = (i + 1) % main.numCtrls
465 time.sleep( 12 )
Pier3b58c652016-09-26 12:03:31 -0700466
Jon Hall1efcb3f2016-08-23 13:42:15 -0700467 if len( nodes ) < main.numCtrls:
Pier3b58c652016-09-26 12:03:31 -0700468
469 nodesToCheck = []
470 for x in range(0, main.numCtrls):
471 if x not in nodes:
472 nodesToCheck.append(x)
473 nodeResults = utilities.retry( Testcaselib.nodesCheck,
474 False,
475 args=[nodesToCheck],
476 attempts=5,
477 sleep=10 )
478 utilities.assert_equals( expect=True, actual=nodeResults,
479 onpass="Nodes check successful",
480 onfail="Nodes check NOT successful" )
481
482 if not nodeResults:
483 for i in nodes:
484 cli = main.CLIs[i]
485 main.log.debug( "{} components not ACTIVE: \n{}".format(
486 cli.name,
487 cli.sendline( "scr:list | grep -v ACTIVE" ) ) )
488 main.log.error( "Failed to kill ONOS, stopping test" )
489 main.cleanup()
490 main.exit()
491
Jon Hall1efcb3f2016-08-23 13:42:15 -0700492 topology = utilities.retry( main.CLIs[ main.active ].checkStatus,
493 main.FALSE,
494 kwargs={ 'numoswitch': switches,
495 'numolink': links,
496 'numoctrl': expNodes },
497 attempts=10,
498 sleep=12 )
499 utilities.assert_equals( expect=main.TRUE, actual=topology,
500 onpass="ONOS Instance down successful",
501 onfail="Failed to turn off ONOS Instance" )
502 else:
503 main.active = -1
504
505 @staticmethod
506 def recoverOnos( main, nodes, switches, links, expNodes ):
507 """
508 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
509 switches, links, nodes: number of expected switches, links and nodes after recoverOnos, ex.: '4', '6'
510 Recover an ONOS instance and verify the ONOS cluster can see the proper change
511 """
512 main.step( "Recovering ONOS instance" )
513 [ main.ONOSbench.onosStart( main.CLIs[ i ].ip_address ) for i in nodes ]
514 for i in nodes:
515 isUp = main.ONOSbench.isup( main.ONOSip[ i ] )
516 utilities.assert_equals( expect=main.TRUE, actual=isUp,
517 onpass="ONOS service is ready",
518 onfail="ONOS service did not start properly" )
519 for i in nodes:
520 main.step( "Checking if ONOS CLI is ready" )
521 main.CLIs[ i ].startCellCli( )
522 cliResult = main.CLIs[ i ].startOnosCli( main.ONOSip[ i ],
523 commandlineTimeout=60,
524 onosStartTimeout=100 )
525 utilities.assert_equals( expect=main.TRUE,
526 actual=cliResult,
527 onpass="ONOS CLI is ready",
528 onfail="ONOS CLI is not ready" )
529 main.active = i if main.active == -1 else main.active
530
Pier3b58c652016-09-26 12:03:31 -0700531 main.step( "Checking ONOS nodes" )
532 nodeResults = utilities.retry( Testcaselib.nodesCheck,
533 False,
534 args=[nodes],
535 attempts=5,
536 sleep=10 )
537 utilities.assert_equals( expect=True, actual=nodeResults,
538 onpass="Nodes check successful",
539 onfail="Nodes check NOT successful" )
540
541 if not nodeResults:
542 for i in nodes:
543 cli = main.CLIs[i]
544 main.log.debug( "{} components not ACTIVE: \n{}".format(
545 cli.name,
546 cli.sendline( "scr:list | grep -v ACTIVE" ) ) )
547 main.log.error( "Failed to start ONOS, stopping test" )
548 main.cleanup()
549 main.exit()
550
Jon Hall1efcb3f2016-08-23 13:42:15 -0700551 topology = utilities.retry( main.CLIs[ main.active ].checkStatus,
552 main.FALSE,
553 kwargs={ 'numoswitch': switches,
554 'numolink': links,
555 'numoctrl': expNodes },
556 attempts=10,
557 sleep=12 )
558 utilities.assert_equals( expect=main.TRUE, actual=topology,
559 onpass="ONOS Instance down successful",
560 onfail="Failed to turn off ONOS Instance" )
561 for i in range( 10 ):
562 ready = True
563 output = main.CLIs[ main.active ].summary( )
564 if not output:
565 ready = False
566 if ready:
567 break
568 time.sleep( 10 )
569 utilities.assert_equals( expect=True, actual=ready,
570 onpass="ONOS summary command succeded",
571 onfail="ONOS summary command failed" )
572 if not ready:
573 main.log.error( "ONOS startup failed!" )
574 main.cleanup( )
575 main.exit( )
576
577 @staticmethod
578 def addHostCfg( main ):
579 """
580 Adds Host Configuration to ONOS
581 Updates expected state of the network (pingChart)
582 """
583 import json
584 hostCfg = { }
585 with open( main.dependencyPath + "/json/extra.json" ) as template:
586 hostCfg = json.load( template )
587 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ]
588 main.step( "Pushing new configuration" )
589 mac, cfg = hostCfg[ 'hosts' ].popitem( )
590 main.RESTs[ main.active ].setNetCfg( cfg[ 'basic' ],
591 subjectClass="hosts",
592 subjectKey=urllib.quote( mac,
593 safe='' ),
594 configKey="basic" )
595 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ]
596 main.step( "Pushing new configuration" )
597 mac, cfg = hostCfg[ 'hosts' ].popitem( )
598 main.RESTs[ main.active ].setNetCfg( cfg[ 'basic' ],
599 subjectClass="hosts",
600 subjectKey=urllib.quote( mac,
601 safe='' ),
602 configKey="basic" )
603 main.pingChart.update( { 'vlan1': { "expect": "True",
604 "hosts": [ "olt1", "vsg1" ] } } )
605 main.pingChart[ 'vlan5' ][ 'expect' ] = 0
606 main.pingChart[ 'vlan10' ][ 'expect' ] = 0
607 ports = "[%s,%s]" % (5, 6)
608 cfg = '{"of:0000000000000001":[{"vlan":1,"ports":%s,"name":"OLT 1"}]}' % ports
609 main.RESTs[ main.active ].setNetCfg( json.loads( cfg ),
610 subjectClass="apps",
611 subjectKey="org.onosproject.segmentrouting",
612 configKey="xconnect" )
613
614 @staticmethod
615 def delHostCfg( main ):
616 """
617 Removest Host Configuration from ONOS
618 Updates expected state of the network (pingChart)
619 """
620 import json
621 hostCfg = { }
622 with open( main.dependencyPath + "/json/extra.json" ) as template:
623 hostCfg = json.load( template )
624 main.step( "Removing host configuration" )
625 main.pingChart[ 'ip' ][ 'expect' ] = 0
626 mac, cfg = hostCfg[ 'hosts' ].popitem( )
627 main.RESTs[ main.active ].removeNetCfg( subjectClass="hosts",
628 subjectKey=urllib.quote(
629 mac,
630 safe='' ),
631 configKey="basic" )
632 main.step( "Removing configuration" )
633 main.pingChart[ 'ip' ][ 'expect' ] = 0
634 mac, cfg = hostCfg[ 'hosts' ].popitem( )
635 main.RESTs[ main.active ].removeNetCfg( subjectClass="hosts",
636 subjectKey=urllib.quote(
637 mac,
638 safe='' ),
639 configKey="basic" )
640 main.step( "Removing vlan configuration" )
641 main.pingChart[ 'vlan1' ][ 'expect' ] = 0
642 main.RESTs[ main.active ].removeNetCfg( subjectClass="apps",
643 subjectKey="org.onosproject.segmentrouting",
644 configKey="xconnect" )
Pier3b58c652016-09-26 12:03:31 -0700645 @staticmethod
646 def nodesCheck( nodes ):
647 nodesOutput = []
648 results = True
649 threads = []
650 for i in nodes:
651 t = main.Thread( target=main.CLIs[i].nodes,
652 name="nodes-" + str( i ),
653 args=[ ] )
654 threads.append( t )
655 t.start()
656
657 for t in threads:
658 t.join()
659 nodesOutput.append( t.result )
660 ips = [ main.ONOSip[ node ] for node in nodes ]
661 ips.sort()
662 for i in nodesOutput:
663 try:
664 current = json.loads( i )
665 activeIps = []
666 currentResult = False
667 for node in current:
668 if node['state'] == 'READY':
669 activeIps.append( node['ip'] )
670 currentResult = True
671 for ip in ips:
672 if ip not in activeIps:
673 currentResult = False
674 break
675 except ( ValueError, TypeError ):
676 main.log.error( "Error parsing nodes output" )
677 main.log.warn( repr( i ) )
678 currentResult = False
679 results = results and currentResult
680 return results