blob: 1bdaea28975be491941b3552dd7c96085644d178 [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
You Wangf5de25b2017-01-06 15:13:01 -080011 useSSH=True
Pierfb719b12016-09-19 14:51:44 -070012
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 """
Devin Lim58046fa2017-07-05 16:55:00 -070024 try:
25 from tests.dependencies.ONOSSetup import ONOSSetup
26 main.testSetUp = ONOSSetup()
27 except ImportError:
28 main.log.error( "ONOSSetup not found. exiting the test" )
29 main.exit()
30 main.testSetUp.envSetupDescription()
31 stepResult = main.FALSE
32 try:
33 main.step( "Constructing test variables" )
34 # Test variables
35 main.cellName = main.params[ 'ENV' ][ 'cellName' ]
36 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
37 main.diff = main.params[ 'ENV' ][ 'diffApps' ]
38 main.path = os.path.dirname( main.testFile )
39 main.dependencyPath = main.path + "/../dependencies/"
40 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
41 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
42 main.scale = (main.params[ 'SCALE' ][ 'size' ]).split( "," )
43 main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
44 # main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
45 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
46 # -- INIT SECTION, ONLY RUNS ONCE -- #
Jon Hall1efcb3f2016-08-23 13:42:15 -070047
Devin Lim58046fa2017-07-05 16:55:00 -070048 copyResult1 = main.ONOSbench.scp( main.Mininet1,
49 main.dependencyPath +
50 main.topology,
51 main.Mininet1.home,
52 direction="to" )
53 stepResult = main.testSetUp.envSetup( hasRest=True )
54 except Exception as e:
55 main.testSetUp.envSetupException( e )
56 main.testSetUp.evnSetupConclusion( stepResult )
Jon Hall1efcb3f2016-08-23 13:42:15 -070057
Jon Hall1efcb3f2016-08-23 13:42:15 -070058
Jon Hall1efcb3f2016-08-23 13:42:15 -070059
60 @staticmethod
61 def installOnos( main, vlanCfg=True ):
62 """
63 - Set up cell
64 - Create cell file
65 - Set cell file
66 - Verify cell file
67 - Kill ONOS process
68 - Uninstall ONOS cluster
69 - Verify ONOS start up
70 - Install ONOS cluster
71 - Connect to cli
72 """
73 # main.scale[ 0 ] determines the current number of ONOS controller
Jon Hall1efcb3f2016-08-23 13:42:15 -070074 if main.diff:
Devin Lim58046fa2017-07-05 16:55:00 -070075 main.apps = main.apps + "," + main.diff
Jon Hall1efcb3f2016-08-23 13:42:15 -070076 else:
77 main.log.error( "App list is empty" )
78 print "NODE COUNT = ", main.numCtrls
79 print main.ONOSip
Jon Hall1efcb3f2016-08-23 13:42:15 -070080 main.dynamicHosts = [ 'in1', 'out1' ]
Devin Lim58046fa2017-07-05 16:55:00 -070081 main.testSetUp.createApplyCell( newCell=True, cellName=main.cellName,
82 Mininet=main.Mininet1, useSSH=Testcaselib.useSSH )
Jon Hall1efcb3f2016-08-23 13:42:15 -070083 # kill off all onos processes
84 main.log.info( "Safety check, killing all ONOS processes" +
85 " before initiating environment setup" )
86 for i in range( main.maxNodes ):
87 main.ONOSbench.onosDie( main.ONOSip[ i ] )
Jon Hall1efcb3f2016-08-23 13:42:15 -070088
Devin Lim58046fa2017-07-05 16:55:00 -070089 main.testSetUp.buildOnos()
Jon Hall1efcb3f2016-08-23 13:42:15 -070090
Devin Lim58046fa2017-07-05 16:55:00 -070091 main.testSetUp.installOnos( False )
92
93 main.testSetUp.setupSsh()
94
95 main.testSetUp.checkOnosService()
96
Jon Hall1efcb3f2016-08-23 13:42:15 -070097 main.step( "Checking if ONOS CLI is ready" )
98 for i in range( main.numCtrls ):
99 main.CLIs[ i ].startCellCli( )
100 cliResult = main.CLIs[ i ].startOnosCli( main.ONOSip[ i ],
101 commandlineTimeout=60,
102 onosStartTimeout=100 )
103 utilities.assert_equals( expect=main.TRUE,
104 actual=cliResult,
105 onpass="ONOS CLI is ready",
106 onfail="ONOS CLI is not ready" )
107 main.active = 0
108 for i in range( 10 ):
109 ready = True
Devin Lim58046fa2017-07-05 16:55:00 -0700110 output = main.CLIs[ main.active ].summary()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700111 if not output:
112 ready = False
113 if ready:
114 break
115 time.sleep( 10 )
116 utilities.assert_equals( expect=True, actual=ready,
117 onpass="ONOS summary command succeded",
118 onfail="ONOS summary command failed" )
119
120 with open( "%s/json/%s.json" % (
121 main.dependencyPath, main.cfgName) ) as cfg:
122 main.RESTs[ main.active ].setNetCfg( json.load( cfg ) )
123 with open( "%s/json/%s.chart" % (
124 main.dependencyPath, main.cfgName) ) as chart:
125 main.pingChart = json.load( chart )
126 if not ready:
127 main.log.error( "ONOS startup failed!" )
128 main.cleanup( )
129 main.exit( )
130
131 for i in range( main.numCtrls ):
132 main.CLIs[ i ].logSet( "DEBUG", "org.onosproject.segmentrouting" )
133 main.CLIs[ i ].logSet( "DEBUG", "org.onosproject.driver.pipeline" )
134 main.CLIs[ i ].logSet( "DEBUG", "org.onosproject.store.group.impl" )
135 main.CLIs[ i ].logSet( "DEBUG",
136 "org.onosproject.net.flowobjective.impl" )
137
138 @staticmethod
139 def startMininet( main, topology, args="" ):
140 main.step( "Starting Mininet Topology" )
141 arg = "--onos %d %s" % (main.numCtrls, args)
142 main.topology = topology
143 topoResult = main.Mininet1.startNet(
144 topoFile=main.Mininet1.home + main.topology, args=arg )
145 stepResult = topoResult
146 utilities.assert_equals( expect=main.TRUE,
147 actual=stepResult,
148 onpass="Successfully loaded topology",
149 onfail="Failed to load topology" )
150 # Exit if topology did not load properly
151 if not topoResult:
152 main.cleanup( )
153 main.exit( )
154
155 @staticmethod
Piera2a7e1b2016-10-04 11:51:43 -0700156 def config(main, cfgName, numCtrls):
157 main.spines = []
158
159 main.failures = int(main.params[ 'failures' ])
160 main.cfgName = cfgName
161 main.numCtrls = numCtrls
162
163 if main.cfgName == '2x2' :
164 spine = {}
165 spine[ 'name' ] = main.params['switches'][ 'spine1' ]
166 spine[ 'dpid' ] = main.params['switches'][ 'spinedpid1' ]
167 main.spines.append(spine)
168
169 spine = {}
170 spine[ 'name' ] = main.params['switches'][ 'spine2' ]
171 spine[ 'dpid' ] = main.params['switches'][ 'spinedpid2' ]
172 main.spines.append(spine)
173
174 elif main.cfgName == '4x4' :
175 spine = {}
176 spine[ 'name' ] = main.params['switches'][ 'spine1' ]
177 spine[ 'dpid' ] = main.params['switches'][ 'spinedpid1' ]
178 main.spines.append(spine)
179
180 spine = {}
181 spine[ 'name' ] = main.params['switches'][ 'spine2' ]
182 spine[ 'dpid' ] = main.params['switches'][ 'spinedpid2' ]
183 main.spines.append(spine)
184
185 spine = {}
186 spine[ 'name' ] = main.params['switches'][ 'spine3' ]
187 spine[ 'dpid' ] = main.params['switches'][ 'spinedpid3' ]
188 main.spines.append(spine)
189
190 spine = {}
191 spine[ 'name' ] = main.params['switches'][ 'spine4' ]
192 spine[ 'dpid' ] = main.params['switches'][ 'spinedpid4' ]
193 main.spines.append(spine)
194
195 else :
196 main.log.error( "Configuration failed!" )
197 main.cleanup( )
198 main.exit( )
199
200 @staticmethod
Jon Hall1efcb3f2016-08-23 13:42:15 -0700201 def checkFlows( main, minFlowCount, dumpflows=True ):
202 main.step(
203 " Check whether the flow count is bigger than %s" % minFlowCount )
204 count = utilities.retry( main.CLIs[ main.active ].checkFlowCount,
205 main.FALSE,
206 kwargs={ 'min': minFlowCount },
207 attempts=10,
208 sleep=10 )
209 utilities.assertEquals( \
210 expect=True,
211 actual=(count > 0),
212 onpass="Flow count looks correct: " + str( count ),
213 onfail="Flow count looks wrong: " + str( count ) )
214
215 main.step( "Check whether all flow status are ADDED" )
216 flowCheck = utilities.retry( main.CLIs[ main.active ].checkFlowsState,
217 main.FALSE,
218 kwargs={ 'isPENDING': False },
219 attempts=2,
220 sleep=10 )
221 utilities.assertEquals( \
222 expect=main.TRUE,
223 actual=flowCheck,
224 onpass="Flow status is correct!",
225 onfail="Flow status is wrong!" )
226 if dumpflows:
Pier50f0bc62016-09-07 17:53:40 -0700227 main.ONOSbench.dumpONOSCmd( main.ONOSip[ main.active ],
228 "flows",
229 main.logdir,
230 "flowsBefore" + main.cfgName )
231 main.ONOSbench.dumpONOSCmd( main.ONOSip[ main.active ],
232 "groups",
233 main.logdir,
234 "groupsBefore" + main.cfgName )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700235
236 @staticmethod
237 def pingAll( main, tag="", dumpflows=True ):
238 main.log.report( "Check full connectivity" )
239 print main.pingChart
240 for entry in main.pingChart.itervalues( ):
241 print entry
242 hosts, expect = entry[ 'hosts' ], entry[ 'expect' ]
243 expect = main.TRUE if expect else main.FALSE
244 main.step( "Connectivity for %s %s" % (str( hosts ), tag) )
245 pa = main.Mininet1.pingallHosts( hosts )
246 utilities.assert_equals( expect=expect, actual=pa,
247 onpass="IP connectivity successfully tested",
248 onfail="IP connectivity failed" )
249 if dumpflows:
Pier50f0bc62016-09-07 17:53:40 -0700250 main.ONOSbench.dumpONOSCmd( main.ONOSip[ main.active ],
251 "flows",
252 main.logdir,
253 "flowsOn" + tag )
254 main.ONOSbench.dumpONOSCmd( main.ONOSip[ main.active ],
255 "groups",
256 main.logdir,
257 "groupsOn" + tag )
Jon Hall1efcb3f2016-08-23 13:42:15 -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' ] )
267 main.step( "Kill link between %s and %s" % (end1, end2) )
268 LinkDown = main.Mininet1.link( END1=end1, END2=end2, OPTION="down" )
Pierfb719b12016-09-19 14:51:44 -0700269 LinkDown = main.Mininet1.link( END2=end1, END1=end2, OPTION="down" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700270 main.log.info(
271 "Waiting %s seconds for link down to be discovered" % main.linkSleep )
272 time.sleep( main.linkSleep )
273 topology = utilities.retry( main.CLIs[ main.active ].checkStatus,
274 main.FALSE,
275 kwargs={ 'numoswitch': switches,
276 'numolink': links },
277 attempts=10,
278 sleep=main.linkSleep )
279 result = topology & LinkDown
280 utilities.assert_equals( expect=main.TRUE, actual=result,
281 onpass="Link down successful",
282 onfail="Failed to turn off link?" )
283
284 @staticmethod
285 def restoreLink( main, end1, end2, dpid1, dpid2, port1, port2, switches,
286 links ):
287 """
288 Params:
289 end1,end2: identify the end switches, ex.: 'leaf1', 'spine1'
290 dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002'
291 port1, port2: respective port of the end switches that connects to the link, ex.:'1'
292 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
293 Kill a link and verify ONOS can see the proper link change
294 """
295 main.step( "Restore link between %s and %s" % (end1, end2) )
296 result = False
297 count = 0
298 while True:
299 count += 1
300 main.Mininet1.link( END1=end1, END2=end2, OPTION="up" )
301 main.Mininet1.link( END2=end1, END1=end2, OPTION="up" )
302 main.log.info(
303 "Waiting %s seconds for link up to be discovered" % main.linkSleep )
304 time.sleep( main.linkSleep )
Pierfb719b12016-09-19 14:51:44 -0700305
306 for i in range(0, main.numCtrls):
307 onosIsUp = main.ONOSbench.isup( main.ONOSip[ i ] )
308 if onosIsUp == main.TRUE:
309 main.CLIs[ i ].portstate( dpid=dpid1, port=port1 )
310 main.CLIs[ i ].portstate( dpid=dpid2, port=port2 )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700311 time.sleep( main.linkSleep )
312
313 result = main.CLIs[ main.active ].checkStatus( numoswitch=switches,
314 numolink=links )
315 if count > 5 or result:
316 break
317 utilities.assert_equals( expect=main.TRUE, actual=result,
318 onpass="Link up successful",
319 onfail="Failed to bring link up" )
320
321 @staticmethod
322 def killSwitch( main, switch, switches, links ):
323 """
324 Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6'
325 Completely kill a switch and verify ONOS can see the proper change
326 """
327 main.switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
328 main.step( "Kill " + switch )
329 main.log.info( "Stopping" + switch )
330 main.Mininet1.switch( SW=switch, OPTION="stop" )
331 # todo make this repeatable
332 main.log.info( "Waiting %s seconds for switch down to be discovered" % (
333 main.switchSleep) )
334 time.sleep( main.switchSleep )
335 topology = utilities.retry( main.CLIs[ main.active ].checkStatus,
336 main.FALSE,
337 kwargs={ 'numoswitch': switches,
338 'numolink': links },
339 attempts=10,
340 sleep=main.switchSleep )
341 utilities.assert_equals( expect=main.TRUE, actual=topology,
342 onpass="Kill switch successful",
343 onfail="Failed to kill switch?" )
344
345 @staticmethod
346 def recoverSwitch( main, switch, switches, links ):
347 """
348 Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6'
349 Recover a switch and verify ONOS can see the proper change
350 """
351 # todo make this repeatable
352 main.step( "Recovering " + switch )
353 main.log.info( "Starting" + switch )
354 main.Mininet1.switch( SW=switch, OPTION="start" )
355 main.log.info( "Waiting %s seconds for switch up to be discovered" % (
356 main.switchSleep) )
357 time.sleep( main.switchSleep )
358 topology = utilities.retry( main.CLIs[ main.active ].checkStatus,
359 main.FALSE,
360 kwargs={ 'numoswitch': switches,
361 'numolink': links },
362 attempts=10,
363 sleep=main.switchSleep )
364 utilities.assert_equals( expect=main.TRUE, actual=topology,
365 onpass="Switch recovery successful",
366 onfail="Failed to recover switch?" )
367
368 @staticmethod
369 def cleanup( main ):
370 """
371 Stop Onos-cluster.
372 Stops Mininet
373 Copies ONOS log
374 """
Devin Lim58046fa2017-07-05 16:55:00 -0700375 try:
376 from tests.dependencies.utils import Utils
377 except ImportError:
378 main.log.error( "Utils not found exiting the test" )
379 main.exit()
380 try:
381 main.Utils
382 except ( NameError, AttributeError ):
383 main.Utils = Utils()
384
385 main.utils.mininetCleanup( main.Mininet1 )
386
387 main.utils.copyKarafLog()
388
Jon Hall1efcb3f2016-08-23 13:42:15 -0700389 for i in range( main.numCtrls ):
390 main.ONOSbench.onosStop( main.ONOSip[ i ] )
391
392 @staticmethod
393 def killOnos( main, nodes, switches, links, expNodes ):
394 """
395 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
396 switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6'
397 Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change
398 """
Pier3b58c652016-09-26 12:03:31 -0700399
Jon Hall1efcb3f2016-08-23 13:42:15 -0700400 main.step( "Killing ONOS instance" )
Pier3b58c652016-09-26 12:03:31 -0700401
Jon Hall1efcb3f2016-08-23 13:42:15 -0700402 for i in nodes:
403 killResult = main.ONOSbench.onosDie( main.CLIs[ i ].ip_address )
404 utilities.assert_equals( expect=main.TRUE, actual=killResult,
405 onpass="ONOS instance Killed",
406 onfail="Error killing ONOS instance" )
407 if i == main.active:
408 main.active = (i + 1) % main.numCtrls
409 time.sleep( 12 )
Pier3b58c652016-09-26 12:03:31 -0700410
Jon Hall1efcb3f2016-08-23 13:42:15 -0700411 if len( nodes ) < main.numCtrls:
Pier3b58c652016-09-26 12:03:31 -0700412
413 nodesToCheck = []
414 for x in range(0, main.numCtrls):
415 if x not in nodes:
416 nodesToCheck.append(x)
417 nodeResults = utilities.retry( Testcaselib.nodesCheck,
418 False,
419 args=[nodesToCheck],
420 attempts=5,
421 sleep=10 )
422 utilities.assert_equals( expect=True, actual=nodeResults,
423 onpass="Nodes check successful",
424 onfail="Nodes check NOT successful" )
425
426 if not nodeResults:
427 for i in nodes:
428 cli = main.CLIs[i]
429 main.log.debug( "{} components not ACTIVE: \n{}".format(
430 cli.name,
431 cli.sendline( "scr:list | grep -v ACTIVE" ) ) )
432 main.log.error( "Failed to kill ONOS, stopping test" )
433 main.cleanup()
434 main.exit()
435
Jon Hall1efcb3f2016-08-23 13:42:15 -0700436 topology = utilities.retry( main.CLIs[ main.active ].checkStatus,
437 main.FALSE,
438 kwargs={ 'numoswitch': switches,
439 'numolink': links,
440 'numoctrl': expNodes },
441 attempts=10,
442 sleep=12 )
443 utilities.assert_equals( expect=main.TRUE, actual=topology,
444 onpass="ONOS Instance down successful",
445 onfail="Failed to turn off ONOS Instance" )
446 else:
447 main.active = -1
448
449 @staticmethod
450 def recoverOnos( main, nodes, switches, links, expNodes ):
451 """
452 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
453 switches, links, nodes: number of expected switches, links and nodes after recoverOnos, ex.: '4', '6'
454 Recover an ONOS instance and verify the ONOS cluster can see the proper change
455 """
456 main.step( "Recovering ONOS instance" )
457 [ main.ONOSbench.onosStart( main.CLIs[ i ].ip_address ) for i in nodes ]
458 for i in nodes:
459 isUp = main.ONOSbench.isup( main.ONOSip[ i ] )
460 utilities.assert_equals( expect=main.TRUE, actual=isUp,
461 onpass="ONOS service is ready",
462 onfail="ONOS service did not start properly" )
463 for i in nodes:
464 main.step( "Checking if ONOS CLI is ready" )
465 main.CLIs[ i ].startCellCli( )
466 cliResult = main.CLIs[ i ].startOnosCli( main.ONOSip[ i ],
467 commandlineTimeout=60,
468 onosStartTimeout=100 )
469 utilities.assert_equals( expect=main.TRUE,
470 actual=cliResult,
471 onpass="ONOS CLI is ready",
472 onfail="ONOS CLI is not ready" )
473 main.active = i if main.active == -1 else main.active
474
Pier3b58c652016-09-26 12:03:31 -0700475 main.step( "Checking ONOS nodes" )
476 nodeResults = utilities.retry( Testcaselib.nodesCheck,
477 False,
478 args=[nodes],
479 attempts=5,
480 sleep=10 )
481 utilities.assert_equals( expect=True, actual=nodeResults,
482 onpass="Nodes check successful",
483 onfail="Nodes check NOT successful" )
484
485 if not nodeResults:
486 for i in nodes:
487 cli = main.CLIs[i]
488 main.log.debug( "{} components not ACTIVE: \n{}".format(
489 cli.name,
490 cli.sendline( "scr:list | grep -v ACTIVE" ) ) )
491 main.log.error( "Failed to start ONOS, stopping test" )
492 main.cleanup()
493 main.exit()
494
Jon Hall1efcb3f2016-08-23 13:42:15 -0700495 topology = utilities.retry( main.CLIs[ main.active ].checkStatus,
496 main.FALSE,
497 kwargs={ 'numoswitch': switches,
498 'numolink': links,
499 'numoctrl': expNodes },
500 attempts=10,
501 sleep=12 )
502 utilities.assert_equals( expect=main.TRUE, actual=topology,
503 onpass="ONOS Instance down successful",
504 onfail="Failed to turn off ONOS Instance" )
505 for i in range( 10 ):
506 ready = True
507 output = main.CLIs[ main.active ].summary( )
508 if not output:
509 ready = False
510 if ready:
511 break
512 time.sleep( 10 )
513 utilities.assert_equals( expect=True, actual=ready,
514 onpass="ONOS summary command succeded",
515 onfail="ONOS summary command failed" )
516 if not ready:
517 main.log.error( "ONOS startup failed!" )
518 main.cleanup( )
519 main.exit( )
520
521 @staticmethod
522 def addHostCfg( main ):
523 """
524 Adds Host Configuration to ONOS
525 Updates expected state of the network (pingChart)
526 """
527 import json
528 hostCfg = { }
529 with open( main.dependencyPath + "/json/extra.json" ) as template:
530 hostCfg = json.load( template )
531 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ]
532 main.step( "Pushing new configuration" )
533 mac, cfg = hostCfg[ 'hosts' ].popitem( )
534 main.RESTs[ main.active ].setNetCfg( cfg[ 'basic' ],
535 subjectClass="hosts",
536 subjectKey=urllib.quote( mac,
537 safe='' ),
538 configKey="basic" )
539 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ]
540 main.step( "Pushing new configuration" )
541 mac, cfg = hostCfg[ 'hosts' ].popitem( )
542 main.RESTs[ main.active ].setNetCfg( cfg[ 'basic' ],
543 subjectClass="hosts",
544 subjectKey=urllib.quote( mac,
545 safe='' ),
546 configKey="basic" )
547 main.pingChart.update( { 'vlan1': { "expect": "True",
548 "hosts": [ "olt1", "vsg1" ] } } )
549 main.pingChart[ 'vlan5' ][ 'expect' ] = 0
550 main.pingChart[ 'vlan10' ][ 'expect' ] = 0
551 ports = "[%s,%s]" % (5, 6)
552 cfg = '{"of:0000000000000001":[{"vlan":1,"ports":%s,"name":"OLT 1"}]}' % ports
553 main.RESTs[ main.active ].setNetCfg( json.loads( cfg ),
554 subjectClass="apps",
555 subjectKey="org.onosproject.segmentrouting",
556 configKey="xconnect" )
557
558 @staticmethod
559 def delHostCfg( main ):
560 """
561 Removest Host Configuration from ONOS
562 Updates expected state of the network (pingChart)
563 """
564 import json
565 hostCfg = { }
566 with open( main.dependencyPath + "/json/extra.json" ) as template:
567 hostCfg = json.load( template )
568 main.step( "Removing host configuration" )
569 main.pingChart[ 'ip' ][ 'expect' ] = 0
570 mac, cfg = hostCfg[ 'hosts' ].popitem( )
571 main.RESTs[ main.active ].removeNetCfg( subjectClass="hosts",
572 subjectKey=urllib.quote(
573 mac,
574 safe='' ),
575 configKey="basic" )
576 main.step( "Removing configuration" )
577 main.pingChart[ 'ip' ][ 'expect' ] = 0
578 mac, cfg = hostCfg[ 'hosts' ].popitem( )
579 main.RESTs[ main.active ].removeNetCfg( subjectClass="hosts",
580 subjectKey=urllib.quote(
581 mac,
582 safe='' ),
583 configKey="basic" )
584 main.step( "Removing vlan configuration" )
585 main.pingChart[ 'vlan1' ][ 'expect' ] = 0
586 main.RESTs[ main.active ].removeNetCfg( subjectClass="apps",
587 subjectKey="org.onosproject.segmentrouting",
588 configKey="xconnect" )
Pier3b58c652016-09-26 12:03:31 -0700589 @staticmethod
590 def nodesCheck( nodes ):
591 nodesOutput = []
592 results = True
593 threads = []
594 for i in nodes:
595 t = main.Thread( target=main.CLIs[i].nodes,
596 name="nodes-" + str( i ),
597 args=[ ] )
598 threads.append( t )
599 t.start()
600
601 for t in threads:
602 t.join()
603 nodesOutput.append( t.result )
604 ips = [ main.ONOSip[ node ] for node in nodes ]
605 ips.sort()
606 for i in nodesOutput:
607 try:
608 current = json.loads( i )
609 activeIps = []
610 currentResult = False
611 for node in current:
612 if node['state'] == 'READY':
613 activeIps.append( node['ip'] )
614 currentResult = True
615 for ip in ips:
616 if ip not in activeIps:
617 currentResult = False
618 break
619 except ( ValueError, TypeError ):
620 main.log.error( "Error parsing nodes output" )
621 main.log.warn( repr( i ) )
622 currentResult = False
623 results = results and currentResult
624 return results