blob: 77e45eaa0641eec34a5adcbe391b8205f0b950c0 [file] [log] [blame]
Jon Hall66e001c2015-11-12 09:45:10 -08001
2# Testing the basic intent functionality of ONOS
3
4class FUNCnetCfg:
5
6 def __init__( self ):
7 self.default = ''
8
9 def CASE1( self, main ):
10 import imp
11 import re
12
13 """
14 - Construct tests variables
15 - GIT ( optional )
16 - Checkout ONOS master branch
17 - Pull latest ONOS code
18 - Building ONOS ( optional )
19 - Install ONOS package
20 - Build ONOS package
21 """
22
23 main.case( "Constructing test variables and building ONOS package" )
24 main.step( "Constructing test variables" )
25 main.caseExplanation = "This test case is mainly for loading " +\
26 "from params file, and pull and build the " +\
27 " latest ONOS package"
28 stepResult = main.FALSE
29
30 # Test variables
31 try:
32 main.testOnDirectory = re.sub( "(/tests)$", "", main.testDir )
33 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
34 gitBranch = main.params[ 'GIT' ][ 'branch' ]
35 main.dependencyPath = main.testOnDirectory + \
36 main.params[ 'DEPENDENCY' ][ 'path' ]
37 if main.ONOSbench.maxNodes:
38 main.maxNodes = int( main.ONOSbench.maxNodes )
39 else:
40 main.maxNodes = 0
41 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
42 wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ]
43 wrapperFile3 = main.params[ 'DEPENDENCY' ][ 'wrapper3' ]
44 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
45 main.gossipTime = int( main.params[ 'SLEEP'][ 'cfgGossip' ] )
alison15124df2016-10-06 12:04:51 -070046 main.SetNetCfgSleep = int( main.params[ 'SLEEP' ][ 'SetNetCfgSleep' ] )
Jon Hall66e001c2015-11-12 09:45:10 -080047 gitPull = main.params[ 'GIT' ][ 'pull' ]
48 main.cellData = {} # for creating cell file
49 main.hostsData = {}
50 main.nodes = []
51 main.ONOSip = []
Ming Yan Shudb74bf22016-06-23 14:56:22 -070052 main.retrytimes = main.params[ 'RETRY' ]
53 main.retrysleep = main.params[ 'RetrySleep' ]
Jon Hall66e001c2015-11-12 09:45:10 -080054 main.ONOSip = main.ONOSbench.getOnosIps()
55
56 # Assigning ONOS cli handles to a list
57 try:
58 for i in range( 1, main.maxNodes + 1 ):
59 main.nodes.append( getattr( main, 'ONOSrest' + str( i ) ) )
60 except AttributeError:
61 main.log.warn( "A " + str( main.maxNodes ) + " node cluster " +
62 "was defined in env variables, but only " +
63 str( len( main.nodes ) ) +
64 " nodes were defined in the .topo file. " +
65 "Using " + str( len( main.nodes ) ) +
66 " nodes for the test." )
67
68 main.numCtrls = len( main.nodes )
69
70 # -- INIT SECTION, SHOULD ONLY BE RUN ONCE -- #
71 main.startUp = imp.load_source( wrapperFile1,
72 main.dependencyPath +
73 wrapperFile1 +
74 ".py" )
75
76 main.netCfg = imp.load_source( wrapperFile2,
77 main.dependencyPath +
78 wrapperFile2 +
79 ".py" )
80
81 main.topo = imp.load_source( wrapperFile3,
82 main.dependencyPath +
83 wrapperFile3 +
84 ".py" )
85
86 if main.nodes:
87 stepResult = main.TRUE
88 else:
89 main.log.error( "Did not properly created list of ONOS handle" )
90 stepResult = main.FALSE
91 except Exception as e:
Jeremy Songster2baa44e2016-06-10 10:18:40 -070092 main.log.exception( e )
Jon Hall66e001c2015-11-12 09:45:10 -080093 main.cleanup()
94 main.exit()
95
96 utilities.assert_equals( expect=main.TRUE,
97 actual=stepResult,
98 onpass="Successfully construct " +
99 "test variables ",
100 onfail="Failed to construct test variables" )
101
102 if gitPull == 'True':
103 main.step( "Building ONOS in " + gitBranch + " branch" )
104 onosBuildResult = main.startUp.onosBuild( main, gitBranch )
105 stepResult = onosBuildResult
106 utilities.assert_equals( expect=main.TRUE,
107 actual=stepResult,
108 onpass="Successfully compiled " +
109 "latest ONOS",
110 onfail="Failed to compile " +
111 "latest ONOS" )
112 else:
113 main.log.warn( "Did not pull new code so skipping mvn " +
114 "clean install" )
115 main.ONOSbench.getVersion( report=True )
116
117 def CASE2( self, main ):
118 """
119 - Set up cell
120 - Create cell file
121 - Set cell file
122 - Verify cell file
123 - Kill ONOS process
124 - Uninstall ONOS cluster
125 - Verify ONOS start up
126 - Install ONOS cluster
127 - Connect to cli
128 """
129 import time
130 main.case( "Starting up " + str( main.numCtrls ) +
131 " node(s) ONOS cluster" )
132 main.caseExplanation = "Set up ONOS with " + str( main.numCtrls ) +\
133 " node(s) ONOS cluster"
134
135 # kill off all onos processes
136 main.log.info( "Safety check, killing all ONOS processes" +
137 " before initiating environment setup" )
138
139 for i in range( main.maxNodes ):
140 main.ONOSbench.onosStop( main.ONOSip[ i ] )
141 main.ONOSbench.onosDie( main.ONOSip[ i ] )
142
143 tempOnosIp = []
144 for i in range( main.numCtrls ):
145 tempOnosIp.append( main.ONOSip[i] )
146
147 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
148 "temp", main.Mininet1.ip_address,
149 main.apps, tempOnosIp )
150
151 main.step( "Apply cell to environment" )
152 cellResult = main.ONOSbench.setCell( "temp" )
153 verifyResult = main.ONOSbench.verifyCell()
154 stepResult = cellResult and verifyResult
155 utilities.assert_equals( expect=main.TRUE,
156 actual=stepResult,
157 onpass="Successfully applied cell to environment",
158 onfail="Failed to apply cell to environment " )
159
160 main.step( "Creating ONOS package" )
Jon Hallbd60ea02016-08-23 10:03:59 -0700161 packageResult = main.ONOSbench.buckBuild()
Jon Hall66e001c2015-11-12 09:45:10 -0800162 stepResult = packageResult
163 utilities.assert_equals( expect=main.TRUE,
164 actual=stepResult,
165 onpass="Successfully created ONOS package",
166 onfail="Failed to create ONOS package" )
167
168 time.sleep( main.startUpSleep )
169 main.step( "Uninstalling ONOS package" )
170 onosUninstallResult = main.TRUE
171 for ip in main.ONOSip:
172 onosUninstallResult = onosUninstallResult and \
173 main.ONOSbench.onosUninstall( nodeIp=ip )
174 stepResult = onosUninstallResult
175 utilities.assert_equals( expect=main.TRUE,
176 actual=stepResult,
177 onpass="Successfully uninstalled ONOS package",
178 onfail="Failed to uninstall ONOS package" )
179
180 time.sleep( main.startUpSleep )
181 main.step( "Installing ONOS package" )
182 onosInstallResult = main.TRUE
183 for i in range( main.numCtrls ):
184 onosInstallResult = onosInstallResult and \
185 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
186 stepResult = onosInstallResult
187 utilities.assert_equals( expect=main.TRUE,
188 actual=stepResult,
189 onpass="Successfully installed ONOS package",
190 onfail="Failed to install ONOS package" )
191
192 time.sleep( main.startUpSleep )
193 main.step( "Starting ONOS service" )
194 stopResult = main.TRUE
195 startResult = main.TRUE
196 onosIsUp = main.TRUE
197
198 for i in range( main.numCtrls ):
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700199 isUp = main.ONOSbench.isup( main.ONOSip[ i ] )
200 onosIsUp = onosIsUp and isUp
201 if isUp == main.TRUE:
202 main.log.report( "ONOS instance {0} is up and ready".format( i + 1 ) )
203 else:
204 main.log.report( "ONOS instance {0} may not be up, stop and ".format( i + 1 ) +
205 "start ONOS again " )
Jon Hall66e001c2015-11-12 09:45:10 -0800206 stopResult = stopResult and \
207 main.ONOSbench.onosStop( main.ONOSip[ i ] )
Jon Hall66e001c2015-11-12 09:45:10 -0800208 startResult = startResult and \
209 main.ONOSbench.onosStart( main.ONOSip[ i ] )
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700210 stepResult = onosIsUp and stopResult and startResult
Jon Hall66e001c2015-11-12 09:45:10 -0800211 utilities.assert_equals( expect=main.TRUE,
212 actual=stepResult,
213 onpass="ONOS service is ready",
214 onfail="ONOS service did not start properly" )
215
216 def CASE8( self, main ):
217 """
218 Compare Topo
219 """
220 import json
221
222 main.case( "Compare ONOS Topology view to Mininet topology" )
223 main.caseExplanation = "Compare topology elements between Mininet" +\
224 " and ONOS"
225
226 main.step( "Gathering topology information" )
227 # TODO: add a parameterized sleep here
228 devicesResults = main.TRUE
229 linksResults = main.TRUE
230 hostsResults = main.TRUE
231 devices = main.topo.getAllDevices( main )
232 hosts = main.topo.getAllHosts( main )
233 ports = main.topo.getAllPorts( main )
234 links = main.topo.getAllLinks( main )
235 clusters = main.topo.getAllClusters( main )
236
237 mnSwitches = main.Mininet1.getSwitches()
238 mnLinks = main.Mininet1.getLinks()
239 mnHosts = main.Mininet1.getHosts()
240
241 main.step( "Comparing MN topology to ONOS topology" )
242 for controller in range( main.numCtrls ):
243 controllerStr = str( controller + 1 )
244 if devices[ controller ] and ports[ controller ] and\
245 "Error" not in devices[ controller ] and\
246 "Error" not in ports[ controller ]:
247
248 currentDevicesResult = main.Mininet1.compareSwitches(
249 mnSwitches,
250 json.loads( devices[ controller ] ),
251 json.loads( ports[ controller ] ) )
252 else:
253 currentDevicesResult = main.FALSE
254 utilities.assert_equals( expect=main.TRUE,
255 actual=currentDevicesResult,
256 onpass="ONOS" + controllerStr +
257 " Switches view is correct",
258 onfail="ONOS" + controllerStr +
259 " Switches view is incorrect" )
260
261 if links[ controller ] and "Error" not in links[ controller ]:
262 currentLinksResult = main.Mininet1.compareLinks(
263 mnSwitches, mnLinks,
264 json.loads( links[ controller ] ) )
265 else:
266 currentLinksResult = main.FALSE
267 utilities.assert_equals( expect=main.TRUE,
268 actual=currentLinksResult,
269 onpass="ONOS" + controllerStr +
270 " links view is correct",
271 onfail="ONOS" + controllerStr +
272 " links view is incorrect" )
273
274 if hosts[ controller ] or "Error" not in hosts[ controller ]:
275 currentHostsResult = main.Mininet1.compareHosts(
276 mnHosts,
277 json.loads( hosts[ controller ] ) )
278 else:
279 currentHostsResult = main.FALSE
280 utilities.assert_equals( expect=main.TRUE,
281 actual=currentHostsResult,
282 onpass="ONOS" + controllerStr +
283 " hosts exist in Mininet",
284 onfail="ONOS" + controllerStr +
285 " hosts don't match Mininet" )
286
287 def CASE9( self, main ):
288 '''
289 Report errors/warnings/exceptions
290 '''
291 main.log.info( "Error report: \n" )
292 main.ONOSbench.logReport(
293 globalONOSip[0],
294 [ "INFO", "WARN", "ERROR" , "Except" ],
295 "s" )
296 # main.ONOSbench.logReport( globalONOSip[1], [ "INFO" ], "d" )
297
298 def CASE10( self, main ):
299 """
300 Start Mininet topology with OF 1.0 switches
301 """
302 main.OFProtocol = "1.0"
303 main.log.report( "Start Mininet topology with OF 1.0 switches" )
304 main.case( "Start Mininet topology with OF 1.0 switches" )
305 main.caseExplanation = "Start mininet topology with OF 1.0 " +\
306 "switches to test intents, exits out if " +\
307 "topology did not start correctly"
308
309 main.step( "Starting Mininet topology with OF 1.0 switches" )
Jon Hall53c5e662016-04-13 16:06:56 -0700310 args = "--controller none --switch ovs,protocols=OpenFlow10"
Jon Hall66e001c2015-11-12 09:45:10 -0800311 switches = int( main.params['MININET']['switch'] )
312 cmd = "mn --topo linear,{} {}".format( switches, args )
313 topoResult = main.Mininet1.startNet( mnCmd = cmd )
314 stepResult = topoResult
315 utilities.assert_equals( expect=main.TRUE,
316 actual=stepResult,
317 onpass="Successfully loaded topology",
318 onfail="Failed to load topology" )
319 # Exit if topology did not load properly
320 if not topoResult:
321 main.cleanup()
322 main.exit()
323
324 def CASE11( self, main ):
325 """
326 Start Mininet topology with OF 1.3 switches
327 """
328 import re
329 main.OFProtocol = "1.3"
330 main.log.report( "Start Mininet topology with OF 1.3 switches" )
331 main.case( "Start Mininet topology with OF 1.3 switches" )
332 main.caseExplanation = "Start mininet topology with OF 1.3 " +\
333 "switches to test intents, exits out if " +\
334 "topology did not start correctly"
335
336 main.step( "Starting Mininet topology with OF 1.3 switches" )
Jon Hall53c5e662016-04-13 16:06:56 -0700337 args = "--controller none --switch ovs,protocols=OpenFlow13"
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700338 switches = int( main.params[ 'MININET' ][ 'switch' ] )
Jon Hall66e001c2015-11-12 09:45:10 -0800339 cmd = "mn --topo linear,{} {}".format( switches, args )
340 topoResult = main.Mininet1.startNet( mnCmd = cmd )
341 stepResult = topoResult
342 utilities.assert_equals( expect=main.TRUE,
343 actual=stepResult,
344 onpass="Successfully loaded topology",
345 onfail="Failed to load topology" )
346 # Exit if topology did not load properly
347 if not topoResult:
348 main.cleanup()
349 main.exit()
350
351 tempONOSip = []
352 for i in range( main.numCtrls ):
353 tempONOSip.append( main.ONOSip[ i ] )
354
355 swList = [ "s" + str( i ) for i in range( 1, switches + 1 ) ]
356 assignResult = main.Mininet1.assignSwController( sw=swList,
357 ip=tempONOSip,
358 port='6653' )
359 if not assignResult:
360 main.cleanup()
361 main.exit()
362
363 assignResult = main.TRUE
364 for sw in swList:
365 response = main.Mininet1.getSwController( "s" + str( i ) )
366 main.log.info( "Response is " + str( response ) )
367 for ip in tempONOSip:
368 if re.search( "tcp:" + ip, response ):
369 assignResult = assignResult and main.TRUE
370 else:
371 assignResult = assignResult and main.FALSE
372 stepResult = assignResult
373 utilities.assert_equals( expect=main.TRUE,
374 actual=stepResult,
375 onpass="Successfully assigned switches" +
376 "to controller",
377 onfail="Failed to assign switches to " +
378 "controller" )
379
380 def CASE14( self, main ):
381 """
382 Stop mininet
383 """
384 main.log.report( "Stop Mininet topology" )
385 main.case( "Stop Mininet topology" )
386 main.caseExplanation = "Stopping the current mininet topology " +\
387 "to start up fresh"
388
389 main.step( "Stopping Mininet Topology" )
390 topoResult = main.Mininet1.stopNet( )
391 stepResult = topoResult
392 utilities.assert_equals( expect=main.TRUE,
393 actual=stepResult,
394 onpass="Successfully stop mininet",
395 onfail="Failed to stop mininet" )
396 # Exit if topology did not load properly
397 if not topoResult:
398 main.cleanup()
399 main.exit()
400
401 def CASE20( self, main ):
402 """
403 Add some device configurations and then check they are distributed
404 to all nodes
405 """
alison15124df2016-10-06 12:04:51 -0700406 import time
Jon Hall66e001c2015-11-12 09:45:10 -0800407 main.case( "Add Network configurations to the cluster" )
408 main.caseExplanation = "Add Network Configurations for devices" +\
409 " not discovered yet. One device is allowed" +\
410 ", the other disallowed."
411 pprint = main.nodes[0].pprint
412
413 main.step( "Add Net Cfg for switch1" )
414 s1Json = { "rackAddress": 1,
415 "name": "Switch1",
416 "owner": "Jimmy",
417 "allowed": True }
418 main.s1Json = s1Json
419 setS1Allow = main.ONOSrest1.setNetCfg( s1Json,
420 subjectClass="devices",
421 subjectKey="of:0000000000000001",
422 configKey="basic" )
423 s1Result = False
alison15124df2016-10-06 12:04:51 -0700424 #Wait 5 secs after set up netCfg
425 time.sleep( main.SetNetCfgSleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800426 if setS1Allow:
427 # Check what we set is what is in ONOS
428 getS1 = main.ONOSrest1.getNetCfg( subjectClass="devices",
429 subjectKey="of:0000000000000001",
430 configKey="basic" )
431 onosCfg = pprint( getS1 )
432 sentCfg = pprint( s1Json )
433 if onosCfg == sentCfg:
alison15124df2016-10-06 12:04:51 -0700434 main.log.info( "ONOS NetCfg match what was sent" )
Jon Hall66e001c2015-11-12 09:45:10 -0800435 s1Result = True
436 else:
437 main.log.error( "ONOS NetCfg doesn't match what was sent" )
438 main.log.debug( "ONOS config: {}".format( onosCfg ) )
439 main.log.debug( "Sent config: {}".format( sentCfg ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700440 utilities.retry( f=main.ONOSrest1.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800441 utilities.assert_equals( expect=True,
442 actual=s1Result,
443 onpass="Net Cfg added for device s1",
444 onfail="Net Cfg for device s1 not correctly set" )
445
446 main.step( "Add Net Cfg for switch3" )
447 s3Json = { "rackAddress": 3,
448 "name": "Switch3",
449 "owner": "Jane",
450 "allowed": False }
451 main.s3Json = s3Json
452 setS3Disallow = main.ONOSrest1.setNetCfg( s3Json,
453 subjectClass="devices",
454 subjectKey="of:0000000000000003",
455 configKey="basic" )
456 s3Result = False
alison15124df2016-10-06 12:04:51 -0700457 time.sleep( main.SetNetCfgSleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800458 if setS3Disallow:
459 # Check what we set is what is in ONOS
460 getS3 = main.ONOSrest1.getNetCfg( subjectClass="devices",
461 subjectKey="of:0000000000000003",
462 configKey="basic" )
463 onosCfg = pprint( getS3 )
464 sentCfg = pprint( s3Json )
465 if onosCfg == sentCfg:
alison15124df2016-10-06 12:04:51 -0700466 main.log.info("ONOS NetCfg match what was sent")
Jon Hall66e001c2015-11-12 09:45:10 -0800467 s3Result = True
468 else:
469 main.log.error( "ONOS NetCfg doesn't match what was sent" )
470 main.log.debug( "ONOS config: {}".format( onosCfg ) )
471 main.log.debug( "Sent config: {}".format( sentCfg ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700472 utilities.retry( f=main.ONOSrest1.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800473 utilities.assert_equals( expect=True,
474 actual=s3Result,
475 onpass="Net Cfg added for device s3",
476 onfail="Net Cfg for device s3 not correctly set" )
477 main.netCfg.compareCfg( main, main.gossipTime )
478
479 def CASE21( self, main ):
480 """
481 Initial check of devices
482 """
483 import json
484 try:
485 assert main.s1Json, "s1Json not defined"
486 except AssertionError:
487 main.log.exception( "Case Prerequisites not set: " )
488 main.cleanup()
489 main.exit()
490 main.case( "Check Devices After they initially connect to ONOS" )
491
492 main.netCfg.compareCfg( main )
493
494 main.step( "ONOS should only show devices S1, S2, and S4" )
495 devices = main.ONOSrest1.devices()
496 main.log.debug( main.ONOSrest1.pprint( devices ) )
497 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4 ] ]
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700498 main.log.debug( allowedDevices )
Jon Hall66e001c2015-11-12 09:45:10 -0800499 onosDevices = []
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700500 try:
501 for sw in json.loads( devices ):
502 onosDevices.append( str( sw['id'] ) )
503 onosDevices.sort()
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700504 main.log.debug( onosDevices )
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700505 except( TypeError, ValueError ):
506 main.log.error( "Problem loading devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800507 utilities.assert_equals( expect=allowedDevices,
508 actual=onosDevices,
509 onpass="Only allowed devices are in ONOS",
510 onfail="ONOS devices doesn't match the list" +
511 " of allowed devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800512 main.step( "Check device annotations" )
513 keys = [ 'name', 'owner', 'rackAddress' ]
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700514 try:
515 for sw in json.loads( devices ):
516 if "of:0000000000000001" in sw['id']:
517 s1Correct = True
518 for k in keys:
519 if str( sw.get( 'annotations', {} ).get( k ) ) != str( main.s1Json[k] ):
520 s1Correct = False
521 main.log.debug( "{} is wrong on s1".format( k ) )
522 if not s1Correct:
523 main.log.error( "Annotations for s1 are incorrect: {}".format( sw ) )
524 except( TypeError, ValueError ):
525 main.log.error( "Problem loading devices" )
526 s1Correct = False
Jon Hall66e001c2015-11-12 09:45:10 -0800527 try:
528 stepResult = s1Correct
529 except NameError:
530 stepResult = False
531 main.log.error( "s1 not found in devices" )
532 utilities.assert_equals( expect=True,
533 actual=stepResult,
534 onpass="Configured device's annotations are correct",
535 onfail="Incorrect annotations for configured devices." )
536
537 def CASE22( self, main ):
538 """
539 Add some device configurations for connected devices and then check
540 they are distributed to all nodes
541 """
542 main.case( "Add Network configurations for connected devices to the cluster" )
543 main.caseExplanation = "Add Network Configurations for discovered " +\
544 "devices. One device is allowed" +\
545 ", the other disallowed."
546 pprint = main.nodes[0].pprint
547
548 main.step( "Add Net Cfg for switch2" )
549 s2Json = { "rackAddress": 2,
550 "name": "Switch2",
551 "owner": "Jenny",
552 "allowed": True }
553 main.s2Json = s2Json
554 setS2Allow = main.ONOSrest2.setNetCfg( s2Json,
555 subjectClass="devices",
556 subjectKey="of:0000000000000002",
557 configKey="basic" )
558 s2Result = False
559 if setS2Allow:
560 # Check what we set is what is in ONOS
561 getS2 = main.ONOSrest2.getNetCfg( subjectClass="devices",
562 subjectKey="of:0000000000000002",
563 configKey="basic" )
564 onosCfg = pprint( getS2 )
565 sentCfg = pprint( s2Json )
566 if onosCfg == sentCfg:
567 s2Result = True
568 else:
569 main.log.error( "ONOS NetCfg doesn't match what was sent" )
570 main.log.debug( "ONOS config: {}".format( onosCfg ) )
571 main.log.debug( "Sent config: {}".format( sentCfg ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700572 utilities.retry( f=main.ONOSrest2.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800573 utilities.assert_equals( expect=True,
574 actual=s2Result,
575 onpass="Net Cfg added for device s2",
576 onfail="Net Cfg for device s2 not correctly set" )
577
578 main.step( "Add Net Cfg for switch4" )
579 s4Json = { "rackAddress": 4,
580 "name": "Switch4",
581 "owner": "John",
582 "allowed": False }
583 main.s4Json = s4Json
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700584 setS4Disallow = main.ONOSrest3.setNetCfg( s4Json,
Jon Hall66e001c2015-11-12 09:45:10 -0800585 subjectClass="devices",
586 subjectKey="of:0000000000000004",
587 configKey="basic" )
588 s4Result = False
589 if setS4Disallow:
590 # Check what we set is what is in ONOS
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700591 getS4 = main.ONOSrest3.getNetCfg( subjectClass="devices",
Jon Hall66e001c2015-11-12 09:45:10 -0800592 subjectKey="of:0000000000000004",
593 configKey="basic" )
594 onosCfg = pprint( getS4 )
595 sentCfg = pprint( s4Json )
596 if onosCfg == sentCfg:
597 s4Result = True
598 else:
599 main.log.error( "ONOS NetCfg doesn't match what was sent" )
600 main.log.debug( "ONOS config: {}".format( onosCfg ) )
601 main.log.debug( "Sent config: {}".format( sentCfg ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700602 main.step( "Retrying main.ONOSrest3.getNetCfg" )
603 utilities.retry( f=main.ONOSrest3.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800604 utilities.assert_equals( expect=True,
605 actual=s4Result,
606 onpass="Net Cfg added for device s4",
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700607 onfail="Net Cfg for device s4 not correctly set" )
Jon Hall66e001c2015-11-12 09:45:10 -0800608
609 main.netCfg.compareCfg( main, main.gossipTime )
610
611 def CASE23( self, main ):
612 """
613 Check of devices after all Network Configurations are set
614 """
615 import json
616 try:
617 assert main.s1Json, "s1Json not defined"
618 assert main.s2Json, "s2Json not defined"
619 except AssertionError:
620 main.log.exception( "Case Prerequisites not set: " )
621 main.cleanup()
622 main.exit()
623 main.case( "Check Devices after all configurations are set" )
624
625 main.netCfg.compareCfg( main )
626
627 main.step( "ONOS should only show devices S1 and S2" )
628 devices = main.ONOSrest1.devices()
629 main.log.debug( main.ONOSrest1.pprint( devices ) )
630 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2 ] ]
631 onosDevices = []
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700632 try:
633 for sw in json.loads( devices ):
634 onosDevices.append( str( sw.get( 'id' ) ) )
635 onosDevices.sort()
636 failMsg = "ONOS devices doesn't match the list of allowed devices.\n"
637 failMsg += "Expected devices: {}\nActual devices: {}".format( allowedDevices,
638 onosDevices )
639 except( TypeError, ValueError ):
640 main.log.error( "Problem loading devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800641 utilities.assert_equals( expect=allowedDevices,
642 actual=onosDevices,
643 onpass="Only allowed devices are in ONOS",
644 onfail=failMsg )
645
646 main.step( "Check device annotations" )
647 keys = [ 'name', 'owner', 'rackAddress' ]
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700648 try:
649 for sw in json.loads( devices ):
650 if "of:0000000000000001" in sw.get( 'id' ):
651 s1Correct = True
652 for k in keys:
653 if str( sw.get( 'annotations', {} ).get( k ) ) != str( main.s1Json[k] ):
654 s1Correct = False
655 main.log.debug( "{} is wrong on s1".format( k ) )
656 if not s1Correct:
657 main.log.error( "Annotations for s1 are incorrect: {}".format( sw ) )
658 elif "of:0000000000000002" in sw['id']:
659 s2Correct = True
660 for k in keys:
661 if str( sw.get( 'annotations', {} ).get( k ) ) != str( main.s2Json[k] ):
662 s2Correct = False
663 main.log.debug( "{} is wrong on s2".format( k ) )
664 if not s2Correct:
665 main.log.error( "Annotations for s2 are incorrect: {}".format( sw ) )
666 except( TypeError, ValueError ):
667 main.log.error( "Problem loading devices" )
668 stepResult = False
Jon Hall66e001c2015-11-12 09:45:10 -0800669 try:
670 stepResult = s1Correct and s2Correct
671 except NameError:
672 stepResult = False
673 main.log.error( "s1 and/or s2 not found in devices" )
674 utilities.assert_equals( expect=True,
675 actual=stepResult,
676 onpass="Configured device's annotations are correct",
677 onfail="Incorrect annotations for configured devices." )
678
679 def CASE24( self, main ):
680 """
681 Testing removal of configurations
682 """
Jon Hall541b8e02015-12-14 19:29:01 -0800683 import time
Jon Hall66e001c2015-11-12 09:45:10 -0800684 try:
685 assert main.s1Json, "s1Json not defined"
686 assert main.s2Json, "s2Json not defined"
687 assert main.s3Json, "s3Json not defined"
688 assert main.s4Json, "s4Json not defined"
689 except AssertionError:
690 main.log.exception( "Case Prerequisites not set: " )
691 main.cleanup()
692 main.exit()
693 main.case( "Testing removal of configurations" )
694 main.step( "Remove 'allowed' configuration from all devices" )
695
696 s1Json = main.s1Json # NOTE: This is a reference
697 try:
698 del s1Json['allowed']
699 except KeyError:
700 main.log.exception( "Key not found" )
701 setS1 = main.ONOSrest1.setNetCfg( s1Json,
702 subjectClass="devices",
703 subjectKey="of:0000000000000001",
704 configKey="basic" )
705
706 s2Json = main.s2Json # NOTE: This is a reference
707 try:
Jon Hall541b8e02015-12-14 19:29:01 -0800708 time.sleep( main.gossipTime )
Jon Hall66e001c2015-11-12 09:45:10 -0800709 del s2Json['allowed']
710 except KeyError:
711 main.log.exception( "Key not found" )
712 setS2 = main.ONOSrest2.setNetCfg( s2Json,
713 subjectClass="devices",
714 subjectKey="of:0000000000000002",
715 configKey="basic" )
716
717 s3Json = main.s3Json # NOTE: This is a reference
718 try:
Jon Hall541b8e02015-12-14 19:29:01 -0800719 time.sleep( main.gossipTime )
Jon Hall66e001c2015-11-12 09:45:10 -0800720 del s3Json['allowed']
721 except KeyError:
722 main.log.exception( "Key not found" )
723 setS3 = main.ONOSrest3.setNetCfg( s3Json,
724 subjectClass="devices",
725 subjectKey="of:0000000000000003",
726 configKey="basic" )
727
728 s4Json = main.s4Json # NOTE: This is a reference
729 try:
Jon Hall541b8e02015-12-14 19:29:01 -0800730 time.sleep( main.gossipTime )
Jon Hall66e001c2015-11-12 09:45:10 -0800731 del s4Json['allowed']
732 except KeyError:
733 main.log.exception( "Key not found" )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700734 setS4 = main.ONOSrest3.setNetCfg( s4Json,
Jon Hall66e001c2015-11-12 09:45:10 -0800735 subjectClass="devices",
736 subjectKey="of:0000000000000004",
737 configKey="basic" )
738 removeAllowed = setS1 and setS2 and setS3 and setS4
739 utilities.assert_equals( expect=main.TRUE,
740 actual=removeAllowed,
741 onpass="Successfully removed 'allowed' config from devices",
742 onfail="Failed to remove the 'allowed' config key." )
743
744 main.netCfg.compareCfg( main, main.gossipTime )
745
746 main.step( "Delete basic config for s1 and s2" )
747 removeS1 = main.ONOSrest1.removeNetCfg( subjectClass="devices",
748 subjectKey="of:0000000000000001",
749 configKey="basic" )
750 removeS2 = main.ONOSrest2.removeNetCfg( subjectClass="devices",
751 subjectKey="of:0000000000000002",
752 configKey="basic" )
753 removeSingles = removeS1 and removeS2
754 utilities.assert_equals( expect=main.TRUE,
755 actual=removeSingles,
756 onpass="Successfully removed S1 and S2 basic config",
757 onfail="Failed to removed S1 and S2 basic config" )
758
759 main.netCfg.compareCfg( main, main.gossipTime )
760
761 main.step( "Delete the net config for S3" )
762 removeS3 = main.ONOSrest3.removeNetCfg( subjectClass="devices",
763 subjectKey="of:0000000000000003" )
764 utilities.assert_equals( expect=main.TRUE,
765 actual=removeS3,
766 onpass="Successfully removed S3's config",
767 onfail="Failed to removed S3's config" )
768
769 main.netCfg.compareCfg( main, main.gossipTime )
770
771 main.step( "Delete the net config for all devices" )
772 remove = main.ONOSrest3.removeNetCfg( subjectClass="devices" )
773 utilities.assert_equals( expect=main.TRUE,
774 actual=remove,
775 onpass="Successfully removed device config",
776 onfail="Failed to remove device config" )
777
778 main.netCfg.compareCfg( main, main.gossipTime )
779
780 main.step( "Assert the net config for devices is empty" )
781 get = main.ONOSrest3.getNetCfg( subjectClass="devices" )
782 utilities.assert_equals( expect='{}',
783 actual=get,
784 onpass="Successfully removed device config",
785 onfail="Failed to remove device config" )
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700786
787 def CASE25( self, main ):
788 """
789 Use network-cfg.json to configure devices during ONOS startup
790 """
791 main.case( "Preparing network-cfg.json to load configurations" )
792 main.step( "Moving network-cfg.json to $ONOS_ROOT/tools/package/config/" )
793 prestartResult = main.TRUE
794 srcPath = "~/OnosSystemTest/TestON/tests/FUNC/FUNCnetCfg/dependencies/network-cfg.json"
795 dstPath = "~/onos/tools/package/config/network-cfg.json"
796 prestartResult = main.ONOSbench.scp( main.ONOSbench, srcPath, dstPath, direction="to" )
797 utilities.assert_equals( expect=main.TRUE,
798 actual=prestartResult,
799 onpass="Successfully copied network-cfg.json to target directory",
800 onfail="Failed to copy network-cfg.json to target directory" )
801
802 def CASE26( self, main ):
803 """
804 Check to see that pre-startup configurations were set correctly
805 """
806 import json
807 main.case( "Check to see if the pre-startup configurations were set, then remove their allowed status" )
808 main.step( "Checking configurations for Switches 5 and 6" )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700809 main.step( "ONOS should only show devices S1, S2, S4, and S5" ) #and S6
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700810 devices = main.ONOSrest1.devices()
811 main.log.debug( main.ONOSrest1.pprint( devices ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700812 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4, 5 ] ] #6
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700813 main.log.debug( allowedDevices )
814 onosDevices = []
815 try:
816 for sw in json.loads( devices ):
817 onosDevices.append( str( sw['id'] ) )
818 onosDevices.sort()
819 main.log.debug( onosDevices )
820 except( TypeError, ValueError ):
821 main.log.error( "Problem loading devices" )
822 utilities.assert_equals( expect=allowedDevices,
823 actual=onosDevices,
824 onpass="Only allowed devices are in ONOS",
825 onfail="ONOS devices doesn't match the list" +
826 " of allowed devices" )
827
828 main.step( "Removing allowed status from Switches 5 and 6" )
829 main.s5Json = { "allowed": False }
830 main.s6Json = { "allowed": False }
831 s5Json = main.s5Json
832 setS1 = main.ONOSrest1.setNetCfg( s5Json,
833 subjectClass="devices",
834 subjectKey="of:0000000000000005",
835 configKey="basic" )
836
837 s6Json = main.s6Json
838 setS1 = main.ONOSrest1.setNetCfg( s6Json,
839 subjectClass="devices",
840 subjectKey="of:0000000000000006",
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700841 configKey="basic" )
842
843 def CASE27( self, main ):
844 """
845 1) A = get /network/configuration
846 2) Post A
847 3) Compare A with ONOS
848 4) Modify A so S6 is disallowed
849 5) Check
850
851 """
852 import json
853 pprint = main.nodes[0].pprint
854 main.case( "Posting network configurations to the top level web resource" )
855 main.step( "Get json object from Net Cfg" )
856 getinfo = main.ONOSrest1.getNetCfg( )
857 main.log.debug( getinfo )
858 main.step( "Posting json object to Net Cfg" )
859 postinfo = main.ONOSrest1.setNetCfg( json.loads( getinfo ) )
860 main.step( "Compare device with ONOS" )
861 main.netCfg.compareCfg( main )
862 main.step ( "ONOS should only show devices S1, S2, S4, S5 and S6" )
863 devices = main.ONOSrest1.devices( )
864 main.log.debug( main.ONOSrest1.pprint( devices ) )
865 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4, 5, 6 ] ]
866 onosDevices = []
867 try:
868 for sw in json.loads( devices ):
869 onosDevices.append( str( sw.get( 'id' ) ) )
870 onosDevices.sort( )
871 failMsg = "ONOS devices doesn't match the list of allowed devices. \n"
872 failMsg += "Expected devices: {}\nActual devices: {}".format( allowedDevices, onosDevices )
873 except( TypeError, ValueError ):
874 main.log.error( "Problem loading devices" )
875 utilities.assert_equals( expect=allowedDevices, actual=onosDevices,
876 onpass="Only allowed devices are in ONOS", onfail=failMsg )
877
878 main.step( "Modify json object so S6 is disallowed" )
879 main.s6Json = { "allowed": False }
880 s6Json = main.s6Json
881 setS6Disallow = main.ONOSrest1.setNetCfg( s6Json, subjectClass="devices",
882 subjectKey="of:0000000000000006", configKey="basic" )
883 s6Result = False
884 if setS6Disallow:
885 getS6 = main.ONOSrest1.getNetCfg( subjectClass="devices",
886 subjectKey="of:0000000000000006", configKey="basic" )
887 onosCfg = pprint( getS6 )
888 sentCfg = pprint( s6Json )
889 if onosCfg == sentCfg:
890 s6Result = True
891 else:
892 main.log.error( "ONOS NetCfg doesn't match what was sent" )
893 main.log.debug( "ONOS config: {}".format( onosCfg ) )
894 main.log.debug( "Sent config: {}".format( sentCfg ) )
895 utilities.retry( f=main.ONOSrest1.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
896 utilities.assert_equals( expect=True, actual=s6Result,
897 onpass="Net Cfg added for devices s6",
898 onfail="Net Cfg for device s6 not correctly set" )