blob: c9d52d317820def50c9f25de6d00211880240c81 [file] [log] [blame]
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07001"""
2Copyright 2016 Open Networking Foundation (ONF)
3
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
7
8 TestON is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
12
13 TestON is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with TestON. If not, see <http://www.gnu.org/licenses/>.
20"""
21
Jon Hall1efcb3f2016-08-23 13:42:15 -070022import os
23import imp
24import time
25import json
26import urllib
27from core import utilities
28
29
30class Testcaselib:
Pierfb719b12016-09-19 14:51:44 -070031
You Wangf5de25b2017-01-06 15:13:01 -080032 useSSH=True
Pierfb719b12016-09-19 14:51:44 -070033
Jon Hall1efcb3f2016-08-23 13:42:15 -070034 @staticmethod
35 def initTest( main ):
36 """
37 - Construct tests variables
38 - GIT ( optional )
39 - Checkout ONOS master branch
40 - Pull latest ONOS code
41 - Building ONOS ( optional )
42 - Install ONOS package
43 - Build ONOS package
44 """
Devin Lim58046fa2017-07-05 16:55:00 -070045 try:
46 from tests.dependencies.ONOSSetup import ONOSSetup
47 main.testSetUp = ONOSSetup()
48 except ImportError:
49 main.log.error( "ONOSSetup not found. exiting the test" )
50 main.exit()
51 main.testSetUp.envSetupDescription()
52 stepResult = main.FALSE
53 try:
54 main.step( "Constructing test variables" )
55 # Test variables
56 main.cellName = main.params[ 'ENV' ][ 'cellName' ]
57 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
58 main.diff = main.params[ 'ENV' ][ 'diffApps' ]
59 main.path = os.path.dirname( main.testFile )
60 main.dependencyPath = main.path + "/../dependencies/"
61 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
62 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
63 main.scale = (main.params[ 'SCALE' ][ 'size' ]).split( "," )
64 main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
65 # main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
66 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
67 # -- INIT SECTION, ONLY RUNS ONCE -- #
Jon Hall1efcb3f2016-08-23 13:42:15 -070068
Devin Lim58046fa2017-07-05 16:55:00 -070069 copyResult1 = main.ONOSbench.scp( main.Mininet1,
70 main.dependencyPath +
71 main.topology,
72 main.Mininet1.home,
73 direction="to" )
74 stepResult = main.testSetUp.envSetup( hasRest=True )
75 except Exception as e:
76 main.testSetUp.envSetupException( e )
77 main.testSetUp.evnSetupConclusion( stepResult )
Jon Hall1efcb3f2016-08-23 13:42:15 -070078
Jon Hall1efcb3f2016-08-23 13:42:15 -070079
Jon Hall1efcb3f2016-08-23 13:42:15 -070080
81 @staticmethod
82 def installOnos( main, vlanCfg=True ):
83 """
84 - Set up cell
85 - Create cell file
86 - Set cell file
87 - Verify cell file
88 - Kill ONOS process
89 - Uninstall ONOS cluster
90 - Verify ONOS start up
91 - Install ONOS cluster
92 - Connect to cli
93 """
94 # main.scale[ 0 ] determines the current number of ONOS controller
Jon Hall1efcb3f2016-08-23 13:42:15 -070095 if main.diff:
Devin Lim58046fa2017-07-05 16:55:00 -070096 main.apps = main.apps + "," + main.diff
Jon Hall1efcb3f2016-08-23 13:42:15 -070097 else:
98 main.log.error( "App list is empty" )
99 print "NODE COUNT = ", main.numCtrls
100 print main.ONOSip
Jon Hall1efcb3f2016-08-23 13:42:15 -0700101 main.dynamicHosts = [ 'in1', 'out1' ]
Devin Lim58046fa2017-07-05 16:55:00 -0700102 main.testSetUp.createApplyCell( newCell=True, cellName=main.cellName,
103 Mininet=main.Mininet1, useSSH=Testcaselib.useSSH )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700104 # kill off all onos processes
105 main.log.info( "Safety check, killing all ONOS processes" +
106 " before initiating environment setup" )
107 for i in range( main.maxNodes ):
108 main.ONOSbench.onosDie( main.ONOSip[ i ] )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700109
Devin Lim58046fa2017-07-05 16:55:00 -0700110 main.testSetUp.buildOnos()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700111
Devin Lim58046fa2017-07-05 16:55:00 -0700112 main.testSetUp.installOnos( False )
113
114 main.testSetUp.setupSsh()
115
116 main.testSetUp.checkOnosService()
117
Jon Hall1efcb3f2016-08-23 13:42:15 -0700118 main.step( "Checking if ONOS CLI is ready" )
119 for i in range( main.numCtrls ):
120 main.CLIs[ i ].startCellCli( )
121 cliResult = main.CLIs[ i ].startOnosCli( main.ONOSip[ i ],
122 commandlineTimeout=60,
123 onosStartTimeout=100 )
124 utilities.assert_equals( expect=main.TRUE,
125 actual=cliResult,
126 onpass="ONOS CLI is ready",
127 onfail="ONOS CLI is not ready" )
128 main.active = 0
129 for i in range( 10 ):
130 ready = True
Devin Lim58046fa2017-07-05 16:55:00 -0700131 output = main.CLIs[ main.active ].summary()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700132 if not output:
133 ready = False
134 if ready:
135 break
136 time.sleep( 10 )
137 utilities.assert_equals( expect=True, actual=ready,
138 onpass="ONOS summary command succeded",
139 onfail="ONOS summary command failed" )
140
141 with open( "%s/json/%s.json" % (
142 main.dependencyPath, main.cfgName) ) as cfg:
143 main.RESTs[ main.active ].setNetCfg( json.load( cfg ) )
144 with open( "%s/json/%s.chart" % (
145 main.dependencyPath, main.cfgName) ) as chart:
146 main.pingChart = json.load( chart )
147 if not ready:
148 main.log.error( "ONOS startup failed!" )
149 main.cleanup( )
150 main.exit( )
151
152 for i in range( main.numCtrls ):
153 main.CLIs[ i ].logSet( "DEBUG", "org.onosproject.segmentrouting" )
154 main.CLIs[ i ].logSet( "DEBUG", "org.onosproject.driver.pipeline" )
155 main.CLIs[ i ].logSet( "DEBUG", "org.onosproject.store.group.impl" )
156 main.CLIs[ i ].logSet( "DEBUG",
157 "org.onosproject.net.flowobjective.impl" )
158
159 @staticmethod
160 def startMininet( main, topology, args="" ):
161 main.step( "Starting Mininet Topology" )
162 arg = "--onos %d %s" % (main.numCtrls, args)
163 main.topology = topology
164 topoResult = main.Mininet1.startNet(
165 topoFile=main.Mininet1.home + main.topology, args=arg )
166 stepResult = topoResult
167 utilities.assert_equals( expect=main.TRUE,
168 actual=stepResult,
169 onpass="Successfully loaded topology",
170 onfail="Failed to load topology" )
171 # Exit if topology did not load properly
172 if not topoResult:
173 main.cleanup( )
174 main.exit( )
175
176 @staticmethod
Piera2a7e1b2016-10-04 11:51:43 -0700177 def config(main, cfgName, numCtrls):
178 main.spines = []
179
180 main.failures = int(main.params[ 'failures' ])
181 main.cfgName = cfgName
182 main.numCtrls = numCtrls
183
184 if main.cfgName == '2x2' :
185 spine = {}
186 spine[ 'name' ] = main.params['switches'][ 'spine1' ]
187 spine[ 'dpid' ] = main.params['switches'][ 'spinedpid1' ]
188 main.spines.append(spine)
189
190 spine = {}
191 spine[ 'name' ] = main.params['switches'][ 'spine2' ]
192 spine[ 'dpid' ] = main.params['switches'][ 'spinedpid2' ]
193 main.spines.append(spine)
194
195 elif main.cfgName == '4x4' :
196 spine = {}
197 spine[ 'name' ] = main.params['switches'][ 'spine1' ]
198 spine[ 'dpid' ] = main.params['switches'][ 'spinedpid1' ]
199 main.spines.append(spine)
200
201 spine = {}
202 spine[ 'name' ] = main.params['switches'][ 'spine2' ]
203 spine[ 'dpid' ] = main.params['switches'][ 'spinedpid2' ]
204 main.spines.append(spine)
205
206 spine = {}
207 spine[ 'name' ] = main.params['switches'][ 'spine3' ]
208 spine[ 'dpid' ] = main.params['switches'][ 'spinedpid3' ]
209 main.spines.append(spine)
210
211 spine = {}
212 spine[ 'name' ] = main.params['switches'][ 'spine4' ]
213 spine[ 'dpid' ] = main.params['switches'][ 'spinedpid4' ]
214 main.spines.append(spine)
215
216 else :
217 main.log.error( "Configuration failed!" )
218 main.cleanup( )
219 main.exit( )
220
221 @staticmethod
Jon Hall1efcb3f2016-08-23 13:42:15 -0700222 def checkFlows( main, minFlowCount, dumpflows=True ):
223 main.step(
224 " Check whether the flow count is bigger than %s" % minFlowCount )
225 count = utilities.retry( main.CLIs[ main.active ].checkFlowCount,
226 main.FALSE,
227 kwargs={ 'min': minFlowCount },
228 attempts=10,
229 sleep=10 )
230 utilities.assertEquals( \
231 expect=True,
232 actual=(count > 0),
233 onpass="Flow count looks correct: " + str( count ),
234 onfail="Flow count looks wrong: " + str( count ) )
235
236 main.step( "Check whether all flow status are ADDED" )
237 flowCheck = utilities.retry( main.CLIs[ main.active ].checkFlowsState,
238 main.FALSE,
239 kwargs={ 'isPENDING': False },
240 attempts=2,
241 sleep=10 )
242 utilities.assertEquals( \
243 expect=main.TRUE,
244 actual=flowCheck,
245 onpass="Flow status is correct!",
246 onfail="Flow status is wrong!" )
247 if dumpflows:
Pier50f0bc62016-09-07 17:53:40 -0700248 main.ONOSbench.dumpONOSCmd( main.ONOSip[ main.active ],
249 "flows",
250 main.logdir,
251 "flowsBefore" + main.cfgName )
252 main.ONOSbench.dumpONOSCmd( main.ONOSip[ main.active ],
253 "groups",
254 main.logdir,
255 "groupsBefore" + main.cfgName )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700256
257 @staticmethod
258 def pingAll( main, tag="", dumpflows=True ):
259 main.log.report( "Check full connectivity" )
260 print main.pingChart
261 for entry in main.pingChart.itervalues( ):
262 print entry
263 hosts, expect = entry[ 'hosts' ], entry[ 'expect' ]
264 expect = main.TRUE if expect else main.FALSE
265 main.step( "Connectivity for %s %s" % (str( hosts ), tag) )
266 pa = main.Mininet1.pingallHosts( hosts )
267 utilities.assert_equals( expect=expect, actual=pa,
268 onpass="IP connectivity successfully tested",
269 onfail="IP connectivity failed" )
270 if dumpflows:
Pier50f0bc62016-09-07 17:53:40 -0700271 main.ONOSbench.dumpONOSCmd( main.ONOSip[ main.active ],
272 "flows",
273 main.logdir,
274 "flowsOn" + tag )
275 main.ONOSbench.dumpONOSCmd( main.ONOSip[ main.active ],
276 "groups",
277 main.logdir,
278 "groupsOn" + tag )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700279
280 @staticmethod
281 def killLink( main, end1, end2, switches, links ):
282 """
283 end1,end2: identify the switches, ex.: 'leaf1', 'spine1'
284 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
285 Kill a link and verify ONOS can see the proper link change
286 """
287 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
288 main.step( "Kill link between %s and %s" % (end1, end2) )
289 LinkDown = main.Mininet1.link( END1=end1, END2=end2, OPTION="down" )
Pierfb719b12016-09-19 14:51:44 -0700290 LinkDown = main.Mininet1.link( END2=end1, END1=end2, OPTION="down" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700291 main.log.info(
292 "Waiting %s seconds for link down to be discovered" % main.linkSleep )
293 time.sleep( main.linkSleep )
294 topology = utilities.retry( main.CLIs[ main.active ].checkStatus,
295 main.FALSE,
296 kwargs={ 'numoswitch': switches,
297 'numolink': links },
298 attempts=10,
299 sleep=main.linkSleep )
300 result = topology & LinkDown
301 utilities.assert_equals( expect=main.TRUE, actual=result,
302 onpass="Link down successful",
303 onfail="Failed to turn off link?" )
304
305 @staticmethod
306 def restoreLink( main, end1, end2, dpid1, dpid2, port1, port2, switches,
307 links ):
308 """
309 Params:
310 end1,end2: identify the end switches, ex.: 'leaf1', 'spine1'
311 dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002'
312 port1, port2: respective port of the end switches that connects to the link, ex.:'1'
313 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
314 Kill a link and verify ONOS can see the proper link change
315 """
316 main.step( "Restore link between %s and %s" % (end1, end2) )
317 result = False
318 count = 0
319 while True:
320 count += 1
321 main.Mininet1.link( END1=end1, END2=end2, OPTION="up" )
322 main.Mininet1.link( END2=end1, END1=end2, OPTION="up" )
323 main.log.info(
324 "Waiting %s seconds for link up to be discovered" % main.linkSleep )
325 time.sleep( main.linkSleep )
Pierfb719b12016-09-19 14:51:44 -0700326
327 for i in range(0, main.numCtrls):
328 onosIsUp = main.ONOSbench.isup( main.ONOSip[ i ] )
329 if onosIsUp == main.TRUE:
330 main.CLIs[ i ].portstate( dpid=dpid1, port=port1 )
331 main.CLIs[ i ].portstate( dpid=dpid2, port=port2 )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700332 time.sleep( main.linkSleep )
333
334 result = main.CLIs[ main.active ].checkStatus( numoswitch=switches,
335 numolink=links )
336 if count > 5 or result:
337 break
338 utilities.assert_equals( expect=main.TRUE, actual=result,
339 onpass="Link up successful",
340 onfail="Failed to bring link up" )
341
342 @staticmethod
343 def killSwitch( main, switch, switches, links ):
344 """
345 Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6'
346 Completely kill a switch and verify ONOS can see the proper change
347 """
348 main.switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
349 main.step( "Kill " + switch )
350 main.log.info( "Stopping" + switch )
351 main.Mininet1.switch( SW=switch, OPTION="stop" )
352 # todo make this repeatable
353 main.log.info( "Waiting %s seconds for switch down to be discovered" % (
354 main.switchSleep) )
355 time.sleep( main.switchSleep )
356 topology = utilities.retry( main.CLIs[ main.active ].checkStatus,
357 main.FALSE,
358 kwargs={ 'numoswitch': switches,
359 'numolink': links },
360 attempts=10,
361 sleep=main.switchSleep )
362 utilities.assert_equals( expect=main.TRUE, actual=topology,
363 onpass="Kill switch successful",
364 onfail="Failed to kill switch?" )
365
366 @staticmethod
367 def recoverSwitch( main, switch, switches, links ):
368 """
369 Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6'
370 Recover a switch and verify ONOS can see the proper change
371 """
372 # todo make this repeatable
373 main.step( "Recovering " + switch )
374 main.log.info( "Starting" + switch )
375 main.Mininet1.switch( SW=switch, OPTION="start" )
376 main.log.info( "Waiting %s seconds for switch up to be discovered" % (
377 main.switchSleep) )
378 time.sleep( main.switchSleep )
379 topology = utilities.retry( main.CLIs[ main.active ].checkStatus,
380 main.FALSE,
381 kwargs={ 'numoswitch': switches,
382 'numolink': links },
383 attempts=10,
384 sleep=main.switchSleep )
385 utilities.assert_equals( expect=main.TRUE, actual=topology,
386 onpass="Switch recovery successful",
387 onfail="Failed to recover switch?" )
388
389 @staticmethod
390 def cleanup( main ):
391 """
392 Stop Onos-cluster.
393 Stops Mininet
394 Copies ONOS log
395 """
Devin Lim58046fa2017-07-05 16:55:00 -0700396 try:
397 from tests.dependencies.utils import Utils
398 except ImportError:
399 main.log.error( "Utils not found exiting the test" )
400 main.exit()
401 try:
402 main.Utils
403 except ( NameError, AttributeError ):
404 main.Utils = Utils()
405
406 main.utils.mininetCleanup( main.Mininet1 )
407
408 main.utils.copyKarafLog()
409
Jon Hall1efcb3f2016-08-23 13:42:15 -0700410 for i in range( main.numCtrls ):
411 main.ONOSbench.onosStop( main.ONOSip[ i ] )
412
413 @staticmethod
414 def killOnos( main, nodes, switches, links, expNodes ):
415 """
416 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
417 switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6'
418 Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change
419 """
Pier3b58c652016-09-26 12:03:31 -0700420
Jon Hall1efcb3f2016-08-23 13:42:15 -0700421 main.step( "Killing ONOS instance" )
Pier3b58c652016-09-26 12:03:31 -0700422
Jon Hall1efcb3f2016-08-23 13:42:15 -0700423 for i in nodes:
424 killResult = main.ONOSbench.onosDie( main.CLIs[ i ].ip_address )
425 utilities.assert_equals( expect=main.TRUE, actual=killResult,
426 onpass="ONOS instance Killed",
427 onfail="Error killing ONOS instance" )
428 if i == main.active:
429 main.active = (i + 1) % main.numCtrls
430 time.sleep( 12 )
Pier3b58c652016-09-26 12:03:31 -0700431
Jon Hall1efcb3f2016-08-23 13:42:15 -0700432 if len( nodes ) < main.numCtrls:
Pier3b58c652016-09-26 12:03:31 -0700433
434 nodesToCheck = []
435 for x in range(0, main.numCtrls):
436 if x not in nodes:
437 nodesToCheck.append(x)
438 nodeResults = utilities.retry( Testcaselib.nodesCheck,
439 False,
440 args=[nodesToCheck],
441 attempts=5,
442 sleep=10 )
443 utilities.assert_equals( expect=True, actual=nodeResults,
444 onpass="Nodes check successful",
445 onfail="Nodes check NOT successful" )
446
447 if not nodeResults:
448 for i in nodes:
449 cli = main.CLIs[i]
450 main.log.debug( "{} components not ACTIVE: \n{}".format(
451 cli.name,
452 cli.sendline( "scr:list | grep -v ACTIVE" ) ) )
453 main.log.error( "Failed to kill ONOS, stopping test" )
454 main.cleanup()
455 main.exit()
456
Jon Hall1efcb3f2016-08-23 13:42:15 -0700457 topology = utilities.retry( main.CLIs[ main.active ].checkStatus,
458 main.FALSE,
459 kwargs={ 'numoswitch': switches,
460 'numolink': links,
461 'numoctrl': expNodes },
462 attempts=10,
463 sleep=12 )
464 utilities.assert_equals( expect=main.TRUE, actual=topology,
465 onpass="ONOS Instance down successful",
466 onfail="Failed to turn off ONOS Instance" )
467 else:
468 main.active = -1
469
470 @staticmethod
471 def recoverOnos( main, nodes, switches, links, expNodes ):
472 """
473 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
474 switches, links, nodes: number of expected switches, links and nodes after recoverOnos, ex.: '4', '6'
475 Recover an ONOS instance and verify the ONOS cluster can see the proper change
476 """
477 main.step( "Recovering ONOS instance" )
478 [ main.ONOSbench.onosStart( main.CLIs[ i ].ip_address ) for i in nodes ]
479 for i in nodes:
480 isUp = main.ONOSbench.isup( main.ONOSip[ i ] )
481 utilities.assert_equals( expect=main.TRUE, actual=isUp,
482 onpass="ONOS service is ready",
483 onfail="ONOS service did not start properly" )
484 for i in nodes:
485 main.step( "Checking if ONOS CLI is ready" )
486 main.CLIs[ i ].startCellCli( )
487 cliResult = main.CLIs[ i ].startOnosCli( main.ONOSip[ i ],
488 commandlineTimeout=60,
489 onosStartTimeout=100 )
490 utilities.assert_equals( expect=main.TRUE,
491 actual=cliResult,
492 onpass="ONOS CLI is ready",
493 onfail="ONOS CLI is not ready" )
494 main.active = i if main.active == -1 else main.active
495
Pier3b58c652016-09-26 12:03:31 -0700496 main.step( "Checking ONOS nodes" )
497 nodeResults = utilities.retry( Testcaselib.nodesCheck,
498 False,
499 args=[nodes],
500 attempts=5,
501 sleep=10 )
502 utilities.assert_equals( expect=True, actual=nodeResults,
503 onpass="Nodes check successful",
504 onfail="Nodes check NOT successful" )
505
506 if not nodeResults:
507 for i in nodes:
508 cli = main.CLIs[i]
509 main.log.debug( "{} components not ACTIVE: \n{}".format(
510 cli.name,
511 cli.sendline( "scr:list | grep -v ACTIVE" ) ) )
512 main.log.error( "Failed to start ONOS, stopping test" )
513 main.cleanup()
514 main.exit()
515
Jon Hall1efcb3f2016-08-23 13:42:15 -0700516 topology = utilities.retry( main.CLIs[ main.active ].checkStatus,
517 main.FALSE,
518 kwargs={ 'numoswitch': switches,
519 'numolink': links,
520 'numoctrl': expNodes },
521 attempts=10,
522 sleep=12 )
523 utilities.assert_equals( expect=main.TRUE, actual=topology,
524 onpass="ONOS Instance down successful",
525 onfail="Failed to turn off ONOS Instance" )
526 for i in range( 10 ):
527 ready = True
528 output = main.CLIs[ main.active ].summary( )
529 if not output:
530 ready = False
531 if ready:
532 break
533 time.sleep( 10 )
534 utilities.assert_equals( expect=True, actual=ready,
535 onpass="ONOS summary command succeded",
536 onfail="ONOS summary command failed" )
537 if not ready:
538 main.log.error( "ONOS startup failed!" )
539 main.cleanup( )
540 main.exit( )
541
542 @staticmethod
543 def addHostCfg( main ):
544 """
545 Adds Host Configuration to ONOS
546 Updates expected state of the network (pingChart)
547 """
548 import json
549 hostCfg = { }
550 with open( main.dependencyPath + "/json/extra.json" ) as template:
551 hostCfg = json.load( template )
552 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ]
553 main.step( "Pushing new configuration" )
554 mac, cfg = hostCfg[ 'hosts' ].popitem( )
555 main.RESTs[ main.active ].setNetCfg( cfg[ 'basic' ],
556 subjectClass="hosts",
557 subjectKey=urllib.quote( mac,
558 safe='' ),
559 configKey="basic" )
560 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ]
561 main.step( "Pushing new configuration" )
562 mac, cfg = hostCfg[ 'hosts' ].popitem( )
563 main.RESTs[ main.active ].setNetCfg( cfg[ 'basic' ],
564 subjectClass="hosts",
565 subjectKey=urllib.quote( mac,
566 safe='' ),
567 configKey="basic" )
568 main.pingChart.update( { 'vlan1': { "expect": "True",
569 "hosts": [ "olt1", "vsg1" ] } } )
570 main.pingChart[ 'vlan5' ][ 'expect' ] = 0
571 main.pingChart[ 'vlan10' ][ 'expect' ] = 0
572 ports = "[%s,%s]" % (5, 6)
573 cfg = '{"of:0000000000000001":[{"vlan":1,"ports":%s,"name":"OLT 1"}]}' % ports
574 main.RESTs[ main.active ].setNetCfg( json.loads( cfg ),
575 subjectClass="apps",
576 subjectKey="org.onosproject.segmentrouting",
577 configKey="xconnect" )
578
579 @staticmethod
580 def delHostCfg( main ):
581 """
582 Removest Host Configuration from ONOS
583 Updates expected state of the network (pingChart)
584 """
585 import json
586 hostCfg = { }
587 with open( main.dependencyPath + "/json/extra.json" ) as template:
588 hostCfg = json.load( template )
589 main.step( "Removing host configuration" )
590 main.pingChart[ 'ip' ][ 'expect' ] = 0
591 mac, cfg = hostCfg[ 'hosts' ].popitem( )
592 main.RESTs[ main.active ].removeNetCfg( subjectClass="hosts",
593 subjectKey=urllib.quote(
594 mac,
595 safe='' ),
596 configKey="basic" )
597 main.step( "Removing configuration" )
598 main.pingChart[ 'ip' ][ 'expect' ] = 0
599 mac, cfg = hostCfg[ 'hosts' ].popitem( )
600 main.RESTs[ main.active ].removeNetCfg( subjectClass="hosts",
601 subjectKey=urllib.quote(
602 mac,
603 safe='' ),
604 configKey="basic" )
605 main.step( "Removing vlan configuration" )
606 main.pingChart[ 'vlan1' ][ 'expect' ] = 0
607 main.RESTs[ main.active ].removeNetCfg( subjectClass="apps",
608 subjectKey="org.onosproject.segmentrouting",
609 configKey="xconnect" )
Pier3b58c652016-09-26 12:03:31 -0700610 @staticmethod
611 def nodesCheck( nodes ):
612 nodesOutput = []
613 results = True
614 threads = []
615 for i in nodes:
616 t = main.Thread( target=main.CLIs[i].nodes,
617 name="nodes-" + str( i ),
618 args=[ ] )
619 threads.append( t )
620 t.start()
621
622 for t in threads:
623 t.join()
624 nodesOutput.append( t.result )
625 ips = [ main.ONOSip[ node ] for node in nodes ]
626 ips.sort()
627 for i in nodesOutput:
628 try:
629 current = json.loads( i )
630 activeIps = []
631 currentResult = False
632 for node in current:
633 if node['state'] == 'READY':
634 activeIps.append( node['ip'] )
635 currentResult = True
636 for ip in ips:
637 if ip not in activeIps:
638 currentResult = False
639 break
640 except ( ValueError, TypeError ):
641 main.log.error( "Error parsing nodes output" )
642 main.log.warn( repr( i ) )
643 currentResult = False
644 results = results and currentResult
645 return results