blob: 030ec9a6a037a43076a2c24e604f0a58ae34f0d2 [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
221 def checkFlows( main, minFlowCount, dumpflows=True ):
222 main.step(
223 " Check whether the flow count is bigger than %s" % minFlowCount )
224 count = utilities.retry( main.CLIs[ main.active ].checkFlowCount,
225 main.FALSE,
226 kwargs={ 'min': minFlowCount },
227 attempts=10,
228 sleep=10 )
229 utilities.assertEquals( \
230 expect=True,
231 actual=(count > 0),
232 onpass="Flow count looks correct: " + str( count ),
233 onfail="Flow count looks wrong: " + str( count ) )
234
235 main.step( "Check whether all flow status are ADDED" )
236 flowCheck = utilities.retry( main.CLIs[ main.active ].checkFlowsState,
237 main.FALSE,
238 kwargs={ 'isPENDING': False },
239 attempts=2,
240 sleep=10 )
241 utilities.assertEquals( \
242 expect=main.TRUE,
243 actual=flowCheck,
244 onpass="Flow status is correct!",
245 onfail="Flow status is wrong!" )
246 if dumpflows:
Pier50f0bc62016-09-07 17:53:40 -0700247 main.ONOSbench.dumpONOSCmd( main.ONOSip[ main.active ],
248 "flows",
249 main.logdir,
250 "flowsBefore" + main.cfgName )
251 main.ONOSbench.dumpONOSCmd( main.ONOSip[ main.active ],
252 "groups",
253 main.logdir,
254 "groupsBefore" + main.cfgName )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700255
256 @staticmethod
257 def pingAll( main, tag="", dumpflows=True ):
258 main.log.report( "Check full connectivity" )
259 print main.pingChart
260 for entry in main.pingChart.itervalues( ):
261 print entry
262 hosts, expect = entry[ 'hosts' ], entry[ 'expect' ]
263 expect = main.TRUE if expect else main.FALSE
264 main.step( "Connectivity for %s %s" % (str( hosts ), tag) )
265 pa = main.Mininet1.pingallHosts( hosts )
266 utilities.assert_equals( expect=expect, actual=pa,
267 onpass="IP connectivity successfully tested",
268 onfail="IP connectivity failed" )
269 if dumpflows:
Pier50f0bc62016-09-07 17:53:40 -0700270 main.ONOSbench.dumpONOSCmd( main.ONOSip[ main.active ],
271 "flows",
272 main.logdir,
273 "flowsOn" + tag )
274 main.ONOSbench.dumpONOSCmd( main.ONOSip[ main.active ],
275 "groups",
276 main.logdir,
277 "groupsOn" + tag )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700278
279 @staticmethod
280 def killLink( main, end1, end2, switches, links ):
281 """
282 end1,end2: identify the switches, ex.: 'leaf1', 'spine1'
283 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
284 Kill a link and verify ONOS can see the proper link change
285 """
286 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
287 main.step( "Kill link between %s and %s" % (end1, end2) )
288 LinkDown = main.Mininet1.link( END1=end1, END2=end2, OPTION="down" )
Pierfb719b12016-09-19 14:51:44 -0700289 LinkDown = main.Mininet1.link( END2=end1, END1=end2, OPTION="down" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700290 main.log.info(
291 "Waiting %s seconds for link down to be discovered" % main.linkSleep )
292 time.sleep( main.linkSleep )
293 topology = utilities.retry( main.CLIs[ main.active ].checkStatus,
294 main.FALSE,
295 kwargs={ 'numoswitch': switches,
296 'numolink': links },
297 attempts=10,
298 sleep=main.linkSleep )
299 result = topology & LinkDown
300 utilities.assert_equals( expect=main.TRUE, actual=result,
301 onpass="Link down successful",
302 onfail="Failed to turn off link?" )
303
304 @staticmethod
305 def restoreLink( main, end1, end2, dpid1, dpid2, port1, port2, switches,
306 links ):
307 """
308 Params:
309 end1,end2: identify the end switches, ex.: 'leaf1', 'spine1'
310 dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002'
311 port1, port2: respective port of the end switches that connects to the link, ex.:'1'
312 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
313 Kill a link and verify ONOS can see the proper link change
314 """
315 main.step( "Restore link between %s and %s" % (end1, end2) )
316 result = False
317 count = 0
318 while True:
319 count += 1
320 main.Mininet1.link( END1=end1, END2=end2, OPTION="up" )
321 main.Mininet1.link( END2=end1, END1=end2, OPTION="up" )
322 main.log.info(
323 "Waiting %s seconds for link up to be discovered" % main.linkSleep )
324 time.sleep( main.linkSleep )
Pierfb719b12016-09-19 14:51:44 -0700325
326 for i in range(0, main.numCtrls):
327 onosIsUp = main.ONOSbench.isup( main.ONOSip[ i ] )
328 if onosIsUp == main.TRUE:
329 main.CLIs[ i ].portstate( dpid=dpid1, port=port1 )
330 main.CLIs[ i ].portstate( dpid=dpid2, port=port2 )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700331 time.sleep( main.linkSleep )
332
333 result = main.CLIs[ main.active ].checkStatus( numoswitch=switches,
334 numolink=links )
335 if count > 5 or result:
336 break
337 utilities.assert_equals( expect=main.TRUE, actual=result,
338 onpass="Link up successful",
339 onfail="Failed to bring link up" )
340
341 @staticmethod
342 def killSwitch( main, switch, switches, links ):
343 """
344 Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6'
345 Completely kill a switch and verify ONOS can see the proper change
346 """
347 main.switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
348 main.step( "Kill " + switch )
349 main.log.info( "Stopping" + switch )
350 main.Mininet1.switch( SW=switch, OPTION="stop" )
351 # todo make this repeatable
352 main.log.info( "Waiting %s seconds for switch down to be discovered" % (
353 main.switchSleep) )
354 time.sleep( main.switchSleep )
355 topology = utilities.retry( main.CLIs[ main.active ].checkStatus,
356 main.FALSE,
357 kwargs={ 'numoswitch': switches,
358 'numolink': links },
359 attempts=10,
360 sleep=main.switchSleep )
361 utilities.assert_equals( expect=main.TRUE, actual=topology,
362 onpass="Kill switch successful",
363 onfail="Failed to kill switch?" )
364
365 @staticmethod
366 def recoverSwitch( main, switch, switches, links ):
367 """
368 Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6'
369 Recover a switch and verify ONOS can see the proper change
370 """
371 # todo make this repeatable
372 main.step( "Recovering " + switch )
373 main.log.info( "Starting" + switch )
374 main.Mininet1.switch( SW=switch, OPTION="start" )
375 main.log.info( "Waiting %s seconds for switch up to be discovered" % (
376 main.switchSleep) )
377 time.sleep( main.switchSleep )
378 topology = utilities.retry( main.CLIs[ main.active ].checkStatus,
379 main.FALSE,
380 kwargs={ 'numoswitch': switches,
381 'numolink': links },
382 attempts=10,
383 sleep=main.switchSleep )
384 utilities.assert_equals( expect=main.TRUE, actual=topology,
385 onpass="Switch recovery successful",
386 onfail="Failed to recover switch?" )
387
388 @staticmethod
389 def cleanup( main ):
390 """
391 Stop Onos-cluster.
392 Stops Mininet
393 Copies ONOS log
394 """
395 main.Mininet1.stopNet( )
396 main.ONOSbench.scp( main.ONOScli1, "/opt/onos/log/karaf.log",
397 "/tmp/karaf.log", direction="from" )
398 main.ONOSbench.cpLogsToDir( "/tmp/karaf.log", main.logdir,
399 copyFileName="karaf.log." + main.cfgName )
400 for i in range( main.numCtrls ):
401 main.ONOSbench.onosStop( main.ONOSip[ i ] )
402
403 @staticmethod
404 def killOnos( main, nodes, switches, links, expNodes ):
405 """
406 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
407 switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6'
408 Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change
409 """
Pier3b58c652016-09-26 12:03:31 -0700410
Jon Hall1efcb3f2016-08-23 13:42:15 -0700411 main.step( "Killing ONOS instance" )
Pier3b58c652016-09-26 12:03:31 -0700412
Jon Hall1efcb3f2016-08-23 13:42:15 -0700413 for i in nodes:
414 killResult = main.ONOSbench.onosDie( main.CLIs[ i ].ip_address )
415 utilities.assert_equals( expect=main.TRUE, actual=killResult,
416 onpass="ONOS instance Killed",
417 onfail="Error killing ONOS instance" )
418 if i == main.active:
419 main.active = (i + 1) % main.numCtrls
420 time.sleep( 12 )
Pier3b58c652016-09-26 12:03:31 -0700421
Jon Hall1efcb3f2016-08-23 13:42:15 -0700422 if len( nodes ) < main.numCtrls:
Pier3b58c652016-09-26 12:03:31 -0700423
424 nodesToCheck = []
425 for x in range(0, main.numCtrls):
426 if x not in nodes:
427 nodesToCheck.append(x)
428 nodeResults = utilities.retry( Testcaselib.nodesCheck,
429 False,
430 args=[nodesToCheck],
431 attempts=5,
432 sleep=10 )
433 utilities.assert_equals( expect=True, actual=nodeResults,
434 onpass="Nodes check successful",
435 onfail="Nodes check NOT successful" )
436
437 if not nodeResults:
438 for i in nodes:
439 cli = main.CLIs[i]
440 main.log.debug( "{} components not ACTIVE: \n{}".format(
441 cli.name,
442 cli.sendline( "scr:list | grep -v ACTIVE" ) ) )
443 main.log.error( "Failed to kill ONOS, stopping test" )
444 main.cleanup()
445 main.exit()
446
Jon Hall1efcb3f2016-08-23 13:42:15 -0700447 topology = utilities.retry( main.CLIs[ main.active ].checkStatus,
448 main.FALSE,
449 kwargs={ 'numoswitch': switches,
450 'numolink': links,
451 'numoctrl': expNodes },
452 attempts=10,
453 sleep=12 )
454 utilities.assert_equals( expect=main.TRUE, actual=topology,
455 onpass="ONOS Instance down successful",
456 onfail="Failed to turn off ONOS Instance" )
457 else:
458 main.active = -1
459
460 @staticmethod
461 def recoverOnos( main, nodes, switches, links, expNodes ):
462 """
463 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
464 switches, links, nodes: number of expected switches, links and nodes after recoverOnos, ex.: '4', '6'
465 Recover an ONOS instance and verify the ONOS cluster can see the proper change
466 """
467 main.step( "Recovering ONOS instance" )
468 [ main.ONOSbench.onosStart( main.CLIs[ i ].ip_address ) for i in nodes ]
469 for i in nodes:
470 isUp = main.ONOSbench.isup( main.ONOSip[ i ] )
471 utilities.assert_equals( expect=main.TRUE, actual=isUp,
472 onpass="ONOS service is ready",
473 onfail="ONOS service did not start properly" )
474 for i in nodes:
475 main.step( "Checking if ONOS CLI is ready" )
476 main.CLIs[ i ].startCellCli( )
477 cliResult = main.CLIs[ i ].startOnosCli( main.ONOSip[ i ],
478 commandlineTimeout=60,
479 onosStartTimeout=100 )
480 utilities.assert_equals( expect=main.TRUE,
481 actual=cliResult,
482 onpass="ONOS CLI is ready",
483 onfail="ONOS CLI is not ready" )
484 main.active = i if main.active == -1 else main.active
485
Pier3b58c652016-09-26 12:03:31 -0700486 main.step( "Checking ONOS nodes" )
487 nodeResults = utilities.retry( Testcaselib.nodesCheck,
488 False,
489 args=[nodes],
490 attempts=5,
491 sleep=10 )
492 utilities.assert_equals( expect=True, actual=nodeResults,
493 onpass="Nodes check successful",
494 onfail="Nodes check NOT successful" )
495
496 if not nodeResults:
497 for i in nodes:
498 cli = main.CLIs[i]
499 main.log.debug( "{} components not ACTIVE: \n{}".format(
500 cli.name,
501 cli.sendline( "scr:list | grep -v ACTIVE" ) ) )
502 main.log.error( "Failed to start ONOS, stopping test" )
503 main.cleanup()
504 main.exit()
505
Jon Hall1efcb3f2016-08-23 13:42:15 -0700506 topology = utilities.retry( main.CLIs[ main.active ].checkStatus,
507 main.FALSE,
508 kwargs={ 'numoswitch': switches,
509 'numolink': links,
510 'numoctrl': expNodes },
511 attempts=10,
512 sleep=12 )
513 utilities.assert_equals( expect=main.TRUE, actual=topology,
514 onpass="ONOS Instance down successful",
515 onfail="Failed to turn off ONOS Instance" )
516 for i in range( 10 ):
517 ready = True
518 output = main.CLIs[ main.active ].summary( )
519 if not output:
520 ready = False
521 if ready:
522 break
523 time.sleep( 10 )
524 utilities.assert_equals( expect=True, actual=ready,
525 onpass="ONOS summary command succeded",
526 onfail="ONOS summary command failed" )
527 if not ready:
528 main.log.error( "ONOS startup failed!" )
529 main.cleanup( )
530 main.exit( )
531
532 @staticmethod
533 def addHostCfg( main ):
534 """
535 Adds Host Configuration to ONOS
536 Updates expected state of the network (pingChart)
537 """
538 import json
539 hostCfg = { }
540 with open( main.dependencyPath + "/json/extra.json" ) as template:
541 hostCfg = json.load( template )
542 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ]
543 main.step( "Pushing new configuration" )
544 mac, cfg = hostCfg[ 'hosts' ].popitem( )
545 main.RESTs[ main.active ].setNetCfg( cfg[ 'basic' ],
546 subjectClass="hosts",
547 subjectKey=urllib.quote( mac,
548 safe='' ),
549 configKey="basic" )
550 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ]
551 main.step( "Pushing new configuration" )
552 mac, cfg = hostCfg[ 'hosts' ].popitem( )
553 main.RESTs[ main.active ].setNetCfg( cfg[ 'basic' ],
554 subjectClass="hosts",
555 subjectKey=urllib.quote( mac,
556 safe='' ),
557 configKey="basic" )
558 main.pingChart.update( { 'vlan1': { "expect": "True",
559 "hosts": [ "olt1", "vsg1" ] } } )
560 main.pingChart[ 'vlan5' ][ 'expect' ] = 0
561 main.pingChart[ 'vlan10' ][ 'expect' ] = 0
562 ports = "[%s,%s]" % (5, 6)
563 cfg = '{"of:0000000000000001":[{"vlan":1,"ports":%s,"name":"OLT 1"}]}' % ports
564 main.RESTs[ main.active ].setNetCfg( json.loads( cfg ),
565 subjectClass="apps",
566 subjectKey="org.onosproject.segmentrouting",
567 configKey="xconnect" )
568
569 @staticmethod
570 def delHostCfg( main ):
571 """
572 Removest Host Configuration from ONOS
573 Updates expected state of the network (pingChart)
574 """
575 import json
576 hostCfg = { }
577 with open( main.dependencyPath + "/json/extra.json" ) as template:
578 hostCfg = json.load( template )
579 main.step( "Removing host configuration" )
580 main.pingChart[ 'ip' ][ 'expect' ] = 0
581 mac, cfg = hostCfg[ 'hosts' ].popitem( )
582 main.RESTs[ main.active ].removeNetCfg( subjectClass="hosts",
583 subjectKey=urllib.quote(
584 mac,
585 safe='' ),
586 configKey="basic" )
587 main.step( "Removing configuration" )
588 main.pingChart[ 'ip' ][ 'expect' ] = 0
589 mac, cfg = hostCfg[ 'hosts' ].popitem( )
590 main.RESTs[ main.active ].removeNetCfg( subjectClass="hosts",
591 subjectKey=urllib.quote(
592 mac,
593 safe='' ),
594 configKey="basic" )
595 main.step( "Removing vlan configuration" )
596 main.pingChart[ 'vlan1' ][ 'expect' ] = 0
597 main.RESTs[ main.active ].removeNetCfg( subjectClass="apps",
598 subjectKey="org.onosproject.segmentrouting",
599 configKey="xconnect" )
Pier3b58c652016-09-26 12:03:31 -0700600 @staticmethod
601 def nodesCheck( nodes ):
602 nodesOutput = []
603 results = True
604 threads = []
605 for i in nodes:
606 t = main.Thread( target=main.CLIs[i].nodes,
607 name="nodes-" + str( i ),
608 args=[ ] )
609 threads.append( t )
610 t.start()
611
612 for t in threads:
613 t.join()
614 nodesOutput.append( t.result )
615 ips = [ main.ONOSip[ node ] for node in nodes ]
616 ips.sort()
617 for i in nodesOutput:
618 try:
619 current = json.loads( i )
620 activeIps = []
621 currentResult = False
622 for node in current:
623 if node['state'] == 'READY':
624 activeIps.append( node['ip'] )
625 currentResult = True
626 for ip in ips:
627 if ip not in activeIps:
628 currentResult = False
629 break
630 except ( ValueError, TypeError ):
631 main.log.error( "Error parsing nodes output" )
632 main.log.warn( repr( i ) )
633 currentResult = False
634 results = results and currentResult
635 return results