blob: 2b444949bd2140fef1dfe1267d2e2d1bec17a1c7 [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 Lim142b5342017-07-20 15:22:39 -070070 stepResult = main.testSetUp.envSetup()
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 Lim142b5342017-07-20 15:22:39 -070088 main.testSetUp.ONOSSetUp( main.Mininet1, main.Cluster )
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(
Devin Lim142b5342017-07-20 15:22:39 -0700111 main.Cluster.active( 0 ).ipAddress,
Jon Hallbc080f92017-05-24 16:29:55 -0700112 [ "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
Devin Lim142b5342017-07-20 15:22:39 -0700169 tempONOSip = main.Cluster.getIps()
Jon Hall66e001c2015-11-12 09:45:10 -0800170
171 swList = [ "s" + str( i ) for i in range( 1, switches + 1 ) ]
172 assignResult = main.Mininet1.assignSwController( sw=swList,
173 ip=tempONOSip,
174 port='6653' )
175 if not assignResult:
176 main.cleanup()
177 main.exit()
178
179 assignResult = main.TRUE
180 for sw in swList:
181 response = main.Mininet1.getSwController( "s" + str( i ) )
182 main.log.info( "Response is " + str( response ) )
183 for ip in tempONOSip:
184 if re.search( "tcp:" + ip, response ):
185 assignResult = assignResult and main.TRUE
186 else:
187 assignResult = assignResult and main.FALSE
188 stepResult = assignResult
189 utilities.assert_equals( expect=main.TRUE,
190 actual=stepResult,
191 onpass="Successfully assigned switches" +
192 "to controller",
193 onfail="Failed to assign switches to " +
194 "controller" )
195
196 def CASE14( self, main ):
197 """
198 Stop mininet
199 """
Devin Lim58046fa2017-07-05 16:55:00 -0700200 try:
201 from tests.dependencies.utils import Utils
202 except ImportError:
203 main.log.error( "Utils not found exiting the test" )
204 main.exit()
205 try:
206 main.Utils
207 except ( NameError, AttributeError ):
208 main.Utils = Utils()
209 main.Utils.mininetCleanIntro()
210 topoResult = main.Utils.mininetCleanup( main.Mininet1 )
Jon Hall66e001c2015-11-12 09:45:10 -0800211 # Exit if topology did not load properly
212 if not topoResult:
213 main.cleanup()
214 main.exit()
215
216 def CASE20( self, main ):
217 """
218 Add some device configurations and then check they are distributed
219 to all nodes
220 """
alison15124df2016-10-06 12:04:51 -0700221 import time
Pratik Parabc6083c22017-04-27 13:24:41 -0700222 import json
223 import os
Jon Hall66e001c2015-11-12 09:45:10 -0800224 main.case( "Add Network configurations to the cluster" )
225 main.caseExplanation = "Add Network Configurations for devices" +\
226 " not discovered yet. One device is allowed" +\
227 ", the other disallowed."
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -0700228
229
Devin Lim142b5342017-07-20 15:22:39 -0700230 pprint = main.Cluster.active( 0 ).REST.pprint
Jon Hall66e001c2015-11-12 09:45:10 -0800231
232 main.step( "Add Net Cfg for switch1" )
Pratik Parab6f418632017-04-25 17:05:50 -0700233
Pratik Parab6f418632017-04-25 17:05:50 -0700234 try:
235 with open( os.path.dirname( main.testFile ) + '/dependencies/s1Json', 'r' ) as s1Jsondata:
236 s1Json = json.load( s1Jsondata )
237 except IOError:
238 main.log.exception( "s1Json File not found." )
Pratik Parabc6083c22017-04-27 13:24:41 -0700239 main.cleanup()
240 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700241 main.log.info( "s1Json:" + str( s1Json ) )
242
Jon Hall66e001c2015-11-12 09:45:10 -0800243 main.s1Json = s1Json
Devin Lim142b5342017-07-20 15:22:39 -0700244 setS1Allow = main.Cluster.active( 0 ).REST.setNetCfg( s1Json,
245 subjectClass="devices",
246 subjectKey="of:0000000000000001",
247 configKey="basic" )
Jon Hall66e001c2015-11-12 09:45:10 -0800248 s1Result = False
alison15124df2016-10-06 12:04:51 -0700249 #Wait 5 secs after set up netCfg
250 time.sleep( main.SetNetCfgSleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800251 if setS1Allow:
Devin Lim142b5342017-07-20 15:22:39 -0700252 getS1 = utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg,
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700253 retValue=False,
254 kwargs={"subjectClass":"devices",
255 "subjectKey" : "of:0000000000000001",
256 "configKey" : "basic"},
257 attempts=main.retrytimes,
258 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800259 onosCfg = pprint( getS1 )
260 sentCfg = pprint( s1Json )
261 if onosCfg == sentCfg:
alison15124df2016-10-06 12:04:51 -0700262 main.log.info( "ONOS NetCfg match what was sent" )
Jon Hall66e001c2015-11-12 09:45:10 -0800263 s1Result = True
264 else:
265 main.log.error( "ONOS NetCfg doesn't match what was sent" )
266 main.log.debug( "ONOS config: {}".format( onosCfg ) )
267 main.log.debug( "Sent config: {}".format( sentCfg ) )
Devin Lim142b5342017-07-20 15:22:39 -0700268 utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg,
269 retValue=False,
270 attempts=main.retrytimes,
271 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800272 utilities.assert_equals( expect=True,
273 actual=s1Result,
274 onpass="Net Cfg added for device s1",
275 onfail="Net Cfg for device s1 not correctly set" )
276
277 main.step( "Add Net Cfg for switch3" )
Pratik Parab6f418632017-04-25 17:05:50 -0700278
279 try:
280 with open( os.path.dirname( main.testFile ) + '/dependencies/s3Json', 'r' ) as s3Jsondata:
281 s3Json = json.load( s3Jsondata )
282 except IOError:
283 main.log.exception( "s3Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700284 main.cleanup()
285 main.exit()
Jon Hallbc080f92017-05-24 16:29:55 -0700286 main.log.info( "s3Json:" + str( s3Json ) )
Pratik Parab6f418632017-04-25 17:05:50 -0700287
Jon Hall66e001c2015-11-12 09:45:10 -0800288 main.s3Json = s3Json
Devin Lim142b5342017-07-20 15:22:39 -0700289 setS3Disallow = main.Cluster.active( 0 ).REST.setNetCfg( s3Json,
290 subjectClass="devices",
291 subjectKey="of:0000000000000003",
292 configKey="basic" )
Jon Hall66e001c2015-11-12 09:45:10 -0800293 s3Result = False
alison15124df2016-10-06 12:04:51 -0700294 time.sleep( main.SetNetCfgSleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800295 if setS3Disallow:
296 # Check what we set is what is in ONOS
Devin Lim142b5342017-07-20 15:22:39 -0700297 getS3 = utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg,
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700298 retValue=False,
299 kwargs={"subjectClass": "devices",
300 "subjectKey": "of:0000000000000003",
301 "configKey": "basic"},
302 attempts=main.retrytimes,
303 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800304 onosCfg = pprint( getS3 )
305 sentCfg = pprint( s3Json )
306 if onosCfg == sentCfg:
Jon Hallbc080f92017-05-24 16:29:55 -0700307 main.log.info( "ONOS NetCfg match what was sent" )
Jon Hall66e001c2015-11-12 09:45:10 -0800308 s3Result = True
309 else:
310 main.log.error( "ONOS NetCfg doesn't match what was sent" )
311 main.log.debug( "ONOS config: {}".format( onosCfg ) )
312 main.log.debug( "Sent config: {}".format( sentCfg ) )
Devin Lim142b5342017-07-20 15:22:39 -0700313 utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg,
314 retValue=False,
315 attempts=main.retrytimes,
316 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800317 utilities.assert_equals( expect=True,
318 actual=s3Result,
319 onpass="Net Cfg added for device s3",
320 onfail="Net Cfg for device s3 not correctly set" )
321 main.netCfg.compareCfg( main, main.gossipTime )
322
323 def CASE21( self, main ):
324 """
325 Initial check of devices
326 """
327 import json
328 try:
329 assert main.s1Json, "s1Json not defined"
330 except AssertionError:
331 main.log.exception( "Case Prerequisites not set: " )
332 main.cleanup()
333 main.exit()
334 main.case( "Check Devices After they initially connect to ONOS" )
335
336 main.netCfg.compareCfg( main )
337
338 main.step( "ONOS should only show devices S1, S2, and S4" )
Devin Lim142b5342017-07-20 15:22:39 -0700339 devices = main.Cluster.active( 0 ).REST.devices()
340 main.log.debug( main.Cluster.active( 0 ).REST.pprint( devices ) )
Jon Hall66e001c2015-11-12 09:45:10 -0800341 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4 ] ]
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700342 main.log.debug( allowedDevices )
Jon Hall66e001c2015-11-12 09:45:10 -0800343 onosDevices = []
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700344 try:
345 for sw in json.loads( devices ):
Jon Hallbc080f92017-05-24 16:29:55 -0700346 onosDevices.append( str( sw[ 'id' ] ) )
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700347 onosDevices.sort()
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700348 main.log.debug( onosDevices )
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700349 except( TypeError, ValueError ):
350 main.log.error( "Problem loading devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800351 utilities.assert_equals( expect=allowedDevices,
352 actual=onosDevices,
353 onpass="Only allowed devices are in ONOS",
354 onfail="ONOS devices doesn't match the list" +
355 " of allowed devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800356 main.step( "Check device annotations" )
357 keys = [ 'name', 'owner', 'rackAddress' ]
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700358 try:
359 for sw in json.loads( devices ):
Jon Hallbc080f92017-05-24 16:29:55 -0700360 if "of:0000000000000001" in sw[ 'id' ]:
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700361 s1Correct = True
362 for k in keys:
Jon Hallbc080f92017-05-24 16:29:55 -0700363 if str( sw.get( 'annotations', {} ).get( k ) ) != str( main.s1Json[ k ] ):
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700364 s1Correct = False
365 main.log.debug( "{} is wrong on s1".format( k ) )
366 if not s1Correct:
367 main.log.error( "Annotations for s1 are incorrect: {}".format( sw ) )
368 except( TypeError, ValueError ):
369 main.log.error( "Problem loading devices" )
370 s1Correct = False
Jon Hall66e001c2015-11-12 09:45:10 -0800371 try:
372 stepResult = s1Correct
373 except NameError:
374 stepResult = False
375 main.log.error( "s1 not found in devices" )
376 utilities.assert_equals( expect=True,
377 actual=stepResult,
378 onpass="Configured device's annotations are correct",
379 onfail="Incorrect annotations for configured devices." )
380
381 def CASE22( self, main ):
382 """
383 Add some device configurations for connected devices and then check
384 they are distributed to all nodes
385 """
386 main.case( "Add Network configurations for connected devices to the cluster" )
387 main.caseExplanation = "Add Network Configurations for discovered " +\
388 "devices. One device is allowed" +\
389 ", the other disallowed."
Devin Lim142b5342017-07-20 15:22:39 -0700390 pprint = main.Cluster.active( 0 ).REST.pprint
Jon Hall66e001c2015-11-12 09:45:10 -0800391
392 main.step( "Add Net Cfg for switch2" )
Pratik Parab6f418632017-04-25 17:05:50 -0700393 try:
394 with open( os.path.dirname( main.testFile ) + '/dependencies/s2Json', 'r' ) as s2Jsondata:
395 s2Json = json.load( s2Jsondata )
396 except IOError:
397 main.log.exception( "s2Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700398 main.cleanup()
399 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700400 main.log.info( "s2Json:" + str( s2Json ) )
Jon Hall66e001c2015-11-12 09:45:10 -0800401 main.s2Json = s2Json
Devin Lim142b5342017-07-20 15:22:39 -0700402 setS2Allow = main.Cluster.active( 1 ).REST.setNetCfg( s2Json,
403 subjectClass="devices",
404 subjectKey="of:0000000000000002",
405 configKey="basic" )
Jon Hall66e001c2015-11-12 09:45:10 -0800406 s2Result = False
407 if setS2Allow:
408 # Check what we set is what is in ONOS
Devin Lim142b5342017-07-20 15:22:39 -0700409 getS2 = utilities.retry( f=main.Cluster.active( 1 ).REST.getNetCfg,
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700410 retValue=False,
411 kwargs={"subjectClass": "devices",
412 "subjectKey": "of:0000000000000002",
413 "configKey": "basic"},
414 attempts=main.retrytimes,
415 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800416 onosCfg = pprint( getS2 )
417 sentCfg = pprint( s2Json )
418 if onosCfg == sentCfg:
419 s2Result = True
420 else:
421 main.log.error( "ONOS NetCfg doesn't match what was sent" )
422 main.log.debug( "ONOS config: {}".format( onosCfg ) )
423 main.log.debug( "Sent config: {}".format( sentCfg ) )
Devin Lim142b5342017-07-20 15:22:39 -0700424 utilities.retry( f=main.Cluster.active( 1 ).REST.getNetCfg,
425 retValue=False,
426 attempts=main.retrytimes,
427 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800428 utilities.assert_equals( expect=True,
429 actual=s2Result,
430 onpass="Net Cfg added for device s2",
431 onfail="Net Cfg for device s2 not correctly set" )
Jon Hall66e001c2015-11-12 09:45:10 -0800432 main.step( "Add Net Cfg for switch4" )
Pratik Parab6f418632017-04-25 17:05:50 -0700433
434 try:
435 with open( os.path.dirname( main.testFile ) + '/dependencies/s4Json', 'r' ) as s4Jsondata:
436 s4Json = json.load( s4Jsondata )
437 except IOError:
438 main.log.exception( "s4Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700439 main.cleanup()
440 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700441 main.log.info( "s4Json:" + str( s4Json ) )
Jon Hall66e001c2015-11-12 09:45:10 -0800442 main.s4Json = s4Json
Devin Lim142b5342017-07-20 15:22:39 -0700443 setS4Disallow = main.Cluster.active( 2 ).REST.setNetCfg( s4Json,
Jon Hall66e001c2015-11-12 09:45:10 -0800444 subjectClass="devices",
445 subjectKey="of:0000000000000004",
446 configKey="basic" )
447 s4Result = False
448 if setS4Disallow:
449 # Check what we set is what is in ONOS
Devin Lim142b5342017-07-20 15:22:39 -0700450 getS4 = utilities.retry( f=main.Cluster.active( 2 ).REST.getNetCfg,
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700451 retValue=False,
452 kwargs={"subjectClass": "devices",
453 "subjectKey": "of:0000000000000004",
454 "configKey": "basic"},
455 attempts=main.retrytimes,
456 sleep=main.retrysleep )
457
Jon Hall66e001c2015-11-12 09:45:10 -0800458 onosCfg = pprint( getS4 )
459 sentCfg = pprint( s4Json )
460 if onosCfg == sentCfg:
461 s4Result = True
462 else:
463 main.log.error( "ONOS NetCfg doesn't match what was sent" )
464 main.log.debug( "ONOS config: {}".format( onosCfg ) )
465 main.log.debug( "Sent config: {}".format( sentCfg ) )
Devin Lim142b5342017-07-20 15:22:39 -0700466 main.step( "Retrying main.Cluster.active( 2 ).REST.getNetCfg" )
467 utilities.retry( f=main.Cluster.active( 2 ).REST.getNetCfg,
468 retValue=False,
469 attempts=main.retrytimes,
470 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800471 utilities.assert_equals( expect=True,
472 actual=s4Result,
473 onpass="Net Cfg added for device s4",
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700474 onfail="Net Cfg for device s4 not correctly set" )
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -0700475
Jon Hall66e001c2015-11-12 09:45:10 -0800476 main.netCfg.compareCfg( main, main.gossipTime )
477
478 def CASE23( self, main ):
479 """
480 Check of devices after all Network Configurations are set
481 """
482 import json
483 try:
484 assert main.s1Json, "s1Json not defined"
485 assert main.s2Json, "s2Json not defined"
486 except AssertionError:
487 main.log.exception( "Case Prerequisites not set: " )
488 main.cleanup()
489 main.exit()
490 main.case( "Check Devices after all configurations are set" )
491
492 main.netCfg.compareCfg( main )
493
494 main.step( "ONOS should only show devices S1 and S2" )
Devin Lim142b5342017-07-20 15:22:39 -0700495 devices = main.Cluster.active( 0 ).REST.devices()
496 main.log.debug( main.Cluster.active( 0 ).REST.pprint( devices ) )
Jon Hall66e001c2015-11-12 09:45:10 -0800497 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2 ] ]
498 onosDevices = []
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700499 try:
500 for sw in json.loads( devices ):
501 onosDevices.append( str( sw.get( 'id' ) ) )
502 onosDevices.sort()
503 failMsg = "ONOS devices doesn't match the list of allowed devices.\n"
504 failMsg += "Expected devices: {}\nActual devices: {}".format( allowedDevices,
505 onosDevices )
506 except( TypeError, ValueError ):
507 main.log.error( "Problem loading devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800508 utilities.assert_equals( expect=allowedDevices,
509 actual=onosDevices,
510 onpass="Only allowed devices are in ONOS",
511 onfail=failMsg )
512
513 main.step( "Check device annotations" )
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -0700514 stepResult = utilities.retry( f=main.netCfg.checkAllDeviceAnnotations,
515 args=( main, json ),
516 retValue=False,
517 attempts=main.retrytimes,
518 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800519 utilities.assert_equals( expect=True,
520 actual=stepResult,
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -0700521 onpass="Configured devices' annotations are correct",
Jon Hall66e001c2015-11-12 09:45:10 -0800522 onfail="Incorrect annotations for configured devices." )
523
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -0700524
525
Jon Hall66e001c2015-11-12 09:45:10 -0800526 def CASE24( self, main ):
527 """
528 Testing removal of configurations
529 """
Jon Hall541b8e02015-12-14 19:29:01 -0800530 import time
Jon Hall66e001c2015-11-12 09:45:10 -0800531 try:
532 assert main.s1Json, "s1Json not defined"
533 assert main.s2Json, "s2Json not defined"
534 assert main.s3Json, "s3Json not defined"
535 assert main.s4Json, "s4Json not defined"
536 except AssertionError:
537 main.log.exception( "Case Prerequisites not set: " )
538 main.cleanup()
539 main.exit()
540 main.case( "Testing removal of configurations" )
541 main.step( "Remove 'allowed' configuration from all devices" )
542
543 s1Json = main.s1Json # NOTE: This is a reference
544 try:
Jon Hallbc080f92017-05-24 16:29:55 -0700545 del s1Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800546 except KeyError:
547 main.log.exception( "Key not found" )
Devin Lim142b5342017-07-20 15:22:39 -0700548 setS1 = main.Cluster.active( 0 ).REST.setNetCfg( s1Json,
549 subjectClass="devices",
550 subjectKey="of:0000000000000001",
551 configKey="basic" )
Jon Hall66e001c2015-11-12 09:45:10 -0800552
553 s2Json = main.s2Json # NOTE: This is a reference
554 try:
Jon Hall541b8e02015-12-14 19:29:01 -0800555 time.sleep( main.gossipTime )
Jon Hallbc080f92017-05-24 16:29:55 -0700556 del s2Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800557 except KeyError:
558 main.log.exception( "Key not found" )
Devin Lim142b5342017-07-20 15:22:39 -0700559 setS2 = main.Cluster.active( 1 ).REST.setNetCfg( s2Json,
560 subjectClass="devices",
561 subjectKey="of:0000000000000002",
562 configKey="basic" )
Jon Hall66e001c2015-11-12 09:45:10 -0800563
564 s3Json = main.s3Json # NOTE: This is a reference
565 try:
Jon Hall541b8e02015-12-14 19:29:01 -0800566 time.sleep( main.gossipTime )
Jon Hallbc080f92017-05-24 16:29:55 -0700567 del s3Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800568 except KeyError:
569 main.log.exception( "Key not found" )
Devin Lim142b5342017-07-20 15:22:39 -0700570 setS3 = main.Cluster.active( 2 ).REST.setNetCfg( s3Json,
571 subjectClass="devices",
572 subjectKey="of:0000000000000003",
573 configKey="basic" )
Jon Hall66e001c2015-11-12 09:45:10 -0800574
575 s4Json = main.s4Json # NOTE: This is a reference
576 try:
Jon Hall541b8e02015-12-14 19:29:01 -0800577 time.sleep( main.gossipTime )
Jon Hallbc080f92017-05-24 16:29:55 -0700578 del s4Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800579 except KeyError:
580 main.log.exception( "Key not found" )
Devin Lim142b5342017-07-20 15:22:39 -0700581 setS4 = main.Cluster.active( 2 ).REST.setNetCfg( s4Json,
582 subjectClass="devices",
583 subjectKey="of:0000000000000004",
584 configKey="basic" )
Jon Hall66e001c2015-11-12 09:45:10 -0800585 removeAllowed = setS1 and setS2 and setS3 and setS4
586 utilities.assert_equals( expect=main.TRUE,
587 actual=removeAllowed,
588 onpass="Successfully removed 'allowed' config from devices",
589 onfail="Failed to remove the 'allowed' config key." )
590
591 main.netCfg.compareCfg( main, main.gossipTime )
592
593 main.step( "Delete basic config for s1 and s2" )
Devin Lim142b5342017-07-20 15:22:39 -0700594 removeS1 = main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="devices",
595 subjectKey="of:0000000000000001",
596 configKey="basic" )
597 removeS2 = main.Cluster.active( 1 ).REST.removeNetCfg( subjectClass="devices",
598 subjectKey="of:0000000000000002",
599 configKey="basic" )
Jon Hall66e001c2015-11-12 09:45:10 -0800600 removeSingles = removeS1 and removeS2
601 utilities.assert_equals( expect=main.TRUE,
602 actual=removeSingles,
603 onpass="Successfully removed S1 and S2 basic config",
604 onfail="Failed to removed S1 and S2 basic config" )
605
606 main.netCfg.compareCfg( main, main.gossipTime )
607
608 main.step( "Delete the net config for S3" )
Devin Lim142b5342017-07-20 15:22:39 -0700609 removeS3 = main.Cluster.active( 2 ).REST.removeNetCfg( subjectClass="devices",
610 subjectKey="of:0000000000000003" )
Jon Hall66e001c2015-11-12 09:45:10 -0800611 utilities.assert_equals( expect=main.TRUE,
612 actual=removeS3,
613 onpass="Successfully removed S3's config",
614 onfail="Failed to removed S3's config" )
615
616 main.netCfg.compareCfg( main, main.gossipTime )
617
618 main.step( "Delete the net config for all devices" )
Devin Lim142b5342017-07-20 15:22:39 -0700619 remove = main.Cluster.active( 2 ).REST.removeNetCfg( subjectClass="devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800620 utilities.assert_equals( expect=main.TRUE,
621 actual=remove,
622 onpass="Successfully removed device config",
623 onfail="Failed to remove device config" )
624
625 main.netCfg.compareCfg( main, main.gossipTime )
626
627 main.step( "Assert the net config for devices is empty" )
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700628
Devin Lim142b5342017-07-20 15:22:39 -0700629 get = utilities.retry( f=main.Cluster.active( 2 ).REST.getNetCfg,
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700630 retValue = False,
631 kwargs={"subjectClass":"devices"},
632 sleep=main.retrysleep,
633 attempts=main.retrytimes )
634
Jon Hall66e001c2015-11-12 09:45:10 -0800635 utilities.assert_equals( expect='{}',
636 actual=get,
637 onpass="Successfully removed device config",
638 onfail="Failed to remove device config" )
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700639
640 def CASE25( self, main ):
641 """
642 Use network-cfg.json to configure devices during ONOS startup
643 """
644 main.case( "Preparing network-cfg.json to load configurations" )
645 main.step( "Moving network-cfg.json to $ONOS_ROOT/tools/package/config/" )
646 prestartResult = main.TRUE
647 srcPath = "~/OnosSystemTest/TestON/tests/FUNC/FUNCnetCfg/dependencies/network-cfg.json"
648 dstPath = "~/onos/tools/package/config/network-cfg.json"
649 prestartResult = main.ONOSbench.scp( main.ONOSbench, srcPath, dstPath, direction="to" )
650 utilities.assert_equals( expect=main.TRUE,
651 actual=prestartResult,
652 onpass="Successfully copied network-cfg.json to target directory",
653 onfail="Failed to copy network-cfg.json to target directory" )
654
655 def CASE26( self, main ):
656 """
657 Check to see that pre-startup configurations were set correctly
658 """
659 import json
660 main.case( "Check to see if the pre-startup configurations were set, then remove their allowed status" )
661 main.step( "Checking configurations for Switches 5 and 6" )
Jon Hallbc080f92017-05-24 16:29:55 -0700662 main.step( "ONOS should only show devices S1, S2, S4, and S5" ) # and S6
Devin Lim142b5342017-07-20 15:22:39 -0700663 devices = main.Cluster.active( 0 ).REST.devices()
664 main.log.debug( main.Cluster.active( 0 ).REST.pprint( devices ) )
Jon Hallbc080f92017-05-24 16:29:55 -0700665 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4, 5 ] ] # 6
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700666 main.log.debug( allowedDevices )
667 onosDevices = []
668 try:
669 for sw in json.loads( devices ):
Jon Hallbc080f92017-05-24 16:29:55 -0700670 onosDevices.append( str( sw[ 'id' ] ) )
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700671 onosDevices.sort()
672 main.log.debug( onosDevices )
673 except( TypeError, ValueError ):
674 main.log.error( "Problem loading devices" )
675 utilities.assert_equals( expect=allowedDevices,
676 actual=onosDevices,
677 onpass="Only allowed devices are in ONOS",
678 onfail="ONOS devices doesn't match the list" +
679 " of allowed devices" )
680
681 main.step( "Removing allowed status from Switches 5 and 6" )
Pratik Parab6f418632017-04-25 17:05:50 -0700682 try:
683 with open( os.path.dirname( main.testFile ) + '/dependencies/s5Json', 'r' ) as s5Jsondata:
684 main.s5Json = json.load( s5Jsondata )
685 except IOError:
686 main.log.exception( "s5Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700687 main.cleanup()
688 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700689 main.log.info( "s5Json:" + str( main.s5Json ) )
690
691 try:
692 with open( os.path.dirname( main.testFile ) + '/dependencies/s6Json', 'r' ) as s6Jsondata:
693 main.s6Json = json.load( s6Jsondata )
694 except IOError:
695 main.log.exception( "s6Json File not found" )
Pratik Parabc6083c22017-04-27 13:24:41 -0700696 main.cleanup()
697 main.exit()
Pratik Parab6f418632017-04-25 17:05:50 -0700698 main.log.info( "s6Json:" + str( main.s6Json ) )
699
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700700 s5Json = main.s5Json
Devin Lim142b5342017-07-20 15:22:39 -0700701 setS1 = main.Cluster.active( 0 ).REST.setNetCfg( s5Json,
702 subjectClass="devices",
703 subjectKey="of:0000000000000005",
704 configKey="basic" )
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700705
706 s6Json = main.s6Json
Devin Lim142b5342017-07-20 15:22:39 -0700707 setS1 = main.Cluster.active( 0 ).REST.setNetCfg( s6Json,
708 subjectClass="devices",
709 subjectKey="of:0000000000000006",
710 configKey="basic" )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700711
712 def CASE27( self, main ):
713 """
Jon Hallbc080f92017-05-24 16:29:55 -0700714 1 ) A = get /network/configuration
715 2 ) Post A
716 3 ) Compare A with ONOS
717 4 ) Modify A so S6 is disallowed
718 5 ) Check
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700719
720 """
721 import json
Devin Lim142b5342017-07-20 15:22:39 -0700722 pprint = main.Cluster.active( 0 ).REST.pprint
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700723 main.case( "Posting network configurations to the top level web resource" )
724 main.step( "Get json object from Net Cfg" )
Devin Lim142b5342017-07-20 15:22:39 -0700725 getinfo = utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg,
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700726 retValue=False,
727 sleep=main.retrysleep,
728 attempts=main.retrytimes )
729
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700730 main.log.debug( getinfo )
731 main.step( "Posting json object to Net Cfg" )
Devin Lim142b5342017-07-20 15:22:39 -0700732 postinfo = main.Cluster.active( 0 ).REST.setNetCfg( json.loads( getinfo ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700733 main.step( "Compare device with ONOS" )
734 main.netCfg.compareCfg( main )
Jon Hallbc080f92017-05-24 16:29:55 -0700735 main.step( "ONOS should only show devices S1, S2, S4, S5 and S6" )
Devin Lim142b5342017-07-20 15:22:39 -0700736 devices = main.Cluster.active( 0 ).REST.devices()
737 main.log.debug( main.Cluster.active( 0 ).REST.pprint( devices ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700738 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4, 5, 6 ] ]
739 onosDevices = []
740 try:
741 for sw in json.loads( devices ):
742 onosDevices.append( str( sw.get( 'id' ) ) )
Jon Hallbc080f92017-05-24 16:29:55 -0700743 onosDevices.sort()
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700744 failMsg = "ONOS devices doesn't match the list of allowed devices. \n"
745 failMsg += "Expected devices: {}\nActual devices: {}".format( allowedDevices, onosDevices )
746 except( TypeError, ValueError ):
747 main.log.error( "Problem loading devices" )
748 utilities.assert_equals( expect=allowedDevices, actual=onosDevices,
749 onpass="Only allowed devices are in ONOS", onfail=failMsg )
750
751 main.step( "Modify json object so S6 is disallowed" )
752 main.s6Json = { "allowed": False }
753 s6Json = main.s6Json
Devin Lim142b5342017-07-20 15:22:39 -0700754 setS6Disallow = main.Cluster.active( 0 ).REST.setNetCfg( s6Json,
755 subjectClass="devices",
756 subjectKey="of:0000000000000006",
757 configKey="basic" )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700758 s6Result = False
759 if setS6Disallow:
Devin Lim142b5342017-07-20 15:22:39 -0700760 getS6 = utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg,
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700761 retValue=False,
762 kwargs={"subjectClass":"devices",
763 "subjectKey" : "of:0000000000000006",
764 "configKey" : "basic"},
765 sleep=main.retrysleep,
766 attempts=main.retrytimes )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700767 onosCfg = pprint( getS6 )
768 sentCfg = pprint( s6Json )
769 if onosCfg == sentCfg:
770 s6Result = True
771 else:
772 main.log.error( "ONOS NetCfg doesn't match what was sent" )
773 main.log.debug( "ONOS config: {}".format( onosCfg ) )
774 main.log.debug( "Sent config: {}".format( sentCfg ) )
Devin Lim142b5342017-07-20 15:22:39 -0700775 utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg,
776 retValue=False,
777 attempts=main.retrytimes,
778 sleep=main.retrysleep )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700779 utilities.assert_equals( expect=True, actual=s6Result,
780 onpass="Net Cfg added for devices s6",
781 onfail="Net Cfg for device s6 not correctly set" )