blob: 65a5477540bd0fbafa880f9e2f7847967516f529 [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
Jon Hall66e001c2015-11-12 09:45:10 -080013 """
14 - Construct tests variables
15 - GIT ( optional )
16 - Checkout ONOS master branch
17 - Pull latest ONOS code
Jon Hall66e001c2015-11-12 09:45:10 -080018 """
Devin Lim58046fa2017-07-05 16:55:00 -070019
20 try:
21 from tests.dependencies.ONOSSetup import ONOSSetup
22 main.testSetUp = ONOSSetup()
23 except ImportError:
24 main.log.error( "ONOSSetup not found. exiting the test" )
25 main.exit()
26 main.testSetUp.envSetupDescription()
Jon Hall66e001c2015-11-12 09:45:10 -080027 stepResult = main.FALSE
28
29 # Test variables
30 try:
Jon Hall66e001c2015-11-12 09:45:10 -080031 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
Jon Hall66e001c2015-11-12 09:45:10 -080032 main.dependencyPath = main.testOnDirectory + \
33 main.params[ 'DEPENDENCY' ][ 'path' ]
Jon Hall66e001c2015-11-12 09:45:10 -080034 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
35 wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ]
36 wrapperFile3 = main.params[ 'DEPENDENCY' ][ 'wrapper3' ]
37 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
Jon Hallbc080f92017-05-24 16:29:55 -070038 main.gossipTime = int( main.params[ 'SLEEP' ][ 'cfgGossip' ] )
alison15124df2016-10-06 12:04:51 -070039 main.SetNetCfgSleep = int( main.params[ 'SLEEP' ][ 'SetNetCfgSleep' ] )
Jon Hall66e001c2015-11-12 09:45:10 -080040 main.hostsData = {}
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -070041 main.retrytimes = int( main.params[ 'RETRY' ] )
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -070042 main.retrysleep = int( main.params[ 'RetrySleep' ] )
Jon Hall66e001c2015-11-12 09:45:10 -080043
44 # -- INIT SECTION, SHOULD ONLY BE RUN ONCE -- #
Jon Hall66e001c2015-11-12 09:45:10 -080045 main.netCfg = imp.load_source( wrapperFile2,
46 main.dependencyPath +
47 wrapperFile2 +
48 ".py" )
49
Devin Lim58046fa2017-07-05 16:55:00 -070050 stepResult = main.testSetUp.envSetup( hasRest=True, hasCli=False )
Jon Hall66e001c2015-11-12 09:45:10 -080051 except Exception as e:
Devin Lim58046fa2017-07-05 16:55:00 -070052 main.testSetUp.envSetupException( e )
53 main.testSetUp.evnSetupConclusion( stepResult )
Jon Hall66e001c2015-11-12 09:45:10 -080054
55 def CASE2( self, main ):
56 """
57 - Set up cell
58 - Create cell file
59 - Set cell file
60 - Verify cell file
61 - Kill ONOS process
62 - Uninstall ONOS cluster
Jon Hall66e001c2015-11-12 09:45:10 -080063 - Install ONOS cluster
Jon Hall72ecaa02017-06-06 09:41:48 -070064 - Verify ONOS start up
Jon Hall66e001c2015-11-12 09:45:10 -080065 - Connect to cli
66 """
67 import time
Devin Lim58046fa2017-07-05 16:55:00 -070068 main.testSetUp.ONOSSetUp( main.Mininet1, hasCli=False )
Jon Hall66e001c2015-11-12 09:45:10 -080069
70 def CASE8( self, main ):
71 """
72 Compare Topo
73 """
Devin Lim58046fa2017-07-05 16:55:00 -070074 try:
75 from tests.dependencies.topology import Topology
76 except ImportError:
77 main.log.error( "Topology not found exiting the test" )
78 main.exit()
79 try:
80 main.topoRelated
81 except ( NameError, AttributeError ):
82 main.topoRelated = Topology()
83 main.topoRelated.compareTopos( main.Mininet1 )
Jon Hall66e001c2015-11-12 09:45:10 -080084
85 def CASE9( self, main ):
Jon Hallbc080f92017-05-24 16:29:55 -070086 """
Jon Hall66e001c2015-11-12 09:45:10 -080087 Report errors/warnings/exceptions
Jon Hallbc080f92017-05-24 16:29:55 -070088 """
Jon Hall66e001c2015-11-12 09:45:10 -080089 main.log.info( "Error report: \n" )
90 main.ONOSbench.logReport(
Jon Hallbc080f92017-05-24 16:29:55 -070091 globalONOSip[ 0 ],
92 [ "INFO", "WARN", "ERROR", "Except" ],
Jon Hall66e001c2015-11-12 09:45:10 -080093 "s" )
Jon Hallbc080f92017-05-24 16:29:55 -070094 # main.ONOSbench.logReport( globalONOSip[ 1 ], [ "INFO" ], "d" )
Jon Hall66e001c2015-11-12 09:45:10 -080095
96 def CASE10( self, main ):
97 """
98 Start Mininet topology with OF 1.0 switches
99 """
100 main.OFProtocol = "1.0"
101 main.log.report( "Start Mininet topology with OF 1.0 switches" )
102 main.case( "Start Mininet topology with OF 1.0 switches" )
103 main.caseExplanation = "Start mininet topology with OF 1.0 " +\
104 "switches to test intents, exits out if " +\
105 "topology did not start correctly"
106
107 main.step( "Starting Mininet topology with OF 1.0 switches" )
Jon Hall53c5e662016-04-13 16:06:56 -0700108 args = "--controller none --switch ovs,protocols=OpenFlow10"
Jon Hallbc080f92017-05-24 16:29:55 -0700109 switches = int( main.params[ 'MININET' ][ 'switch' ] )
Jon Hall66e001c2015-11-12 09:45:10 -0800110 cmd = "mn --topo linear,{} {}".format( switches, args )
Jon Hallbc080f92017-05-24 16:29:55 -0700111 topoResult = main.Mininet1.startNet( mnCmd=cmd )
Jon Hall66e001c2015-11-12 09:45:10 -0800112 stepResult = topoResult
113 utilities.assert_equals( expect=main.TRUE,
114 actual=stepResult,
115 onpass="Successfully loaded topology",
116 onfail="Failed to load topology" )
117 # Exit if topology did not load properly
118 if not topoResult:
119 main.cleanup()
120 main.exit()
121
122 def CASE11( self, main ):
123 """
124 Start Mininet topology with OF 1.3 switches
125 """
126 import re
127 main.OFProtocol = "1.3"
128 main.log.report( "Start Mininet topology with OF 1.3 switches" )
129 main.case( "Start Mininet topology with OF 1.3 switches" )
130 main.caseExplanation = "Start mininet topology with OF 1.3 " +\
131 "switches to test intents, exits out if " +\
132 "topology did not start correctly"
133
134 main.step( "Starting Mininet topology with OF 1.3 switches" )
Jon Hall53c5e662016-04-13 16:06:56 -0700135 args = "--controller none --switch ovs,protocols=OpenFlow13"
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700136 switches = int( main.params[ 'MININET' ][ 'switch' ] )
Jon Hall66e001c2015-11-12 09:45:10 -0800137 cmd = "mn --topo linear,{} {}".format( switches, args )
Jon Hallbc080f92017-05-24 16:29:55 -0700138 topoResult = main.Mininet1.startNet( mnCmd=cmd )
Jon Hall66e001c2015-11-12 09:45:10 -0800139 stepResult = topoResult
140 utilities.assert_equals( expect=main.TRUE,
141 actual=stepResult,
142 onpass="Successfully loaded topology",
143 onfail="Failed to load topology" )
144 # Exit if topology did not load properly
145 if not topoResult:
146 main.cleanup()
147 main.exit()
148
149 tempONOSip = []
150 for i in range( main.numCtrls ):
151 tempONOSip.append( main.ONOSip[ i ] )
152
153 swList = [ "s" + str( i ) for i in range( 1, switches + 1 ) ]
154 assignResult = main.Mininet1.assignSwController( sw=swList,
155 ip=tempONOSip,
156 port='6653' )
157 if not assignResult:
158 main.cleanup()
159 main.exit()
160
161 assignResult = main.TRUE
162 for sw in swList:
163 response = main.Mininet1.getSwController( "s" + str( i ) )
164 main.log.info( "Response is " + str( response ) )
165 for ip in tempONOSip:
166 if re.search( "tcp:" + ip, response ):
167 assignResult = assignResult and main.TRUE
168 else:
169 assignResult = assignResult and main.FALSE
170 stepResult = assignResult
171 utilities.assert_equals( expect=main.TRUE,
172 actual=stepResult,
173 onpass="Successfully assigned switches" +
174 "to controller",
175 onfail="Failed to assign switches to " +
176 "controller" )
177
178 def CASE14( self, main ):
179 """
180 Stop mininet
181 """
Devin Lim58046fa2017-07-05 16:55:00 -0700182 try:
183 from tests.dependencies.utils import Utils
184 except ImportError:
185 main.log.error( "Utils not found exiting the test" )
186 main.exit()
187 try:
188 main.Utils
189 except ( NameError, AttributeError ):
190 main.Utils = Utils()
191 main.Utils.mininetCleanIntro()
192 topoResult = main.Utils.mininetCleanup( main.Mininet1 )
Jon Hall66e001c2015-11-12 09:45:10 -0800193 # Exit if topology did not load properly
194 if not topoResult:
195 main.cleanup()
196 main.exit()
197
198 def CASE20( self, main ):
199 """
200 Add some device configurations and then check they are distributed
201 to all nodes
202 """
alison15124df2016-10-06 12:04:51 -0700203 import time
Pratik Parabc6083c22017-04-27 13:24:41 -0700204 import json
205 import os
Jon Hall66e001c2015-11-12 09:45:10 -0800206 main.case( "Add Network configurations to the cluster" )
207 main.caseExplanation = "Add Network Configurations for devices" +\
208 " not discovered yet. One device is allowed" +\
209 ", the other disallowed."
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -0700210
211
Devin Lim58046fa2017-07-05 16:55:00 -0700212 pprint = main.RESTs[ 0 ].pprint
Jon Hall66e001c2015-11-12 09:45:10 -0800213
214 main.step( "Add Net Cfg for switch1" )
Pratik Parab6f418632017-04-25 17:05:50 -0700215
Pratik Parab6f418632017-04-25 17:05:50 -0700216 try:
217 with open( os.path.dirname( main.testFile ) + '/dependencies/s1Json', 'r' ) as s1Jsondata:
218 s1Json = json.load( s1Jsondata )
219 except IOError:
220 main.log.exception( "s1Json File not found." )
Pratik Parabc6083c22017-04-27 13:24:41 -0700221 main.cleanup()
222 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700223 main.log.info( "s1Json:" + str( s1Json ) )
224
Jon Hall66e001c2015-11-12 09:45:10 -0800225 main.s1Json = s1Json
226 setS1Allow = main.ONOSrest1.setNetCfg( s1Json,
227 subjectClass="devices",
228 subjectKey="of:0000000000000001",
229 configKey="basic" )
230 s1Result = False
alison15124df2016-10-06 12:04:51 -0700231 #Wait 5 secs after set up netCfg
232 time.sleep( main.SetNetCfgSleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800233 if setS1Allow:
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700234 getS1 = utilities.retry( f=main.ONOSrest1.getNetCfg,
235 retValue=False,
236 kwargs={"subjectClass":"devices",
237 "subjectKey" : "of:0000000000000001",
238 "configKey" : "basic"},
239 attempts=main.retrytimes,
240 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800241 onosCfg = pprint( getS1 )
242 sentCfg = pprint( s1Json )
243 if onosCfg == sentCfg:
alison15124df2016-10-06 12:04:51 -0700244 main.log.info( "ONOS NetCfg match what was sent" )
Jon Hall66e001c2015-11-12 09:45:10 -0800245 s1Result = True
246 else:
247 main.log.error( "ONOS NetCfg doesn't match what was sent" )
248 main.log.debug( "ONOS config: {}".format( onosCfg ) )
249 main.log.debug( "Sent config: {}".format( sentCfg ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700250 utilities.retry( f=main.ONOSrest1.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800251 utilities.assert_equals( expect=True,
252 actual=s1Result,
253 onpass="Net Cfg added for device s1",
254 onfail="Net Cfg for device s1 not correctly set" )
255
256 main.step( "Add Net Cfg for switch3" )
Pratik Parab6f418632017-04-25 17:05:50 -0700257
258 try:
259 with open( os.path.dirname( main.testFile ) + '/dependencies/s3Json', 'r' ) as s3Jsondata:
260 s3Json = json.load( s3Jsondata )
261 except IOError:
262 main.log.exception( "s3Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700263 main.cleanup()
264 main.exit()
Jon Hallbc080f92017-05-24 16:29:55 -0700265 main.log.info( "s3Json:" + str( s3Json ) )
Pratik Parab6f418632017-04-25 17:05:50 -0700266
Jon Hall66e001c2015-11-12 09:45:10 -0800267 main.s3Json = s3Json
268 setS3Disallow = main.ONOSrest1.setNetCfg( s3Json,
269 subjectClass="devices",
270 subjectKey="of:0000000000000003",
271 configKey="basic" )
272 s3Result = False
alison15124df2016-10-06 12:04:51 -0700273 time.sleep( main.SetNetCfgSleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800274 if setS3Disallow:
275 # Check what we set is what is in ONOS
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700276 getS3 = utilities.retry( f=main.ONOSrest1.getNetCfg,
277 retValue=False,
278 kwargs={"subjectClass": "devices",
279 "subjectKey": "of:0000000000000003",
280 "configKey": "basic"},
281 attempts=main.retrytimes,
282 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800283 onosCfg = pprint( getS3 )
284 sentCfg = pprint( s3Json )
285 if onosCfg == sentCfg:
Jon Hallbc080f92017-05-24 16:29:55 -0700286 main.log.info( "ONOS NetCfg match what was sent" )
Jon Hall66e001c2015-11-12 09:45:10 -0800287 s3Result = True
288 else:
289 main.log.error( "ONOS NetCfg doesn't match what was sent" )
290 main.log.debug( "ONOS config: {}".format( onosCfg ) )
291 main.log.debug( "Sent config: {}".format( sentCfg ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700292 utilities.retry( f=main.ONOSrest1.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800293 utilities.assert_equals( expect=True,
294 actual=s3Result,
295 onpass="Net Cfg added for device s3",
296 onfail="Net Cfg for device s3 not correctly set" )
297 main.netCfg.compareCfg( main, main.gossipTime )
298
299 def CASE21( self, main ):
300 """
301 Initial check of devices
302 """
303 import json
304 try:
305 assert main.s1Json, "s1Json not defined"
306 except AssertionError:
307 main.log.exception( "Case Prerequisites not set: " )
308 main.cleanup()
309 main.exit()
310 main.case( "Check Devices After they initially connect to ONOS" )
311
312 main.netCfg.compareCfg( main )
313
314 main.step( "ONOS should only show devices S1, S2, and S4" )
315 devices = main.ONOSrest1.devices()
316 main.log.debug( main.ONOSrest1.pprint( devices ) )
317 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4 ] ]
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700318 main.log.debug( allowedDevices )
Jon Hall66e001c2015-11-12 09:45:10 -0800319 onosDevices = []
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700320 try:
321 for sw in json.loads( devices ):
Jon Hallbc080f92017-05-24 16:29:55 -0700322 onosDevices.append( str( sw[ 'id' ] ) )
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700323 onosDevices.sort()
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700324 main.log.debug( onosDevices )
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700325 except( TypeError, ValueError ):
326 main.log.error( "Problem loading devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800327 utilities.assert_equals( expect=allowedDevices,
328 actual=onosDevices,
329 onpass="Only allowed devices are in ONOS",
330 onfail="ONOS devices doesn't match the list" +
331 " of allowed devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800332 main.step( "Check device annotations" )
333 keys = [ 'name', 'owner', 'rackAddress' ]
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700334 try:
335 for sw in json.loads( devices ):
Jon Hallbc080f92017-05-24 16:29:55 -0700336 if "of:0000000000000001" in sw[ 'id' ]:
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700337 s1Correct = True
338 for k in keys:
Jon Hallbc080f92017-05-24 16:29:55 -0700339 if str( sw.get( 'annotations', {} ).get( k ) ) != str( main.s1Json[ k ] ):
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700340 s1Correct = False
341 main.log.debug( "{} is wrong on s1".format( k ) )
342 if not s1Correct:
343 main.log.error( "Annotations for s1 are incorrect: {}".format( sw ) )
344 except( TypeError, ValueError ):
345 main.log.error( "Problem loading devices" )
346 s1Correct = False
Jon Hall66e001c2015-11-12 09:45:10 -0800347 try:
348 stepResult = s1Correct
349 except NameError:
350 stepResult = False
351 main.log.error( "s1 not found in devices" )
352 utilities.assert_equals( expect=True,
353 actual=stepResult,
354 onpass="Configured device's annotations are correct",
355 onfail="Incorrect annotations for configured devices." )
356
357 def CASE22( self, main ):
358 """
359 Add some device configurations for connected devices and then check
360 they are distributed to all nodes
361 """
362 main.case( "Add Network configurations for connected devices to the cluster" )
363 main.caseExplanation = "Add Network Configurations for discovered " +\
364 "devices. One device is allowed" +\
365 ", the other disallowed."
Devin Lim58046fa2017-07-05 16:55:00 -0700366 pprint = main.RESTs[ 0 ].pprint
Jon Hall66e001c2015-11-12 09:45:10 -0800367
368 main.step( "Add Net Cfg for switch2" )
Pratik Parab6f418632017-04-25 17:05:50 -0700369 try:
370 with open( os.path.dirname( main.testFile ) + '/dependencies/s2Json', 'r' ) as s2Jsondata:
371 s2Json = json.load( s2Jsondata )
372 except IOError:
373 main.log.exception( "s2Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700374 main.cleanup()
375 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700376 main.log.info( "s2Json:" + str( s2Json ) )
Jon Hall66e001c2015-11-12 09:45:10 -0800377 main.s2Json = s2Json
378 setS2Allow = main.ONOSrest2.setNetCfg( s2Json,
379 subjectClass="devices",
380 subjectKey="of:0000000000000002",
381 configKey="basic" )
382 s2Result = False
383 if setS2Allow:
384 # Check what we set is what is in ONOS
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700385 getS2 = utilities.retry( f=main.ONOSrest2.getNetCfg,
386 retValue=False,
387 kwargs={"subjectClass": "devices",
388 "subjectKey": "of:0000000000000002",
389 "configKey": "basic"},
390 attempts=main.retrytimes,
391 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800392 onosCfg = pprint( getS2 )
393 sentCfg = pprint( s2Json )
394 if onosCfg == sentCfg:
395 s2Result = True
396 else:
397 main.log.error( "ONOS NetCfg doesn't match what was sent" )
398 main.log.debug( "ONOS config: {}".format( onosCfg ) )
399 main.log.debug( "Sent config: {}".format( sentCfg ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700400 utilities.retry( f=main.ONOSrest2.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800401 utilities.assert_equals( expect=True,
402 actual=s2Result,
403 onpass="Net Cfg added for device s2",
404 onfail="Net Cfg for device s2 not correctly set" )
Jon Hall66e001c2015-11-12 09:45:10 -0800405 main.step( "Add Net Cfg for switch4" )
Pratik Parab6f418632017-04-25 17:05:50 -0700406
407 try:
408 with open( os.path.dirname( main.testFile ) + '/dependencies/s4Json', 'r' ) as s4Jsondata:
409 s4Json = json.load( s4Jsondata )
410 except IOError:
411 main.log.exception( "s4Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700412 main.cleanup()
413 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700414 main.log.info( "s4Json:" + str( s4Json ) )
Jon Hall66e001c2015-11-12 09:45:10 -0800415 main.s4Json = s4Json
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700416 setS4Disallow = main.ONOSrest3.setNetCfg( s4Json,
Jon Hall66e001c2015-11-12 09:45:10 -0800417 subjectClass="devices",
418 subjectKey="of:0000000000000004",
419 configKey="basic" )
420 s4Result = False
421 if setS4Disallow:
422 # Check what we set is what is in ONOS
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700423 getS4 = utilities.retry( f=main.ONOSrest3.getNetCfg,
424 retValue=False,
425 kwargs={"subjectClass": "devices",
426 "subjectKey": "of:0000000000000004",
427 "configKey": "basic"},
428 attempts=main.retrytimes,
429 sleep=main.retrysleep )
430
Jon Hall66e001c2015-11-12 09:45:10 -0800431 onosCfg = pprint( getS4 )
432 sentCfg = pprint( s4Json )
433 if onosCfg == sentCfg:
434 s4Result = True
435 else:
436 main.log.error( "ONOS NetCfg doesn't match what was sent" )
437 main.log.debug( "ONOS config: {}".format( onosCfg ) )
438 main.log.debug( "Sent config: {}".format( sentCfg ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700439 main.step( "Retrying main.ONOSrest3.getNetCfg" )
440 utilities.retry( f=main.ONOSrest3.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800441 utilities.assert_equals( expect=True,
442 actual=s4Result,
443 onpass="Net Cfg added for device s4",
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700444 onfail="Net Cfg for device s4 not correctly set" )
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -0700445
Jon Hall66e001c2015-11-12 09:45:10 -0800446 main.netCfg.compareCfg( main, main.gossipTime )
447
448 def CASE23( self, main ):
449 """
450 Check of devices after all Network Configurations are set
451 """
452 import json
453 try:
454 assert main.s1Json, "s1Json not defined"
455 assert main.s2Json, "s2Json not defined"
456 except AssertionError:
457 main.log.exception( "Case Prerequisites not set: " )
458 main.cleanup()
459 main.exit()
460 main.case( "Check Devices after all configurations are set" )
461
462 main.netCfg.compareCfg( main )
463
464 main.step( "ONOS should only show devices S1 and S2" )
465 devices = main.ONOSrest1.devices()
466 main.log.debug( main.ONOSrest1.pprint( devices ) )
467 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2 ] ]
468 onosDevices = []
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700469 try:
470 for sw in json.loads( devices ):
471 onosDevices.append( str( sw.get( 'id' ) ) )
472 onosDevices.sort()
473 failMsg = "ONOS devices doesn't match the list of allowed devices.\n"
474 failMsg += "Expected devices: {}\nActual devices: {}".format( allowedDevices,
475 onosDevices )
476 except( TypeError, ValueError ):
477 main.log.error( "Problem loading devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800478 utilities.assert_equals( expect=allowedDevices,
479 actual=onosDevices,
480 onpass="Only allowed devices are in ONOS",
481 onfail=failMsg )
482
483 main.step( "Check device annotations" )
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -0700484 stepResult = utilities.retry( f=main.netCfg.checkAllDeviceAnnotations,
485 args=( main, json ),
486 retValue=False,
487 attempts=main.retrytimes,
488 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800489 utilities.assert_equals( expect=True,
490 actual=stepResult,
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -0700491 onpass="Configured devices' annotations are correct",
Jon Hall66e001c2015-11-12 09:45:10 -0800492 onfail="Incorrect annotations for configured devices." )
493
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -0700494
495
Jon Hall66e001c2015-11-12 09:45:10 -0800496 def CASE24( self, main ):
497 """
498 Testing removal of configurations
499 """
Jon Hall541b8e02015-12-14 19:29:01 -0800500 import time
Jon Hall66e001c2015-11-12 09:45:10 -0800501 try:
502 assert main.s1Json, "s1Json not defined"
503 assert main.s2Json, "s2Json not defined"
504 assert main.s3Json, "s3Json not defined"
505 assert main.s4Json, "s4Json not defined"
506 except AssertionError:
507 main.log.exception( "Case Prerequisites not set: " )
508 main.cleanup()
509 main.exit()
510 main.case( "Testing removal of configurations" )
511 main.step( "Remove 'allowed' configuration from all devices" )
512
513 s1Json = main.s1Json # NOTE: This is a reference
514 try:
Jon Hallbc080f92017-05-24 16:29:55 -0700515 del s1Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800516 except KeyError:
517 main.log.exception( "Key not found" )
518 setS1 = main.ONOSrest1.setNetCfg( s1Json,
519 subjectClass="devices",
520 subjectKey="of:0000000000000001",
521 configKey="basic" )
522
523 s2Json = main.s2Json # NOTE: This is a reference
524 try:
Jon Hall541b8e02015-12-14 19:29:01 -0800525 time.sleep( main.gossipTime )
Jon Hallbc080f92017-05-24 16:29:55 -0700526 del s2Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800527 except KeyError:
528 main.log.exception( "Key not found" )
529 setS2 = main.ONOSrest2.setNetCfg( s2Json,
530 subjectClass="devices",
531 subjectKey="of:0000000000000002",
532 configKey="basic" )
533
534 s3Json = main.s3Json # NOTE: This is a reference
535 try:
Jon Hall541b8e02015-12-14 19:29:01 -0800536 time.sleep( main.gossipTime )
Jon Hallbc080f92017-05-24 16:29:55 -0700537 del s3Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800538 except KeyError:
539 main.log.exception( "Key not found" )
540 setS3 = main.ONOSrest3.setNetCfg( s3Json,
541 subjectClass="devices",
542 subjectKey="of:0000000000000003",
543 configKey="basic" )
544
545 s4Json = main.s4Json # NOTE: This is a reference
546 try:
Jon Hall541b8e02015-12-14 19:29:01 -0800547 time.sleep( main.gossipTime )
Jon Hallbc080f92017-05-24 16:29:55 -0700548 del s4Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800549 except KeyError:
550 main.log.exception( "Key not found" )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700551 setS4 = main.ONOSrest3.setNetCfg( s4Json,
Jon Hall66e001c2015-11-12 09:45:10 -0800552 subjectClass="devices",
553 subjectKey="of:0000000000000004",
554 configKey="basic" )
555 removeAllowed = setS1 and setS2 and setS3 and setS4
556 utilities.assert_equals( expect=main.TRUE,
557 actual=removeAllowed,
558 onpass="Successfully removed 'allowed' config from devices",
559 onfail="Failed to remove the 'allowed' config key." )
560
561 main.netCfg.compareCfg( main, main.gossipTime )
562
563 main.step( "Delete basic config for s1 and s2" )
564 removeS1 = main.ONOSrest1.removeNetCfg( subjectClass="devices",
565 subjectKey="of:0000000000000001",
566 configKey="basic" )
567 removeS2 = main.ONOSrest2.removeNetCfg( subjectClass="devices",
568 subjectKey="of:0000000000000002",
569 configKey="basic" )
570 removeSingles = removeS1 and removeS2
571 utilities.assert_equals( expect=main.TRUE,
572 actual=removeSingles,
573 onpass="Successfully removed S1 and S2 basic config",
574 onfail="Failed to removed S1 and S2 basic config" )
575
576 main.netCfg.compareCfg( main, main.gossipTime )
577
578 main.step( "Delete the net config for S3" )
579 removeS3 = main.ONOSrest3.removeNetCfg( subjectClass="devices",
580 subjectKey="of:0000000000000003" )
581 utilities.assert_equals( expect=main.TRUE,
582 actual=removeS3,
583 onpass="Successfully removed S3's config",
584 onfail="Failed to removed S3's config" )
585
586 main.netCfg.compareCfg( main, main.gossipTime )
587
588 main.step( "Delete the net config for all devices" )
589 remove = main.ONOSrest3.removeNetCfg( subjectClass="devices" )
590 utilities.assert_equals( expect=main.TRUE,
591 actual=remove,
592 onpass="Successfully removed device config",
593 onfail="Failed to remove device config" )
594
595 main.netCfg.compareCfg( main, main.gossipTime )
596
597 main.step( "Assert the net config for devices is empty" )
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700598
599 get = utilities.retry( f=main.ONOSrest3.getNetCfg,
600 retValue = False,
601 kwargs={"subjectClass":"devices"},
602 sleep=main.retrysleep,
603 attempts=main.retrytimes )
604
Jon Hall66e001c2015-11-12 09:45:10 -0800605 utilities.assert_equals( expect='{}',
606 actual=get,
607 onpass="Successfully removed device config",
608 onfail="Failed to remove device config" )
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700609
610 def CASE25( self, main ):
611 """
612 Use network-cfg.json to configure devices during ONOS startup
613 """
614 main.case( "Preparing network-cfg.json to load configurations" )
615 main.step( "Moving network-cfg.json to $ONOS_ROOT/tools/package/config/" )
616 prestartResult = main.TRUE
617 srcPath = "~/OnosSystemTest/TestON/tests/FUNC/FUNCnetCfg/dependencies/network-cfg.json"
618 dstPath = "~/onos/tools/package/config/network-cfg.json"
619 prestartResult = main.ONOSbench.scp( main.ONOSbench, srcPath, dstPath, direction="to" )
620 utilities.assert_equals( expect=main.TRUE,
621 actual=prestartResult,
622 onpass="Successfully copied network-cfg.json to target directory",
623 onfail="Failed to copy network-cfg.json to target directory" )
624
625 def CASE26( self, main ):
626 """
627 Check to see that pre-startup configurations were set correctly
628 """
629 import json
630 main.case( "Check to see if the pre-startup configurations were set, then remove their allowed status" )
631 main.step( "Checking configurations for Switches 5 and 6" )
Jon Hallbc080f92017-05-24 16:29:55 -0700632 main.step( "ONOS should only show devices S1, S2, S4, and S5" ) # and S6
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700633 devices = main.ONOSrest1.devices()
634 main.log.debug( main.ONOSrest1.pprint( devices ) )
Jon Hallbc080f92017-05-24 16:29:55 -0700635 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4, 5 ] ] # 6
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700636 main.log.debug( allowedDevices )
637 onosDevices = []
638 try:
639 for sw in json.loads( devices ):
Jon Hallbc080f92017-05-24 16:29:55 -0700640 onosDevices.append( str( sw[ 'id' ] ) )
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700641 onosDevices.sort()
642 main.log.debug( onosDevices )
643 except( TypeError, ValueError ):
644 main.log.error( "Problem loading devices" )
645 utilities.assert_equals( expect=allowedDevices,
646 actual=onosDevices,
647 onpass="Only allowed devices are in ONOS",
648 onfail="ONOS devices doesn't match the list" +
649 " of allowed devices" )
650
651 main.step( "Removing allowed status from Switches 5 and 6" )
Pratik Parab6f418632017-04-25 17:05:50 -0700652 try:
653 with open( os.path.dirname( main.testFile ) + '/dependencies/s5Json', 'r' ) as s5Jsondata:
654 main.s5Json = json.load( s5Jsondata )
655 except IOError:
656 main.log.exception( "s5Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700657 main.cleanup()
658 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700659 main.log.info( "s5Json:" + str( main.s5Json ) )
660
661 try:
662 with open( os.path.dirname( main.testFile ) + '/dependencies/s6Json', 'r' ) as s6Jsondata:
663 main.s6Json = json.load( s6Jsondata )
664 except IOError:
665 main.log.exception( "s6Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700666 main.cleanup()
667 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700668 main.log.info( "s6Json:" + str( main.s6Json ) )
669
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700670 s5Json = main.s5Json
671 setS1 = main.ONOSrest1.setNetCfg( s5Json,
672 subjectClass="devices",
673 subjectKey="of:0000000000000005",
674 configKey="basic" )
675
676 s6Json = main.s6Json
677 setS1 = main.ONOSrest1.setNetCfg( s6Json,
678 subjectClass="devices",
679 subjectKey="of:0000000000000006",
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700680 configKey="basic" )
681
682 def CASE27( self, main ):
683 """
Jon Hallbc080f92017-05-24 16:29:55 -0700684 1 ) A = get /network/configuration
685 2 ) Post A
686 3 ) Compare A with ONOS
687 4 ) Modify A so S6 is disallowed
688 5 ) Check
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700689
690 """
691 import json
Devin Lim58046fa2017-07-05 16:55:00 -0700692 pprint = main.RESTs[ 0 ].pprint
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700693 main.case( "Posting network configurations to the top level web resource" )
694 main.step( "Get json object from Net Cfg" )
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700695 getinfo = utilities.retry( f=main.ONOSrest1.getNetCfg,
696 retValue=False,
697 sleep=main.retrysleep,
698 attempts=main.retrytimes )
699
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700700 main.log.debug( getinfo )
701 main.step( "Posting json object to Net Cfg" )
702 postinfo = main.ONOSrest1.setNetCfg( json.loads( getinfo ) )
703 main.step( "Compare device with ONOS" )
704 main.netCfg.compareCfg( main )
Jon Hallbc080f92017-05-24 16:29:55 -0700705 main.step( "ONOS should only show devices S1, S2, S4, S5 and S6" )
706 devices = main.ONOSrest1.devices()
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700707 main.log.debug( main.ONOSrest1.pprint( devices ) )
708 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4, 5, 6 ] ]
709 onosDevices = []
710 try:
711 for sw in json.loads( devices ):
712 onosDevices.append( str( sw.get( 'id' ) ) )
Jon Hallbc080f92017-05-24 16:29:55 -0700713 onosDevices.sort()
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700714 failMsg = "ONOS devices doesn't match the list of allowed devices. \n"
715 failMsg += "Expected devices: {}\nActual devices: {}".format( allowedDevices, onosDevices )
716 except( TypeError, ValueError ):
717 main.log.error( "Problem loading devices" )
718 utilities.assert_equals( expect=allowedDevices, actual=onosDevices,
719 onpass="Only allowed devices are in ONOS", onfail=failMsg )
720
721 main.step( "Modify json object so S6 is disallowed" )
722 main.s6Json = { "allowed": False }
723 s6Json = main.s6Json
724 setS6Disallow = main.ONOSrest1.setNetCfg( s6Json, subjectClass="devices",
725 subjectKey="of:0000000000000006", configKey="basic" )
726 s6Result = False
727 if setS6Disallow:
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700728 getS6 = utilities.retry( f=main.ONOSrest1.getNetCfg,
729 retValue=False,
730 kwargs={"subjectClass":"devices",
731 "subjectKey" : "of:0000000000000006",
732 "configKey" : "basic"},
733 sleep=main.retrysleep,
734 attempts=main.retrytimes )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700735 onosCfg = pprint( getS6 )
736 sentCfg = pprint( s6Json )
737 if onosCfg == sentCfg:
738 s6Result = True
739 else:
740 main.log.error( "ONOS NetCfg doesn't match what was sent" )
741 main.log.debug( "ONOS config: {}".format( onosCfg ) )
742 main.log.debug( "Sent config: {}".format( sentCfg ) )
743 utilities.retry( f=main.ONOSrest1.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
744 utilities.assert_equals( expect=True, actual=s6Result,
745 onpass="Net Cfg added for devices s6",
746 onfail="Net Cfg for device s6 not correctly set" )