blob: d8fe99811a981ee03f8ed186b7fef9be5e778c2c [file] [log] [blame]
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07001"""
2Copyright 2015 Open Networking Foundation (ONF)
3
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/x/voMg>,
6or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg>
7
8 TestON is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
12
13 TestON is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with TestON. If not, see <http://www.gnu.org/licenses/>.
20"""
Jon Hall66e001c2015-11-12 09:45:10 -080021
22# Testing the basic intent functionality of ONOS
23
Jon Hallbc080f92017-05-24 16:29:55 -070024
Jon Hall66e001c2015-11-12 09:45:10 -080025class FUNCnetCfg:
26
27 def __init__( self ):
28 self.default = ''
29
30 def CASE1( self, main ):
31 import imp
32 import re
Jon Hall66e001c2015-11-12 09:45:10 -080033 """
34 - Construct tests variables
35 - GIT ( optional )
36 - Checkout ONOS master branch
37 - Pull latest ONOS code
Jon Hall66e001c2015-11-12 09:45:10 -080038 """
Devin Lim58046fa2017-07-05 16:55:00 -070039
40 try:
41 from tests.dependencies.ONOSSetup import ONOSSetup
42 main.testSetUp = ONOSSetup()
43 except ImportError:
44 main.log.error( "ONOSSetup not found. exiting the test" )
45 main.exit()
46 main.testSetUp.envSetupDescription()
Jon Hall66e001c2015-11-12 09:45:10 -080047 stepResult = main.FALSE
48
49 # Test variables
50 try:
Jon Hall66e001c2015-11-12 09:45:10 -080051 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
Jon Hall66e001c2015-11-12 09:45:10 -080052 main.dependencyPath = main.testOnDirectory + \
53 main.params[ 'DEPENDENCY' ][ 'path' ]
Jon Hall66e001c2015-11-12 09:45:10 -080054 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
55 wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ]
56 wrapperFile3 = main.params[ 'DEPENDENCY' ][ 'wrapper3' ]
57 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
Jon Hallbc080f92017-05-24 16:29:55 -070058 main.gossipTime = int( main.params[ 'SLEEP' ][ 'cfgGossip' ] )
alison15124df2016-10-06 12:04:51 -070059 main.SetNetCfgSleep = int( main.params[ 'SLEEP' ][ 'SetNetCfgSleep' ] )
Jon Hall66e001c2015-11-12 09:45:10 -080060 main.hostsData = {}
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -070061 main.retrytimes = int( main.params[ 'RETRY' ] )
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -070062 main.retrysleep = int( main.params[ 'RetrySleep' ] )
Jon Hall66e001c2015-11-12 09:45:10 -080063
64 # -- INIT SECTION, SHOULD ONLY BE RUN ONCE -- #
Jon Hall66e001c2015-11-12 09:45:10 -080065 main.netCfg = imp.load_source( wrapperFile2,
66 main.dependencyPath +
67 wrapperFile2 +
68 ".py" )
69
Devin Lim58046fa2017-07-05 16:55:00 -070070 stepResult = main.testSetUp.envSetup( hasRest=True, hasCli=False )
Jon Hall66e001c2015-11-12 09:45:10 -080071 except Exception as e:
Devin Lim58046fa2017-07-05 16:55:00 -070072 main.testSetUp.envSetupException( e )
73 main.testSetUp.evnSetupConclusion( stepResult )
Jon Hall66e001c2015-11-12 09:45:10 -080074
75 def CASE2( self, main ):
76 """
77 - Set up cell
78 - Create cell file
79 - Set cell file
80 - Verify cell file
81 - Kill ONOS process
82 - Uninstall ONOS cluster
Jon Hall66e001c2015-11-12 09:45:10 -080083 - Install ONOS cluster
Jon Hall72ecaa02017-06-06 09:41:48 -070084 - Verify ONOS start up
Jon Hall66e001c2015-11-12 09:45:10 -080085 - Connect to cli
86 """
87 import time
Devin Lim58046fa2017-07-05 16:55:00 -070088 main.testSetUp.ONOSSetUp( main.Mininet1, hasCli=False )
Jon Hall66e001c2015-11-12 09:45:10 -080089
90 def CASE8( self, main ):
91 """
92 Compare Topo
93 """
Devin Lim58046fa2017-07-05 16:55:00 -070094 try:
95 from tests.dependencies.topology import Topology
96 except ImportError:
97 main.log.error( "Topology not found exiting the test" )
98 main.exit()
99 try:
100 main.topoRelated
101 except ( NameError, AttributeError ):
102 main.topoRelated = Topology()
103 main.topoRelated.compareTopos( main.Mininet1 )
Jon Hall66e001c2015-11-12 09:45:10 -0800104
105 def CASE9( self, main ):
Jon Hallbc080f92017-05-24 16:29:55 -0700106 """
Jon Hall66e001c2015-11-12 09:45:10 -0800107 Report errors/warnings/exceptions
Jon Hallbc080f92017-05-24 16:29:55 -0700108 """
Jon Hall66e001c2015-11-12 09:45:10 -0800109 main.log.info( "Error report: \n" )
110 main.ONOSbench.logReport(
Jon Hallbc080f92017-05-24 16:29:55 -0700111 globalONOSip[ 0 ],
112 [ "INFO", "WARN", "ERROR", "Except" ],
Jon Hall66e001c2015-11-12 09:45:10 -0800113 "s" )
Jon Hallbc080f92017-05-24 16:29:55 -0700114 # main.ONOSbench.logReport( globalONOSip[ 1 ], [ "INFO" ], "d" )
Jon Hall66e001c2015-11-12 09:45:10 -0800115
116 def CASE10( self, main ):
117 """
118 Start Mininet topology with OF 1.0 switches
119 """
120 main.OFProtocol = "1.0"
121 main.log.report( "Start Mininet topology with OF 1.0 switches" )
122 main.case( "Start Mininet topology with OF 1.0 switches" )
123 main.caseExplanation = "Start mininet topology with OF 1.0 " +\
124 "switches to test intents, exits out if " +\
125 "topology did not start correctly"
126
127 main.step( "Starting Mininet topology with OF 1.0 switches" )
Jon Hall53c5e662016-04-13 16:06:56 -0700128 args = "--controller none --switch ovs,protocols=OpenFlow10"
Jon Hallbc080f92017-05-24 16:29:55 -0700129 switches = int( main.params[ 'MININET' ][ 'switch' ] )
Jon Hall66e001c2015-11-12 09:45:10 -0800130 cmd = "mn --topo linear,{} {}".format( switches, args )
Jon Hallbc080f92017-05-24 16:29:55 -0700131 topoResult = main.Mininet1.startNet( mnCmd=cmd )
Jon Hall66e001c2015-11-12 09:45:10 -0800132 stepResult = topoResult
133 utilities.assert_equals( expect=main.TRUE,
134 actual=stepResult,
135 onpass="Successfully loaded topology",
136 onfail="Failed to load topology" )
137 # Exit if topology did not load properly
138 if not topoResult:
139 main.cleanup()
140 main.exit()
141
142 def CASE11( self, main ):
143 """
144 Start Mininet topology with OF 1.3 switches
145 """
146 import re
147 main.OFProtocol = "1.3"
148 main.log.report( "Start Mininet topology with OF 1.3 switches" )
149 main.case( "Start Mininet topology with OF 1.3 switches" )
150 main.caseExplanation = "Start mininet topology with OF 1.3 " +\
151 "switches to test intents, exits out if " +\
152 "topology did not start correctly"
153
154 main.step( "Starting Mininet topology with OF 1.3 switches" )
Jon Hall53c5e662016-04-13 16:06:56 -0700155 args = "--controller none --switch ovs,protocols=OpenFlow13"
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700156 switches = int( main.params[ 'MININET' ][ 'switch' ] )
Jon Hall66e001c2015-11-12 09:45:10 -0800157 cmd = "mn --topo linear,{} {}".format( switches, args )
Jon Hallbc080f92017-05-24 16:29:55 -0700158 topoResult = main.Mininet1.startNet( mnCmd=cmd )
Jon Hall66e001c2015-11-12 09:45:10 -0800159 stepResult = topoResult
160 utilities.assert_equals( expect=main.TRUE,
161 actual=stepResult,
162 onpass="Successfully loaded topology",
163 onfail="Failed to load topology" )
164 # Exit if topology did not load properly
165 if not topoResult:
166 main.cleanup()
167 main.exit()
168
169 tempONOSip = []
170 for i in range( main.numCtrls ):
171 tempONOSip.append( main.ONOSip[ i ] )
172
173 swList = [ "s" + str( i ) for i in range( 1, switches + 1 ) ]
174 assignResult = main.Mininet1.assignSwController( sw=swList,
175 ip=tempONOSip,
176 port='6653' )
177 if not assignResult:
178 main.cleanup()
179 main.exit()
180
181 assignResult = main.TRUE
182 for sw in swList:
183 response = main.Mininet1.getSwController( "s" + str( i ) )
184 main.log.info( "Response is " + str( response ) )
185 for ip in tempONOSip:
186 if re.search( "tcp:" + ip, response ):
187 assignResult = assignResult and main.TRUE
188 else:
189 assignResult = assignResult and main.FALSE
190 stepResult = assignResult
191 utilities.assert_equals( expect=main.TRUE,
192 actual=stepResult,
193 onpass="Successfully assigned switches" +
194 "to controller",
195 onfail="Failed to assign switches to " +
196 "controller" )
197
198 def CASE14( self, main ):
199 """
200 Stop mininet
201 """
Devin Lim58046fa2017-07-05 16:55:00 -0700202 try:
203 from tests.dependencies.utils import Utils
204 except ImportError:
205 main.log.error( "Utils not found exiting the test" )
206 main.exit()
207 try:
208 main.Utils
209 except ( NameError, AttributeError ):
210 main.Utils = Utils()
211 main.Utils.mininetCleanIntro()
212 topoResult = main.Utils.mininetCleanup( main.Mininet1 )
Jon Hall66e001c2015-11-12 09:45:10 -0800213 # Exit if topology did not load properly
214 if not topoResult:
215 main.cleanup()
216 main.exit()
217
218 def CASE20( self, main ):
219 """
220 Add some device configurations and then check they are distributed
221 to all nodes
222 """
alison15124df2016-10-06 12:04:51 -0700223 import time
Pratik Parabc6083c22017-04-27 13:24:41 -0700224 import json
225 import os
Jon Hall66e001c2015-11-12 09:45:10 -0800226 main.case( "Add Network configurations to the cluster" )
227 main.caseExplanation = "Add Network Configurations for devices" +\
228 " not discovered yet. One device is allowed" +\
229 ", the other disallowed."
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -0700230
231
Devin Lim58046fa2017-07-05 16:55:00 -0700232 pprint = main.RESTs[ 0 ].pprint
Jon Hall66e001c2015-11-12 09:45:10 -0800233
234 main.step( "Add Net Cfg for switch1" )
Pratik Parab6f418632017-04-25 17:05:50 -0700235
Pratik Parab6f418632017-04-25 17:05:50 -0700236 try:
237 with open( os.path.dirname( main.testFile ) + '/dependencies/s1Json', 'r' ) as s1Jsondata:
238 s1Json = json.load( s1Jsondata )
239 except IOError:
240 main.log.exception( "s1Json File not found." )
Pratik Parabc6083c22017-04-27 13:24:41 -0700241 main.cleanup()
242 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700243 main.log.info( "s1Json:" + str( s1Json ) )
244
Jon Hall66e001c2015-11-12 09:45:10 -0800245 main.s1Json = s1Json
246 setS1Allow = main.ONOSrest1.setNetCfg( s1Json,
247 subjectClass="devices",
248 subjectKey="of:0000000000000001",
249 configKey="basic" )
250 s1Result = False
alison15124df2016-10-06 12:04:51 -0700251 #Wait 5 secs after set up netCfg
252 time.sleep( main.SetNetCfgSleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800253 if setS1Allow:
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700254 getS1 = utilities.retry( f=main.ONOSrest1.getNetCfg,
255 retValue=False,
256 kwargs={"subjectClass":"devices",
257 "subjectKey" : "of:0000000000000001",
258 "configKey" : "basic"},
259 attempts=main.retrytimes,
260 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800261 onosCfg = pprint( getS1 )
262 sentCfg = pprint( s1Json )
263 if onosCfg == sentCfg:
alison15124df2016-10-06 12:04:51 -0700264 main.log.info( "ONOS NetCfg match what was sent" )
Jon Hall66e001c2015-11-12 09:45:10 -0800265 s1Result = True
266 else:
267 main.log.error( "ONOS NetCfg doesn't match what was sent" )
268 main.log.debug( "ONOS config: {}".format( onosCfg ) )
269 main.log.debug( "Sent config: {}".format( sentCfg ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700270 utilities.retry( f=main.ONOSrest1.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800271 utilities.assert_equals( expect=True,
272 actual=s1Result,
273 onpass="Net Cfg added for device s1",
274 onfail="Net Cfg for device s1 not correctly set" )
275
276 main.step( "Add Net Cfg for switch3" )
Pratik Parab6f418632017-04-25 17:05:50 -0700277
278 try:
279 with open( os.path.dirname( main.testFile ) + '/dependencies/s3Json', 'r' ) as s3Jsondata:
280 s3Json = json.load( s3Jsondata )
281 except IOError:
282 main.log.exception( "s3Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700283 main.cleanup()
284 main.exit()
Jon Hallbc080f92017-05-24 16:29:55 -0700285 main.log.info( "s3Json:" + str( s3Json ) )
Pratik Parab6f418632017-04-25 17:05:50 -0700286
Jon Hall66e001c2015-11-12 09:45:10 -0800287 main.s3Json = s3Json
288 setS3Disallow = main.ONOSrest1.setNetCfg( s3Json,
289 subjectClass="devices",
290 subjectKey="of:0000000000000003",
291 configKey="basic" )
292 s3Result = False
alison15124df2016-10-06 12:04:51 -0700293 time.sleep( main.SetNetCfgSleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800294 if setS3Disallow:
295 # Check what we set is what is in ONOS
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700296 getS3 = utilities.retry( f=main.ONOSrest1.getNetCfg,
297 retValue=False,
298 kwargs={"subjectClass": "devices",
299 "subjectKey": "of:0000000000000003",
300 "configKey": "basic"},
301 attempts=main.retrytimes,
302 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800303 onosCfg = pprint( getS3 )
304 sentCfg = pprint( s3Json )
305 if onosCfg == sentCfg:
Jon Hallbc080f92017-05-24 16:29:55 -0700306 main.log.info( "ONOS NetCfg match what was sent" )
Jon Hall66e001c2015-11-12 09:45:10 -0800307 s3Result = True
308 else:
309 main.log.error( "ONOS NetCfg doesn't match what was sent" )
310 main.log.debug( "ONOS config: {}".format( onosCfg ) )
311 main.log.debug( "Sent config: {}".format( sentCfg ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700312 utilities.retry( f=main.ONOSrest1.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800313 utilities.assert_equals( expect=True,
314 actual=s3Result,
315 onpass="Net Cfg added for device s3",
316 onfail="Net Cfg for device s3 not correctly set" )
317 main.netCfg.compareCfg( main, main.gossipTime )
318
319 def CASE21( self, main ):
320 """
321 Initial check of devices
322 """
323 import json
324 try:
325 assert main.s1Json, "s1Json not defined"
326 except AssertionError:
327 main.log.exception( "Case Prerequisites not set: " )
328 main.cleanup()
329 main.exit()
330 main.case( "Check Devices After they initially connect to ONOS" )
331
332 main.netCfg.compareCfg( main )
333
334 main.step( "ONOS should only show devices S1, S2, and S4" )
335 devices = main.ONOSrest1.devices()
336 main.log.debug( main.ONOSrest1.pprint( devices ) )
337 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4 ] ]
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700338 main.log.debug( allowedDevices )
Jon Hall66e001c2015-11-12 09:45:10 -0800339 onosDevices = []
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700340 try:
341 for sw in json.loads( devices ):
Jon Hallbc080f92017-05-24 16:29:55 -0700342 onosDevices.append( str( sw[ 'id' ] ) )
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700343 onosDevices.sort()
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700344 main.log.debug( onosDevices )
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700345 except( TypeError, ValueError ):
346 main.log.error( "Problem loading devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800347 utilities.assert_equals( expect=allowedDevices,
348 actual=onosDevices,
349 onpass="Only allowed devices are in ONOS",
350 onfail="ONOS devices doesn't match the list" +
351 " of allowed devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800352 main.step( "Check device annotations" )
353 keys = [ 'name', 'owner', 'rackAddress' ]
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700354 try:
355 for sw in json.loads( devices ):
Jon Hallbc080f92017-05-24 16:29:55 -0700356 if "of:0000000000000001" in sw[ 'id' ]:
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700357 s1Correct = True
358 for k in keys:
Jon Hallbc080f92017-05-24 16:29:55 -0700359 if str( sw.get( 'annotations', {} ).get( k ) ) != str( main.s1Json[ k ] ):
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700360 s1Correct = False
361 main.log.debug( "{} is wrong on s1".format( k ) )
362 if not s1Correct:
363 main.log.error( "Annotations for s1 are incorrect: {}".format( sw ) )
364 except( TypeError, ValueError ):
365 main.log.error( "Problem loading devices" )
366 s1Correct = False
Jon Hall66e001c2015-11-12 09:45:10 -0800367 try:
368 stepResult = s1Correct
369 except NameError:
370 stepResult = False
371 main.log.error( "s1 not found in devices" )
372 utilities.assert_equals( expect=True,
373 actual=stepResult,
374 onpass="Configured device's annotations are correct",
375 onfail="Incorrect annotations for configured devices." )
376
377 def CASE22( self, main ):
378 """
379 Add some device configurations for connected devices and then check
380 they are distributed to all nodes
381 """
382 main.case( "Add Network configurations for connected devices to the cluster" )
383 main.caseExplanation = "Add Network Configurations for discovered " +\
384 "devices. One device is allowed" +\
385 ", the other disallowed."
Devin Lim58046fa2017-07-05 16:55:00 -0700386 pprint = main.RESTs[ 0 ].pprint
Jon Hall66e001c2015-11-12 09:45:10 -0800387
388 main.step( "Add Net Cfg for switch2" )
Pratik Parab6f418632017-04-25 17:05:50 -0700389 try:
390 with open( os.path.dirname( main.testFile ) + '/dependencies/s2Json', 'r' ) as s2Jsondata:
391 s2Json = json.load( s2Jsondata )
392 except IOError:
393 main.log.exception( "s2Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700394 main.cleanup()
395 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700396 main.log.info( "s2Json:" + str( s2Json ) )
Jon Hall66e001c2015-11-12 09:45:10 -0800397 main.s2Json = s2Json
398 setS2Allow = main.ONOSrest2.setNetCfg( s2Json,
399 subjectClass="devices",
400 subjectKey="of:0000000000000002",
401 configKey="basic" )
402 s2Result = False
403 if setS2Allow:
404 # Check what we set is what is in ONOS
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700405 getS2 = utilities.retry( f=main.ONOSrest2.getNetCfg,
406 retValue=False,
407 kwargs={"subjectClass": "devices",
408 "subjectKey": "of:0000000000000002",
409 "configKey": "basic"},
410 attempts=main.retrytimes,
411 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800412 onosCfg = pprint( getS2 )
413 sentCfg = pprint( s2Json )
414 if onosCfg == sentCfg:
415 s2Result = True
416 else:
417 main.log.error( "ONOS NetCfg doesn't match what was sent" )
418 main.log.debug( "ONOS config: {}".format( onosCfg ) )
419 main.log.debug( "Sent config: {}".format( sentCfg ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700420 utilities.retry( f=main.ONOSrest2.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800421 utilities.assert_equals( expect=True,
422 actual=s2Result,
423 onpass="Net Cfg added for device s2",
424 onfail="Net Cfg for device s2 not correctly set" )
Jon Hall66e001c2015-11-12 09:45:10 -0800425 main.step( "Add Net Cfg for switch4" )
Pratik Parab6f418632017-04-25 17:05:50 -0700426
427 try:
428 with open( os.path.dirname( main.testFile ) + '/dependencies/s4Json', 'r' ) as s4Jsondata:
429 s4Json = json.load( s4Jsondata )
430 except IOError:
431 main.log.exception( "s4Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700432 main.cleanup()
433 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700434 main.log.info( "s4Json:" + str( s4Json ) )
Jon Hall66e001c2015-11-12 09:45:10 -0800435 main.s4Json = s4Json
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700436 setS4Disallow = main.ONOSrest3.setNetCfg( s4Json,
Jon Hall66e001c2015-11-12 09:45:10 -0800437 subjectClass="devices",
438 subjectKey="of:0000000000000004",
439 configKey="basic" )
440 s4Result = False
441 if setS4Disallow:
442 # Check what we set is what is in ONOS
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700443 getS4 = utilities.retry( f=main.ONOSrest3.getNetCfg,
444 retValue=False,
445 kwargs={"subjectClass": "devices",
446 "subjectKey": "of:0000000000000004",
447 "configKey": "basic"},
448 attempts=main.retrytimes,
449 sleep=main.retrysleep )
450
Jon Hall66e001c2015-11-12 09:45:10 -0800451 onosCfg = pprint( getS4 )
452 sentCfg = pprint( s4Json )
453 if onosCfg == sentCfg:
454 s4Result = True
455 else:
456 main.log.error( "ONOS NetCfg doesn't match what was sent" )
457 main.log.debug( "ONOS config: {}".format( onosCfg ) )
458 main.log.debug( "Sent config: {}".format( sentCfg ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700459 main.step( "Retrying main.ONOSrest3.getNetCfg" )
460 utilities.retry( f=main.ONOSrest3.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800461 utilities.assert_equals( expect=True,
462 actual=s4Result,
463 onpass="Net Cfg added for device s4",
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700464 onfail="Net Cfg for device s4 not correctly set" )
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -0700465
Jon Hall66e001c2015-11-12 09:45:10 -0800466 main.netCfg.compareCfg( main, main.gossipTime )
467
468 def CASE23( self, main ):
469 """
470 Check of devices after all Network Configurations are set
471 """
472 import json
473 try:
474 assert main.s1Json, "s1Json not defined"
475 assert main.s2Json, "s2Json not defined"
476 except AssertionError:
477 main.log.exception( "Case Prerequisites not set: " )
478 main.cleanup()
479 main.exit()
480 main.case( "Check Devices after all configurations are set" )
481
482 main.netCfg.compareCfg( main )
483
484 main.step( "ONOS should only show devices S1 and S2" )
485 devices = main.ONOSrest1.devices()
486 main.log.debug( main.ONOSrest1.pprint( devices ) )
487 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2 ] ]
488 onosDevices = []
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700489 try:
490 for sw in json.loads( devices ):
491 onosDevices.append( str( sw.get( 'id' ) ) )
492 onosDevices.sort()
493 failMsg = "ONOS devices doesn't match the list of allowed devices.\n"
494 failMsg += "Expected devices: {}\nActual devices: {}".format( allowedDevices,
495 onosDevices )
496 except( TypeError, ValueError ):
497 main.log.error( "Problem loading devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800498 utilities.assert_equals( expect=allowedDevices,
499 actual=onosDevices,
500 onpass="Only allowed devices are in ONOS",
501 onfail=failMsg )
502
503 main.step( "Check device annotations" )
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -0700504 stepResult = utilities.retry( f=main.netCfg.checkAllDeviceAnnotations,
505 args=( main, json ),
506 retValue=False,
507 attempts=main.retrytimes,
508 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800509 utilities.assert_equals( expect=True,
510 actual=stepResult,
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -0700511 onpass="Configured devices' annotations are correct",
Jon Hall66e001c2015-11-12 09:45:10 -0800512 onfail="Incorrect annotations for configured devices." )
513
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -0700514
515
Jon Hall66e001c2015-11-12 09:45:10 -0800516 def CASE24( self, main ):
517 """
518 Testing removal of configurations
519 """
Jon Hall541b8e02015-12-14 19:29:01 -0800520 import time
Jon Hall66e001c2015-11-12 09:45:10 -0800521 try:
522 assert main.s1Json, "s1Json not defined"
523 assert main.s2Json, "s2Json not defined"
524 assert main.s3Json, "s3Json not defined"
525 assert main.s4Json, "s4Json not defined"
526 except AssertionError:
527 main.log.exception( "Case Prerequisites not set: " )
528 main.cleanup()
529 main.exit()
530 main.case( "Testing removal of configurations" )
531 main.step( "Remove 'allowed' configuration from all devices" )
532
533 s1Json = main.s1Json # NOTE: This is a reference
534 try:
Jon Hallbc080f92017-05-24 16:29:55 -0700535 del s1Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800536 except KeyError:
537 main.log.exception( "Key not found" )
538 setS1 = main.ONOSrest1.setNetCfg( s1Json,
539 subjectClass="devices",
540 subjectKey="of:0000000000000001",
541 configKey="basic" )
542
543 s2Json = main.s2Json # NOTE: This is a reference
544 try:
Jon Hall541b8e02015-12-14 19:29:01 -0800545 time.sleep( main.gossipTime )
Jon Hallbc080f92017-05-24 16:29:55 -0700546 del s2Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800547 except KeyError:
548 main.log.exception( "Key not found" )
549 setS2 = main.ONOSrest2.setNetCfg( s2Json,
550 subjectClass="devices",
551 subjectKey="of:0000000000000002",
552 configKey="basic" )
553
554 s3Json = main.s3Json # NOTE: This is a reference
555 try:
Jon Hall541b8e02015-12-14 19:29:01 -0800556 time.sleep( main.gossipTime )
Jon Hallbc080f92017-05-24 16:29:55 -0700557 del s3Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800558 except KeyError:
559 main.log.exception( "Key not found" )
560 setS3 = main.ONOSrest3.setNetCfg( s3Json,
561 subjectClass="devices",
562 subjectKey="of:0000000000000003",
563 configKey="basic" )
564
565 s4Json = main.s4Json # NOTE: This is a reference
566 try:
Jon Hall541b8e02015-12-14 19:29:01 -0800567 time.sleep( main.gossipTime )
Jon Hallbc080f92017-05-24 16:29:55 -0700568 del s4Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800569 except KeyError:
570 main.log.exception( "Key not found" )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700571 setS4 = main.ONOSrest3.setNetCfg( s4Json,
Jon Hall66e001c2015-11-12 09:45:10 -0800572 subjectClass="devices",
573 subjectKey="of:0000000000000004",
574 configKey="basic" )
575 removeAllowed = setS1 and setS2 and setS3 and setS4
576 utilities.assert_equals( expect=main.TRUE,
577 actual=removeAllowed,
578 onpass="Successfully removed 'allowed' config from devices",
579 onfail="Failed to remove the 'allowed' config key." )
580
581 main.netCfg.compareCfg( main, main.gossipTime )
582
583 main.step( "Delete basic config for s1 and s2" )
584 removeS1 = main.ONOSrest1.removeNetCfg( subjectClass="devices",
585 subjectKey="of:0000000000000001",
586 configKey="basic" )
587 removeS2 = main.ONOSrest2.removeNetCfg( subjectClass="devices",
588 subjectKey="of:0000000000000002",
589 configKey="basic" )
590 removeSingles = removeS1 and removeS2
591 utilities.assert_equals( expect=main.TRUE,
592 actual=removeSingles,
593 onpass="Successfully removed S1 and S2 basic config",
594 onfail="Failed to removed S1 and S2 basic config" )
595
596 main.netCfg.compareCfg( main, main.gossipTime )
597
598 main.step( "Delete the net config for S3" )
599 removeS3 = main.ONOSrest3.removeNetCfg( subjectClass="devices",
600 subjectKey="of:0000000000000003" )
601 utilities.assert_equals( expect=main.TRUE,
602 actual=removeS3,
603 onpass="Successfully removed S3's config",
604 onfail="Failed to removed S3's config" )
605
606 main.netCfg.compareCfg( main, main.gossipTime )
607
608 main.step( "Delete the net config for all devices" )
609 remove = main.ONOSrest3.removeNetCfg( subjectClass="devices" )
610 utilities.assert_equals( expect=main.TRUE,
611 actual=remove,
612 onpass="Successfully removed device config",
613 onfail="Failed to remove device config" )
614
615 main.netCfg.compareCfg( main, main.gossipTime )
616
617 main.step( "Assert the net config for devices is empty" )
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700618
619 get = utilities.retry( f=main.ONOSrest3.getNetCfg,
620 retValue = False,
621 kwargs={"subjectClass":"devices"},
622 sleep=main.retrysleep,
623 attempts=main.retrytimes )
624
Jon Hall66e001c2015-11-12 09:45:10 -0800625 utilities.assert_equals( expect='{}',
626 actual=get,
627 onpass="Successfully removed device config",
628 onfail="Failed to remove device config" )
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700629
630 def CASE25( self, main ):
631 """
632 Use network-cfg.json to configure devices during ONOS startup
633 """
634 main.case( "Preparing network-cfg.json to load configurations" )
635 main.step( "Moving network-cfg.json to $ONOS_ROOT/tools/package/config/" )
636 prestartResult = main.TRUE
637 srcPath = "~/OnosSystemTest/TestON/tests/FUNC/FUNCnetCfg/dependencies/network-cfg.json"
638 dstPath = "~/onos/tools/package/config/network-cfg.json"
639 prestartResult = main.ONOSbench.scp( main.ONOSbench, srcPath, dstPath, direction="to" )
640 utilities.assert_equals( expect=main.TRUE,
641 actual=prestartResult,
642 onpass="Successfully copied network-cfg.json to target directory",
643 onfail="Failed to copy network-cfg.json to target directory" )
644
645 def CASE26( self, main ):
646 """
647 Check to see that pre-startup configurations were set correctly
648 """
649 import json
650 main.case( "Check to see if the pre-startup configurations were set, then remove their allowed status" )
651 main.step( "Checking configurations for Switches 5 and 6" )
Jon Hallbc080f92017-05-24 16:29:55 -0700652 main.step( "ONOS should only show devices S1, S2, S4, and S5" ) # and S6
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700653 devices = main.ONOSrest1.devices()
654 main.log.debug( main.ONOSrest1.pprint( devices ) )
Jon Hallbc080f92017-05-24 16:29:55 -0700655 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4, 5 ] ] # 6
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700656 main.log.debug( allowedDevices )
657 onosDevices = []
658 try:
659 for sw in json.loads( devices ):
Jon Hallbc080f92017-05-24 16:29:55 -0700660 onosDevices.append( str( sw[ 'id' ] ) )
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700661 onosDevices.sort()
662 main.log.debug( onosDevices )
663 except( TypeError, ValueError ):
664 main.log.error( "Problem loading devices" )
665 utilities.assert_equals( expect=allowedDevices,
666 actual=onosDevices,
667 onpass="Only allowed devices are in ONOS",
668 onfail="ONOS devices doesn't match the list" +
669 " of allowed devices" )
670
671 main.step( "Removing allowed status from Switches 5 and 6" )
Pratik Parab6f418632017-04-25 17:05:50 -0700672 try:
673 with open( os.path.dirname( main.testFile ) + '/dependencies/s5Json', 'r' ) as s5Jsondata:
674 main.s5Json = json.load( s5Jsondata )
675 except IOError:
676 main.log.exception( "s5Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700677 main.cleanup()
678 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700679 main.log.info( "s5Json:" + str( main.s5Json ) )
680
681 try:
682 with open( os.path.dirname( main.testFile ) + '/dependencies/s6Json', 'r' ) as s6Jsondata:
683 main.s6Json = json.load( s6Jsondata )
684 except IOError:
685 main.log.exception( "s6Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700686 main.cleanup()
687 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700688 main.log.info( "s6Json:" + str( main.s6Json ) )
689
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700690 s5Json = main.s5Json
691 setS1 = main.ONOSrest1.setNetCfg( s5Json,
692 subjectClass="devices",
693 subjectKey="of:0000000000000005",
694 configKey="basic" )
695
696 s6Json = main.s6Json
697 setS1 = main.ONOSrest1.setNetCfg( s6Json,
698 subjectClass="devices",
699 subjectKey="of:0000000000000006",
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700700 configKey="basic" )
701
702 def CASE27( self, main ):
703 """
Jon Hallbc080f92017-05-24 16:29:55 -0700704 1 ) A = get /network/configuration
705 2 ) Post A
706 3 ) Compare A with ONOS
707 4 ) Modify A so S6 is disallowed
708 5 ) Check
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700709
710 """
711 import json
Devin Lim58046fa2017-07-05 16:55:00 -0700712 pprint = main.RESTs[ 0 ].pprint
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700713 main.case( "Posting network configurations to the top level web resource" )
714 main.step( "Get json object from Net Cfg" )
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700715 getinfo = utilities.retry( f=main.ONOSrest1.getNetCfg,
716 retValue=False,
717 sleep=main.retrysleep,
718 attempts=main.retrytimes )
719
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700720 main.log.debug( getinfo )
721 main.step( "Posting json object to Net Cfg" )
722 postinfo = main.ONOSrest1.setNetCfg( json.loads( getinfo ) )
723 main.step( "Compare device with ONOS" )
724 main.netCfg.compareCfg( main )
Jon Hallbc080f92017-05-24 16:29:55 -0700725 main.step( "ONOS should only show devices S1, S2, S4, S5 and S6" )
726 devices = main.ONOSrest1.devices()
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700727 main.log.debug( main.ONOSrest1.pprint( devices ) )
728 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4, 5, 6 ] ]
729 onosDevices = []
730 try:
731 for sw in json.loads( devices ):
732 onosDevices.append( str( sw.get( 'id' ) ) )
Jon Hallbc080f92017-05-24 16:29:55 -0700733 onosDevices.sort()
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700734 failMsg = "ONOS devices doesn't match the list of allowed devices. \n"
735 failMsg += "Expected devices: {}\nActual devices: {}".format( allowedDevices, onosDevices )
736 except( TypeError, ValueError ):
737 main.log.error( "Problem loading devices" )
738 utilities.assert_equals( expect=allowedDevices, actual=onosDevices,
739 onpass="Only allowed devices are in ONOS", onfail=failMsg )
740
741 main.step( "Modify json object so S6 is disallowed" )
742 main.s6Json = { "allowed": False }
743 s6Json = main.s6Json
744 setS6Disallow = main.ONOSrest1.setNetCfg( s6Json, subjectClass="devices",
745 subjectKey="of:0000000000000006", configKey="basic" )
746 s6Result = False
747 if setS6Disallow:
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700748 getS6 = utilities.retry( f=main.ONOSrest1.getNetCfg,
749 retValue=False,
750 kwargs={"subjectClass":"devices",
751 "subjectKey" : "of:0000000000000006",
752 "configKey" : "basic"},
753 sleep=main.retrysleep,
754 attempts=main.retrytimes )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700755 onosCfg = pprint( getS6 )
756 sentCfg = pprint( s6Json )
757 if onosCfg == sentCfg:
758 s6Result = True
759 else:
760 main.log.error( "ONOS NetCfg doesn't match what was sent" )
761 main.log.debug( "ONOS config: {}".format( onosCfg ) )
762 main.log.debug( "Sent config: {}".format( sentCfg ) )
763 utilities.retry( f=main.ONOSrest1.getNetCfg, retValue=False, attempts=main.retrytimes, sleep=main.retrysleep )
764 utilities.assert_equals( expect=True, actual=s6Result,
765 onpass="Net Cfg added for devices s6",
766 onfail="Net Cfg for device s6 not correctly set" )