blob: 8a4bdacd6cd9c3c34f5b1766d21c4277fd01b393 [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
Jon Hall66e001c2015-11-12 09:45:10 -080019 """
Jon Hall66e001c2015-11-12 09:45:10 -080020 main.case( "Constructing test variables and building ONOS package" )
21 main.step( "Constructing test variables" )
22 main.caseExplanation = "This test case is mainly for loading " +\
23 "from params file, and pull and build the " +\
24 " latest ONOS package"
25 stepResult = main.FALSE
26
27 # Test variables
28 try:
29 main.testOnDirectory = re.sub( "(/tests)$", "", main.testDir )
30 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
31 gitBranch = main.params[ 'GIT' ][ 'branch' ]
32 main.dependencyPath = main.testOnDirectory + \
33 main.params[ 'DEPENDENCY' ][ 'path' ]
34 if main.ONOSbench.maxNodes:
35 main.maxNodes = int( main.ONOSbench.maxNodes )
36 else:
37 main.maxNodes = 0
38 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
39 wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ]
40 wrapperFile3 = main.params[ 'DEPENDENCY' ][ 'wrapper3' ]
41 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
Jon Hallbc080f92017-05-24 16:29:55 -070042 main.gossipTime = int( main.params[ 'SLEEP' ][ 'cfgGossip' ] )
alison15124df2016-10-06 12:04:51 -070043 main.SetNetCfgSleep = int( main.params[ 'SLEEP' ][ 'SetNetCfgSleep' ] )
Jon Hall66e001c2015-11-12 09:45:10 -080044 gitPull = main.params[ 'GIT' ][ 'pull' ]
45 main.cellData = {} # for creating cell file
46 main.hostsData = {}
47 main.nodes = []
48 main.ONOSip = []
Ming Yan Shudb74bf22016-06-23 14:56:22 -070049 main.retrytimes = main.params[ 'RETRY' ]
50 main.retrysleep = main.params[ 'RetrySleep' ]
Jon Hall66e001c2015-11-12 09:45:10 -080051 main.ONOSip = main.ONOSbench.getOnosIps()
52
53 # Assigning ONOS cli handles to a list
54 try:
55 for i in range( 1, main.maxNodes + 1 ):
56 main.nodes.append( getattr( main, 'ONOSrest' + str( i ) ) )
57 except AttributeError:
58 main.log.warn( "A " + str( main.maxNodes ) + " node cluster " +
59 "was defined in env variables, but only " +
60 str( len( main.nodes ) ) +
61 " nodes were defined in the .topo file. " +
62 "Using " + str( len( main.nodes ) ) +
63 " nodes for the test." )
64
65 main.numCtrls = len( main.nodes )
66
67 # -- INIT SECTION, SHOULD ONLY BE RUN ONCE -- #
68 main.startUp = imp.load_source( wrapperFile1,
69 main.dependencyPath +
70 wrapperFile1 +
71 ".py" )
72
73 main.netCfg = imp.load_source( wrapperFile2,
74 main.dependencyPath +
75 wrapperFile2 +
76 ".py" )
77
78 main.topo = imp.load_source( wrapperFile3,
79 main.dependencyPath +
80 wrapperFile3 +
81 ".py" )
82
83 if main.nodes:
84 stepResult = main.TRUE
85 else:
86 main.log.error( "Did not properly created list of ONOS handle" )
87 stepResult = main.FALSE
88 except Exception as e:
Jeremy Songster2baa44e2016-06-10 10:18:40 -070089 main.log.exception( e )
Jon Hall66e001c2015-11-12 09:45:10 -080090 main.cleanup()
91 main.exit()
92
93 utilities.assert_equals( expect=main.TRUE,
94 actual=stepResult,
95 onpass="Successfully construct " +
96 "test variables ",
97 onfail="Failed to construct test variables" )
98
99 if gitPull == 'True':
100 main.step( "Building ONOS in " + gitBranch + " branch" )
101 onosBuildResult = main.startUp.onosBuild( main, gitBranch )
102 stepResult = onosBuildResult
103 utilities.assert_equals( expect=main.TRUE,
104 actual=stepResult,
105 onpass="Successfully compiled " +
106 "latest ONOS",
107 onfail="Failed to compile " +
108 "latest ONOS" )
109 else:
110 main.log.warn( "Did not pull new code so skipping mvn " +
111 "clean install" )
112 main.ONOSbench.getVersion( report=True )
113
114 def CASE2( self, main ):
115 """
116 - Set up cell
117 - Create cell file
118 - Set cell file
119 - Verify cell file
120 - Kill ONOS process
121 - Uninstall ONOS cluster
Jon Hall66e001c2015-11-12 09:45:10 -0800122 - Install ONOS cluster
Jon Hall72ecaa02017-06-06 09:41:48 -0700123 - Verify ONOS start up
Jon Hall66e001c2015-11-12 09:45:10 -0800124 - Connect to cli
125 """
126 import time
127 main.case( "Starting up " + str( main.numCtrls ) +
128 " node(s) ONOS cluster" )
129 main.caseExplanation = "Set up ONOS with " + str( main.numCtrls ) +\
130 " node(s) ONOS cluster"
131
132 # kill off all onos processes
133 main.log.info( "Safety check, killing all ONOS processes" +
134 " before initiating environment setup" )
135
136 for i in range( main.maxNodes ):
137 main.ONOSbench.onosStop( main.ONOSip[ i ] )
138 main.ONOSbench.onosDie( main.ONOSip[ i ] )
139
140 tempOnosIp = []
141 for i in range( main.numCtrls ):
Jon Hallbc080f92017-05-24 16:29:55 -0700142 tempOnosIp.append( main.ONOSip[ i ] )
Jon Hall66e001c2015-11-12 09:45:10 -0800143
144 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
145 "temp", main.Mininet1.ip_address,
146 main.apps, tempOnosIp )
147
148 main.step( "Apply cell to environment" )
149 cellResult = main.ONOSbench.setCell( "temp" )
150 verifyResult = main.ONOSbench.verifyCell()
151 stepResult = cellResult and verifyResult
152 utilities.assert_equals( expect=main.TRUE,
153 actual=stepResult,
154 onpass="Successfully applied cell to environment",
155 onfail="Failed to apply cell to environment " )
156
157 main.step( "Creating ONOS package" )
Jon Hallbd60ea02016-08-23 10:03:59 -0700158 packageResult = main.ONOSbench.buckBuild()
Jon Hall66e001c2015-11-12 09:45:10 -0800159 stepResult = packageResult
160 utilities.assert_equals( expect=main.TRUE,
161 actual=stepResult,
162 onpass="Successfully created ONOS package",
163 onfail="Failed to create ONOS package" )
164
Jon Hall66e001c2015-11-12 09:45:10 -0800165 main.step( "Uninstalling ONOS package" )
166 onosUninstallResult = main.TRUE
167 for ip in main.ONOSip:
168 onosUninstallResult = onosUninstallResult and \
169 main.ONOSbench.onosUninstall( nodeIp=ip )
170 stepResult = onosUninstallResult
171 utilities.assert_equals( expect=main.TRUE,
172 actual=stepResult,
173 onpass="Successfully uninstalled ONOS package",
174 onfail="Failed to uninstall ONOS package" )
175
176 time.sleep( main.startUpSleep )
177 main.step( "Installing ONOS package" )
178 onosInstallResult = main.TRUE
179 for i in range( main.numCtrls ):
180 onosInstallResult = onosInstallResult and \
181 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
182 stepResult = onosInstallResult
183 utilities.assert_equals( expect=main.TRUE,
184 actual=stepResult,
185 onpass="Successfully installed ONOS package",
186 onfail="Failed to install ONOS package" )
187
188 time.sleep( main.startUpSleep )
Jon Hall72ecaa02017-06-06 09:41:48 -0700189 main.step( "Set up ONOS secure SSH" )
190 secureSshResult = main.TRUE
191 for i in range( int( main.numCtrls ) ):
192 secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=main.ONOSip[ i ] )
193 utilities.assert_equals( expect=main.TRUE, actual=secureSshResult,
194 onpass="Test step PASS",
195 onfail="Test step FAIL" )
196
197 time.sleep( main.startUpSleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800198 main.step( "Starting ONOS service" )
199 stopResult = main.TRUE
200 startResult = main.TRUE
201 onosIsUp = main.TRUE
202
203 for i in range( main.numCtrls ):
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700204 isUp = main.ONOSbench.isup( main.ONOSip[ i ] )
205 onosIsUp = onosIsUp and isUp
206 if isUp == main.TRUE:
207 main.log.report( "ONOS instance {0} is up and ready".format( i + 1 ) )
208 else:
209 main.log.report( "ONOS instance {0} may not be up, stop and ".format( i + 1 ) +
210 "start ONOS again " )
Jon Hall66e001c2015-11-12 09:45:10 -0800211 stopResult = stopResult and \
212 main.ONOSbench.onosStop( main.ONOSip[ i ] )
Jon Hall66e001c2015-11-12 09:45:10 -0800213 startResult = startResult and \
214 main.ONOSbench.onosStart( main.ONOSip[ i ] )
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700215 stepResult = onosIsUp and stopResult and startResult
Jon Hall66e001c2015-11-12 09:45:10 -0800216 utilities.assert_equals( expect=main.TRUE,
217 actual=stepResult,
218 onpass="ONOS service is ready",
219 onfail="ONOS service did not start properly" )
220
221 def CASE8( self, main ):
222 """
223 Compare Topo
224 """
225 import json
226
227 main.case( "Compare ONOS Topology view to Mininet topology" )
228 main.caseExplanation = "Compare topology elements between Mininet" +\
229 " and ONOS"
230
231 main.step( "Gathering topology information" )
232 # TODO: add a parameterized sleep here
233 devicesResults = main.TRUE
234 linksResults = main.TRUE
235 hostsResults = main.TRUE
236 devices = main.topo.getAllDevices( main )
237 hosts = main.topo.getAllHosts( main )
238 ports = main.topo.getAllPorts( main )
239 links = main.topo.getAllLinks( main )
240 clusters = main.topo.getAllClusters( main )
241
242 mnSwitches = main.Mininet1.getSwitches()
243 mnLinks = main.Mininet1.getLinks()
244 mnHosts = main.Mininet1.getHosts()
245
246 main.step( "Comparing MN topology to ONOS topology" )
247 for controller in range( main.numCtrls ):
248 controllerStr = str( controller + 1 )
249 if devices[ controller ] and ports[ controller ] and\
250 "Error" not in devices[ controller ] and\
251 "Error" not in ports[ controller ]:
252
253 currentDevicesResult = main.Mininet1.compareSwitches(
254 mnSwitches,
255 json.loads( devices[ controller ] ),
256 json.loads( ports[ controller ] ) )
257 else:
258 currentDevicesResult = main.FALSE
259 utilities.assert_equals( expect=main.TRUE,
260 actual=currentDevicesResult,
261 onpass="ONOS" + controllerStr +
262 " Switches view is correct",
263 onfail="ONOS" + controllerStr +
264 " Switches view is incorrect" )
265
266 if links[ controller ] and "Error" not in links[ controller ]:
267 currentLinksResult = main.Mininet1.compareLinks(
268 mnSwitches, mnLinks,
269 json.loads( links[ controller ] ) )
270 else:
271 currentLinksResult = main.FALSE
272 utilities.assert_equals( expect=main.TRUE,
273 actual=currentLinksResult,
274 onpass="ONOS" + controllerStr +
275 " links view is correct",
276 onfail="ONOS" + controllerStr +
277 " links view is incorrect" )
278
279 if hosts[ controller ] or "Error" not in hosts[ controller ]:
280 currentHostsResult = main.Mininet1.compareHosts(
281 mnHosts,
282 json.loads( hosts[ controller ] ) )
283 else:
284 currentHostsResult = main.FALSE
285 utilities.assert_equals( expect=main.TRUE,
286 actual=currentHostsResult,
287 onpass="ONOS" + controllerStr +
288 " hosts exist in Mininet",
289 onfail="ONOS" + controllerStr +
290 " hosts don't match Mininet" )
291
292 def CASE9( self, main ):
Jon Hallbc080f92017-05-24 16:29:55 -0700293 """
Jon Hall66e001c2015-11-12 09:45:10 -0800294 Report errors/warnings/exceptions
Jon Hallbc080f92017-05-24 16:29:55 -0700295 """
Jon Hall66e001c2015-11-12 09:45:10 -0800296 main.log.info( "Error report: \n" )
297 main.ONOSbench.logReport(
Jon Hallbc080f92017-05-24 16:29:55 -0700298 globalONOSip[ 0 ],
299 [ "INFO", "WARN", "ERROR", "Except" ],
Jon Hall66e001c2015-11-12 09:45:10 -0800300 "s" )
Jon Hallbc080f92017-05-24 16:29:55 -0700301 # main.ONOSbench.logReport( globalONOSip[ 1 ], [ "INFO" ], "d" )
Jon Hall66e001c2015-11-12 09:45:10 -0800302
303 def CASE10( self, main ):
304 """
305 Start Mininet topology with OF 1.0 switches
306 """
307 main.OFProtocol = "1.0"
308 main.log.report( "Start Mininet topology with OF 1.0 switches" )
309 main.case( "Start Mininet topology with OF 1.0 switches" )
310 main.caseExplanation = "Start mininet topology with OF 1.0 " +\
311 "switches to test intents, exits out if " +\
312 "topology did not start correctly"
313
314 main.step( "Starting Mininet topology with OF 1.0 switches" )
Jon Hall53c5e662016-04-13 16:06:56 -0700315 args = "--controller none --switch ovs,protocols=OpenFlow10"
Jon Hallbc080f92017-05-24 16:29:55 -0700316 switches = int( main.params[ 'MININET' ][ 'switch' ] )
Jon Hall66e001c2015-11-12 09:45:10 -0800317 cmd = "mn --topo linear,{} {}".format( switches, args )
Jon Hallbc080f92017-05-24 16:29:55 -0700318 topoResult = main.Mininet1.startNet( mnCmd=cmd )
Jon Hall66e001c2015-11-12 09:45:10 -0800319 stepResult = topoResult
320 utilities.assert_equals( expect=main.TRUE,
321 actual=stepResult,
322 onpass="Successfully loaded topology",
323 onfail="Failed to load topology" )
324 # Exit if topology did not load properly
325 if not topoResult:
326 main.cleanup()
327 main.exit()
328
329 def CASE11( self, main ):
330 """
331 Start Mininet topology with OF 1.3 switches
332 """
333 import re
334 main.OFProtocol = "1.3"
335 main.log.report( "Start Mininet topology with OF 1.3 switches" )
336 main.case( "Start Mininet topology with OF 1.3 switches" )
337 main.caseExplanation = "Start mininet topology with OF 1.3 " +\
338 "switches to test intents, exits out if " +\
339 "topology did not start correctly"
340
341 main.step( "Starting Mininet topology with OF 1.3 switches" )
Jon Hall53c5e662016-04-13 16:06:56 -0700342 args = "--controller none --switch ovs,protocols=OpenFlow13"
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700343 switches = int( main.params[ 'MININET' ][ 'switch' ] )
Jon Hall66e001c2015-11-12 09:45:10 -0800344 cmd = "mn --topo linear,{} {}".format( switches, args )
Jon Hallbc080f92017-05-24 16:29:55 -0700345 topoResult = main.Mininet1.startNet( mnCmd=cmd )
Jon Hall66e001c2015-11-12 09:45:10 -0800346 stepResult = topoResult
347 utilities.assert_equals( expect=main.TRUE,
348 actual=stepResult,
349 onpass="Successfully loaded topology",
350 onfail="Failed to load topology" )
351 # Exit if topology did not load properly
352 if not topoResult:
353 main.cleanup()
354 main.exit()
355
356 tempONOSip = []
357 for i in range( main.numCtrls ):
358 tempONOSip.append( main.ONOSip[ i ] )
359
360 swList = [ "s" + str( i ) for i in range( 1, switches + 1 ) ]
361 assignResult = main.Mininet1.assignSwController( sw=swList,
362 ip=tempONOSip,
363 port='6653' )
364 if not assignResult:
365 main.cleanup()
366 main.exit()
367
368 assignResult = main.TRUE
369 for sw in swList:
370 response = main.Mininet1.getSwController( "s" + str( i ) )
371 main.log.info( "Response is " + str( response ) )
372 for ip in tempONOSip:
373 if re.search( "tcp:" + ip, response ):
374 assignResult = assignResult and main.TRUE
375 else:
376 assignResult = assignResult and main.FALSE
377 stepResult = assignResult
378 utilities.assert_equals( expect=main.TRUE,
379 actual=stepResult,
380 onpass="Successfully assigned switches" +
381 "to controller",
382 onfail="Failed to assign switches to " +
383 "controller" )
384
385 def CASE14( self, main ):
386 """
387 Stop mininet
388 """
389 main.log.report( "Stop Mininet topology" )
390 main.case( "Stop Mininet topology" )
391 main.caseExplanation = "Stopping the current mininet topology " +\
392 "to start up fresh"
393
394 main.step( "Stopping Mininet Topology" )
Jon Hallbc080f92017-05-24 16:29:55 -0700395 topoResult = main.Mininet1.stopNet()
Jon Hall66e001c2015-11-12 09:45:10 -0800396 stepResult = topoResult
397 utilities.assert_equals( expect=main.TRUE,
398 actual=stepResult,
399 onpass="Successfully stop mininet",
400 onfail="Failed to stop mininet" )
401 # Exit if topology did not load properly
402 if not topoResult:
403 main.cleanup()
404 main.exit()
405
406 def CASE20( self, main ):
407 """
408 Add some device configurations and then check they are distributed
409 to all nodes
410 """
alison15124df2016-10-06 12:04:51 -0700411 import time
Pratik Parabc6083c22017-04-27 13:24:41 -0700412 import json
413 import os
Jon Hall66e001c2015-11-12 09:45:10 -0800414 main.case( "Add Network configurations to the cluster" )
415 main.caseExplanation = "Add Network Configurations for devices" +\
416 " not discovered yet. One device is allowed" +\
417 ", the other disallowed."
Jon Hallbc080f92017-05-24 16:29:55 -0700418 pprint = main.nodes[ 0 ].pprint
Jon Hall66e001c2015-11-12 09:45:10 -0800419
420 main.step( "Add Net Cfg for switch1" )
Pratik Parab6f418632017-04-25 17:05:50 -0700421
Pratik Parab6f418632017-04-25 17:05:50 -0700422 try:
423 with open( os.path.dirname( main.testFile ) + '/dependencies/s1Json', 'r' ) as s1Jsondata:
424 s1Json = json.load( s1Jsondata )
425 except IOError:
426 main.log.exception( "s1Json File not found." )
Pratik Parabc6083c22017-04-27 13:24:41 -0700427 main.cleanup()
428 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700429 main.log.info( "s1Json:" + str( s1Json ) )
430
Jon Hall66e001c2015-11-12 09:45:10 -0800431 main.s1Json = s1Json
432 setS1Allow = main.ONOSrest1.setNetCfg( s1Json,
433 subjectClass="devices",
434 subjectKey="of:0000000000000001",
435 configKey="basic" )
436 s1Result = False
alison15124df2016-10-06 12:04:51 -0700437 #Wait 5 secs after set up netCfg
438 time.sleep( main.SetNetCfgSleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800439 if setS1Allow:
440 # Check what we set is what is in ONOS
441 getS1 = main.ONOSrest1.getNetCfg( subjectClass="devices",
442 subjectKey="of:0000000000000001",
443 configKey="basic" )
444 onosCfg = pprint( getS1 )
445 sentCfg = pprint( s1Json )
446 if onosCfg == sentCfg:
alison15124df2016-10-06 12:04:51 -0700447 main.log.info( "ONOS NetCfg match what was sent" )
Jon Hall66e001c2015-11-12 09:45:10 -0800448 s1Result = True
449 else:
450 main.log.error( "ONOS NetCfg doesn't match what was sent" )
451 main.log.debug( "ONOS config: {}".format( onosCfg ) )
452 main.log.debug( "Sent config: {}".format( sentCfg ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700453 utilities.retry( f=main.ONOSrest1.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800454 utilities.assert_equals( expect=True,
455 actual=s1Result,
456 onpass="Net Cfg added for device s1",
457 onfail="Net Cfg for device s1 not correctly set" )
458
459 main.step( "Add Net Cfg for switch3" )
Pratik Parab6f418632017-04-25 17:05:50 -0700460
461 try:
462 with open( os.path.dirname( main.testFile ) + '/dependencies/s3Json', 'r' ) as s3Jsondata:
463 s3Json = json.load( s3Jsondata )
464 except IOError:
465 main.log.exception( "s3Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700466 main.cleanup()
467 main.exit()
Jon Hallbc080f92017-05-24 16:29:55 -0700468 main.log.info( "s3Json:" + str( s3Json ) )
Pratik Parab6f418632017-04-25 17:05:50 -0700469
Jon Hall66e001c2015-11-12 09:45:10 -0800470 main.s3Json = s3Json
471 setS3Disallow = main.ONOSrest1.setNetCfg( s3Json,
472 subjectClass="devices",
473 subjectKey="of:0000000000000003",
474 configKey="basic" )
475 s3Result = False
alison15124df2016-10-06 12:04:51 -0700476 time.sleep( main.SetNetCfgSleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800477 if setS3Disallow:
478 # Check what we set is what is in ONOS
479 getS3 = main.ONOSrest1.getNetCfg( subjectClass="devices",
480 subjectKey="of:0000000000000003",
481 configKey="basic" )
482 onosCfg = pprint( getS3 )
483 sentCfg = pprint( s3Json )
484 if onosCfg == sentCfg:
Jon Hallbc080f92017-05-24 16:29:55 -0700485 main.log.info( "ONOS NetCfg match what was sent" )
Jon Hall66e001c2015-11-12 09:45:10 -0800486 s3Result = True
487 else:
488 main.log.error( "ONOS NetCfg doesn't match what was sent" )
489 main.log.debug( "ONOS config: {}".format( onosCfg ) )
490 main.log.debug( "Sent config: {}".format( sentCfg ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700491 utilities.retry( f=main.ONOSrest1.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800492 utilities.assert_equals( expect=True,
493 actual=s3Result,
494 onpass="Net Cfg added for device s3",
495 onfail="Net Cfg for device s3 not correctly set" )
496 main.netCfg.compareCfg( main, main.gossipTime )
497
498 def CASE21( self, main ):
499 """
500 Initial check of devices
501 """
502 import json
503 try:
504 assert main.s1Json, "s1Json not defined"
505 except AssertionError:
506 main.log.exception( "Case Prerequisites not set: " )
507 main.cleanup()
508 main.exit()
509 main.case( "Check Devices After they initially connect to ONOS" )
510
511 main.netCfg.compareCfg( main )
512
513 main.step( "ONOS should only show devices S1, S2, and S4" )
514 devices = main.ONOSrest1.devices()
515 main.log.debug( main.ONOSrest1.pprint( devices ) )
516 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4 ] ]
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700517 main.log.debug( allowedDevices )
Jon Hall66e001c2015-11-12 09:45:10 -0800518 onosDevices = []
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700519 try:
520 for sw in json.loads( devices ):
Jon Hallbc080f92017-05-24 16:29:55 -0700521 onosDevices.append( str( sw[ 'id' ] ) )
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700522 onosDevices.sort()
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700523 main.log.debug( onosDevices )
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700524 except( TypeError, ValueError ):
525 main.log.error( "Problem loading devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800526 utilities.assert_equals( expect=allowedDevices,
527 actual=onosDevices,
528 onpass="Only allowed devices are in ONOS",
529 onfail="ONOS devices doesn't match the list" +
530 " of allowed devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800531 main.step( "Check device annotations" )
532 keys = [ 'name', 'owner', 'rackAddress' ]
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700533 try:
534 for sw in json.loads( devices ):
Jon Hallbc080f92017-05-24 16:29:55 -0700535 if "of:0000000000000001" in sw[ 'id' ]:
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700536 s1Correct = True
537 for k in keys:
Jon Hallbc080f92017-05-24 16:29:55 -0700538 if str( sw.get( 'annotations', {} ).get( k ) ) != str( main.s1Json[ k ] ):
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700539 s1Correct = False
540 main.log.debug( "{} is wrong on s1".format( k ) )
541 if not s1Correct:
542 main.log.error( "Annotations for s1 are incorrect: {}".format( sw ) )
543 except( TypeError, ValueError ):
544 main.log.error( "Problem loading devices" )
545 s1Correct = False
Jon Hall66e001c2015-11-12 09:45:10 -0800546 try:
547 stepResult = s1Correct
548 except NameError:
549 stepResult = False
550 main.log.error( "s1 not found in devices" )
551 utilities.assert_equals( expect=True,
552 actual=stepResult,
553 onpass="Configured device's annotations are correct",
554 onfail="Incorrect annotations for configured devices." )
555
556 def CASE22( self, main ):
557 """
558 Add some device configurations for connected devices and then check
559 they are distributed to all nodes
560 """
561 main.case( "Add Network configurations for connected devices to the cluster" )
562 main.caseExplanation = "Add Network Configurations for discovered " +\
563 "devices. One device is allowed" +\
564 ", the other disallowed."
Jon Hallbc080f92017-05-24 16:29:55 -0700565 pprint = main.nodes[ 0 ].pprint
Jon Hall66e001c2015-11-12 09:45:10 -0800566
567 main.step( "Add Net Cfg for switch2" )
Pratik Parab6f418632017-04-25 17:05:50 -0700568 try:
569 with open( os.path.dirname( main.testFile ) + '/dependencies/s2Json', 'r' ) as s2Jsondata:
570 s2Json = json.load( s2Jsondata )
571 except IOError:
572 main.log.exception( "s2Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700573 main.cleanup()
574 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700575 main.log.info( "s2Json:" + str( s2Json ) )
Jon Hall66e001c2015-11-12 09:45:10 -0800576 main.s2Json = s2Json
577 setS2Allow = main.ONOSrest2.setNetCfg( s2Json,
578 subjectClass="devices",
579 subjectKey="of:0000000000000002",
580 configKey="basic" )
581 s2Result = False
582 if setS2Allow:
583 # Check what we set is what is in ONOS
584 getS2 = main.ONOSrest2.getNetCfg( subjectClass="devices",
585 subjectKey="of:0000000000000002",
586 configKey="basic" )
587 onosCfg = pprint( getS2 )
588 sentCfg = pprint( s2Json )
589 if onosCfg == sentCfg:
590 s2Result = True
591 else:
592 main.log.error( "ONOS NetCfg doesn't match what was sent" )
593 main.log.debug( "ONOS config: {}".format( onosCfg ) )
594 main.log.debug( "Sent config: {}".format( sentCfg ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700595 utilities.retry( f=main.ONOSrest2.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800596 utilities.assert_equals( expect=True,
597 actual=s2Result,
598 onpass="Net Cfg added for device s2",
599 onfail="Net Cfg for device s2 not correctly set" )
600
601 main.step( "Add Net Cfg for switch4" )
Pratik Parab6f418632017-04-25 17:05:50 -0700602
603 try:
604 with open( os.path.dirname( main.testFile ) + '/dependencies/s4Json', 'r' ) as s4Jsondata:
605 s4Json = json.load( s4Jsondata )
606 except IOError:
607 main.log.exception( "s4Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700608 main.cleanup()
609 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700610 main.log.info( "s4Json:" + str( s4Json ) )
Jon Hall66e001c2015-11-12 09:45:10 -0800611 main.s4Json = s4Json
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700612 setS4Disallow = main.ONOSrest3.setNetCfg( s4Json,
Jon Hall66e001c2015-11-12 09:45:10 -0800613 subjectClass="devices",
614 subjectKey="of:0000000000000004",
615 configKey="basic" )
616 s4Result = False
617 if setS4Disallow:
618 # Check what we set is what is in ONOS
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700619 getS4 = main.ONOSrest3.getNetCfg( subjectClass="devices",
Jon Hall66e001c2015-11-12 09:45:10 -0800620 subjectKey="of:0000000000000004",
621 configKey="basic" )
622 onosCfg = pprint( getS4 )
623 sentCfg = pprint( s4Json )
624 if onosCfg == sentCfg:
625 s4Result = True
626 else:
627 main.log.error( "ONOS NetCfg doesn't match what was sent" )
628 main.log.debug( "ONOS config: {}".format( onosCfg ) )
629 main.log.debug( "Sent config: {}".format( sentCfg ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700630 main.step( "Retrying main.ONOSrest3.getNetCfg" )
631 utilities.retry( f=main.ONOSrest3.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800632 utilities.assert_equals( expect=True,
633 actual=s4Result,
634 onpass="Net Cfg added for device s4",
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700635 onfail="Net Cfg for device s4 not correctly set" )
Jon Hall66e001c2015-11-12 09:45:10 -0800636
637 main.netCfg.compareCfg( main, main.gossipTime )
638
639 def CASE23( self, main ):
640 """
641 Check of devices after all Network Configurations are set
642 """
643 import json
644 try:
645 assert main.s1Json, "s1Json not defined"
646 assert main.s2Json, "s2Json not defined"
647 except AssertionError:
648 main.log.exception( "Case Prerequisites not set: " )
649 main.cleanup()
650 main.exit()
651 main.case( "Check Devices after all configurations are set" )
652
653 main.netCfg.compareCfg( main )
654
655 main.step( "ONOS should only show devices S1 and S2" )
656 devices = main.ONOSrest1.devices()
657 main.log.debug( main.ONOSrest1.pprint( devices ) )
658 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2 ] ]
659 onosDevices = []
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700660 try:
661 for sw in json.loads( devices ):
662 onosDevices.append( str( sw.get( 'id' ) ) )
663 onosDevices.sort()
664 failMsg = "ONOS devices doesn't match the list of allowed devices.\n"
665 failMsg += "Expected devices: {}\nActual devices: {}".format( allowedDevices,
666 onosDevices )
667 except( TypeError, ValueError ):
668 main.log.error( "Problem loading devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800669 utilities.assert_equals( expect=allowedDevices,
670 actual=onosDevices,
671 onpass="Only allowed devices are in ONOS",
672 onfail=failMsg )
673
674 main.step( "Check device annotations" )
675 keys = [ 'name', 'owner', 'rackAddress' ]
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700676 try:
677 for sw in json.loads( devices ):
678 if "of:0000000000000001" in sw.get( 'id' ):
679 s1Correct = True
680 for k in keys:
Jon Hallbc080f92017-05-24 16:29:55 -0700681 if str( sw.get( 'annotations', {} ).get( k ) ) != str( main.s1Json[ k ] ):
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700682 s1Correct = False
683 main.log.debug( "{} is wrong on s1".format( k ) )
684 if not s1Correct:
685 main.log.error( "Annotations for s1 are incorrect: {}".format( sw ) )
Jon Hallbc080f92017-05-24 16:29:55 -0700686 elif "of:0000000000000002" in sw[ 'id' ]:
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700687 s2Correct = True
688 for k in keys:
Jon Hallbc080f92017-05-24 16:29:55 -0700689 if str( sw.get( 'annotations', {} ).get( k ) ) != str( main.s2Json[ k ] ):
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700690 s2Correct = False
691 main.log.debug( "{} is wrong on s2".format( k ) )
692 if not s2Correct:
693 main.log.error( "Annotations for s2 are incorrect: {}".format( sw ) )
694 except( TypeError, ValueError ):
695 main.log.error( "Problem loading devices" )
696 stepResult = False
Jon Hall66e001c2015-11-12 09:45:10 -0800697 try:
698 stepResult = s1Correct and s2Correct
699 except NameError:
700 stepResult = False
701 main.log.error( "s1 and/or s2 not found in devices" )
702 utilities.assert_equals( expect=True,
703 actual=stepResult,
704 onpass="Configured device's annotations are correct",
705 onfail="Incorrect annotations for configured devices." )
706
707 def CASE24( self, main ):
708 """
709 Testing removal of configurations
710 """
Jon Hall541b8e02015-12-14 19:29:01 -0800711 import time
Jon Hall66e001c2015-11-12 09:45:10 -0800712 try:
713 assert main.s1Json, "s1Json not defined"
714 assert main.s2Json, "s2Json not defined"
715 assert main.s3Json, "s3Json not defined"
716 assert main.s4Json, "s4Json not defined"
717 except AssertionError:
718 main.log.exception( "Case Prerequisites not set: " )
719 main.cleanup()
720 main.exit()
721 main.case( "Testing removal of configurations" )
722 main.step( "Remove 'allowed' configuration from all devices" )
723
724 s1Json = main.s1Json # NOTE: This is a reference
725 try:
Jon Hallbc080f92017-05-24 16:29:55 -0700726 del s1Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800727 except KeyError:
728 main.log.exception( "Key not found" )
729 setS1 = main.ONOSrest1.setNetCfg( s1Json,
730 subjectClass="devices",
731 subjectKey="of:0000000000000001",
732 configKey="basic" )
733
734 s2Json = main.s2Json # NOTE: This is a reference
735 try:
Jon Hall541b8e02015-12-14 19:29:01 -0800736 time.sleep( main.gossipTime )
Jon Hallbc080f92017-05-24 16:29:55 -0700737 del s2Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800738 except KeyError:
739 main.log.exception( "Key not found" )
740 setS2 = main.ONOSrest2.setNetCfg( s2Json,
741 subjectClass="devices",
742 subjectKey="of:0000000000000002",
743 configKey="basic" )
744
745 s3Json = main.s3Json # NOTE: This is a reference
746 try:
Jon Hall541b8e02015-12-14 19:29:01 -0800747 time.sleep( main.gossipTime )
Jon Hallbc080f92017-05-24 16:29:55 -0700748 del s3Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800749 except KeyError:
750 main.log.exception( "Key not found" )
751 setS3 = main.ONOSrest3.setNetCfg( s3Json,
752 subjectClass="devices",
753 subjectKey="of:0000000000000003",
754 configKey="basic" )
755
756 s4Json = main.s4Json # NOTE: This is a reference
757 try:
Jon Hall541b8e02015-12-14 19:29:01 -0800758 time.sleep( main.gossipTime )
Jon Hallbc080f92017-05-24 16:29:55 -0700759 del s4Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800760 except KeyError:
761 main.log.exception( "Key not found" )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700762 setS4 = main.ONOSrest3.setNetCfg( s4Json,
Jon Hall66e001c2015-11-12 09:45:10 -0800763 subjectClass="devices",
764 subjectKey="of:0000000000000004",
765 configKey="basic" )
766 removeAllowed = setS1 and setS2 and setS3 and setS4
767 utilities.assert_equals( expect=main.TRUE,
768 actual=removeAllowed,
769 onpass="Successfully removed 'allowed' config from devices",
770 onfail="Failed to remove the 'allowed' config key." )
771
772 main.netCfg.compareCfg( main, main.gossipTime )
773
774 main.step( "Delete basic config for s1 and s2" )
775 removeS1 = main.ONOSrest1.removeNetCfg( subjectClass="devices",
776 subjectKey="of:0000000000000001",
777 configKey="basic" )
778 removeS2 = main.ONOSrest2.removeNetCfg( subjectClass="devices",
779 subjectKey="of:0000000000000002",
780 configKey="basic" )
781 removeSingles = removeS1 and removeS2
782 utilities.assert_equals( expect=main.TRUE,
783 actual=removeSingles,
784 onpass="Successfully removed S1 and S2 basic config",
785 onfail="Failed to removed S1 and S2 basic config" )
786
787 main.netCfg.compareCfg( main, main.gossipTime )
788
789 main.step( "Delete the net config for S3" )
790 removeS3 = main.ONOSrest3.removeNetCfg( subjectClass="devices",
791 subjectKey="of:0000000000000003" )
792 utilities.assert_equals( expect=main.TRUE,
793 actual=removeS3,
794 onpass="Successfully removed S3's config",
795 onfail="Failed to removed S3's config" )
796
797 main.netCfg.compareCfg( main, main.gossipTime )
798
799 main.step( "Delete the net config for all devices" )
800 remove = main.ONOSrest3.removeNetCfg( subjectClass="devices" )
801 utilities.assert_equals( expect=main.TRUE,
802 actual=remove,
803 onpass="Successfully removed device config",
804 onfail="Failed to remove device config" )
805
806 main.netCfg.compareCfg( main, main.gossipTime )
807
808 main.step( "Assert the net config for devices is empty" )
809 get = main.ONOSrest3.getNetCfg( subjectClass="devices" )
810 utilities.assert_equals( expect='{}',
811 actual=get,
812 onpass="Successfully removed device config",
813 onfail="Failed to remove device config" )
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700814
815 def CASE25( self, main ):
816 """
817 Use network-cfg.json to configure devices during ONOS startup
818 """
819 main.case( "Preparing network-cfg.json to load configurations" )
820 main.step( "Moving network-cfg.json to $ONOS_ROOT/tools/package/config/" )
821 prestartResult = main.TRUE
822 srcPath = "~/OnosSystemTest/TestON/tests/FUNC/FUNCnetCfg/dependencies/network-cfg.json"
823 dstPath = "~/onos/tools/package/config/network-cfg.json"
824 prestartResult = main.ONOSbench.scp( main.ONOSbench, srcPath, dstPath, direction="to" )
825 utilities.assert_equals( expect=main.TRUE,
826 actual=prestartResult,
827 onpass="Successfully copied network-cfg.json to target directory",
828 onfail="Failed to copy network-cfg.json to target directory" )
829
830 def CASE26( self, main ):
831 """
832 Check to see that pre-startup configurations were set correctly
833 """
834 import json
835 main.case( "Check to see if the pre-startup configurations were set, then remove their allowed status" )
836 main.step( "Checking configurations for Switches 5 and 6" )
Jon Hallbc080f92017-05-24 16:29:55 -0700837 main.step( "ONOS should only show devices S1, S2, S4, and S5" ) # and S6
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700838 devices = main.ONOSrest1.devices()
839 main.log.debug( main.ONOSrest1.pprint( devices ) )
Jon Hallbc080f92017-05-24 16:29:55 -0700840 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4, 5 ] ] # 6
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700841 main.log.debug( allowedDevices )
842 onosDevices = []
843 try:
844 for sw in json.loads( devices ):
Jon Hallbc080f92017-05-24 16:29:55 -0700845 onosDevices.append( str( sw[ 'id' ] ) )
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700846 onosDevices.sort()
847 main.log.debug( onosDevices )
848 except( TypeError, ValueError ):
849 main.log.error( "Problem loading devices" )
850 utilities.assert_equals( expect=allowedDevices,
851 actual=onosDevices,
852 onpass="Only allowed devices are in ONOS",
853 onfail="ONOS devices doesn't match the list" +
854 " of allowed devices" )
855
856 main.step( "Removing allowed status from Switches 5 and 6" )
Pratik Parab6f418632017-04-25 17:05:50 -0700857 try:
858 with open( os.path.dirname( main.testFile ) + '/dependencies/s5Json', 'r' ) as s5Jsondata:
859 main.s5Json = json.load( s5Jsondata )
860 except IOError:
861 main.log.exception( "s5Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700862 main.cleanup()
863 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700864 main.log.info( "s5Json:" + str( main.s5Json ) )
865
866 try:
867 with open( os.path.dirname( main.testFile ) + '/dependencies/s6Json', 'r' ) as s6Jsondata:
868 main.s6Json = json.load( s6Jsondata )
869 except IOError:
870 main.log.exception( "s6Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700871 main.cleanup()
872 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700873 main.log.info( "s6Json:" + str( main.s6Json ) )
874
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700875 s5Json = main.s5Json
876 setS1 = main.ONOSrest1.setNetCfg( s5Json,
877 subjectClass="devices",
878 subjectKey="of:0000000000000005",
879 configKey="basic" )
880
881 s6Json = main.s6Json
882 setS1 = main.ONOSrest1.setNetCfg( s6Json,
883 subjectClass="devices",
884 subjectKey="of:0000000000000006",
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700885 configKey="basic" )
886
887 def CASE27( self, main ):
888 """
Jon Hallbc080f92017-05-24 16:29:55 -0700889 1 ) A = get /network/configuration
890 2 ) Post A
891 3 ) Compare A with ONOS
892 4 ) Modify A so S6 is disallowed
893 5 ) Check
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700894
895 """
896 import json
Jon Hallbc080f92017-05-24 16:29:55 -0700897 pprint = main.nodes[ 0 ].pprint
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700898 main.case( "Posting network configurations to the top level web resource" )
899 main.step( "Get json object from Net Cfg" )
Jon Hallbc080f92017-05-24 16:29:55 -0700900 getinfo = main.ONOSrest1.getNetCfg()
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700901 main.log.debug( getinfo )
902 main.step( "Posting json object to Net Cfg" )
903 postinfo = main.ONOSrest1.setNetCfg( json.loads( getinfo ) )
904 main.step( "Compare device with ONOS" )
905 main.netCfg.compareCfg( main )
Jon Hallbc080f92017-05-24 16:29:55 -0700906 main.step( "ONOS should only show devices S1, S2, S4, S5 and S6" )
907 devices = main.ONOSrest1.devices()
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700908 main.log.debug( main.ONOSrest1.pprint( devices ) )
909 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4, 5, 6 ] ]
910 onosDevices = []
911 try:
912 for sw in json.loads( devices ):
913 onosDevices.append( str( sw.get( 'id' ) ) )
Jon Hallbc080f92017-05-24 16:29:55 -0700914 onosDevices.sort()
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700915 failMsg = "ONOS devices doesn't match the list of allowed devices. \n"
916 failMsg += "Expected devices: {}\nActual devices: {}".format( allowedDevices, onosDevices )
917 except( TypeError, ValueError ):
918 main.log.error( "Problem loading devices" )
919 utilities.assert_equals( expect=allowedDevices, actual=onosDevices,
920 onpass="Only allowed devices are in ONOS", onfail=failMsg )
921
922 main.step( "Modify json object so S6 is disallowed" )
923 main.s6Json = { "allowed": False }
924 s6Json = main.s6Json
925 setS6Disallow = main.ONOSrest1.setNetCfg( s6Json, subjectClass="devices",
926 subjectKey="of:0000000000000006", configKey="basic" )
927 s6Result = False
928 if setS6Disallow:
929 getS6 = main.ONOSrest1.getNetCfg( subjectClass="devices",
930 subjectKey="of:0000000000000006", configKey="basic" )
931 onosCfg = pprint( getS6 )
932 sentCfg = pprint( s6Json )
933 if onosCfg == sentCfg:
934 s6Result = True
935 else:
936 main.log.error( "ONOS NetCfg doesn't match what was sent" )
937 main.log.debug( "ONOS config: {}".format( onosCfg ) )
938 main.log.debug( "Sent config: {}".format( sentCfg ) )
939 utilities.retry( f=main.ONOSrest1.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
940 utilities.assert_equals( expect=True, actual=s6Result,
941 onpass="Net Cfg added for devices s6",
942 onfail="Net Cfg for device s6 not correctly set" )