blob: 61d7e134230d968958421f66349238e5d6c73412 [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
Jon Hall66e001c2015-11-12 09:45:10 -080099 main.ONOSbench.getVersion( report=True )
100
101 def CASE2( self, main ):
102 """
103 - Set up cell
104 - Create cell file
105 - Set cell file
106 - Verify cell file
107 - Kill ONOS process
108 - Uninstall ONOS cluster
Jon Hall66e001c2015-11-12 09:45:10 -0800109 - Install ONOS cluster
Jon Hall72ecaa02017-06-06 09:41:48 -0700110 - Verify ONOS start up
Jon Hall66e001c2015-11-12 09:45:10 -0800111 - Connect to cli
112 """
113 import time
114 main.case( "Starting up " + str( main.numCtrls ) +
115 " node(s) ONOS cluster" )
116 main.caseExplanation = "Set up ONOS with " + str( main.numCtrls ) +\
117 " node(s) ONOS cluster"
118
119 # kill off all onos processes
120 main.log.info( "Safety check, killing all ONOS processes" +
121 " before initiating environment setup" )
122
123 for i in range( main.maxNodes ):
124 main.ONOSbench.onosStop( main.ONOSip[ i ] )
125 main.ONOSbench.onosDie( main.ONOSip[ i ] )
126
127 tempOnosIp = []
128 for i in range( main.numCtrls ):
Jon Hallbc080f92017-05-24 16:29:55 -0700129 tempOnosIp.append( main.ONOSip[ i ] )
Jon Hall66e001c2015-11-12 09:45:10 -0800130
131 main.ONOSbench.createCellFile( main.ONOSbench.ip_address,
132 "temp", main.Mininet1.ip_address,
Devin Lim461f0872017-06-05 16:49:33 -0700133 main.apps, tempOnosIp, main.ONOScli1.user_name )
Jon Hall66e001c2015-11-12 09:45:10 -0800134
135 main.step( "Apply cell to environment" )
136 cellResult = main.ONOSbench.setCell( "temp" )
137 verifyResult = main.ONOSbench.verifyCell()
138 stepResult = cellResult and verifyResult
139 utilities.assert_equals( expect=main.TRUE,
140 actual=stepResult,
141 onpass="Successfully applied cell to environment",
142 onfail="Failed to apply cell to environment " )
143
144 main.step( "Creating ONOS package" )
Jon Hallbd60ea02016-08-23 10:03:59 -0700145 packageResult = main.ONOSbench.buckBuild()
Jon Hall66e001c2015-11-12 09:45:10 -0800146 stepResult = packageResult
147 utilities.assert_equals( expect=main.TRUE,
148 actual=stepResult,
149 onpass="Successfully created ONOS package",
150 onfail="Failed to create ONOS package" )
151
Jon Hall66e001c2015-11-12 09:45:10 -0800152 main.step( "Uninstalling ONOS package" )
153 onosUninstallResult = main.TRUE
154 for ip in main.ONOSip:
155 onosUninstallResult = onosUninstallResult and \
156 main.ONOSbench.onosUninstall( nodeIp=ip )
157 stepResult = onosUninstallResult
158 utilities.assert_equals( expect=main.TRUE,
159 actual=stepResult,
160 onpass="Successfully uninstalled ONOS package",
161 onfail="Failed to uninstall ONOS package" )
162
163 time.sleep( main.startUpSleep )
164 main.step( "Installing ONOS package" )
165 onosInstallResult = main.TRUE
166 for i in range( main.numCtrls ):
167 onosInstallResult = onosInstallResult and \
168 main.ONOSbench.onosInstall( node=main.ONOSip[ i ] )
169 stepResult = onosInstallResult
170 utilities.assert_equals( expect=main.TRUE,
171 actual=stepResult,
172 onpass="Successfully installed ONOS package",
173 onfail="Failed to install ONOS package" )
174
175 time.sleep( main.startUpSleep )
Jon Hall72ecaa02017-06-06 09:41:48 -0700176 main.step( "Set up ONOS secure SSH" )
177 secureSshResult = main.TRUE
178 for i in range( int( main.numCtrls ) ):
179 secureSshResult = secureSshResult and main.ONOSbench.onosSecureSSH( node=main.ONOSip[ i ] )
180 utilities.assert_equals( expect=main.TRUE, actual=secureSshResult,
181 onpass="Test step PASS",
182 onfail="Test step FAIL" )
183
184 time.sleep( main.startUpSleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800185 main.step( "Starting ONOS service" )
186 stopResult = main.TRUE
187 startResult = main.TRUE
188 onosIsUp = main.TRUE
189
190 for i in range( main.numCtrls ):
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700191 isUp = main.ONOSbench.isup( main.ONOSip[ i ] )
192 onosIsUp = onosIsUp and isUp
193 if isUp == main.TRUE:
194 main.log.report( "ONOS instance {0} is up and ready".format( i + 1 ) )
195 else:
196 main.log.report( "ONOS instance {0} may not be up, stop and ".format( i + 1 ) +
197 "start ONOS again " )
Jon Hall66e001c2015-11-12 09:45:10 -0800198 stopResult = stopResult and \
199 main.ONOSbench.onosStop( main.ONOSip[ i ] )
Jon Hall66e001c2015-11-12 09:45:10 -0800200 startResult = startResult and \
201 main.ONOSbench.onosStart( main.ONOSip[ i ] )
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700202 stepResult = onosIsUp and stopResult and startResult
Jon Hall66e001c2015-11-12 09:45:10 -0800203 utilities.assert_equals( expect=main.TRUE,
204 actual=stepResult,
205 onpass="ONOS service is ready",
206 onfail="ONOS service did not start properly" )
207
208 def CASE8( self, main ):
209 """
210 Compare Topo
211 """
212 import json
213
214 main.case( "Compare ONOS Topology view to Mininet topology" )
215 main.caseExplanation = "Compare topology elements between Mininet" +\
216 " and ONOS"
217
218 main.step( "Gathering topology information" )
219 # TODO: add a parameterized sleep here
220 devicesResults = main.TRUE
221 linksResults = main.TRUE
222 hostsResults = main.TRUE
223 devices = main.topo.getAllDevices( main )
224 hosts = main.topo.getAllHosts( main )
225 ports = main.topo.getAllPorts( main )
226 links = main.topo.getAllLinks( main )
227 clusters = main.topo.getAllClusters( main )
228
229 mnSwitches = main.Mininet1.getSwitches()
230 mnLinks = main.Mininet1.getLinks()
231 mnHosts = main.Mininet1.getHosts()
232
233 main.step( "Comparing MN topology to ONOS topology" )
234 for controller in range( main.numCtrls ):
235 controllerStr = str( controller + 1 )
236 if devices[ controller ] and ports[ controller ] and\
237 "Error" not in devices[ controller ] and\
238 "Error" not in ports[ controller ]:
239
240 currentDevicesResult = main.Mininet1.compareSwitches(
241 mnSwitches,
242 json.loads( devices[ controller ] ),
243 json.loads( ports[ controller ] ) )
244 else:
245 currentDevicesResult = main.FALSE
246 utilities.assert_equals( expect=main.TRUE,
247 actual=currentDevicesResult,
248 onpass="ONOS" + controllerStr +
249 " Switches view is correct",
250 onfail="ONOS" + controllerStr +
251 " Switches view is incorrect" )
252
253 if links[ controller ] and "Error" not in links[ controller ]:
254 currentLinksResult = main.Mininet1.compareLinks(
255 mnSwitches, mnLinks,
256 json.loads( links[ controller ] ) )
257 else:
258 currentLinksResult = main.FALSE
259 utilities.assert_equals( expect=main.TRUE,
260 actual=currentLinksResult,
261 onpass="ONOS" + controllerStr +
262 " links view is correct",
263 onfail="ONOS" + controllerStr +
264 " links view is incorrect" )
265
266 if hosts[ controller ] or "Error" not in hosts[ controller ]:
267 currentHostsResult = main.Mininet1.compareHosts(
268 mnHosts,
269 json.loads( hosts[ controller ] ) )
270 else:
271 currentHostsResult = main.FALSE
272 utilities.assert_equals( expect=main.TRUE,
273 actual=currentHostsResult,
274 onpass="ONOS" + controllerStr +
275 " hosts exist in Mininet",
276 onfail="ONOS" + controllerStr +
277 " hosts don't match Mininet" )
278
279 def CASE9( self, main ):
Jon Hallbc080f92017-05-24 16:29:55 -0700280 """
Jon Hall66e001c2015-11-12 09:45:10 -0800281 Report errors/warnings/exceptions
Jon Hallbc080f92017-05-24 16:29:55 -0700282 """
Jon Hall66e001c2015-11-12 09:45:10 -0800283 main.log.info( "Error report: \n" )
284 main.ONOSbench.logReport(
Jon Hallbc080f92017-05-24 16:29:55 -0700285 globalONOSip[ 0 ],
286 [ "INFO", "WARN", "ERROR", "Except" ],
Jon Hall66e001c2015-11-12 09:45:10 -0800287 "s" )
Jon Hallbc080f92017-05-24 16:29:55 -0700288 # main.ONOSbench.logReport( globalONOSip[ 1 ], [ "INFO" ], "d" )
Jon Hall66e001c2015-11-12 09:45:10 -0800289
290 def CASE10( self, main ):
291 """
292 Start Mininet topology with OF 1.0 switches
293 """
294 main.OFProtocol = "1.0"
295 main.log.report( "Start Mininet topology with OF 1.0 switches" )
296 main.case( "Start Mininet topology with OF 1.0 switches" )
297 main.caseExplanation = "Start mininet topology with OF 1.0 " +\
298 "switches to test intents, exits out if " +\
299 "topology did not start correctly"
300
301 main.step( "Starting Mininet topology with OF 1.0 switches" )
Jon Hall53c5e662016-04-13 16:06:56 -0700302 args = "--controller none --switch ovs,protocols=OpenFlow10"
Jon Hallbc080f92017-05-24 16:29:55 -0700303 switches = int( main.params[ 'MININET' ][ 'switch' ] )
Jon Hall66e001c2015-11-12 09:45:10 -0800304 cmd = "mn --topo linear,{} {}".format( switches, args )
Jon Hallbc080f92017-05-24 16:29:55 -0700305 topoResult = main.Mininet1.startNet( mnCmd=cmd )
Jon Hall66e001c2015-11-12 09:45:10 -0800306 stepResult = topoResult
307 utilities.assert_equals( expect=main.TRUE,
308 actual=stepResult,
309 onpass="Successfully loaded topology",
310 onfail="Failed to load topology" )
311 # Exit if topology did not load properly
312 if not topoResult:
313 main.cleanup()
314 main.exit()
315
316 def CASE11( self, main ):
317 """
318 Start Mininet topology with OF 1.3 switches
319 """
320 import re
321 main.OFProtocol = "1.3"
322 main.log.report( "Start Mininet topology with OF 1.3 switches" )
323 main.case( "Start Mininet topology with OF 1.3 switches" )
324 main.caseExplanation = "Start mininet topology with OF 1.3 " +\
325 "switches to test intents, exits out if " +\
326 "topology did not start correctly"
327
328 main.step( "Starting Mininet topology with OF 1.3 switches" )
Jon Hall53c5e662016-04-13 16:06:56 -0700329 args = "--controller none --switch ovs,protocols=OpenFlow13"
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700330 switches = int( main.params[ 'MININET' ][ 'switch' ] )
Jon Hall66e001c2015-11-12 09:45:10 -0800331 cmd = "mn --topo linear,{} {}".format( switches, args )
Jon Hallbc080f92017-05-24 16:29:55 -0700332 topoResult = main.Mininet1.startNet( mnCmd=cmd )
Jon Hall66e001c2015-11-12 09:45:10 -0800333 stepResult = topoResult
334 utilities.assert_equals( expect=main.TRUE,
335 actual=stepResult,
336 onpass="Successfully loaded topology",
337 onfail="Failed to load topology" )
338 # Exit if topology did not load properly
339 if not topoResult:
340 main.cleanup()
341 main.exit()
342
343 tempONOSip = []
344 for i in range( main.numCtrls ):
345 tempONOSip.append( main.ONOSip[ i ] )
346
347 swList = [ "s" + str( i ) for i in range( 1, switches + 1 ) ]
348 assignResult = main.Mininet1.assignSwController( sw=swList,
349 ip=tempONOSip,
350 port='6653' )
351 if not assignResult:
352 main.cleanup()
353 main.exit()
354
355 assignResult = main.TRUE
356 for sw in swList:
357 response = main.Mininet1.getSwController( "s" + str( i ) )
358 main.log.info( "Response is " + str( response ) )
359 for ip in tempONOSip:
360 if re.search( "tcp:" + ip, response ):
361 assignResult = assignResult and main.TRUE
362 else:
363 assignResult = assignResult and main.FALSE
364 stepResult = assignResult
365 utilities.assert_equals( expect=main.TRUE,
366 actual=stepResult,
367 onpass="Successfully assigned switches" +
368 "to controller",
369 onfail="Failed to assign switches to " +
370 "controller" )
371
372 def CASE14( self, main ):
373 """
374 Stop mininet
375 """
376 main.log.report( "Stop Mininet topology" )
377 main.case( "Stop Mininet topology" )
378 main.caseExplanation = "Stopping the current mininet topology " +\
379 "to start up fresh"
380
381 main.step( "Stopping Mininet Topology" )
Jon Hallbc080f92017-05-24 16:29:55 -0700382 topoResult = main.Mininet1.stopNet()
Jon Hall66e001c2015-11-12 09:45:10 -0800383 stepResult = topoResult
384 utilities.assert_equals( expect=main.TRUE,
385 actual=stepResult,
386 onpass="Successfully stop mininet",
387 onfail="Failed to stop mininet" )
388 # Exit if topology did not load properly
389 if not topoResult:
390 main.cleanup()
391 main.exit()
392
393 def CASE20( self, main ):
394 """
395 Add some device configurations and then check they are distributed
396 to all nodes
397 """
alison15124df2016-10-06 12:04:51 -0700398 import time
Pratik Parabc6083c22017-04-27 13:24:41 -0700399 import json
400 import os
Jon Hall66e001c2015-11-12 09:45:10 -0800401 main.case( "Add Network configurations to the cluster" )
402 main.caseExplanation = "Add Network Configurations for devices" +\
403 " not discovered yet. One device is allowed" +\
404 ", the other disallowed."
Jon Hallbc080f92017-05-24 16:29:55 -0700405 pprint = main.nodes[ 0 ].pprint
Jon Hall66e001c2015-11-12 09:45:10 -0800406
407 main.step( "Add Net Cfg for switch1" )
Pratik Parab6f418632017-04-25 17:05:50 -0700408
Pratik Parab6f418632017-04-25 17:05:50 -0700409 try:
410 with open( os.path.dirname( main.testFile ) + '/dependencies/s1Json', 'r' ) as s1Jsondata:
411 s1Json = json.load( s1Jsondata )
412 except IOError:
413 main.log.exception( "s1Json File not found." )
Pratik Parabc6083c22017-04-27 13:24:41 -0700414 main.cleanup()
415 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700416 main.log.info( "s1Json:" + str( s1Json ) )
417
Jon Hall66e001c2015-11-12 09:45:10 -0800418 main.s1Json = s1Json
419 setS1Allow = main.ONOSrest1.setNetCfg( s1Json,
420 subjectClass="devices",
421 subjectKey="of:0000000000000001",
422 configKey="basic" )
423 s1Result = False
alison15124df2016-10-06 12:04:51 -0700424 #Wait 5 secs after set up netCfg
425 time.sleep( main.SetNetCfgSleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800426 if setS1Allow:
427 # Check what we set is what is in ONOS
428 getS1 = main.ONOSrest1.getNetCfg( subjectClass="devices",
429 subjectKey="of:0000000000000001",
430 configKey="basic" )
431 onosCfg = pprint( getS1 )
432 sentCfg = pprint( s1Json )
433 if onosCfg == sentCfg:
alison15124df2016-10-06 12:04:51 -0700434 main.log.info( "ONOS NetCfg match what was sent" )
Jon Hall66e001c2015-11-12 09:45:10 -0800435 s1Result = True
436 else:
437 main.log.error( "ONOS NetCfg doesn't match what was sent" )
438 main.log.debug( "ONOS config: {}".format( onosCfg ) )
439 main.log.debug( "Sent config: {}".format( sentCfg ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700440 utilities.retry( f=main.ONOSrest1.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800441 utilities.assert_equals( expect=True,
442 actual=s1Result,
443 onpass="Net Cfg added for device s1",
444 onfail="Net Cfg for device s1 not correctly set" )
445
446 main.step( "Add Net Cfg for switch3" )
Pratik Parab6f418632017-04-25 17:05:50 -0700447
448 try:
449 with open( os.path.dirname( main.testFile ) + '/dependencies/s3Json', 'r' ) as s3Jsondata:
450 s3Json = json.load( s3Jsondata )
451 except IOError:
452 main.log.exception( "s3Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700453 main.cleanup()
454 main.exit()
Jon Hallbc080f92017-05-24 16:29:55 -0700455 main.log.info( "s3Json:" + str( s3Json ) )
Pratik Parab6f418632017-04-25 17:05:50 -0700456
Jon Hall66e001c2015-11-12 09:45:10 -0800457 main.s3Json = s3Json
458 setS3Disallow = main.ONOSrest1.setNetCfg( s3Json,
459 subjectClass="devices",
460 subjectKey="of:0000000000000003",
461 configKey="basic" )
462 s3Result = False
alison15124df2016-10-06 12:04:51 -0700463 time.sleep( main.SetNetCfgSleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800464 if setS3Disallow:
465 # Check what we set is what is in ONOS
466 getS3 = main.ONOSrest1.getNetCfg( subjectClass="devices",
467 subjectKey="of:0000000000000003",
468 configKey="basic" )
469 onosCfg = pprint( getS3 )
470 sentCfg = pprint( s3Json )
471 if onosCfg == sentCfg:
Jon Hallbc080f92017-05-24 16:29:55 -0700472 main.log.info( "ONOS NetCfg match what was sent" )
Jon Hall66e001c2015-11-12 09:45:10 -0800473 s3Result = True
474 else:
475 main.log.error( "ONOS NetCfg doesn't match what was sent" )
476 main.log.debug( "ONOS config: {}".format( onosCfg ) )
477 main.log.debug( "Sent config: {}".format( sentCfg ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700478 utilities.retry( f=main.ONOSrest1.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800479 utilities.assert_equals( expect=True,
480 actual=s3Result,
481 onpass="Net Cfg added for device s3",
482 onfail="Net Cfg for device s3 not correctly set" )
483 main.netCfg.compareCfg( main, main.gossipTime )
484
485 def CASE21( self, main ):
486 """
487 Initial check of devices
488 """
489 import json
490 try:
491 assert main.s1Json, "s1Json not defined"
492 except AssertionError:
493 main.log.exception( "Case Prerequisites not set: " )
494 main.cleanup()
495 main.exit()
496 main.case( "Check Devices After they initially connect to ONOS" )
497
498 main.netCfg.compareCfg( main )
499
500 main.step( "ONOS should only show devices S1, S2, and S4" )
501 devices = main.ONOSrest1.devices()
502 main.log.debug( main.ONOSrest1.pprint( devices ) )
503 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4 ] ]
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700504 main.log.debug( allowedDevices )
Jon Hall66e001c2015-11-12 09:45:10 -0800505 onosDevices = []
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700506 try:
507 for sw in json.loads( devices ):
Jon Hallbc080f92017-05-24 16:29:55 -0700508 onosDevices.append( str( sw[ 'id' ] ) )
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700509 onosDevices.sort()
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700510 main.log.debug( onosDevices )
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700511 except( TypeError, ValueError ):
512 main.log.error( "Problem loading devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800513 utilities.assert_equals( expect=allowedDevices,
514 actual=onosDevices,
515 onpass="Only allowed devices are in ONOS",
516 onfail="ONOS devices doesn't match the list" +
517 " of allowed devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800518 main.step( "Check device annotations" )
519 keys = [ 'name', 'owner', 'rackAddress' ]
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700520 try:
521 for sw in json.loads( devices ):
Jon Hallbc080f92017-05-24 16:29:55 -0700522 if "of:0000000000000001" in sw[ 'id' ]:
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700523 s1Correct = True
524 for k in keys:
Jon Hallbc080f92017-05-24 16:29:55 -0700525 if str( sw.get( 'annotations', {} ).get( k ) ) != str( main.s1Json[ k ] ):
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700526 s1Correct = False
527 main.log.debug( "{} is wrong on s1".format( k ) )
528 if not s1Correct:
529 main.log.error( "Annotations for s1 are incorrect: {}".format( sw ) )
530 except( TypeError, ValueError ):
531 main.log.error( "Problem loading devices" )
532 s1Correct = False
Jon Hall66e001c2015-11-12 09:45:10 -0800533 try:
534 stepResult = s1Correct
535 except NameError:
536 stepResult = False
537 main.log.error( "s1 not found in devices" )
538 utilities.assert_equals( expect=True,
539 actual=stepResult,
540 onpass="Configured device's annotations are correct",
541 onfail="Incorrect annotations for configured devices." )
542
543 def CASE22( self, main ):
544 """
545 Add some device configurations for connected devices and then check
546 they are distributed to all nodes
547 """
548 main.case( "Add Network configurations for connected devices to the cluster" )
549 main.caseExplanation = "Add Network Configurations for discovered " +\
550 "devices. One device is allowed" +\
551 ", the other disallowed."
Jon Hallbc080f92017-05-24 16:29:55 -0700552 pprint = main.nodes[ 0 ].pprint
Jon Hall66e001c2015-11-12 09:45:10 -0800553
554 main.step( "Add Net Cfg for switch2" )
Pratik Parab6f418632017-04-25 17:05:50 -0700555 try:
556 with open( os.path.dirname( main.testFile ) + '/dependencies/s2Json', 'r' ) as s2Jsondata:
557 s2Json = json.load( s2Jsondata )
558 except IOError:
559 main.log.exception( "s2Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700560 main.cleanup()
561 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700562 main.log.info( "s2Json:" + str( s2Json ) )
Jon Hall66e001c2015-11-12 09:45:10 -0800563 main.s2Json = s2Json
564 setS2Allow = main.ONOSrest2.setNetCfg( s2Json,
565 subjectClass="devices",
566 subjectKey="of:0000000000000002",
567 configKey="basic" )
568 s2Result = False
569 if setS2Allow:
570 # Check what we set is what is in ONOS
571 getS2 = main.ONOSrest2.getNetCfg( subjectClass="devices",
572 subjectKey="of:0000000000000002",
573 configKey="basic" )
574 onosCfg = pprint( getS2 )
575 sentCfg = pprint( s2Json )
576 if onosCfg == sentCfg:
577 s2Result = True
578 else:
579 main.log.error( "ONOS NetCfg doesn't match what was sent" )
580 main.log.debug( "ONOS config: {}".format( onosCfg ) )
581 main.log.debug( "Sent config: {}".format( sentCfg ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700582 utilities.retry( f=main.ONOSrest2.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800583 utilities.assert_equals( expect=True,
584 actual=s2Result,
585 onpass="Net Cfg added for device s2",
586 onfail="Net Cfg for device s2 not correctly set" )
587
588 main.step( "Add Net Cfg for switch4" )
Pratik Parab6f418632017-04-25 17:05:50 -0700589
590 try:
591 with open( os.path.dirname( main.testFile ) + '/dependencies/s4Json', 'r' ) as s4Jsondata:
592 s4Json = json.load( s4Jsondata )
593 except IOError:
594 main.log.exception( "s4Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700595 main.cleanup()
596 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700597 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:
Jon Hallbc080f92017-05-24 16:29:55 -0700668 if str( sw.get( 'annotations', {} ).get( k ) ) != str( main.s1Json[ k ] ):
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700669 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 ) )
Jon Hallbc080f92017-05-24 16:29:55 -0700673 elif "of:0000000000000002" in sw[ 'id' ]:
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700674 s2Correct = True
675 for k in keys:
Jon Hallbc080f92017-05-24 16:29:55 -0700676 if str( sw.get( 'annotations', {} ).get( k ) ) != str( main.s2Json[ k ] ):
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700677 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:
Jon Hallbc080f92017-05-24 16:29:55 -0700713 del s1Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800714 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 Hallbc080f92017-05-24 16:29:55 -0700724 del s2Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800725 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 Hallbc080f92017-05-24 16:29:55 -0700735 del s3Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800736 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 Hallbc080f92017-05-24 16:29:55 -0700746 del s4Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800747 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" )
Jon Hallbc080f92017-05-24 16:29:55 -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 ) )
Jon Hallbc080f92017-05-24 16:29:55 -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 ):
Jon Hallbc080f92017-05-24 16:29:55 -0700832 onosDevices.append( str( sw[ 'id' ] ) )
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700833 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" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700849 main.cleanup()
850 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700851 main.log.info( "s5Json:" + str( main.s5Json ) )
852
853 try:
854 with open( os.path.dirname( main.testFile ) + '/dependencies/s6Json', 'r' ) as s6Jsondata:
855 main.s6Json = json.load( s6Jsondata )
856 except IOError:
857 main.log.exception( "s6Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700858 main.cleanup()
859 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700860 main.log.info( "s6Json:" + str( main.s6Json ) )
861
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700862 s5Json = main.s5Json
863 setS1 = main.ONOSrest1.setNetCfg( s5Json,
864 subjectClass="devices",
865 subjectKey="of:0000000000000005",
866 configKey="basic" )
867
868 s6Json = main.s6Json
869 setS1 = main.ONOSrest1.setNetCfg( s6Json,
870 subjectClass="devices",
871 subjectKey="of:0000000000000006",
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700872 configKey="basic" )
873
874 def CASE27( self, main ):
875 """
Jon Hallbc080f92017-05-24 16:29:55 -0700876 1 ) A = get /network/configuration
877 2 ) Post A
878 3 ) Compare A with ONOS
879 4 ) Modify A so S6 is disallowed
880 5 ) Check
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700881
882 """
883 import json
Jon Hallbc080f92017-05-24 16:29:55 -0700884 pprint = main.nodes[ 0 ].pprint
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700885 main.case( "Posting network configurations to the top level web resource" )
886 main.step( "Get json object from Net Cfg" )
Jon Hallbc080f92017-05-24 16:29:55 -0700887 getinfo = main.ONOSrest1.getNetCfg()
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700888 main.log.debug( getinfo )
889 main.step( "Posting json object to Net Cfg" )
890 postinfo = main.ONOSrest1.setNetCfg( json.loads( getinfo ) )
891 main.step( "Compare device with ONOS" )
892 main.netCfg.compareCfg( main )
Jon Hallbc080f92017-05-24 16:29:55 -0700893 main.step( "ONOS should only show devices S1, S2, S4, S5 and S6" )
894 devices = main.ONOSrest1.devices()
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700895 main.log.debug( main.ONOSrest1.pprint( devices ) )
896 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4, 5, 6 ] ]
897 onosDevices = []
898 try:
899 for sw in json.loads( devices ):
900 onosDevices.append( str( sw.get( 'id' ) ) )
Jon Hallbc080f92017-05-24 16:29:55 -0700901 onosDevices.sort()
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700902 failMsg = "ONOS devices doesn't match the list of allowed devices. \n"
903 failMsg += "Expected devices: {}\nActual devices: {}".format( allowedDevices, onosDevices )
904 except( TypeError, ValueError ):
905 main.log.error( "Problem loading devices" )
906 utilities.assert_equals( expect=allowedDevices, actual=onosDevices,
907 onpass="Only allowed devices are in ONOS", onfail=failMsg )
908
909 main.step( "Modify json object so S6 is disallowed" )
910 main.s6Json = { "allowed": False }
911 s6Json = main.s6Json
912 setS6Disallow = main.ONOSrest1.setNetCfg( s6Json, subjectClass="devices",
913 subjectKey="of:0000000000000006", configKey="basic" )
914 s6Result = False
915 if setS6Disallow:
916 getS6 = main.ONOSrest1.getNetCfg( subjectClass="devices",
917 subjectKey="of:0000000000000006", configKey="basic" )
918 onosCfg = pprint( getS6 )
919 sentCfg = pprint( s6Json )
920 if onosCfg == sentCfg:
921 s6Result = True
922 else:
923 main.log.error( "ONOS NetCfg doesn't match what was sent" )
924 main.log.debug( "ONOS config: {}".format( onosCfg ) )
925 main.log.debug( "Sent config: {}".format( sentCfg ) )
926 utilities.retry( f=main.ONOSrest1.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
927 utilities.assert_equals( expect=True, actual=s6Result,
928 onpass="Net Cfg added for devices s6",
929 onfail="Net Cfg for device s6 not correctly set" )