blob: ec1a0f19cd2e4f329ae052f25b373b73bb7c828a [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" )
Pratik Parab6f418632017-04-25 17:05:50 -0700414
415 import json
416 import os
417 try:
418 with open( os.path.dirname( main.testFile ) + '/dependencies/s1Json', 'r' ) as s1Jsondata:
419 s1Json = json.load( s1Jsondata )
420 except IOError:
421 main.log.exception( "s1Json File not found." )
422 main.log.info( "s1Json:" + str( s1Json ) )
423
Jon Hall66e001c2015-11-12 09:45:10 -0800424 main.s1Json = s1Json
425 setS1Allow = main.ONOSrest1.setNetCfg( s1Json,
426 subjectClass="devices",
427 subjectKey="of:0000000000000001",
428 configKey="basic" )
429 s1Result = False
alison15124df2016-10-06 12:04:51 -0700430 #Wait 5 secs after set up netCfg
431 time.sleep( main.SetNetCfgSleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800432 if setS1Allow:
433 # Check what we set is what is in ONOS
434 getS1 = main.ONOSrest1.getNetCfg( subjectClass="devices",
435 subjectKey="of:0000000000000001",
436 configKey="basic" )
437 onosCfg = pprint( getS1 )
438 sentCfg = pprint( s1Json )
439 if onosCfg == sentCfg:
alison15124df2016-10-06 12:04:51 -0700440 main.log.info( "ONOS NetCfg match what was sent" )
Jon Hall66e001c2015-11-12 09:45:10 -0800441 s1Result = True
442 else:
443 main.log.error( "ONOS NetCfg doesn't match what was sent" )
444 main.log.debug( "ONOS config: {}".format( onosCfg ) )
445 main.log.debug( "Sent config: {}".format( sentCfg ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700446 utilities.retry( f=main.ONOSrest1.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800447 utilities.assert_equals( expect=True,
448 actual=s1Result,
449 onpass="Net Cfg added for device s1",
450 onfail="Net Cfg for device s1 not correctly set" )
451
452 main.step( "Add Net Cfg for switch3" )
Pratik Parab6f418632017-04-25 17:05:50 -0700453
454 try:
455 with open( os.path.dirname( main.testFile ) + '/dependencies/s3Json', 'r' ) as s3Jsondata:
456 s3Json = json.load( s3Jsondata )
457 except IOError:
458 main.log.exception( "s3Json File not found" )
459 main.log.info( "s3Json:" + str( s3Json) )
460
Jon Hall66e001c2015-11-12 09:45:10 -0800461 main.s3Json = s3Json
462 setS3Disallow = main.ONOSrest1.setNetCfg( s3Json,
463 subjectClass="devices",
464 subjectKey="of:0000000000000003",
465 configKey="basic" )
466 s3Result = False
alison15124df2016-10-06 12:04:51 -0700467 time.sleep( main.SetNetCfgSleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800468 if setS3Disallow:
469 # Check what we set is what is in ONOS
470 getS3 = main.ONOSrest1.getNetCfg( subjectClass="devices",
471 subjectKey="of:0000000000000003",
472 configKey="basic" )
473 onosCfg = pprint( getS3 )
474 sentCfg = pprint( s3Json )
475 if onosCfg == sentCfg:
alison15124df2016-10-06 12:04:51 -0700476 main.log.info("ONOS NetCfg match what was sent")
Jon Hall66e001c2015-11-12 09:45:10 -0800477 s3Result = True
478 else:
479 main.log.error( "ONOS NetCfg doesn't match what was sent" )
480 main.log.debug( "ONOS config: {}".format( onosCfg ) )
481 main.log.debug( "Sent config: {}".format( sentCfg ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700482 utilities.retry( f=main.ONOSrest1.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800483 utilities.assert_equals( expect=True,
484 actual=s3Result,
485 onpass="Net Cfg added for device s3",
486 onfail="Net Cfg for device s3 not correctly set" )
487 main.netCfg.compareCfg( main, main.gossipTime )
488
489 def CASE21( self, main ):
490 """
491 Initial check of devices
492 """
493 import json
494 try:
495 assert main.s1Json, "s1Json not defined"
496 except AssertionError:
497 main.log.exception( "Case Prerequisites not set: " )
498 main.cleanup()
499 main.exit()
500 main.case( "Check Devices After they initially connect to ONOS" )
501
502 main.netCfg.compareCfg( main )
503
504 main.step( "ONOS should only show devices S1, S2, and S4" )
505 devices = main.ONOSrest1.devices()
506 main.log.debug( main.ONOSrest1.pprint( devices ) )
507 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4 ] ]
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700508 main.log.debug( allowedDevices )
Jon Hall66e001c2015-11-12 09:45:10 -0800509 onosDevices = []
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700510 try:
511 for sw in json.loads( devices ):
512 onosDevices.append( str( sw['id'] ) )
513 onosDevices.sort()
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700514 main.log.debug( onosDevices )
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700515 except( TypeError, ValueError ):
516 main.log.error( "Problem loading devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800517 utilities.assert_equals( expect=allowedDevices,
518 actual=onosDevices,
519 onpass="Only allowed devices are in ONOS",
520 onfail="ONOS devices doesn't match the list" +
521 " of allowed devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800522 main.step( "Check device annotations" )
523 keys = [ 'name', 'owner', 'rackAddress' ]
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700524 try:
525 for sw in json.loads( devices ):
526 if "of:0000000000000001" in sw['id']:
527 s1Correct = True
528 for k in keys:
529 if str( sw.get( 'annotations', {} ).get( k ) ) != str( main.s1Json[k] ):
530 s1Correct = False
531 main.log.debug( "{} is wrong on s1".format( k ) )
532 if not s1Correct:
533 main.log.error( "Annotations for s1 are incorrect: {}".format( sw ) )
534 except( TypeError, ValueError ):
535 main.log.error( "Problem loading devices" )
536 s1Correct = False
Jon Hall66e001c2015-11-12 09:45:10 -0800537 try:
538 stepResult = s1Correct
539 except NameError:
540 stepResult = False
541 main.log.error( "s1 not found in devices" )
542 utilities.assert_equals( expect=True,
543 actual=stepResult,
544 onpass="Configured device's annotations are correct",
545 onfail="Incorrect annotations for configured devices." )
546
547 def CASE22( self, main ):
548 """
549 Add some device configurations for connected devices and then check
550 they are distributed to all nodes
551 """
552 main.case( "Add Network configurations for connected devices to the cluster" )
553 main.caseExplanation = "Add Network Configurations for discovered " +\
554 "devices. One device is allowed" +\
555 ", the other disallowed."
556 pprint = main.nodes[0].pprint
557
558 main.step( "Add Net Cfg for switch2" )
Pratik Parab6f418632017-04-25 17:05:50 -0700559 try:
560 with open( os.path.dirname( main.testFile ) + '/dependencies/s2Json', 'r' ) as s2Jsondata:
561 s2Json = json.load( s2Jsondata )
562 except IOError:
563 main.log.exception( "s2Json File not found" )
564 main.log.info( "s2Json:" + str( s2Json ) )
Jon Hall66e001c2015-11-12 09:45:10 -0800565 main.s2Json = s2Json
566 setS2Allow = main.ONOSrest2.setNetCfg( s2Json,
567 subjectClass="devices",
568 subjectKey="of:0000000000000002",
569 configKey="basic" )
570 s2Result = False
571 if setS2Allow:
572 # Check what we set is what is in ONOS
573 getS2 = main.ONOSrest2.getNetCfg( subjectClass="devices",
574 subjectKey="of:0000000000000002",
575 configKey="basic" )
576 onosCfg = pprint( getS2 )
577 sentCfg = pprint( s2Json )
578 if onosCfg == sentCfg:
579 s2Result = True
580 else:
581 main.log.error( "ONOS NetCfg doesn't match what was sent" )
582 main.log.debug( "ONOS config: {}".format( onosCfg ) )
583 main.log.debug( "Sent config: {}".format( sentCfg ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700584 utilities.retry( f=main.ONOSrest2.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800585 utilities.assert_equals( expect=True,
586 actual=s2Result,
587 onpass="Net Cfg added for device s2",
588 onfail="Net Cfg for device s2 not correctly set" )
589
590 main.step( "Add Net Cfg for switch4" )
Pratik Parab6f418632017-04-25 17:05:50 -0700591
592 try:
593 with open( os.path.dirname( main.testFile ) + '/dependencies/s4Json', 'r' ) as s4Jsondata:
594 s4Json = json.load( s4Jsondata )
595 except IOError:
596 main.log.exception( "s4Json File not found" )
597 main.log.info( "s4Json:" + str( s4Json ) )
Jon Hall66e001c2015-11-12 09:45:10 -0800598 main.s4Json = s4Json
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700599 setS4Disallow = main.ONOSrest3.setNetCfg( s4Json,
Jon Hall66e001c2015-11-12 09:45:10 -0800600 subjectClass="devices",
601 subjectKey="of:0000000000000004",
602 configKey="basic" )
603 s4Result = False
604 if setS4Disallow:
605 # Check what we set is what is in ONOS
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700606 getS4 = main.ONOSrest3.getNetCfg( subjectClass="devices",
Jon Hall66e001c2015-11-12 09:45:10 -0800607 subjectKey="of:0000000000000004",
608 configKey="basic" )
609 onosCfg = pprint( getS4 )
610 sentCfg = pprint( s4Json )
611 if onosCfg == sentCfg:
612 s4Result = True
613 else:
614 main.log.error( "ONOS NetCfg doesn't match what was sent" )
615 main.log.debug( "ONOS config: {}".format( onosCfg ) )
616 main.log.debug( "Sent config: {}".format( sentCfg ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700617 main.step( "Retrying main.ONOSrest3.getNetCfg" )
618 utilities.retry( f=main.ONOSrest3.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800619 utilities.assert_equals( expect=True,
620 actual=s4Result,
621 onpass="Net Cfg added for device s4",
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700622 onfail="Net Cfg for device s4 not correctly set" )
Jon Hall66e001c2015-11-12 09:45:10 -0800623
624 main.netCfg.compareCfg( main, main.gossipTime )
625
626 def CASE23( self, main ):
627 """
628 Check of devices after all Network Configurations are set
629 """
630 import json
631 try:
632 assert main.s1Json, "s1Json not defined"
633 assert main.s2Json, "s2Json not defined"
634 except AssertionError:
635 main.log.exception( "Case Prerequisites not set: " )
636 main.cleanup()
637 main.exit()
638 main.case( "Check Devices after all configurations are set" )
639
640 main.netCfg.compareCfg( main )
641
642 main.step( "ONOS should only show devices S1 and S2" )
643 devices = main.ONOSrest1.devices()
644 main.log.debug( main.ONOSrest1.pprint( devices ) )
645 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2 ] ]
646 onosDevices = []
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700647 try:
648 for sw in json.loads( devices ):
649 onosDevices.append( str( sw.get( 'id' ) ) )
650 onosDevices.sort()
651 failMsg = "ONOS devices doesn't match the list of allowed devices.\n"
652 failMsg += "Expected devices: {}\nActual devices: {}".format( allowedDevices,
653 onosDevices )
654 except( TypeError, ValueError ):
655 main.log.error( "Problem loading devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800656 utilities.assert_equals( expect=allowedDevices,
657 actual=onosDevices,
658 onpass="Only allowed devices are in ONOS",
659 onfail=failMsg )
660
661 main.step( "Check device annotations" )
662 keys = [ 'name', 'owner', 'rackAddress' ]
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700663 try:
664 for sw in json.loads( devices ):
665 if "of:0000000000000001" in sw.get( 'id' ):
666 s1Correct = True
667 for k in keys:
668 if str( sw.get( 'annotations', {} ).get( k ) ) != str( main.s1Json[k] ):
669 s1Correct = False
670 main.log.debug( "{} is wrong on s1".format( k ) )
671 if not s1Correct:
672 main.log.error( "Annotations for s1 are incorrect: {}".format( sw ) )
673 elif "of:0000000000000002" in sw['id']:
674 s2Correct = True
675 for k in keys:
676 if str( sw.get( 'annotations', {} ).get( k ) ) != str( main.s2Json[k] ):
677 s2Correct = False
678 main.log.debug( "{} is wrong on s2".format( k ) )
679 if not s2Correct:
680 main.log.error( "Annotations for s2 are incorrect: {}".format( sw ) )
681 except( TypeError, ValueError ):
682 main.log.error( "Problem loading devices" )
683 stepResult = False
Jon Hall66e001c2015-11-12 09:45:10 -0800684 try:
685 stepResult = s1Correct and s2Correct
686 except NameError:
687 stepResult = False
688 main.log.error( "s1 and/or s2 not found in devices" )
689 utilities.assert_equals( expect=True,
690 actual=stepResult,
691 onpass="Configured device's annotations are correct",
692 onfail="Incorrect annotations for configured devices." )
693
694 def CASE24( self, main ):
695 """
696 Testing removal of configurations
697 """
Jon Hall541b8e02015-12-14 19:29:01 -0800698 import time
Jon Hall66e001c2015-11-12 09:45:10 -0800699 try:
700 assert main.s1Json, "s1Json not defined"
701 assert main.s2Json, "s2Json not defined"
702 assert main.s3Json, "s3Json not defined"
703 assert main.s4Json, "s4Json not defined"
704 except AssertionError:
705 main.log.exception( "Case Prerequisites not set: " )
706 main.cleanup()
707 main.exit()
708 main.case( "Testing removal of configurations" )
709 main.step( "Remove 'allowed' configuration from all devices" )
710
711 s1Json = main.s1Json # NOTE: This is a reference
712 try:
713 del s1Json['allowed']
714 except KeyError:
715 main.log.exception( "Key not found" )
716 setS1 = main.ONOSrest1.setNetCfg( s1Json,
717 subjectClass="devices",
718 subjectKey="of:0000000000000001",
719 configKey="basic" )
720
721 s2Json = main.s2Json # NOTE: This is a reference
722 try:
Jon Hall541b8e02015-12-14 19:29:01 -0800723 time.sleep( main.gossipTime )
Jon Hall66e001c2015-11-12 09:45:10 -0800724 del s2Json['allowed']
725 except KeyError:
726 main.log.exception( "Key not found" )
727 setS2 = main.ONOSrest2.setNetCfg( s2Json,
728 subjectClass="devices",
729 subjectKey="of:0000000000000002",
730 configKey="basic" )
731
732 s3Json = main.s3Json # NOTE: This is a reference
733 try:
Jon Hall541b8e02015-12-14 19:29:01 -0800734 time.sleep( main.gossipTime )
Jon Hall66e001c2015-11-12 09:45:10 -0800735 del s3Json['allowed']
736 except KeyError:
737 main.log.exception( "Key not found" )
738 setS3 = main.ONOSrest3.setNetCfg( s3Json,
739 subjectClass="devices",
740 subjectKey="of:0000000000000003",
741 configKey="basic" )
742
743 s4Json = main.s4Json # NOTE: This is a reference
744 try:
Jon Hall541b8e02015-12-14 19:29:01 -0800745 time.sleep( main.gossipTime )
Jon Hall66e001c2015-11-12 09:45:10 -0800746 del s4Json['allowed']
747 except KeyError:
748 main.log.exception( "Key not found" )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700749 setS4 = main.ONOSrest3.setNetCfg( s4Json,
Jon Hall66e001c2015-11-12 09:45:10 -0800750 subjectClass="devices",
751 subjectKey="of:0000000000000004",
752 configKey="basic" )
753 removeAllowed = setS1 and setS2 and setS3 and setS4
754 utilities.assert_equals( expect=main.TRUE,
755 actual=removeAllowed,
756 onpass="Successfully removed 'allowed' config from devices",
757 onfail="Failed to remove the 'allowed' config key." )
758
759 main.netCfg.compareCfg( main, main.gossipTime )
760
761 main.step( "Delete basic config for s1 and s2" )
762 removeS1 = main.ONOSrest1.removeNetCfg( subjectClass="devices",
763 subjectKey="of:0000000000000001",
764 configKey="basic" )
765 removeS2 = main.ONOSrest2.removeNetCfg( subjectClass="devices",
766 subjectKey="of:0000000000000002",
767 configKey="basic" )
768 removeSingles = removeS1 and removeS2
769 utilities.assert_equals( expect=main.TRUE,
770 actual=removeSingles,
771 onpass="Successfully removed S1 and S2 basic config",
772 onfail="Failed to removed S1 and S2 basic config" )
773
774 main.netCfg.compareCfg( main, main.gossipTime )
775
776 main.step( "Delete the net config for S3" )
777 removeS3 = main.ONOSrest3.removeNetCfg( subjectClass="devices",
778 subjectKey="of:0000000000000003" )
779 utilities.assert_equals( expect=main.TRUE,
780 actual=removeS3,
781 onpass="Successfully removed S3's config",
782 onfail="Failed to removed S3's config" )
783
784 main.netCfg.compareCfg( main, main.gossipTime )
785
786 main.step( "Delete the net config for all devices" )
787 remove = main.ONOSrest3.removeNetCfg( subjectClass="devices" )
788 utilities.assert_equals( expect=main.TRUE,
789 actual=remove,
790 onpass="Successfully removed device config",
791 onfail="Failed to remove device config" )
792
793 main.netCfg.compareCfg( main, main.gossipTime )
794
795 main.step( "Assert the net config for devices is empty" )
796 get = main.ONOSrest3.getNetCfg( subjectClass="devices" )
797 utilities.assert_equals( expect='{}',
798 actual=get,
799 onpass="Successfully removed device config",
800 onfail="Failed to remove device config" )
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700801
802 def CASE25( self, main ):
803 """
804 Use network-cfg.json to configure devices during ONOS startup
805 """
806 main.case( "Preparing network-cfg.json to load configurations" )
807 main.step( "Moving network-cfg.json to $ONOS_ROOT/tools/package/config/" )
808 prestartResult = main.TRUE
809 srcPath = "~/OnosSystemTest/TestON/tests/FUNC/FUNCnetCfg/dependencies/network-cfg.json"
810 dstPath = "~/onos/tools/package/config/network-cfg.json"
811 prestartResult = main.ONOSbench.scp( main.ONOSbench, srcPath, dstPath, direction="to" )
812 utilities.assert_equals( expect=main.TRUE,
813 actual=prestartResult,
814 onpass="Successfully copied network-cfg.json to target directory",
815 onfail="Failed to copy network-cfg.json to target directory" )
816
817 def CASE26( self, main ):
818 """
819 Check to see that pre-startup configurations were set correctly
820 """
821 import json
822 main.case( "Check to see if the pre-startup configurations were set, then remove their allowed status" )
823 main.step( "Checking configurations for Switches 5 and 6" )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700824 main.step( "ONOS should only show devices S1, S2, S4, and S5" ) #and S6
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700825 devices = main.ONOSrest1.devices()
826 main.log.debug( main.ONOSrest1.pprint( devices ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700827 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4, 5 ] ] #6
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700828 main.log.debug( allowedDevices )
829 onosDevices = []
830 try:
831 for sw in json.loads( devices ):
832 onosDevices.append( str( sw['id'] ) )
833 onosDevices.sort()
834 main.log.debug( onosDevices )
835 except( TypeError, ValueError ):
836 main.log.error( "Problem loading devices" )
837 utilities.assert_equals( expect=allowedDevices,
838 actual=onosDevices,
839 onpass="Only allowed devices are in ONOS",
840 onfail="ONOS devices doesn't match the list" +
841 " of allowed devices" )
842
843 main.step( "Removing allowed status from Switches 5 and 6" )
Pratik Parab6f418632017-04-25 17:05:50 -0700844 try:
845 with open( os.path.dirname( main.testFile ) + '/dependencies/s5Json', 'r' ) as s5Jsondata:
846 main.s5Json = json.load( s5Jsondata )
847 except IOError:
848 main.log.exception( "s5Json File not found" )
849 main.log.info( "s5Json:" + str( main.s5Json ) )
850
851 try:
852 with open( os.path.dirname( main.testFile ) + '/dependencies/s6Json', 'r' ) as s6Jsondata:
853 main.s6Json = json.load( s6Jsondata )
854 except IOError:
855 main.log.exception( "s6Json File not found" )
856 main.log.info( "s6Json:" + str( main.s6Json ) )
857
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700858 s5Json = main.s5Json
859 setS1 = main.ONOSrest1.setNetCfg( s5Json,
860 subjectClass="devices",
861 subjectKey="of:0000000000000005",
862 configKey="basic" )
863
864 s6Json = main.s6Json
865 setS1 = main.ONOSrest1.setNetCfg( s6Json,
866 subjectClass="devices",
867 subjectKey="of:0000000000000006",
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700868 configKey="basic" )
869
870 def CASE27( self, main ):
871 """
872 1) A = get /network/configuration
873 2) Post A
874 3) Compare A with ONOS
875 4) Modify A so S6 is disallowed
876 5) Check
877
878 """
879 import json
880 pprint = main.nodes[0].pprint
881 main.case( "Posting network configurations to the top level web resource" )
882 main.step( "Get json object from Net Cfg" )
883 getinfo = main.ONOSrest1.getNetCfg( )
884 main.log.debug( getinfo )
885 main.step( "Posting json object to Net Cfg" )
886 postinfo = main.ONOSrest1.setNetCfg( json.loads( getinfo ) )
887 main.step( "Compare device with ONOS" )
888 main.netCfg.compareCfg( main )
889 main.step ( "ONOS should only show devices S1, S2, S4, S5 and S6" )
890 devices = main.ONOSrest1.devices( )
891 main.log.debug( main.ONOSrest1.pprint( devices ) )
892 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4, 5, 6 ] ]
893 onosDevices = []
894 try:
895 for sw in json.loads( devices ):
896 onosDevices.append( str( sw.get( 'id' ) ) )
897 onosDevices.sort( )
898 failMsg = "ONOS devices doesn't match the list of allowed devices. \n"
899 failMsg += "Expected devices: {}\nActual devices: {}".format( allowedDevices, onosDevices )
900 except( TypeError, ValueError ):
901 main.log.error( "Problem loading devices" )
902 utilities.assert_equals( expect=allowedDevices, actual=onosDevices,
903 onpass="Only allowed devices are in ONOS", onfail=failMsg )
904
905 main.step( "Modify json object so S6 is disallowed" )
906 main.s6Json = { "allowed": False }
907 s6Json = main.s6Json
908 setS6Disallow = main.ONOSrest1.setNetCfg( s6Json, subjectClass="devices",
909 subjectKey="of:0000000000000006", configKey="basic" )
910 s6Result = False
911 if setS6Disallow:
912 getS6 = main.ONOSrest1.getNetCfg( subjectClass="devices",
913 subjectKey="of:0000000000000006", configKey="basic" )
914 onosCfg = pprint( getS6 )
915 sentCfg = pprint( s6Json )
916 if onosCfg == sentCfg:
917 s6Result = True
918 else:
919 main.log.error( "ONOS NetCfg doesn't match what was sent" )
920 main.log.debug( "ONOS config: {}".format( onosCfg ) )
921 main.log.debug( "Sent config: {}".format( sentCfg ) )
922 utilities.retry( f=main.ONOSrest1.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
923 utilities.assert_equals( expect=True, actual=s6Result,
924 onpass="Net Cfg added for devices s6",
925 onfail="Net Cfg for device s6 not correctly set" )