blob: 190357d4dc90ffd70ef359158e6e7a20dac0aa57 [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' ] )
46 gitPull = main.params[ 'GIT' ][ 'pull' ]
47 main.cellData = {} # for creating cell file
48 main.hostsData = {}
49 main.nodes = []
50 main.ONOSip = []
51
52 main.ONOSip = main.ONOSbench.getOnosIps()
53
54 # Assigning ONOS cli handles to a list
55 try:
56 for i in range( 1, main.maxNodes + 1 ):
57 main.nodes.append( getattr( main, 'ONOSrest' + str( i ) ) )
58 except AttributeError:
59 main.log.warn( "A " + str( main.maxNodes ) + " node cluster " +
60 "was defined in env variables, but only " +
61 str( len( main.nodes ) ) +
62 " nodes were defined in the .topo file. " +
63 "Using " + str( len( main.nodes ) ) +
64 " nodes for the test." )
65
66 main.numCtrls = len( main.nodes )
67
68 # -- INIT SECTION, SHOULD ONLY BE RUN ONCE -- #
69 main.startUp = imp.load_source( wrapperFile1,
70 main.dependencyPath +
71 wrapperFile1 +
72 ".py" )
73
74 main.netCfg = imp.load_source( wrapperFile2,
75 main.dependencyPath +
76 wrapperFile2 +
77 ".py" )
78
79 main.topo = imp.load_source( wrapperFile3,
80 main.dependencyPath +
81 wrapperFile3 +
82 ".py" )
83
84 if main.nodes:
85 stepResult = main.TRUE
86 else:
87 main.log.error( "Did not properly created list of ONOS handle" )
88 stepResult = main.FALSE
89 except Exception as e:
90 main.log.exception(e)
91 main.cleanup()
92 main.exit()
93
94 utilities.assert_equals( expect=main.TRUE,
95 actual=stepResult,
96 onpass="Successfully construct " +
97 "test variables ",
98 onfail="Failed to construct test variables" )
99
100 if gitPull == 'True':
101 main.step( "Building ONOS in " + gitBranch + " branch" )
102 onosBuildResult = main.startUp.onosBuild( main, gitBranch )
103 stepResult = onosBuildResult
104 utilities.assert_equals( expect=main.TRUE,
105 actual=stepResult,
106 onpass="Successfully compiled " +
107 "latest ONOS",
108 onfail="Failed to compile " +
109 "latest ONOS" )
110 else:
111 main.log.warn( "Did not pull new code so skipping mvn " +
112 "clean install" )
113 main.ONOSbench.getVersion( report=True )
114
115 def CASE2( self, main ):
116 """
117 - Set up cell
118 - Create cell file
119 - Set cell file
120 - Verify cell file
121 - Kill ONOS process
122 - Uninstall ONOS cluster
123 - Verify ONOS start up
124 - Install ONOS cluster
125 - Connect to cli
126 """
127 import time
128 main.case( "Starting up " + str( main.numCtrls ) +
129 " node(s) ONOS cluster" )
130 main.caseExplanation = "Set up ONOS with " + str( main.numCtrls ) +\
131 " node(s) ONOS cluster"
132
133 # kill off all onos processes
134 main.log.info( "Safety check, killing all ONOS processes" +
135 " before initiating environment setup" )
136
137 for i in range( main.maxNodes ):
138 main.ONOSbench.onosStop( main.ONOSip[ i ] )
139 main.ONOSbench.onosDie( main.ONOSip[ i ] )
140
141 tempOnosIp = []
142 for i in range( main.numCtrls ):
143 tempOnosIp.append( main.ONOSip[i] )
144
145 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
146 "temp", main.Mininet1.ip_address,
147 main.apps, tempOnosIp )
148
149 main.step( "Apply cell to environment" )
150 cellResult = main.ONOSbench.setCell( "temp" )
151 verifyResult = main.ONOSbench.verifyCell()
152 stepResult = cellResult and verifyResult
153 utilities.assert_equals( expect=main.TRUE,
154 actual=stepResult,
155 onpass="Successfully applied cell to environment",
156 onfail="Failed to apply cell to environment " )
157
158 main.step( "Creating ONOS package" )
159 packageResult = main.ONOSbench.onosPackage()
160 stepResult = packageResult
161 utilities.assert_equals( expect=main.TRUE,
162 actual=stepResult,
163 onpass="Successfully created ONOS package",
164 onfail="Failed to create ONOS package" )
165
166 time.sleep( main.startUpSleep )
167 main.step( "Uninstalling ONOS package" )
168 onosUninstallResult = main.TRUE
169 for ip in main.ONOSip:
170 onosUninstallResult = onosUninstallResult and \
171 main.ONOSbench.onosUninstall( nodeIp=ip )
172 stepResult = onosUninstallResult
173 utilities.assert_equals( expect=main.TRUE,
174 actual=stepResult,
175 onpass="Successfully uninstalled ONOS package",
176 onfail="Failed to uninstall ONOS package" )
177
178 time.sleep( main.startUpSleep )
179 main.step( "Installing ONOS package" )
180 onosInstallResult = main.TRUE
181 for i in range( main.numCtrls ):
182 onosInstallResult = onosInstallResult and \
183 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
184 stepResult = onosInstallResult
185 utilities.assert_equals( expect=main.TRUE,
186 actual=stepResult,
187 onpass="Successfully installed ONOS package",
188 onfail="Failed to install ONOS package" )
189
190 time.sleep( main.startUpSleep )
191 main.step( "Starting ONOS service" )
192 stopResult = main.TRUE
193 startResult = main.TRUE
194 onosIsUp = main.TRUE
195
196 for i in range( main.numCtrls ):
197 onosIsUp = onosIsUp and main.ONOSbench.isup( main.ONOSip[ i ] )
198 if onosIsUp == main.TRUE:
199 main.log.report( "ONOS instance is up and ready" )
200 else:
201 main.log.report( "ONOS instance may not be up, stop and " +
202 "start ONOS again " )
203 for i in range( main.numCtrls ):
204 stopResult = stopResult and \
205 main.ONOSbench.onosStop( main.ONOSip[ i ] )
206 for i in range( main.numCtrls ):
207 startResult = startResult and \
208 main.ONOSbench.onosStart( main.ONOSip[ i ] )
209 stepResult = onosIsUp and stopResult and startResult
210 utilities.assert_equals( expect=main.TRUE,
211 actual=stepResult,
212 onpass="ONOS service is ready",
213 onfail="ONOS service did not start properly" )
214
215 def CASE8( self, main ):
216 """
217 Compare Topo
218 """
219 import json
220
221 main.case( "Compare ONOS Topology view to Mininet topology" )
222 main.caseExplanation = "Compare topology elements between Mininet" +\
223 " and ONOS"
224
225 main.step( "Gathering topology information" )
226 # TODO: add a parameterized sleep here
227 devicesResults = main.TRUE
228 linksResults = main.TRUE
229 hostsResults = main.TRUE
230 devices = main.topo.getAllDevices( main )
231 hosts = main.topo.getAllHosts( main )
232 ports = main.topo.getAllPorts( main )
233 links = main.topo.getAllLinks( main )
234 clusters = main.topo.getAllClusters( main )
235
236 mnSwitches = main.Mininet1.getSwitches()
237 mnLinks = main.Mininet1.getLinks()
238 mnHosts = main.Mininet1.getHosts()
239
240 main.step( "Comparing MN topology to ONOS topology" )
241 for controller in range( main.numCtrls ):
242 controllerStr = str( controller + 1 )
243 if devices[ controller ] and ports[ controller ] and\
244 "Error" not in devices[ controller ] and\
245 "Error" not in ports[ controller ]:
246
247 currentDevicesResult = main.Mininet1.compareSwitches(
248 mnSwitches,
249 json.loads( devices[ controller ] ),
250 json.loads( ports[ controller ] ) )
251 else:
252 currentDevicesResult = main.FALSE
253 utilities.assert_equals( expect=main.TRUE,
254 actual=currentDevicesResult,
255 onpass="ONOS" + controllerStr +
256 " Switches view is correct",
257 onfail="ONOS" + controllerStr +
258 " Switches view is incorrect" )
259
260 if links[ controller ] and "Error" not in links[ controller ]:
261 currentLinksResult = main.Mininet1.compareLinks(
262 mnSwitches, mnLinks,
263 json.loads( links[ controller ] ) )
264 else:
265 currentLinksResult = main.FALSE
266 utilities.assert_equals( expect=main.TRUE,
267 actual=currentLinksResult,
268 onpass="ONOS" + controllerStr +
269 " links view is correct",
270 onfail="ONOS" + controllerStr +
271 " links view is incorrect" )
272
273 if hosts[ controller ] or "Error" not in hosts[ controller ]:
274 currentHostsResult = main.Mininet1.compareHosts(
275 mnHosts,
276 json.loads( hosts[ controller ] ) )
277 else:
278 currentHostsResult = main.FALSE
279 utilities.assert_equals( expect=main.TRUE,
280 actual=currentHostsResult,
281 onpass="ONOS" + controllerStr +
282 " hosts exist in Mininet",
283 onfail="ONOS" + controllerStr +
284 " hosts don't match Mininet" )
285
286 def CASE9( self, main ):
287 '''
288 Report errors/warnings/exceptions
289 '''
290 main.log.info( "Error report: \n" )
291 main.ONOSbench.logReport(
292 globalONOSip[0],
293 [ "INFO", "WARN", "ERROR" , "Except" ],
294 "s" )
295 # main.ONOSbench.logReport( globalONOSip[1], [ "INFO" ], "d" )
296
297 def CASE10( self, main ):
298 """
299 Start Mininet topology with OF 1.0 switches
300 """
301 main.OFProtocol = "1.0"
302 main.log.report( "Start Mininet topology with OF 1.0 switches" )
303 main.case( "Start Mininet topology with OF 1.0 switches" )
304 main.caseExplanation = "Start mininet topology with OF 1.0 " +\
305 "switches to test intents, exits out if " +\
306 "topology did not start correctly"
307
308 main.step( "Starting Mininet topology with OF 1.0 switches" )
309 args = "--switch ovs,protocols=OpenFlow10"
310 switches = int( main.params['MININET']['switch'] )
311 cmd = "mn --topo linear,{} {}".format( switches, args )
312 topoResult = main.Mininet1.startNet( mnCmd = cmd )
313 stepResult = topoResult
314 utilities.assert_equals( expect=main.TRUE,
315 actual=stepResult,
316 onpass="Successfully loaded topology",
317 onfail="Failed to load topology" )
318 # Exit if topology did not load properly
319 if not topoResult:
320 main.cleanup()
321 main.exit()
322
323 def CASE11( self, main ):
324 """
325 Start Mininet topology with OF 1.3 switches
326 """
327 import re
328 main.OFProtocol = "1.3"
329 main.log.report( "Start Mininet topology with OF 1.3 switches" )
330 main.case( "Start Mininet topology with OF 1.3 switches" )
331 main.caseExplanation = "Start mininet topology with OF 1.3 " +\
332 "switches to test intents, exits out if " +\
333 "topology did not start correctly"
334
335 main.step( "Starting Mininet topology with OF 1.3 switches" )
336 args = "--switch ovs,protocols=OpenFlow13"
337 switches = int( main.params['MININET']['switch'] )
338 cmd = "mn --topo linear,{} {}".format( switches, args )
339 topoResult = main.Mininet1.startNet( mnCmd = cmd )
340 stepResult = topoResult
341 utilities.assert_equals( expect=main.TRUE,
342 actual=stepResult,
343 onpass="Successfully loaded topology",
344 onfail="Failed to load topology" )
345 # Exit if topology did not load properly
346 if not topoResult:
347 main.cleanup()
348 main.exit()
349
350 tempONOSip = []
351 for i in range( main.numCtrls ):
352 tempONOSip.append( main.ONOSip[ i ] )
353
354 swList = [ "s" + str( i ) for i in range( 1, switches + 1 ) ]
355 assignResult = main.Mininet1.assignSwController( sw=swList,
356 ip=tempONOSip,
357 port='6653' )
358 if not assignResult:
359 main.cleanup()
360 main.exit()
361
362 assignResult = main.TRUE
363 for sw in swList:
364 response = main.Mininet1.getSwController( "s" + str( i ) )
365 main.log.info( "Response is " + str( response ) )
366 for ip in tempONOSip:
367 if re.search( "tcp:" + ip, response ):
368 assignResult = assignResult and main.TRUE
369 else:
370 assignResult = assignResult and main.FALSE
371 stepResult = assignResult
372 utilities.assert_equals( expect=main.TRUE,
373 actual=stepResult,
374 onpass="Successfully assigned switches" +
375 "to controller",
376 onfail="Failed to assign switches to " +
377 "controller" )
378
379 def CASE14( self, main ):
380 """
381 Stop mininet
382 """
383 main.log.report( "Stop Mininet topology" )
384 main.case( "Stop Mininet topology" )
385 main.caseExplanation = "Stopping the current mininet topology " +\
386 "to start up fresh"
387
388 main.step( "Stopping Mininet Topology" )
389 topoResult = main.Mininet1.stopNet( )
390 stepResult = topoResult
391 utilities.assert_equals( expect=main.TRUE,
392 actual=stepResult,
393 onpass="Successfully stop mininet",
394 onfail="Failed to stop mininet" )
395 # Exit if topology did not load properly
396 if not topoResult:
397 main.cleanup()
398 main.exit()
399
400 def CASE20( self, main ):
401 """
402 Add some device configurations and then check they are distributed
403 to all nodes
404 """
405 main.case( "Add Network configurations to the cluster" )
406 main.caseExplanation = "Add Network Configurations for devices" +\
407 " not discovered yet. One device is allowed" +\
408 ", the other disallowed."
409 pprint = main.nodes[0].pprint
410
411 main.step( "Add Net Cfg for switch1" )
412 s1Json = { "rackAddress": 1,
413 "name": "Switch1",
414 "owner": "Jimmy",
415 "allowed": True }
416 main.s1Json = s1Json
417 setS1Allow = main.ONOSrest1.setNetCfg( s1Json,
418 subjectClass="devices",
419 subjectKey="of:0000000000000001",
420 configKey="basic" )
421 s1Result = False
422 if setS1Allow:
423 # Check what we set is what is in ONOS
424 getS1 = main.ONOSrest1.getNetCfg( subjectClass="devices",
425 subjectKey="of:0000000000000001",
426 configKey="basic" )
427 onosCfg = pprint( getS1 )
428 sentCfg = pprint( s1Json )
429 if onosCfg == sentCfg:
430 s1Result = True
431 else:
432 main.log.error( "ONOS NetCfg doesn't match what was sent" )
433 main.log.debug( "ONOS config: {}".format( onosCfg ) )
434 main.log.debug( "Sent config: {}".format( sentCfg ) )
435 utilities.assert_equals( expect=True,
436 actual=s1Result,
437 onpass="Net Cfg added for device s1",
438 onfail="Net Cfg for device s1 not correctly set" )
439
440 main.step( "Add Net Cfg for switch3" )
441 s3Json = { "rackAddress": 3,
442 "name": "Switch3",
443 "owner": "Jane",
444 "allowed": False }
445 main.s3Json = s3Json
446 setS3Disallow = main.ONOSrest1.setNetCfg( s3Json,
447 subjectClass="devices",
448 subjectKey="of:0000000000000003",
449 configKey="basic" )
450 s3Result = False
451 if setS3Disallow:
452 # Check what we set is what is in ONOS
453 getS3 = main.ONOSrest1.getNetCfg( subjectClass="devices",
454 subjectKey="of:0000000000000003",
455 configKey="basic" )
456 onosCfg = pprint( getS3 )
457 sentCfg = pprint( s3Json )
458 if onosCfg == sentCfg:
459 s3Result = True
460 else:
461 main.log.error( "ONOS NetCfg doesn't match what was sent" )
462 main.log.debug( "ONOS config: {}".format( onosCfg ) )
463 main.log.debug( "Sent config: {}".format( sentCfg ) )
464 utilities.assert_equals( expect=True,
465 actual=s3Result,
466 onpass="Net Cfg added for device s3",
467 onfail="Net Cfg for device s3 not correctly set" )
468 main.netCfg.compareCfg( main, main.gossipTime )
469
470 def CASE21( self, main ):
471 """
472 Initial check of devices
473 """
474 import json
475 try:
476 assert main.s1Json, "s1Json not defined"
477 except AssertionError:
478 main.log.exception( "Case Prerequisites not set: " )
479 main.cleanup()
480 main.exit()
481 main.case( "Check Devices After they initially connect to ONOS" )
482
483 main.netCfg.compareCfg( main )
484
485 main.step( "ONOS should only show devices S1, S2, and S4" )
486 devices = main.ONOSrest1.devices()
487 main.log.debug( main.ONOSrest1.pprint( devices ) )
488 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4 ] ]
489 print allowedDevices
490 onosDevices = []
491 for sw in json.loads( devices ):
492 onosDevices.append( str( sw['id'] ) )
493 onosDevices.sort()
494 print onosDevices
495 utilities.assert_equals( expect=allowedDevices,
496 actual=onosDevices,
497 onpass="Only allowed devices are in ONOS",
498 onfail="ONOS devices doesn't match the list" +
499 " of allowed devices" )
500
501 main.step( "Check device annotations" )
502 keys = [ 'name', 'owner', 'rackAddress' ]
503 for sw in json.loads( devices ):
504 if "of:0000000000000001" in sw['id']:
505 s1Correct = True
506 for k in keys:
507 if str( sw['annotations'][k] ) != str( main.s1Json[k] ):
508 s1Correct = False
509 main.log.debug( "{} is wrong on s1".format( k ) )
510 if not s1Correct:
511 main.log.error( "Annotations for s1 are incorrect: {}".format( sw ) )
512 try:
513 stepResult = s1Correct
514 except NameError:
515 stepResult = False
516 main.log.error( "s1 not found in devices" )
517 utilities.assert_equals( expect=True,
518 actual=stepResult,
519 onpass="Configured device's annotations are correct",
520 onfail="Incorrect annotations for configured devices." )
521
522 def CASE22( self, main ):
523 """
524 Add some device configurations for connected devices and then check
525 they are distributed to all nodes
526 """
527 main.case( "Add Network configurations for connected devices to the cluster" )
528 main.caseExplanation = "Add Network Configurations for discovered " +\
529 "devices. One device is allowed" +\
530 ", the other disallowed."
531 pprint = main.nodes[0].pprint
532
533 main.step( "Add Net Cfg for switch2" )
534 s2Json = { "rackAddress": 2,
535 "name": "Switch2",
536 "owner": "Jenny",
537 "allowed": True }
538 main.s2Json = s2Json
539 setS2Allow = main.ONOSrest2.setNetCfg( s2Json,
540 subjectClass="devices",
541 subjectKey="of:0000000000000002",
542 configKey="basic" )
543 s2Result = False
544 if setS2Allow:
545 # Check what we set is what is in ONOS
546 getS2 = main.ONOSrest2.getNetCfg( subjectClass="devices",
547 subjectKey="of:0000000000000002",
548 configKey="basic" )
549 onosCfg = pprint( getS2 )
550 sentCfg = pprint( s2Json )
551 if onosCfg == sentCfg:
552 s2Result = True
553 else:
554 main.log.error( "ONOS NetCfg doesn't match what was sent" )
555 main.log.debug( "ONOS config: {}".format( onosCfg ) )
556 main.log.debug( "Sent config: {}".format( sentCfg ) )
557 utilities.assert_equals( expect=True,
558 actual=s2Result,
559 onpass="Net Cfg added for device s2",
560 onfail="Net Cfg for device s2 not correctly set" )
561
562 main.step( "Add Net Cfg for switch4" )
563 s4Json = { "rackAddress": 4,
564 "name": "Switch4",
565 "owner": "John",
566 "allowed": False }
567 main.s4Json = s4Json
568 setS4Disallow = main.ONOSrest4.setNetCfg( s4Json,
569 subjectClass="devices",
570 subjectKey="of:0000000000000004",
571 configKey="basic" )
572 s4Result = False
573 if setS4Disallow:
574 # Check what we set is what is in ONOS
575 getS4 = main.ONOSrest4.getNetCfg( subjectClass="devices",
576 subjectKey="of:0000000000000004",
577 configKey="basic" )
578 onosCfg = pprint( getS4 )
579 sentCfg = pprint( s4Json )
580 if onosCfg == sentCfg:
581 s4Result = True
582 else:
583 main.log.error( "ONOS NetCfg doesn't match what was sent" )
584 main.log.debug( "ONOS config: {}".format( onosCfg ) )
585 main.log.debug( "Sent config: {}".format( sentCfg ) )
586 utilities.assert_equals( expect=True,
587 actual=s4Result,
588 onpass="Net Cfg added for device s4",
589 onfail="Net Cfg for device s3 not correctly set" )
590
591 main.netCfg.compareCfg( main, main.gossipTime )
592
593 def CASE23( self, main ):
594 """
595 Check of devices after all Network Configurations are set
596 """
597 import json
598 try:
599 assert main.s1Json, "s1Json not defined"
600 assert main.s2Json, "s2Json not defined"
601 except AssertionError:
602 main.log.exception( "Case Prerequisites not set: " )
603 main.cleanup()
604 main.exit()
605 main.case( "Check Devices after all configurations are set" )
606
607 main.netCfg.compareCfg( main )
608
609 main.step( "ONOS should only show devices S1 and S2" )
610 devices = main.ONOSrest1.devices()
611 main.log.debug( main.ONOSrest1.pprint( devices ) )
612 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2 ] ]
613 onosDevices = []
614 for sw in json.loads( devices ):
615 onosDevices.append( str( sw['id'] ) )
616 onosDevices.sort()
617 failMsg = "ONOS devices doesn't match the list of allowed devices.\n"
618 failMsg += "Expected devices: {}\nActual devices: {}".format( allowedDevices,
619 onosDevices )
620 utilities.assert_equals( expect=allowedDevices,
621 actual=onosDevices,
622 onpass="Only allowed devices are in ONOS",
623 onfail=failMsg )
624
625 main.step( "Check device annotations" )
626 keys = [ 'name', 'owner', 'rackAddress' ]
627 for sw in json.loads( devices ):
628 if "of:0000000000000001" in sw['id']:
629 s1Correct = True
630 for k in keys:
631 if str( sw['annotations'][k] ) != str( main.s1Json[k] ):
632 s1Correct = False
633 main.log.debug( "{} is wrong on s1".format( k ) )
634 if not s1Correct:
635 main.log.error( "Annotations for s1 are incorrect: {}".format( sw ) )
636 elif "of:0000000000000002" in sw['id']:
637 s2Correct = True
638 for k in keys:
639 if str( sw['annotations'][k] ) != str( main.s2Json[k] ):
640 s2Correct = False
641 main.log.debug( "{} is wrong on s2".format( k ) )
642 if not s2Correct:
643 main.log.error( "Annotations for s2 are incorrect: {}".format( sw ) )
644 try:
645 stepResult = s1Correct and s2Correct
646 except NameError:
647 stepResult = False
648 main.log.error( "s1 and/or s2 not found in devices" )
649 utilities.assert_equals( expect=True,
650 actual=stepResult,
651 onpass="Configured device's annotations are correct",
652 onfail="Incorrect annotations for configured devices." )
653
654 def CASE24( self, main ):
655 """
656 Testing removal of configurations
657 """
658 try:
659 assert main.s1Json, "s1Json not defined"
660 assert main.s2Json, "s2Json not defined"
661 assert main.s3Json, "s3Json not defined"
662 assert main.s4Json, "s4Json not defined"
663 except AssertionError:
664 main.log.exception( "Case Prerequisites not set: " )
665 main.cleanup()
666 main.exit()
667 main.case( "Testing removal of configurations" )
668 main.step( "Remove 'allowed' configuration from all devices" )
669
670 s1Json = main.s1Json # NOTE: This is a reference
671 try:
672 del s1Json['allowed']
673 except KeyError:
674 main.log.exception( "Key not found" )
675 setS1 = main.ONOSrest1.setNetCfg( s1Json,
676 subjectClass="devices",
677 subjectKey="of:0000000000000001",
678 configKey="basic" )
679
680 s2Json = main.s2Json # NOTE: This is a reference
681 try:
682 del s2Json['allowed']
683 except KeyError:
684 main.log.exception( "Key not found" )
685 setS2 = main.ONOSrest2.setNetCfg( s2Json,
686 subjectClass="devices",
687 subjectKey="of:0000000000000002",
688 configKey="basic" )
689
690 s3Json = main.s3Json # NOTE: This is a reference
691 try:
692 del s3Json['allowed']
693 except KeyError:
694 main.log.exception( "Key not found" )
695 setS3 = main.ONOSrest3.setNetCfg( s3Json,
696 subjectClass="devices",
697 subjectKey="of:0000000000000003",
698 configKey="basic" )
699
700 s4Json = main.s4Json # NOTE: This is a reference
701 try:
702 del s4Json['allowed']
703 except KeyError:
704 main.log.exception( "Key not found" )
705 setS4 = main.ONOSrest4.setNetCfg( s4Json,
706 subjectClass="devices",
707 subjectKey="of:0000000000000004",
708 configKey="basic" )
709 removeAllowed = setS1 and setS2 and setS3 and setS4
710 utilities.assert_equals( expect=main.TRUE,
711 actual=removeAllowed,
712 onpass="Successfully removed 'allowed' config from devices",
713 onfail="Failed to remove the 'allowed' config key." )
714
715 main.netCfg.compareCfg( main, main.gossipTime )
716
717 main.step( "Delete basic config for s1 and s2" )
718 removeS1 = main.ONOSrest1.removeNetCfg( subjectClass="devices",
719 subjectKey="of:0000000000000001",
720 configKey="basic" )
721 removeS2 = main.ONOSrest2.removeNetCfg( subjectClass="devices",
722 subjectKey="of:0000000000000002",
723 configKey="basic" )
724 removeSingles = removeS1 and removeS2
725 utilities.assert_equals( expect=main.TRUE,
726 actual=removeSingles,
727 onpass="Successfully removed S1 and S2 basic config",
728 onfail="Failed to removed S1 and S2 basic config" )
729
730 main.netCfg.compareCfg( main, main.gossipTime )
731
732 main.step( "Delete the net config for S3" )
733 removeS3 = main.ONOSrest3.removeNetCfg( subjectClass="devices",
734 subjectKey="of:0000000000000003" )
735 utilities.assert_equals( expect=main.TRUE,
736 actual=removeS3,
737 onpass="Successfully removed S3's config",
738 onfail="Failed to removed S3's config" )
739
740 main.netCfg.compareCfg( main, main.gossipTime )
741
742 main.step( "Delete the net config for all devices" )
743 remove = main.ONOSrest3.removeNetCfg( subjectClass="devices" )
744 utilities.assert_equals( expect=main.TRUE,
745 actual=remove,
746 onpass="Successfully removed device config",
747 onfail="Failed to remove device config" )
748
749 main.netCfg.compareCfg( main, main.gossipTime )
750
751 main.step( "Assert the net config for devices is empty" )
752 get = main.ONOSrest3.getNetCfg( subjectClass="devices" )
753 utilities.assert_equals( expect='{}',
754 actual=get,
755 onpass="Successfully removed device config",
756 onfail="Failed to remove device config" )