blob: bb280d8d7de690f97f29c9b839af675b8045cd79 [file] [log] [blame]
Jon Hall66e001c2015-11-12 09:45:10 -08001
2# Testing the basic intent functionality of ONOS
3
Jon Hallbc080f92017-05-24 16:29:55 -07004
Jon Hall66e001c2015-11-12 09:45:10 -08005class FUNCnetCfg:
6
7 def __init__( self ):
8 self.default = ''
9
10 def CASE1( self, main ):
11 import imp
12 import re
13
14 """
15 - Construct tests variables
16 - GIT ( optional )
17 - Checkout ONOS master branch
18 - Pull latest ONOS code
19 - Building ONOS ( optional )
20 - Install ONOS package
21 - Build ONOS package
22 """
Jon Hall66e001c2015-11-12 09:45:10 -080023 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' ] )
Jon Hallbc080f92017-05-24 16:29:55 -070045 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 ):
Jon Hallbc080f92017-05-24 16:29:55 -0700145 tempOnosIp.append( main.ONOSip[ i ] )
Jon Hall66e001c2015-11-12 09:45:10 -0800146
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 ):
Jon Hallbc080f92017-05-24 16:29:55 -0700288 """
Jon Hall66e001c2015-11-12 09:45:10 -0800289 Report errors/warnings/exceptions
Jon Hallbc080f92017-05-24 16:29:55 -0700290 """
Jon Hall66e001c2015-11-12 09:45:10 -0800291 main.log.info( "Error report: \n" )
292 main.ONOSbench.logReport(
Jon Hallbc080f92017-05-24 16:29:55 -0700293 globalONOSip[ 0 ],
294 [ "INFO", "WARN", "ERROR", "Except" ],
Jon Hall66e001c2015-11-12 09:45:10 -0800295 "s" )
Jon Hallbc080f92017-05-24 16:29:55 -0700296 # main.ONOSbench.logReport( globalONOSip[ 1 ], [ "INFO" ], "d" )
Jon Hall66e001c2015-11-12 09:45:10 -0800297
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 Hallbc080f92017-05-24 16:29:55 -0700311 switches = int( main.params[ 'MININET' ][ 'switch' ] )
Jon Hall66e001c2015-11-12 09:45:10 -0800312 cmd = "mn --topo linear,{} {}".format( switches, args )
Jon Hallbc080f92017-05-24 16:29:55 -0700313 topoResult = main.Mininet1.startNet( mnCmd=cmd )
Jon Hall66e001c2015-11-12 09:45:10 -0800314 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 )
Jon Hallbc080f92017-05-24 16:29:55 -0700340 topoResult = main.Mininet1.startNet( mnCmd=cmd )
Jon Hall66e001c2015-11-12 09:45:10 -0800341 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" )
Jon Hallbc080f92017-05-24 16:29:55 -0700390 topoResult = main.Mininet1.stopNet()
Jon Hall66e001c2015-11-12 09:45:10 -0800391 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
Pratik Parabc6083c22017-04-27 13:24:41 -0700407 import json
408 import os
Jon Hall66e001c2015-11-12 09:45:10 -0800409 main.case( "Add Network configurations to the cluster" )
410 main.caseExplanation = "Add Network Configurations for devices" +\
411 " not discovered yet. One device is allowed" +\
412 ", the other disallowed."
Jon Hallbc080f92017-05-24 16:29:55 -0700413 pprint = main.nodes[ 0 ].pprint
Jon Hall66e001c2015-11-12 09:45:10 -0800414
415 main.step( "Add Net Cfg for switch1" )
Pratik Parab6f418632017-04-25 17:05:50 -0700416
Pratik Parab6f418632017-04-25 17:05:50 -0700417 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." )
Pratik Parabc6083c22017-04-27 13:24:41 -0700422 main.cleanup()
423 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700424 main.log.info( "s1Json:" + str( s1Json ) )
425
Jon Hall66e001c2015-11-12 09:45:10 -0800426 main.s1Json = s1Json
427 setS1Allow = main.ONOSrest1.setNetCfg( s1Json,
428 subjectClass="devices",
429 subjectKey="of:0000000000000001",
430 configKey="basic" )
431 s1Result = False
alison15124df2016-10-06 12:04:51 -0700432 #Wait 5 secs after set up netCfg
433 time.sleep( main.SetNetCfgSleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800434 if setS1Allow:
435 # Check what we set is what is in ONOS
436 getS1 = main.ONOSrest1.getNetCfg( subjectClass="devices",
437 subjectKey="of:0000000000000001",
438 configKey="basic" )
439 onosCfg = pprint( getS1 )
440 sentCfg = pprint( s1Json )
441 if onosCfg == sentCfg:
alison15124df2016-10-06 12:04:51 -0700442 main.log.info( "ONOS NetCfg match what was sent" )
Jon Hall66e001c2015-11-12 09:45:10 -0800443 s1Result = True
444 else:
445 main.log.error( "ONOS NetCfg doesn't match what was sent" )
446 main.log.debug( "ONOS config: {}".format( onosCfg ) )
447 main.log.debug( "Sent config: {}".format( sentCfg ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700448 utilities.retry( f=main.ONOSrest1.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800449 utilities.assert_equals( expect=True,
450 actual=s1Result,
451 onpass="Net Cfg added for device s1",
452 onfail="Net Cfg for device s1 not correctly set" )
453
454 main.step( "Add Net Cfg for switch3" )
Pratik Parab6f418632017-04-25 17:05:50 -0700455
456 try:
457 with open( os.path.dirname( main.testFile ) + '/dependencies/s3Json', 'r' ) as s3Jsondata:
458 s3Json = json.load( s3Jsondata )
459 except IOError:
460 main.log.exception( "s3Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700461 main.cleanup()
462 main.exit()
Jon Hallbc080f92017-05-24 16:29:55 -0700463 main.log.info( "s3Json:" + str( s3Json ) )
Pratik Parab6f418632017-04-25 17:05:50 -0700464
Jon Hall66e001c2015-11-12 09:45:10 -0800465 main.s3Json = s3Json
466 setS3Disallow = main.ONOSrest1.setNetCfg( s3Json,
467 subjectClass="devices",
468 subjectKey="of:0000000000000003",
469 configKey="basic" )
470 s3Result = False
alison15124df2016-10-06 12:04:51 -0700471 time.sleep( main.SetNetCfgSleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800472 if setS3Disallow:
473 # Check what we set is what is in ONOS
474 getS3 = main.ONOSrest1.getNetCfg( subjectClass="devices",
475 subjectKey="of:0000000000000003",
476 configKey="basic" )
477 onosCfg = pprint( getS3 )
478 sentCfg = pprint( s3Json )
479 if onosCfg == sentCfg:
Jon Hallbc080f92017-05-24 16:29:55 -0700480 main.log.info( "ONOS NetCfg match what was sent" )
Jon Hall66e001c2015-11-12 09:45:10 -0800481 s3Result = True
482 else:
483 main.log.error( "ONOS NetCfg doesn't match what was sent" )
484 main.log.debug( "ONOS config: {}".format( onosCfg ) )
485 main.log.debug( "Sent config: {}".format( sentCfg ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700486 utilities.retry( f=main.ONOSrest1.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800487 utilities.assert_equals( expect=True,
488 actual=s3Result,
489 onpass="Net Cfg added for device s3",
490 onfail="Net Cfg for device s3 not correctly set" )
491 main.netCfg.compareCfg( main, main.gossipTime )
492
493 def CASE21( self, main ):
494 """
495 Initial check of devices
496 """
497 import json
498 try:
499 assert main.s1Json, "s1Json not defined"
500 except AssertionError:
501 main.log.exception( "Case Prerequisites not set: " )
502 main.cleanup()
503 main.exit()
504 main.case( "Check Devices After they initially connect to ONOS" )
505
506 main.netCfg.compareCfg( main )
507
508 main.step( "ONOS should only show devices S1, S2, and S4" )
509 devices = main.ONOSrest1.devices()
510 main.log.debug( main.ONOSrest1.pprint( devices ) )
511 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4 ] ]
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700512 main.log.debug( allowedDevices )
Jon Hall66e001c2015-11-12 09:45:10 -0800513 onosDevices = []
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700514 try:
515 for sw in json.loads( devices ):
Jon Hallbc080f92017-05-24 16:29:55 -0700516 onosDevices.append( str( sw[ 'id' ] ) )
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700517 onosDevices.sort()
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700518 main.log.debug( onosDevices )
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700519 except( TypeError, ValueError ):
520 main.log.error( "Problem loading devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800521 utilities.assert_equals( expect=allowedDevices,
522 actual=onosDevices,
523 onpass="Only allowed devices are in ONOS",
524 onfail="ONOS devices doesn't match the list" +
525 " of allowed devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800526 main.step( "Check device annotations" )
527 keys = [ 'name', 'owner', 'rackAddress' ]
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700528 try:
529 for sw in json.loads( devices ):
Jon Hallbc080f92017-05-24 16:29:55 -0700530 if "of:0000000000000001" in sw[ 'id' ]:
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700531 s1Correct = True
532 for k in keys:
Jon Hallbc080f92017-05-24 16:29:55 -0700533 if str( sw.get( 'annotations', {} ).get( k ) ) != str( main.s1Json[ k ] ):
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700534 s1Correct = False
535 main.log.debug( "{} is wrong on s1".format( k ) )
536 if not s1Correct:
537 main.log.error( "Annotations for s1 are incorrect: {}".format( sw ) )
538 except( TypeError, ValueError ):
539 main.log.error( "Problem loading devices" )
540 s1Correct = False
Jon Hall66e001c2015-11-12 09:45:10 -0800541 try:
542 stepResult = s1Correct
543 except NameError:
544 stepResult = False
545 main.log.error( "s1 not found in devices" )
546 utilities.assert_equals( expect=True,
547 actual=stepResult,
548 onpass="Configured device's annotations are correct",
549 onfail="Incorrect annotations for configured devices." )
550
551 def CASE22( self, main ):
552 """
553 Add some device configurations for connected devices and then check
554 they are distributed to all nodes
555 """
556 main.case( "Add Network configurations for connected devices to the cluster" )
557 main.caseExplanation = "Add Network Configurations for discovered " +\
558 "devices. One device is allowed" +\
559 ", the other disallowed."
Jon Hallbc080f92017-05-24 16:29:55 -0700560 pprint = main.nodes[ 0 ].pprint
Jon Hall66e001c2015-11-12 09:45:10 -0800561
562 main.step( "Add Net Cfg for switch2" )
Pratik Parab6f418632017-04-25 17:05:50 -0700563 try:
564 with open( os.path.dirname( main.testFile ) + '/dependencies/s2Json', 'r' ) as s2Jsondata:
565 s2Json = json.load( s2Jsondata )
566 except IOError:
567 main.log.exception( "s2Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700568 main.cleanup()
569 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700570 main.log.info( "s2Json:" + str( s2Json ) )
Jon Hall66e001c2015-11-12 09:45:10 -0800571 main.s2Json = s2Json
572 setS2Allow = main.ONOSrest2.setNetCfg( s2Json,
573 subjectClass="devices",
574 subjectKey="of:0000000000000002",
575 configKey="basic" )
576 s2Result = False
577 if setS2Allow:
578 # Check what we set is what is in ONOS
579 getS2 = main.ONOSrest2.getNetCfg( subjectClass="devices",
580 subjectKey="of:0000000000000002",
581 configKey="basic" )
582 onosCfg = pprint( getS2 )
583 sentCfg = pprint( s2Json )
584 if onosCfg == sentCfg:
585 s2Result = True
586 else:
587 main.log.error( "ONOS NetCfg doesn't match what was sent" )
588 main.log.debug( "ONOS config: {}".format( onosCfg ) )
589 main.log.debug( "Sent config: {}".format( sentCfg ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700590 utilities.retry( f=main.ONOSrest2.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800591 utilities.assert_equals( expect=True,
592 actual=s2Result,
593 onpass="Net Cfg added for device s2",
594 onfail="Net Cfg for device s2 not correctly set" )
595
596 main.step( "Add Net Cfg for switch4" )
Pratik Parab6f418632017-04-25 17:05:50 -0700597
598 try:
599 with open( os.path.dirname( main.testFile ) + '/dependencies/s4Json', 'r' ) as s4Jsondata:
600 s4Json = json.load( s4Jsondata )
601 except IOError:
602 main.log.exception( "s4Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700603 main.cleanup()
604 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700605 main.log.info( "s4Json:" + str( s4Json ) )
Jon Hall66e001c2015-11-12 09:45:10 -0800606 main.s4Json = s4Json
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700607 setS4Disallow = main.ONOSrest3.setNetCfg( s4Json,
Jon Hall66e001c2015-11-12 09:45:10 -0800608 subjectClass="devices",
609 subjectKey="of:0000000000000004",
610 configKey="basic" )
611 s4Result = False
612 if setS4Disallow:
613 # Check what we set is what is in ONOS
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700614 getS4 = main.ONOSrest3.getNetCfg( subjectClass="devices",
Jon Hall66e001c2015-11-12 09:45:10 -0800615 subjectKey="of:0000000000000004",
616 configKey="basic" )
617 onosCfg = pprint( getS4 )
618 sentCfg = pprint( s4Json )
619 if onosCfg == sentCfg:
620 s4Result = True
621 else:
622 main.log.error( "ONOS NetCfg doesn't match what was sent" )
623 main.log.debug( "ONOS config: {}".format( onosCfg ) )
624 main.log.debug( "Sent config: {}".format( sentCfg ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700625 main.step( "Retrying main.ONOSrest3.getNetCfg" )
626 utilities.retry( f=main.ONOSrest3.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800627 utilities.assert_equals( expect=True,
628 actual=s4Result,
629 onpass="Net Cfg added for device s4",
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700630 onfail="Net Cfg for device s4 not correctly set" )
Jon Hall66e001c2015-11-12 09:45:10 -0800631
632 main.netCfg.compareCfg( main, main.gossipTime )
633
634 def CASE23( self, main ):
635 """
636 Check of devices after all Network Configurations are set
637 """
638 import json
639 try:
640 assert main.s1Json, "s1Json not defined"
641 assert main.s2Json, "s2Json not defined"
642 except AssertionError:
643 main.log.exception( "Case Prerequisites not set: " )
644 main.cleanup()
645 main.exit()
646 main.case( "Check Devices after all configurations are set" )
647
648 main.netCfg.compareCfg( main )
649
650 main.step( "ONOS should only show devices S1 and S2" )
651 devices = main.ONOSrest1.devices()
652 main.log.debug( main.ONOSrest1.pprint( devices ) )
653 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2 ] ]
654 onosDevices = []
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700655 try:
656 for sw in json.loads( devices ):
657 onosDevices.append( str( sw.get( 'id' ) ) )
658 onosDevices.sort()
659 failMsg = "ONOS devices doesn't match the list of allowed devices.\n"
660 failMsg += "Expected devices: {}\nActual devices: {}".format( allowedDevices,
661 onosDevices )
662 except( TypeError, ValueError ):
663 main.log.error( "Problem loading devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800664 utilities.assert_equals( expect=allowedDevices,
665 actual=onosDevices,
666 onpass="Only allowed devices are in ONOS",
667 onfail=failMsg )
668
669 main.step( "Check device annotations" )
670 keys = [ 'name', 'owner', 'rackAddress' ]
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700671 try:
672 for sw in json.loads( devices ):
673 if "of:0000000000000001" in sw.get( 'id' ):
674 s1Correct = True
675 for k in keys:
Jon Hallbc080f92017-05-24 16:29:55 -0700676 if str( sw.get( 'annotations', {} ).get( k ) ) != str( main.s1Json[ k ] ):
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700677 s1Correct = False
678 main.log.debug( "{} is wrong on s1".format( k ) )
679 if not s1Correct:
680 main.log.error( "Annotations for s1 are incorrect: {}".format( sw ) )
Jon Hallbc080f92017-05-24 16:29:55 -0700681 elif "of:0000000000000002" in sw[ 'id' ]:
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700682 s2Correct = True
683 for k in keys:
Jon Hallbc080f92017-05-24 16:29:55 -0700684 if str( sw.get( 'annotations', {} ).get( k ) ) != str( main.s2Json[ k ] ):
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700685 s2Correct = False
686 main.log.debug( "{} is wrong on s2".format( k ) )
687 if not s2Correct:
688 main.log.error( "Annotations for s2 are incorrect: {}".format( sw ) )
689 except( TypeError, ValueError ):
690 main.log.error( "Problem loading devices" )
691 stepResult = False
Jon Hall66e001c2015-11-12 09:45:10 -0800692 try:
693 stepResult = s1Correct and s2Correct
694 except NameError:
695 stepResult = False
696 main.log.error( "s1 and/or s2 not found in devices" )
697 utilities.assert_equals( expect=True,
698 actual=stepResult,
699 onpass="Configured device's annotations are correct",
700 onfail="Incorrect annotations for configured devices." )
701
702 def CASE24( self, main ):
703 """
704 Testing removal of configurations
705 """
Jon Hall541b8e02015-12-14 19:29:01 -0800706 import time
Jon Hall66e001c2015-11-12 09:45:10 -0800707 try:
708 assert main.s1Json, "s1Json not defined"
709 assert main.s2Json, "s2Json not defined"
710 assert main.s3Json, "s3Json not defined"
711 assert main.s4Json, "s4Json not defined"
712 except AssertionError:
713 main.log.exception( "Case Prerequisites not set: " )
714 main.cleanup()
715 main.exit()
716 main.case( "Testing removal of configurations" )
717 main.step( "Remove 'allowed' configuration from all devices" )
718
719 s1Json = main.s1Json # NOTE: This is a reference
720 try:
Jon Hallbc080f92017-05-24 16:29:55 -0700721 del s1Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800722 except KeyError:
723 main.log.exception( "Key not found" )
724 setS1 = main.ONOSrest1.setNetCfg( s1Json,
725 subjectClass="devices",
726 subjectKey="of:0000000000000001",
727 configKey="basic" )
728
729 s2Json = main.s2Json # NOTE: This is a reference
730 try:
Jon Hall541b8e02015-12-14 19:29:01 -0800731 time.sleep( main.gossipTime )
Jon Hallbc080f92017-05-24 16:29:55 -0700732 del s2Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800733 except KeyError:
734 main.log.exception( "Key not found" )
735 setS2 = main.ONOSrest2.setNetCfg( s2Json,
736 subjectClass="devices",
737 subjectKey="of:0000000000000002",
738 configKey="basic" )
739
740 s3Json = main.s3Json # NOTE: This is a reference
741 try:
Jon Hall541b8e02015-12-14 19:29:01 -0800742 time.sleep( main.gossipTime )
Jon Hallbc080f92017-05-24 16:29:55 -0700743 del s3Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800744 except KeyError:
745 main.log.exception( "Key not found" )
746 setS3 = main.ONOSrest3.setNetCfg( s3Json,
747 subjectClass="devices",
748 subjectKey="of:0000000000000003",
749 configKey="basic" )
750
751 s4Json = main.s4Json # NOTE: This is a reference
752 try:
Jon Hall541b8e02015-12-14 19:29:01 -0800753 time.sleep( main.gossipTime )
Jon Hallbc080f92017-05-24 16:29:55 -0700754 del s4Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800755 except KeyError:
756 main.log.exception( "Key not found" )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700757 setS4 = main.ONOSrest3.setNetCfg( s4Json,
Jon Hall66e001c2015-11-12 09:45:10 -0800758 subjectClass="devices",
759 subjectKey="of:0000000000000004",
760 configKey="basic" )
761 removeAllowed = setS1 and setS2 and setS3 and setS4
762 utilities.assert_equals( expect=main.TRUE,
763 actual=removeAllowed,
764 onpass="Successfully removed 'allowed' config from devices",
765 onfail="Failed to remove the 'allowed' config key." )
766
767 main.netCfg.compareCfg( main, main.gossipTime )
768
769 main.step( "Delete basic config for s1 and s2" )
770 removeS1 = main.ONOSrest1.removeNetCfg( subjectClass="devices",
771 subjectKey="of:0000000000000001",
772 configKey="basic" )
773 removeS2 = main.ONOSrest2.removeNetCfg( subjectClass="devices",
774 subjectKey="of:0000000000000002",
775 configKey="basic" )
776 removeSingles = removeS1 and removeS2
777 utilities.assert_equals( expect=main.TRUE,
778 actual=removeSingles,
779 onpass="Successfully removed S1 and S2 basic config",
780 onfail="Failed to removed S1 and S2 basic config" )
781
782 main.netCfg.compareCfg( main, main.gossipTime )
783
784 main.step( "Delete the net config for S3" )
785 removeS3 = main.ONOSrest3.removeNetCfg( subjectClass="devices",
786 subjectKey="of:0000000000000003" )
787 utilities.assert_equals( expect=main.TRUE,
788 actual=removeS3,
789 onpass="Successfully removed S3's config",
790 onfail="Failed to removed S3's config" )
791
792 main.netCfg.compareCfg( main, main.gossipTime )
793
794 main.step( "Delete the net config for all devices" )
795 remove = main.ONOSrest3.removeNetCfg( subjectClass="devices" )
796 utilities.assert_equals( expect=main.TRUE,
797 actual=remove,
798 onpass="Successfully removed device config",
799 onfail="Failed to remove device config" )
800
801 main.netCfg.compareCfg( main, main.gossipTime )
802
803 main.step( "Assert the net config for devices is empty" )
804 get = main.ONOSrest3.getNetCfg( subjectClass="devices" )
805 utilities.assert_equals( expect='{}',
806 actual=get,
807 onpass="Successfully removed device config",
808 onfail="Failed to remove device config" )
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700809
810 def CASE25( self, main ):
811 """
812 Use network-cfg.json to configure devices during ONOS startup
813 """
814 main.case( "Preparing network-cfg.json to load configurations" )
815 main.step( "Moving network-cfg.json to $ONOS_ROOT/tools/package/config/" )
816 prestartResult = main.TRUE
817 srcPath = "~/OnosSystemTest/TestON/tests/FUNC/FUNCnetCfg/dependencies/network-cfg.json"
818 dstPath = "~/onos/tools/package/config/network-cfg.json"
819 prestartResult = main.ONOSbench.scp( main.ONOSbench, srcPath, dstPath, direction="to" )
820 utilities.assert_equals( expect=main.TRUE,
821 actual=prestartResult,
822 onpass="Successfully copied network-cfg.json to target directory",
823 onfail="Failed to copy network-cfg.json to target directory" )
824
825 def CASE26( self, main ):
826 """
827 Check to see that pre-startup configurations were set correctly
828 """
829 import json
830 main.case( "Check to see if the pre-startup configurations were set, then remove their allowed status" )
831 main.step( "Checking configurations for Switches 5 and 6" )
Jon Hallbc080f92017-05-24 16:29:55 -0700832 main.step( "ONOS should only show devices S1, S2, S4, and S5" ) # and S6
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700833 devices = main.ONOSrest1.devices()
834 main.log.debug( main.ONOSrest1.pprint( devices ) )
Jon Hallbc080f92017-05-24 16:29:55 -0700835 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4, 5 ] ] # 6
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700836 main.log.debug( allowedDevices )
837 onosDevices = []
838 try:
839 for sw in json.loads( devices ):
Jon Hallbc080f92017-05-24 16:29:55 -0700840 onosDevices.append( str( sw[ 'id' ] ) )
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700841 onosDevices.sort()
842 main.log.debug( onosDevices )
843 except( TypeError, ValueError ):
844 main.log.error( "Problem loading devices" )
845 utilities.assert_equals( expect=allowedDevices,
846 actual=onosDevices,
847 onpass="Only allowed devices are in ONOS",
848 onfail="ONOS devices doesn't match the list" +
849 " of allowed devices" )
850
851 main.step( "Removing allowed status from Switches 5 and 6" )
Pratik Parab6f418632017-04-25 17:05:50 -0700852 try:
853 with open( os.path.dirname( main.testFile ) + '/dependencies/s5Json', 'r' ) as s5Jsondata:
854 main.s5Json = json.load( s5Jsondata )
855 except IOError:
856 main.log.exception( "s5Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700857 main.cleanup()
858 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700859 main.log.info( "s5Json:" + str( main.s5Json ) )
860
861 try:
862 with open( os.path.dirname( main.testFile ) + '/dependencies/s6Json', 'r' ) as s6Jsondata:
863 main.s6Json = json.load( s6Jsondata )
864 except IOError:
865 main.log.exception( "s6Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700866 main.cleanup()
867 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700868 main.log.info( "s6Json:" + str( main.s6Json ) )
869
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700870 s5Json = main.s5Json
871 setS1 = main.ONOSrest1.setNetCfg( s5Json,
872 subjectClass="devices",
873 subjectKey="of:0000000000000005",
874 configKey="basic" )
875
876 s6Json = main.s6Json
877 setS1 = main.ONOSrest1.setNetCfg( s6Json,
878 subjectClass="devices",
879 subjectKey="of:0000000000000006",
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700880 configKey="basic" )
881
882 def CASE27( self, main ):
883 """
Jon Hallbc080f92017-05-24 16:29:55 -0700884 1 ) A = get /network/configuration
885 2 ) Post A
886 3 ) Compare A with ONOS
887 4 ) Modify A so S6 is disallowed
888 5 ) Check
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700889
890 """
891 import json
Jon Hallbc080f92017-05-24 16:29:55 -0700892 pprint = main.nodes[ 0 ].pprint
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700893 main.case( "Posting network configurations to the top level web resource" )
894 main.step( "Get json object from Net Cfg" )
Jon Hallbc080f92017-05-24 16:29:55 -0700895 getinfo = main.ONOSrest1.getNetCfg()
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700896 main.log.debug( getinfo )
897 main.step( "Posting json object to Net Cfg" )
898 postinfo = main.ONOSrest1.setNetCfg( json.loads( getinfo ) )
899 main.step( "Compare device with ONOS" )
900 main.netCfg.compareCfg( main )
Jon Hallbc080f92017-05-24 16:29:55 -0700901 main.step( "ONOS should only show devices S1, S2, S4, S5 and S6" )
902 devices = main.ONOSrest1.devices()
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700903 main.log.debug( main.ONOSrest1.pprint( devices ) )
904 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4, 5, 6 ] ]
905 onosDevices = []
906 try:
907 for sw in json.loads( devices ):
908 onosDevices.append( str( sw.get( 'id' ) ) )
Jon Hallbc080f92017-05-24 16:29:55 -0700909 onosDevices.sort()
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700910 failMsg = "ONOS devices doesn't match the list of allowed devices. \n"
911 failMsg += "Expected devices: {}\nActual devices: {}".format( allowedDevices, onosDevices )
912 except( TypeError, ValueError ):
913 main.log.error( "Problem loading devices" )
914 utilities.assert_equals( expect=allowedDevices, actual=onosDevices,
915 onpass="Only allowed devices are in ONOS", onfail=failMsg )
916
917 main.step( "Modify json object so S6 is disallowed" )
918 main.s6Json = { "allowed": False }
919 s6Json = main.s6Json
920 setS6Disallow = main.ONOSrest1.setNetCfg( s6Json, subjectClass="devices",
921 subjectKey="of:0000000000000006", configKey="basic" )
922 s6Result = False
923 if setS6Disallow:
924 getS6 = main.ONOSrest1.getNetCfg( subjectClass="devices",
925 subjectKey="of:0000000000000006", configKey="basic" )
926 onosCfg = pprint( getS6 )
927 sentCfg = pprint( s6Json )
928 if onosCfg == sentCfg:
929 s6Result = True
930 else:
931 main.log.error( "ONOS NetCfg doesn't match what was sent" )
932 main.log.debug( "ONOS config: {}".format( onosCfg ) )
933 main.log.debug( "Sent config: {}".format( sentCfg ) )
934 utilities.retry( f=main.ONOSrest1.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
935 utilities.assert_equals( expect=True, actual=s6Result,
936 onpass="Net Cfg added for devices s6",
937 onfail="Net Cfg for device s6 not correctly set" )