blob: 4895b3bd2fad9585f85bf8b3b7ef8a46a296a86c [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 = []
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -070049 main.retrytimes = int( main.params[ 'RETRY' ] )
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -070050 main.retrysleep = int( 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 Limdc78e202017-06-09 18:30:07 -0700133 main.apps, tempOnosIp, main.ONOScli1.karafUser )
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."
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -0700405
406
Jon Hallbc080f92017-05-24 16:29:55 -0700407 pprint = main.nodes[ 0 ].pprint
Jon Hall66e001c2015-11-12 09:45:10 -0800408
409 main.step( "Add Net Cfg for switch1" )
Pratik Parab6f418632017-04-25 17:05:50 -0700410
Pratik Parab6f418632017-04-25 17:05:50 -0700411 try:
412 with open( os.path.dirname( main.testFile ) + '/dependencies/s1Json', 'r' ) as s1Jsondata:
413 s1Json = json.load( s1Jsondata )
414 except IOError:
415 main.log.exception( "s1Json File not found." )
Pratik Parabc6083c22017-04-27 13:24:41 -0700416 main.cleanup()
417 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700418 main.log.info( "s1Json:" + str( s1Json ) )
419
Jon Hall66e001c2015-11-12 09:45:10 -0800420 main.s1Json = s1Json
421 setS1Allow = main.ONOSrest1.setNetCfg( s1Json,
422 subjectClass="devices",
423 subjectKey="of:0000000000000001",
424 configKey="basic" )
425 s1Result = False
alison15124df2016-10-06 12:04:51 -0700426 #Wait 5 secs after set up netCfg
427 time.sleep( main.SetNetCfgSleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800428 if setS1Allow:
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700429 getS1 = utilities.retry( f=main.ONOSrest1.getNetCfg,
430 retValue=False,
431 kwargs={"subjectClass":"devices",
432 "subjectKey" : "of:0000000000000001",
433 "configKey" : "basic"},
434 attempts=main.retrytimes,
435 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800436 onosCfg = pprint( getS1 )
437 sentCfg = pprint( s1Json )
438 if onosCfg == sentCfg:
alison15124df2016-10-06 12:04:51 -0700439 main.log.info( "ONOS NetCfg match what was sent" )
Jon Hall66e001c2015-11-12 09:45:10 -0800440 s1Result = True
441 else:
442 main.log.error( "ONOS NetCfg doesn't match what was sent" )
443 main.log.debug( "ONOS config: {}".format( onosCfg ) )
444 main.log.debug( "Sent config: {}".format( sentCfg ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700445 utilities.retry( f=main.ONOSrest1.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800446 utilities.assert_equals( expect=True,
447 actual=s1Result,
448 onpass="Net Cfg added for device s1",
449 onfail="Net Cfg for device s1 not correctly set" )
450
451 main.step( "Add Net Cfg for switch3" )
Pratik Parab6f418632017-04-25 17:05:50 -0700452
453 try:
454 with open( os.path.dirname( main.testFile ) + '/dependencies/s3Json', 'r' ) as s3Jsondata:
455 s3Json = json.load( s3Jsondata )
456 except IOError:
457 main.log.exception( "s3Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700458 main.cleanup()
459 main.exit()
Jon Hallbc080f92017-05-24 16:29:55 -0700460 main.log.info( "s3Json:" + str( s3Json ) )
Pratik Parab6f418632017-04-25 17:05:50 -0700461
Jon Hall66e001c2015-11-12 09:45:10 -0800462 main.s3Json = s3Json
463 setS3Disallow = main.ONOSrest1.setNetCfg( s3Json,
464 subjectClass="devices",
465 subjectKey="of:0000000000000003",
466 configKey="basic" )
467 s3Result = False
alison15124df2016-10-06 12:04:51 -0700468 time.sleep( main.SetNetCfgSleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800469 if setS3Disallow:
470 # Check what we set is what is in ONOS
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700471 getS3 = utilities.retry( f=main.ONOSrest1.getNetCfg,
472 retValue=False,
473 kwargs={"subjectClass": "devices",
474 "subjectKey": "of:0000000000000003",
475 "configKey": "basic"},
476 attempts=main.retrytimes,
477 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800478 onosCfg = pprint( getS3 )
479 sentCfg = pprint( s3Json )
480 if onosCfg == sentCfg:
Jon Hallbc080f92017-05-24 16:29:55 -0700481 main.log.info( "ONOS NetCfg match what was sent" )
Jon Hall66e001c2015-11-12 09:45:10 -0800482 s3Result = True
483 else:
484 main.log.error( "ONOS NetCfg doesn't match what was sent" )
485 main.log.debug( "ONOS config: {}".format( onosCfg ) )
486 main.log.debug( "Sent config: {}".format( sentCfg ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700487 utilities.retry( f=main.ONOSrest1.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800488 utilities.assert_equals( expect=True,
489 actual=s3Result,
490 onpass="Net Cfg added for device s3",
491 onfail="Net Cfg for device s3 not correctly set" )
492 main.netCfg.compareCfg( main, main.gossipTime )
493
494 def CASE21( self, main ):
495 """
496 Initial check of devices
497 """
498 import json
499 try:
500 assert main.s1Json, "s1Json not defined"
501 except AssertionError:
502 main.log.exception( "Case Prerequisites not set: " )
503 main.cleanup()
504 main.exit()
505 main.case( "Check Devices After they initially connect to ONOS" )
506
507 main.netCfg.compareCfg( main )
508
509 main.step( "ONOS should only show devices S1, S2, and S4" )
510 devices = main.ONOSrest1.devices()
511 main.log.debug( main.ONOSrest1.pprint( devices ) )
512 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4 ] ]
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700513 main.log.debug( allowedDevices )
Jon Hall66e001c2015-11-12 09:45:10 -0800514 onosDevices = []
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700515 try:
516 for sw in json.loads( devices ):
Jon Hallbc080f92017-05-24 16:29:55 -0700517 onosDevices.append( str( sw[ 'id' ] ) )
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700518 onosDevices.sort()
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700519 main.log.debug( onosDevices )
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700520 except( TypeError, ValueError ):
521 main.log.error( "Problem loading devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800522 utilities.assert_equals( expect=allowedDevices,
523 actual=onosDevices,
524 onpass="Only allowed devices are in ONOS",
525 onfail="ONOS devices doesn't match the list" +
526 " of allowed devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800527 main.step( "Check device annotations" )
528 keys = [ 'name', 'owner', 'rackAddress' ]
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700529 try:
530 for sw in json.loads( devices ):
Jon Hallbc080f92017-05-24 16:29:55 -0700531 if "of:0000000000000001" in sw[ 'id' ]:
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700532 s1Correct = True
533 for k in keys:
Jon Hallbc080f92017-05-24 16:29:55 -0700534 if str( sw.get( 'annotations', {} ).get( k ) ) != str( main.s1Json[ k ] ):
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700535 s1Correct = False
536 main.log.debug( "{} is wrong on s1".format( k ) )
537 if not s1Correct:
538 main.log.error( "Annotations for s1 are incorrect: {}".format( sw ) )
539 except( TypeError, ValueError ):
540 main.log.error( "Problem loading devices" )
541 s1Correct = False
Jon Hall66e001c2015-11-12 09:45:10 -0800542 try:
543 stepResult = s1Correct
544 except NameError:
545 stepResult = False
546 main.log.error( "s1 not found in devices" )
547 utilities.assert_equals( expect=True,
548 actual=stepResult,
549 onpass="Configured device's annotations are correct",
550 onfail="Incorrect annotations for configured devices." )
551
552 def CASE22( self, main ):
553 """
554 Add some device configurations for connected devices and then check
555 they are distributed to all nodes
556 """
557 main.case( "Add Network configurations for connected devices to the cluster" )
558 main.caseExplanation = "Add Network Configurations for discovered " +\
559 "devices. One device is allowed" +\
560 ", the other disallowed."
Jon Hallbc080f92017-05-24 16:29:55 -0700561 pprint = main.nodes[ 0 ].pprint
Jon Hall66e001c2015-11-12 09:45:10 -0800562
563 main.step( "Add Net Cfg for switch2" )
Pratik Parab6f418632017-04-25 17:05:50 -0700564 try:
565 with open( os.path.dirname( main.testFile ) + '/dependencies/s2Json', 'r' ) as s2Jsondata:
566 s2Json = json.load( s2Jsondata )
567 except IOError:
568 main.log.exception( "s2Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700569 main.cleanup()
570 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700571 main.log.info( "s2Json:" + str( s2Json ) )
Jon Hall66e001c2015-11-12 09:45:10 -0800572 main.s2Json = s2Json
573 setS2Allow = main.ONOSrest2.setNetCfg( s2Json,
574 subjectClass="devices",
575 subjectKey="of:0000000000000002",
576 configKey="basic" )
577 s2Result = False
578 if setS2Allow:
579 # Check what we set is what is in ONOS
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700580 getS2 = utilities.retry( f=main.ONOSrest2.getNetCfg,
581 retValue=False,
582 kwargs={"subjectClass": "devices",
583 "subjectKey": "of:0000000000000002",
584 "configKey": "basic"},
585 attempts=main.retrytimes,
586 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800587 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" )
Jon Hall66e001c2015-11-12 09:45:10 -0800600 main.step( "Add Net Cfg for switch4" )
Pratik Parab6f418632017-04-25 17:05:50 -0700601
602 try:
603 with open( os.path.dirname( main.testFile ) + '/dependencies/s4Json', 'r' ) as s4Jsondata:
604 s4Json = json.load( s4Jsondata )
605 except IOError:
606 main.log.exception( "s4Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700607 main.cleanup()
608 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700609 main.log.info( "s4Json:" + str( s4Json ) )
Jon Hall66e001c2015-11-12 09:45:10 -0800610 main.s4Json = s4Json
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700611 setS4Disallow = main.ONOSrest3.setNetCfg( s4Json,
Jon Hall66e001c2015-11-12 09:45:10 -0800612 subjectClass="devices",
613 subjectKey="of:0000000000000004",
614 configKey="basic" )
615 s4Result = False
616 if setS4Disallow:
617 # Check what we set is what is in ONOS
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700618 getS4 = utilities.retry( f=main.ONOSrest3.getNetCfg,
619 retValue=False,
620 kwargs={"subjectClass": "devices",
621 "subjectKey": "of:0000000000000004",
622 "configKey": "basic"},
623 attempts=main.retrytimes,
624 sleep=main.retrysleep )
625
Jon Hall66e001c2015-11-12 09:45:10 -0800626 onosCfg = pprint( getS4 )
627 sentCfg = pprint( s4Json )
628 if onosCfg == sentCfg:
629 s4Result = True
630 else:
631 main.log.error( "ONOS NetCfg doesn't match what was sent" )
632 main.log.debug( "ONOS config: {}".format( onosCfg ) )
633 main.log.debug( "Sent config: {}".format( sentCfg ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700634 main.step( "Retrying main.ONOSrest3.getNetCfg" )
635 utilities.retry( f=main.ONOSrest3.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800636 utilities.assert_equals( expect=True,
637 actual=s4Result,
638 onpass="Net Cfg added for device s4",
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700639 onfail="Net Cfg for device s4 not correctly set" )
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -0700640
Jon Hall66e001c2015-11-12 09:45:10 -0800641 main.netCfg.compareCfg( main, main.gossipTime )
642
643 def CASE23( self, main ):
644 """
645 Check of devices after all Network Configurations are set
646 """
647 import json
648 try:
649 assert main.s1Json, "s1Json not defined"
650 assert main.s2Json, "s2Json not defined"
651 except AssertionError:
652 main.log.exception( "Case Prerequisites not set: " )
653 main.cleanup()
654 main.exit()
655 main.case( "Check Devices after all configurations are set" )
656
657 main.netCfg.compareCfg( main )
658
659 main.step( "ONOS should only show devices S1 and S2" )
660 devices = main.ONOSrest1.devices()
661 main.log.debug( main.ONOSrest1.pprint( devices ) )
662 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2 ] ]
663 onosDevices = []
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700664 try:
665 for sw in json.loads( devices ):
666 onosDevices.append( str( sw.get( 'id' ) ) )
667 onosDevices.sort()
668 failMsg = "ONOS devices doesn't match the list of allowed devices.\n"
669 failMsg += "Expected devices: {}\nActual devices: {}".format( allowedDevices,
670 onosDevices )
671 except( TypeError, ValueError ):
672 main.log.error( "Problem loading devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800673 utilities.assert_equals( expect=allowedDevices,
674 actual=onosDevices,
675 onpass="Only allowed devices are in ONOS",
676 onfail=failMsg )
677
678 main.step( "Check device annotations" )
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -0700679 stepResult = utilities.retry( f=main.netCfg.checkAllDeviceAnnotations,
680 args=( main, json ),
681 retValue=False,
682 attempts=main.retrytimes,
683 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800684 utilities.assert_equals( expect=True,
685 actual=stepResult,
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -0700686 onpass="Configured devices' annotations are correct",
Jon Hall66e001c2015-11-12 09:45:10 -0800687 onfail="Incorrect annotations for configured devices." )
688
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -0700689
690
Jon Hall66e001c2015-11-12 09:45:10 -0800691 def CASE24( self, main ):
692 """
693 Testing removal of configurations
694 """
Jon Hall541b8e02015-12-14 19:29:01 -0800695 import time
Jon Hall66e001c2015-11-12 09:45:10 -0800696 try:
697 assert main.s1Json, "s1Json not defined"
698 assert main.s2Json, "s2Json not defined"
699 assert main.s3Json, "s3Json not defined"
700 assert main.s4Json, "s4Json not defined"
701 except AssertionError:
702 main.log.exception( "Case Prerequisites not set: " )
703 main.cleanup()
704 main.exit()
705 main.case( "Testing removal of configurations" )
706 main.step( "Remove 'allowed' configuration from all devices" )
707
708 s1Json = main.s1Json # NOTE: This is a reference
709 try:
Jon Hallbc080f92017-05-24 16:29:55 -0700710 del s1Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800711 except KeyError:
712 main.log.exception( "Key not found" )
713 setS1 = main.ONOSrest1.setNetCfg( s1Json,
714 subjectClass="devices",
715 subjectKey="of:0000000000000001",
716 configKey="basic" )
717
718 s2Json = main.s2Json # NOTE: This is a reference
719 try:
Jon Hall541b8e02015-12-14 19:29:01 -0800720 time.sleep( main.gossipTime )
Jon Hallbc080f92017-05-24 16:29:55 -0700721 del s2Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800722 except KeyError:
723 main.log.exception( "Key not found" )
724 setS2 = main.ONOSrest2.setNetCfg( s2Json,
725 subjectClass="devices",
726 subjectKey="of:0000000000000002",
727 configKey="basic" )
728
729 s3Json = main.s3Json # 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 s3Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800733 except KeyError:
734 main.log.exception( "Key not found" )
735 setS3 = main.ONOSrest3.setNetCfg( s3Json,
736 subjectClass="devices",
737 subjectKey="of:0000000000000003",
738 configKey="basic" )
739
740 s4Json = main.s4Json # 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 s4Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800744 except KeyError:
745 main.log.exception( "Key not found" )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700746 setS4 = main.ONOSrest3.setNetCfg( s4Json,
Jon Hall66e001c2015-11-12 09:45:10 -0800747 subjectClass="devices",
748 subjectKey="of:0000000000000004",
749 configKey="basic" )
750 removeAllowed = setS1 and setS2 and setS3 and setS4
751 utilities.assert_equals( expect=main.TRUE,
752 actual=removeAllowed,
753 onpass="Successfully removed 'allowed' config from devices",
754 onfail="Failed to remove the 'allowed' config key." )
755
756 main.netCfg.compareCfg( main, main.gossipTime )
757
758 main.step( "Delete basic config for s1 and s2" )
759 removeS1 = main.ONOSrest1.removeNetCfg( subjectClass="devices",
760 subjectKey="of:0000000000000001",
761 configKey="basic" )
762 removeS2 = main.ONOSrest2.removeNetCfg( subjectClass="devices",
763 subjectKey="of:0000000000000002",
764 configKey="basic" )
765 removeSingles = removeS1 and removeS2
766 utilities.assert_equals( expect=main.TRUE,
767 actual=removeSingles,
768 onpass="Successfully removed S1 and S2 basic config",
769 onfail="Failed to removed S1 and S2 basic config" )
770
771 main.netCfg.compareCfg( main, main.gossipTime )
772
773 main.step( "Delete the net config for S3" )
774 removeS3 = main.ONOSrest3.removeNetCfg( subjectClass="devices",
775 subjectKey="of:0000000000000003" )
776 utilities.assert_equals( expect=main.TRUE,
777 actual=removeS3,
778 onpass="Successfully removed S3's config",
779 onfail="Failed to removed S3's config" )
780
781 main.netCfg.compareCfg( main, main.gossipTime )
782
783 main.step( "Delete the net config for all devices" )
784 remove = main.ONOSrest3.removeNetCfg( subjectClass="devices" )
785 utilities.assert_equals( expect=main.TRUE,
786 actual=remove,
787 onpass="Successfully removed device config",
788 onfail="Failed to remove device config" )
789
790 main.netCfg.compareCfg( main, main.gossipTime )
791
792 main.step( "Assert the net config for devices is empty" )
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700793
794 get = utilities.retry( f=main.ONOSrest3.getNetCfg,
795 retValue = False,
796 kwargs={"subjectClass":"devices"},
797 sleep=main.retrysleep,
798 attempts=main.retrytimes )
799
Jon Hall66e001c2015-11-12 09:45:10 -0800800 utilities.assert_equals( expect='{}',
801 actual=get,
802 onpass="Successfully removed device config",
803 onfail="Failed to remove device config" )
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700804
805 def CASE25( self, main ):
806 """
807 Use network-cfg.json to configure devices during ONOS startup
808 """
809 main.case( "Preparing network-cfg.json to load configurations" )
810 main.step( "Moving network-cfg.json to $ONOS_ROOT/tools/package/config/" )
811 prestartResult = main.TRUE
812 srcPath = "~/OnosSystemTest/TestON/tests/FUNC/FUNCnetCfg/dependencies/network-cfg.json"
813 dstPath = "~/onos/tools/package/config/network-cfg.json"
814 prestartResult = main.ONOSbench.scp( main.ONOSbench, srcPath, dstPath, direction="to" )
815 utilities.assert_equals( expect=main.TRUE,
816 actual=prestartResult,
817 onpass="Successfully copied network-cfg.json to target directory",
818 onfail="Failed to copy network-cfg.json to target directory" )
819
820 def CASE26( self, main ):
821 """
822 Check to see that pre-startup configurations were set correctly
823 """
824 import json
825 main.case( "Check to see if the pre-startup configurations were set, then remove their allowed status" )
826 main.step( "Checking configurations for Switches 5 and 6" )
Jon Hallbc080f92017-05-24 16:29:55 -0700827 main.step( "ONOS should only show devices S1, S2, S4, and S5" ) # and S6
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700828 devices = main.ONOSrest1.devices()
829 main.log.debug( main.ONOSrest1.pprint( devices ) )
Jon Hallbc080f92017-05-24 16:29:55 -0700830 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4, 5 ] ] # 6
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700831 main.log.debug( allowedDevices )
832 onosDevices = []
833 try:
834 for sw in json.loads( devices ):
Jon Hallbc080f92017-05-24 16:29:55 -0700835 onosDevices.append( str( sw[ 'id' ] ) )
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700836 onosDevices.sort()
837 main.log.debug( onosDevices )
838 except( TypeError, ValueError ):
839 main.log.error( "Problem loading devices" )
840 utilities.assert_equals( expect=allowedDevices,
841 actual=onosDevices,
842 onpass="Only allowed devices are in ONOS",
843 onfail="ONOS devices doesn't match the list" +
844 " of allowed devices" )
845
846 main.step( "Removing allowed status from Switches 5 and 6" )
Pratik Parab6f418632017-04-25 17:05:50 -0700847 try:
848 with open( os.path.dirname( main.testFile ) + '/dependencies/s5Json', 'r' ) as s5Jsondata:
849 main.s5Json = json.load( s5Jsondata )
850 except IOError:
851 main.log.exception( "s5Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700852 main.cleanup()
853 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700854 main.log.info( "s5Json:" + str( main.s5Json ) )
855
856 try:
857 with open( os.path.dirname( main.testFile ) + '/dependencies/s6Json', 'r' ) as s6Jsondata:
858 main.s6Json = json.load( s6Jsondata )
859 except IOError:
860 main.log.exception( "s6Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700861 main.cleanup()
862 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700863 main.log.info( "s6Json:" + str( main.s6Json ) )
864
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700865 s5Json = main.s5Json
866 setS1 = main.ONOSrest1.setNetCfg( s5Json,
867 subjectClass="devices",
868 subjectKey="of:0000000000000005",
869 configKey="basic" )
870
871 s6Json = main.s6Json
872 setS1 = main.ONOSrest1.setNetCfg( s6Json,
873 subjectClass="devices",
874 subjectKey="of:0000000000000006",
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700875 configKey="basic" )
876
877 def CASE27( self, main ):
878 """
Jon Hallbc080f92017-05-24 16:29:55 -0700879 1 ) A = get /network/configuration
880 2 ) Post A
881 3 ) Compare A with ONOS
882 4 ) Modify A so S6 is disallowed
883 5 ) Check
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700884
885 """
886 import json
Jon Hallbc080f92017-05-24 16:29:55 -0700887 pprint = main.nodes[ 0 ].pprint
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700888 main.case( "Posting network configurations to the top level web resource" )
889 main.step( "Get json object from Net Cfg" )
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700890 getinfo = utilities.retry( f=main.ONOSrest1.getNetCfg,
891 retValue=False,
892 sleep=main.retrysleep,
893 attempts=main.retrytimes )
894
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700895 main.log.debug( getinfo )
896 main.step( "Posting json object to Net Cfg" )
897 postinfo = main.ONOSrest1.setNetCfg( json.loads( getinfo ) )
898 main.step( "Compare device with ONOS" )
899 main.netCfg.compareCfg( main )
Jon Hallbc080f92017-05-24 16:29:55 -0700900 main.step( "ONOS should only show devices S1, S2, S4, S5 and S6" )
901 devices = main.ONOSrest1.devices()
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700902 main.log.debug( main.ONOSrest1.pprint( devices ) )
903 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4, 5, 6 ] ]
904 onosDevices = []
905 try:
906 for sw in json.loads( devices ):
907 onosDevices.append( str( sw.get( 'id' ) ) )
Jon Hallbc080f92017-05-24 16:29:55 -0700908 onosDevices.sort()
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700909 failMsg = "ONOS devices doesn't match the list of allowed devices. \n"
910 failMsg += "Expected devices: {}\nActual devices: {}".format( allowedDevices, onosDevices )
911 except( TypeError, ValueError ):
912 main.log.error( "Problem loading devices" )
913 utilities.assert_equals( expect=allowedDevices, actual=onosDevices,
914 onpass="Only allowed devices are in ONOS", onfail=failMsg )
915
916 main.step( "Modify json object so S6 is disallowed" )
917 main.s6Json = { "allowed": False }
918 s6Json = main.s6Json
919 setS6Disallow = main.ONOSrest1.setNetCfg( s6Json, subjectClass="devices",
920 subjectKey="of:0000000000000006", configKey="basic" )
921 s6Result = False
922 if setS6Disallow:
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700923 getS6 = utilities.retry( f=main.ONOSrest1.getNetCfg,
924 retValue=False,
925 kwargs={"subjectClass":"devices",
926 "subjectKey" : "of:0000000000000006",
927 "configKey" : "basic"},
928 sleep=main.retrysleep,
929 attempts=main.retrytimes )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700930 onosCfg = pprint( getS6 )
931 sentCfg = pprint( s6Json )
932 if onosCfg == sentCfg:
933 s6Result = True
934 else:
935 main.log.error( "ONOS NetCfg doesn't match what was sent" )
936 main.log.debug( "ONOS config: {}".format( onosCfg ) )
937 main.log.debug( "Sent config: {}".format( sentCfg ) )
938 utilities.retry( f=main.ONOSrest1.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
939 utilities.assert_equals( expect=True, actual=s6Result,
940 onpass="Net Cfg added for devices s6",
941 onfail="Net Cfg for device s6 not correctly set" )