blob: ef5eb99035c5f4597fd71a9a32c6a379c17e1326 [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" )
Devin Lim44075962017-08-11 10:56:37 -070045 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070046 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" )
Devin Lim44075962017-08-11 10:56:37 -070098 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070099 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:
Devin Lim44075962017-08-11 10:56:37 -0700139 main.cleanAndExit()
Jon Hall66e001c2015-11-12 09:45:10 -0800140
141 def CASE11( self, main ):
142 """
143 Start Mininet topology with OF 1.3 switches
144 """
145 import re
146 main.OFProtocol = "1.3"
147 main.log.report( "Start Mininet topology with OF 1.3 switches" )
148 main.case( "Start Mininet topology with OF 1.3 switches" )
149 main.caseExplanation = "Start mininet topology with OF 1.3 " +\
150 "switches to test intents, exits out if " +\
151 "topology did not start correctly"
152
153 main.step( "Starting Mininet topology with OF 1.3 switches" )
Jon Hall53c5e662016-04-13 16:06:56 -0700154 args = "--controller none --switch ovs,protocols=OpenFlow13"
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700155 switches = int( main.params[ 'MININET' ][ 'switch' ] )
Jon Hall66e001c2015-11-12 09:45:10 -0800156 cmd = "mn --topo linear,{} {}".format( switches, args )
Jon Hallbc080f92017-05-24 16:29:55 -0700157 topoResult = main.Mininet1.startNet( mnCmd=cmd )
Jon Hall66e001c2015-11-12 09:45:10 -0800158 stepResult = topoResult
159 utilities.assert_equals( expect=main.TRUE,
160 actual=stepResult,
161 onpass="Successfully loaded topology",
162 onfail="Failed to load topology" )
163 # Exit if topology did not load properly
164 if not topoResult:
Devin Lim44075962017-08-11 10:56:37 -0700165 main.cleanAndExit()
Jon Hall66e001c2015-11-12 09:45:10 -0800166
Devin Lim142b5342017-07-20 15:22:39 -0700167 tempONOSip = main.Cluster.getIps()
Jon Hall66e001c2015-11-12 09:45:10 -0800168
169 swList = [ "s" + str( i ) for i in range( 1, switches + 1 ) ]
170 assignResult = main.Mininet1.assignSwController( sw=swList,
171 ip=tempONOSip,
172 port='6653' )
173 if not assignResult:
Devin Lim44075962017-08-11 10:56:37 -0700174 main.cleanAndExit()
Jon Hall66e001c2015-11-12 09:45:10 -0800175
176 assignResult = main.TRUE
177 for sw in swList:
178 response = main.Mininet1.getSwController( "s" + str( i ) )
179 main.log.info( "Response is " + str( response ) )
180 for ip in tempONOSip:
181 if re.search( "tcp:" + ip, response ):
182 assignResult = assignResult and main.TRUE
183 else:
184 assignResult = assignResult and main.FALSE
185 stepResult = assignResult
186 utilities.assert_equals( expect=main.TRUE,
187 actual=stepResult,
188 onpass="Successfully assigned switches" +
189 "to controller",
190 onfail="Failed to assign switches to " +
191 "controller" )
192
193 def CASE14( self, main ):
194 """
195 Stop mininet
196 """
Devin Lim58046fa2017-07-05 16:55:00 -0700197 try:
198 from tests.dependencies.utils import Utils
199 except ImportError:
200 main.log.error( "Utils not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700201 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700202 try:
203 main.Utils
204 except ( NameError, AttributeError ):
205 main.Utils = Utils()
206 main.Utils.mininetCleanIntro()
207 topoResult = main.Utils.mininetCleanup( main.Mininet1 )
Jon Hall66e001c2015-11-12 09:45:10 -0800208 # Exit if topology did not load properly
209 if not topoResult:
Devin Lim44075962017-08-11 10:56:37 -0700210 main.cleanAndExit()
Jon Hall66e001c2015-11-12 09:45:10 -0800211
212 def CASE20( self, main ):
213 """
214 Add some device configurations and then check they are distributed
215 to all nodes
216 """
alison15124df2016-10-06 12:04:51 -0700217 import time
Pratik Parabc6083c22017-04-27 13:24:41 -0700218 import json
219 import os
Jon Hall66e001c2015-11-12 09:45:10 -0800220 main.case( "Add Network configurations to the cluster" )
221 main.caseExplanation = "Add Network Configurations for devices" +\
222 " not discovered yet. One device is allowed" +\
223 ", the other disallowed."
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -0700224
225
Devin Lim142b5342017-07-20 15:22:39 -0700226 pprint = main.Cluster.active( 0 ).REST.pprint
Jon Hall66e001c2015-11-12 09:45:10 -0800227
228 main.step( "Add Net Cfg for switch1" )
Pratik Parab6f418632017-04-25 17:05:50 -0700229
Pratik Parab6f418632017-04-25 17:05:50 -0700230 try:
231 with open( os.path.dirname( main.testFile ) + '/dependencies/s1Json', 'r' ) as s1Jsondata:
232 s1Json = json.load( s1Jsondata )
233 except IOError:
234 main.log.exception( "s1Json File not found." )
Devin Lim44075962017-08-11 10:56:37 -0700235 main.cleanAndExit()
Pratik Parab6f418632017-04-25 17:05:50 -0700236 main.log.info( "s1Json:" + str( s1Json ) )
237
Jon Hall66e001c2015-11-12 09:45:10 -0800238 main.s1Json = s1Json
Devin Lim142b5342017-07-20 15:22:39 -0700239 setS1Allow = main.Cluster.active( 0 ).REST.setNetCfg( s1Json,
240 subjectClass="devices",
241 subjectKey="of:0000000000000001",
242 configKey="basic" )
Jon Hall66e001c2015-11-12 09:45:10 -0800243 s1Result = False
alison15124df2016-10-06 12:04:51 -0700244 #Wait 5 secs after set up netCfg
245 time.sleep( main.SetNetCfgSleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800246 if setS1Allow:
Devin Lim142b5342017-07-20 15:22:39 -0700247 getS1 = utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg,
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700248 retValue=False,
249 kwargs={"subjectClass":"devices",
250 "subjectKey" : "of:0000000000000001",
251 "configKey" : "basic"},
252 attempts=main.retrytimes,
253 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800254 onosCfg = pprint( getS1 )
255 sentCfg = pprint( s1Json )
256 if onosCfg == sentCfg:
alison15124df2016-10-06 12:04:51 -0700257 main.log.info( "ONOS NetCfg match what was sent" )
Jon Hall66e001c2015-11-12 09:45:10 -0800258 s1Result = True
259 else:
260 main.log.error( "ONOS NetCfg doesn't match what was sent" )
261 main.log.debug( "ONOS config: {}".format( onosCfg ) )
262 main.log.debug( "Sent config: {}".format( sentCfg ) )
Devin Lim142b5342017-07-20 15:22:39 -0700263 utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg,
264 retValue=False,
265 attempts=main.retrytimes,
266 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800267 utilities.assert_equals( expect=True,
268 actual=s1Result,
269 onpass="Net Cfg added for device s1",
270 onfail="Net Cfg for device s1 not correctly set" )
271
272 main.step( "Add Net Cfg for switch3" )
Pratik Parab6f418632017-04-25 17:05:50 -0700273
274 try:
275 with open( os.path.dirname( main.testFile ) + '/dependencies/s3Json', 'r' ) as s3Jsondata:
276 s3Json = json.load( s3Jsondata )
277 except IOError:
278 main.log.exception( "s3Json File not found" )
Devin Lim44075962017-08-11 10:56:37 -0700279 main.cleanAndExit()
Jon Hallbc080f92017-05-24 16:29:55 -0700280 main.log.info( "s3Json:" + str( s3Json ) )
Pratik Parab6f418632017-04-25 17:05:50 -0700281
Jon Hall66e001c2015-11-12 09:45:10 -0800282 main.s3Json = s3Json
Devin Lim142b5342017-07-20 15:22:39 -0700283 setS3Disallow = main.Cluster.active( 0 ).REST.setNetCfg( s3Json,
284 subjectClass="devices",
285 subjectKey="of:0000000000000003",
286 configKey="basic" )
Jon Hall66e001c2015-11-12 09:45:10 -0800287 s3Result = False
alison15124df2016-10-06 12:04:51 -0700288 time.sleep( main.SetNetCfgSleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800289 if setS3Disallow:
290 # Check what we set is what is in ONOS
Devin Lim142b5342017-07-20 15:22:39 -0700291 getS3 = utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg,
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700292 retValue=False,
293 kwargs={"subjectClass": "devices",
294 "subjectKey": "of:0000000000000003",
295 "configKey": "basic"},
296 attempts=main.retrytimes,
297 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800298 onosCfg = pprint( getS3 )
299 sentCfg = pprint( s3Json )
300 if onosCfg == sentCfg:
Jon Hallbc080f92017-05-24 16:29:55 -0700301 main.log.info( "ONOS NetCfg match what was sent" )
Jon Hall66e001c2015-11-12 09:45:10 -0800302 s3Result = True
303 else:
304 main.log.error( "ONOS NetCfg doesn't match what was sent" )
305 main.log.debug( "ONOS config: {}".format( onosCfg ) )
306 main.log.debug( "Sent config: {}".format( sentCfg ) )
Devin Lim142b5342017-07-20 15:22:39 -0700307 utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg,
308 retValue=False,
309 attempts=main.retrytimes,
310 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800311 utilities.assert_equals( expect=True,
312 actual=s3Result,
313 onpass="Net Cfg added for device s3",
314 onfail="Net Cfg for device s3 not correctly set" )
315 main.netCfg.compareCfg( main, main.gossipTime )
316
317 def CASE21( self, main ):
318 """
319 Initial check of devices
320 """
321 import json
322 try:
323 assert main.s1Json, "s1Json not defined"
324 except AssertionError:
325 main.log.exception( "Case Prerequisites not set: " )
Devin Lim44075962017-08-11 10:56:37 -0700326 main.cleanAndExit()
Jon Hall66e001c2015-11-12 09:45:10 -0800327 main.case( "Check Devices After they initially connect to ONOS" )
328
329 main.netCfg.compareCfg( main )
330
331 main.step( "ONOS should only show devices S1, S2, and S4" )
Devin Lim142b5342017-07-20 15:22:39 -0700332 devices = main.Cluster.active( 0 ).REST.devices()
333 main.log.debug( main.Cluster.active( 0 ).REST.pprint( devices ) )
Jon Hall66e001c2015-11-12 09:45:10 -0800334 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4 ] ]
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700335 main.log.debug( allowedDevices )
Jon Hall66e001c2015-11-12 09:45:10 -0800336 onosDevices = []
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700337 try:
338 for sw in json.loads( devices ):
Jon Hallbc080f92017-05-24 16:29:55 -0700339 onosDevices.append( str( sw[ 'id' ] ) )
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700340 onosDevices.sort()
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700341 main.log.debug( onosDevices )
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700342 except( TypeError, ValueError ):
343 main.log.error( "Problem loading devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800344 utilities.assert_equals( expect=allowedDevices,
345 actual=onosDevices,
346 onpass="Only allowed devices are in ONOS",
347 onfail="ONOS devices doesn't match the list" +
348 " of allowed devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800349 main.step( "Check device annotations" )
350 keys = [ 'name', 'owner', 'rackAddress' ]
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700351 try:
352 for sw in json.loads( devices ):
Jon Hallbc080f92017-05-24 16:29:55 -0700353 if "of:0000000000000001" in sw[ 'id' ]:
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700354 s1Correct = True
355 for k in keys:
Jon Hallbc080f92017-05-24 16:29:55 -0700356 if str( sw.get( 'annotations', {} ).get( k ) ) != str( main.s1Json[ k ] ):
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700357 s1Correct = False
358 main.log.debug( "{} is wrong on s1".format( k ) )
359 if not s1Correct:
360 main.log.error( "Annotations for s1 are incorrect: {}".format( sw ) )
361 except( TypeError, ValueError ):
362 main.log.error( "Problem loading devices" )
363 s1Correct = False
Jon Hall66e001c2015-11-12 09:45:10 -0800364 try:
365 stepResult = s1Correct
366 except NameError:
367 stepResult = False
368 main.log.error( "s1 not found in devices" )
369 utilities.assert_equals( expect=True,
370 actual=stepResult,
371 onpass="Configured device's annotations are correct",
372 onfail="Incorrect annotations for configured devices." )
373
374 def CASE22( self, main ):
375 """
376 Add some device configurations for connected devices and then check
377 they are distributed to all nodes
378 """
379 main.case( "Add Network configurations for connected devices to the cluster" )
380 main.caseExplanation = "Add Network Configurations for discovered " +\
381 "devices. One device is allowed" +\
382 ", the other disallowed."
Devin Lim142b5342017-07-20 15:22:39 -0700383 pprint = main.Cluster.active( 0 ).REST.pprint
Jon Hall66e001c2015-11-12 09:45:10 -0800384
385 main.step( "Add Net Cfg for switch2" )
Pratik Parab6f418632017-04-25 17:05:50 -0700386 try:
387 with open( os.path.dirname( main.testFile ) + '/dependencies/s2Json', 'r' ) as s2Jsondata:
388 s2Json = json.load( s2Jsondata )
389 except IOError:
390 main.log.exception( "s2Json File not found" )
Devin Lim44075962017-08-11 10:56:37 -0700391 main.cleanAndExit()
Pratik Parab6f418632017-04-25 17:05:50 -0700392 main.log.info( "s2Json:" + str( s2Json ) )
Jon Hall66e001c2015-11-12 09:45:10 -0800393 main.s2Json = s2Json
Devin Lim142b5342017-07-20 15:22:39 -0700394 setS2Allow = main.Cluster.active( 1 ).REST.setNetCfg( s2Json,
395 subjectClass="devices",
396 subjectKey="of:0000000000000002",
397 configKey="basic" )
Jon Hall66e001c2015-11-12 09:45:10 -0800398 s2Result = False
399 if setS2Allow:
400 # Check what we set is what is in ONOS
Devin Lim142b5342017-07-20 15:22:39 -0700401 getS2 = utilities.retry( f=main.Cluster.active( 1 ).REST.getNetCfg,
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700402 retValue=False,
403 kwargs={"subjectClass": "devices",
404 "subjectKey": "of:0000000000000002",
405 "configKey": "basic"},
406 attempts=main.retrytimes,
407 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800408 onosCfg = pprint( getS2 )
409 sentCfg = pprint( s2Json )
410 if onosCfg == sentCfg:
411 s2Result = True
412 else:
413 main.log.error( "ONOS NetCfg doesn't match what was sent" )
414 main.log.debug( "ONOS config: {}".format( onosCfg ) )
415 main.log.debug( "Sent config: {}".format( sentCfg ) )
Devin Lim142b5342017-07-20 15:22:39 -0700416 utilities.retry( f=main.Cluster.active( 1 ).REST.getNetCfg,
417 retValue=False,
418 attempts=main.retrytimes,
419 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800420 utilities.assert_equals( expect=True,
421 actual=s2Result,
422 onpass="Net Cfg added for device s2",
423 onfail="Net Cfg for device s2 not correctly set" )
Jon Hall66e001c2015-11-12 09:45:10 -0800424 main.step( "Add Net Cfg for switch4" )
Pratik Parab6f418632017-04-25 17:05:50 -0700425
426 try:
427 with open( os.path.dirname( main.testFile ) + '/dependencies/s4Json', 'r' ) as s4Jsondata:
428 s4Json = json.load( s4Jsondata )
429 except IOError:
430 main.log.exception( "s4Json File not found" )
Devin Lim44075962017-08-11 10:56:37 -0700431 main.cleanAndExit()
Pratik Parab6f418632017-04-25 17:05:50 -0700432 main.log.info( "s4Json:" + str( s4Json ) )
Jon Hall66e001c2015-11-12 09:45:10 -0800433 main.s4Json = s4Json
Devin Lim142b5342017-07-20 15:22:39 -0700434 setS4Disallow = main.Cluster.active( 2 ).REST.setNetCfg( s4Json,
Jon Hall66e001c2015-11-12 09:45:10 -0800435 subjectClass="devices",
436 subjectKey="of:0000000000000004",
437 configKey="basic" )
438 s4Result = False
439 if setS4Disallow:
440 # Check what we set is what is in ONOS
Devin Lim142b5342017-07-20 15:22:39 -0700441 getS4 = utilities.retry( f=main.Cluster.active( 2 ).REST.getNetCfg,
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700442 retValue=False,
443 kwargs={"subjectClass": "devices",
444 "subjectKey": "of:0000000000000004",
445 "configKey": "basic"},
446 attempts=main.retrytimes,
447 sleep=main.retrysleep )
448
Jon Hall66e001c2015-11-12 09:45:10 -0800449 onosCfg = pprint( getS4 )
450 sentCfg = pprint( s4Json )
451 if onosCfg == sentCfg:
452 s4Result = True
453 else:
454 main.log.error( "ONOS NetCfg doesn't match what was sent" )
455 main.log.debug( "ONOS config: {}".format( onosCfg ) )
456 main.log.debug( "Sent config: {}".format( sentCfg ) )
Devin Lim142b5342017-07-20 15:22:39 -0700457 main.step( "Retrying main.Cluster.active( 2 ).REST.getNetCfg" )
458 utilities.retry( f=main.Cluster.active( 2 ).REST.getNetCfg,
459 retValue=False,
460 attempts=main.retrytimes,
461 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800462 utilities.assert_equals( expect=True,
463 actual=s4Result,
464 onpass="Net Cfg added for device s4",
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700465 onfail="Net Cfg for device s4 not correctly set" )
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -0700466
Jon Hall66e001c2015-11-12 09:45:10 -0800467 main.netCfg.compareCfg( main, main.gossipTime )
468
469 def CASE23( self, main ):
470 """
471 Check of devices after all Network Configurations are set
472 """
473 import json
474 try:
475 assert main.s1Json, "s1Json not defined"
476 assert main.s2Json, "s2Json not defined"
477 except AssertionError:
478 main.log.exception( "Case Prerequisites not set: " )
Devin Lim44075962017-08-11 10:56:37 -0700479 main.cleanAndExit()
Jon Hall66e001c2015-11-12 09:45:10 -0800480 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" )
Devin Lim142b5342017-07-20 15:22:39 -0700485 devices = main.Cluster.active( 0 ).REST.devices()
486 main.log.debug( main.Cluster.active( 0 ).REST.pprint( devices ) )
Jon Hall66e001c2015-11-12 09:45:10 -0800487 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: " )
Devin Lim44075962017-08-11 10:56:37 -0700528 main.cleanAndExit()
Jon Hall66e001c2015-11-12 09:45:10 -0800529 main.case( "Testing removal of configurations" )
530 main.step( "Remove 'allowed' configuration from all devices" )
531
532 s1Json = main.s1Json # NOTE: This is a reference
533 try:
Jon Hallbc080f92017-05-24 16:29:55 -0700534 del s1Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800535 except KeyError:
536 main.log.exception( "Key not found" )
Devin Lim142b5342017-07-20 15:22:39 -0700537 setS1 = main.Cluster.active( 0 ).REST.setNetCfg( s1Json,
538 subjectClass="devices",
539 subjectKey="of:0000000000000001",
540 configKey="basic" )
Jon Hall66e001c2015-11-12 09:45:10 -0800541
542 s2Json = main.s2Json # NOTE: This is a reference
543 try:
Jon Hall541b8e02015-12-14 19:29:01 -0800544 time.sleep( main.gossipTime )
Jon Hallbc080f92017-05-24 16:29:55 -0700545 del s2Json[ '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 setS2 = main.Cluster.active( 1 ).REST.setNetCfg( s2Json,
549 subjectClass="devices",
550 subjectKey="of:0000000000000002",
551 configKey="basic" )
Jon Hall66e001c2015-11-12 09:45:10 -0800552
553 s3Json = main.s3Json # 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 s3Json[ '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 setS3 = main.Cluster.active( 2 ).REST.setNetCfg( s3Json,
560 subjectClass="devices",
561 subjectKey="of:0000000000000003",
562 configKey="basic" )
Jon Hall66e001c2015-11-12 09:45:10 -0800563
564 s4Json = main.s4Json # 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 s4Json[ '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 setS4 = main.Cluster.active( 2 ).REST.setNetCfg( s4Json,
571 subjectClass="devices",
572 subjectKey="of:0000000000000004",
573 configKey="basic" )
Jon Hall66e001c2015-11-12 09:45:10 -0800574 removeAllowed = setS1 and setS2 and setS3 and setS4
575 utilities.assert_equals( expect=main.TRUE,
576 actual=removeAllowed,
577 onpass="Successfully removed 'allowed' config from devices",
578 onfail="Failed to remove the 'allowed' config key." )
579
580 main.netCfg.compareCfg( main, main.gossipTime )
581
582 main.step( "Delete basic config for s1 and s2" )
Devin Lim142b5342017-07-20 15:22:39 -0700583 removeS1 = main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="devices",
584 subjectKey="of:0000000000000001",
585 configKey="basic" )
586 removeS2 = main.Cluster.active( 1 ).REST.removeNetCfg( subjectClass="devices",
587 subjectKey="of:0000000000000002",
588 configKey="basic" )
Jon Hall66e001c2015-11-12 09:45:10 -0800589 removeSingles = removeS1 and removeS2
590 utilities.assert_equals( expect=main.TRUE,
591 actual=removeSingles,
592 onpass="Successfully removed S1 and S2 basic config",
593 onfail="Failed to removed S1 and S2 basic config" )
594
595 main.netCfg.compareCfg( main, main.gossipTime )
596
597 main.step( "Delete the net config for S3" )
Devin Lim142b5342017-07-20 15:22:39 -0700598 removeS3 = main.Cluster.active( 2 ).REST.removeNetCfg( subjectClass="devices",
599 subjectKey="of:0000000000000003" )
Jon Hall66e001c2015-11-12 09:45:10 -0800600 utilities.assert_equals( expect=main.TRUE,
601 actual=removeS3,
602 onpass="Successfully removed S3's config",
603 onfail="Failed to removed S3's config" )
604
605 main.netCfg.compareCfg( main, main.gossipTime )
606
607 main.step( "Delete the net config for all devices" )
Devin Lim142b5342017-07-20 15:22:39 -0700608 remove = main.Cluster.active( 2 ).REST.removeNetCfg( subjectClass="devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800609 utilities.assert_equals( expect=main.TRUE,
610 actual=remove,
611 onpass="Successfully removed device config",
612 onfail="Failed to remove device config" )
613
614 main.netCfg.compareCfg( main, main.gossipTime )
615
616 main.step( "Assert the net config for devices is empty" )
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700617
Devin Lim142b5342017-07-20 15:22:39 -0700618 get = utilities.retry( f=main.Cluster.active( 2 ).REST.getNetCfg,
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700619 retValue = False,
620 kwargs={"subjectClass":"devices"},
621 sleep=main.retrysleep,
622 attempts=main.retrytimes )
623
Jon Hall66e001c2015-11-12 09:45:10 -0800624 utilities.assert_equals( expect='{}',
625 actual=get,
626 onpass="Successfully removed device config",
627 onfail="Failed to remove device config" )
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700628
629 def CASE25( self, main ):
630 """
631 Use network-cfg.json to configure devices during ONOS startup
632 """
633 main.case( "Preparing network-cfg.json to load configurations" )
634 main.step( "Moving network-cfg.json to $ONOS_ROOT/tools/package/config/" )
635 prestartResult = main.TRUE
636 srcPath = "~/OnosSystemTest/TestON/tests/FUNC/FUNCnetCfg/dependencies/network-cfg.json"
637 dstPath = "~/onos/tools/package/config/network-cfg.json"
638 prestartResult = main.ONOSbench.scp( main.ONOSbench, srcPath, dstPath, direction="to" )
639 utilities.assert_equals( expect=main.TRUE,
640 actual=prestartResult,
641 onpass="Successfully copied network-cfg.json to target directory",
642 onfail="Failed to copy network-cfg.json to target directory" )
643
644 def CASE26( self, main ):
645 """
646 Check to see that pre-startup configurations were set correctly
647 """
648 import json
649 main.case( "Check to see if the pre-startup configurations were set, then remove their allowed status" )
650 main.step( "Checking configurations for Switches 5 and 6" )
Jon Hallbc080f92017-05-24 16:29:55 -0700651 main.step( "ONOS should only show devices S1, S2, S4, and S5" ) # and S6
Devin Lim142b5342017-07-20 15:22:39 -0700652 devices = main.Cluster.active( 0 ).REST.devices()
653 main.log.debug( main.Cluster.active( 0 ).REST.pprint( devices ) )
Jon Hallbc080f92017-05-24 16:29:55 -0700654 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4, 5 ] ] # 6
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700655 main.log.debug( allowedDevices )
656 onosDevices = []
657 try:
658 for sw in json.loads( devices ):
Jon Hallbc080f92017-05-24 16:29:55 -0700659 onosDevices.append( str( sw[ 'id' ] ) )
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700660 onosDevices.sort()
661 main.log.debug( onosDevices )
662 except( TypeError, ValueError ):
663 main.log.error( "Problem loading devices" )
664 utilities.assert_equals( expect=allowedDevices,
665 actual=onosDevices,
666 onpass="Only allowed devices are in ONOS",
667 onfail="ONOS devices doesn't match the list" +
668 " of allowed devices" )
669
670 main.step( "Removing allowed status from Switches 5 and 6" )
Pratik Parab6f418632017-04-25 17:05:50 -0700671 try:
672 with open( os.path.dirname( main.testFile ) + '/dependencies/s5Json', 'r' ) as s5Jsondata:
673 main.s5Json = json.load( s5Jsondata )
674 except IOError:
675 main.log.exception( "s5Json File not found" )
Devin Lim44075962017-08-11 10:56:37 -0700676 main.cleanAndExit()
Pratik Parab6f418632017-04-25 17:05:50 -0700677 main.log.info( "s5Json:" + str( main.s5Json ) )
678
679 try:
680 with open( os.path.dirname( main.testFile ) + '/dependencies/s6Json', 'r' ) as s6Jsondata:
681 main.s6Json = json.load( s6Jsondata )
682 except IOError:
683 main.log.exception( "s6Json File not found" )
Devin Lim44075962017-08-11 10:56:37 -0700684 main.cleanAndExit()
Pratik Parab6f418632017-04-25 17:05:50 -0700685 main.log.info( "s6Json:" + str( main.s6Json ) )
686
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700687 s5Json = main.s5Json
Devin Lim142b5342017-07-20 15:22:39 -0700688 setS1 = main.Cluster.active( 0 ).REST.setNetCfg( s5Json,
689 subjectClass="devices",
690 subjectKey="of:0000000000000005",
691 configKey="basic" )
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700692
693 s6Json = main.s6Json
Devin Lim142b5342017-07-20 15:22:39 -0700694 setS1 = main.Cluster.active( 0 ).REST.setNetCfg( s6Json,
695 subjectClass="devices",
696 subjectKey="of:0000000000000006",
697 configKey="basic" )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700698
699 def CASE27( self, main ):
700 """
Jon Hallbc080f92017-05-24 16:29:55 -0700701 1 ) A = get /network/configuration
702 2 ) Post A
703 3 ) Compare A with ONOS
704 4 ) Modify A so S6 is disallowed
705 5 ) Check
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700706
707 """
708 import json
Devin Lim142b5342017-07-20 15:22:39 -0700709 pprint = main.Cluster.active( 0 ).REST.pprint
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700710 main.case( "Posting network configurations to the top level web resource" )
711 main.step( "Get json object from Net Cfg" )
Devin Lim142b5342017-07-20 15:22:39 -0700712 getinfo = utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg,
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700713 retValue=False,
714 sleep=main.retrysleep,
715 attempts=main.retrytimes )
716
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700717 main.log.debug( getinfo )
718 main.step( "Posting json object to Net Cfg" )
Devin Lim142b5342017-07-20 15:22:39 -0700719 postinfo = main.Cluster.active( 0 ).REST.setNetCfg( json.loads( getinfo ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700720 main.step( "Compare device with ONOS" )
721 main.netCfg.compareCfg( main )
Jon Hallbc080f92017-05-24 16:29:55 -0700722 main.step( "ONOS should only show devices S1, S2, S4, S5 and S6" )
Devin Lim142b5342017-07-20 15:22:39 -0700723 devices = main.Cluster.active( 0 ).REST.devices()
724 main.log.debug( main.Cluster.active( 0 ).REST.pprint( devices ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700725 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4, 5, 6 ] ]
726 onosDevices = []
727 try:
728 for sw in json.loads( devices ):
729 onosDevices.append( str( sw.get( 'id' ) ) )
Jon Hallbc080f92017-05-24 16:29:55 -0700730 onosDevices.sort()
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700731 failMsg = "ONOS devices doesn't match the list of allowed devices. \n"
732 failMsg += "Expected devices: {}\nActual devices: {}".format( allowedDevices, onosDevices )
733 except( TypeError, ValueError ):
734 main.log.error( "Problem loading devices" )
735 utilities.assert_equals( expect=allowedDevices, actual=onosDevices,
736 onpass="Only allowed devices are in ONOS", onfail=failMsg )
737
738 main.step( "Modify json object so S6 is disallowed" )
739 main.s6Json = { "allowed": False }
740 s6Json = main.s6Json
Devin Lim142b5342017-07-20 15:22:39 -0700741 setS6Disallow = main.Cluster.active( 0 ).REST.setNetCfg( s6Json,
742 subjectClass="devices",
743 subjectKey="of:0000000000000006",
744 configKey="basic" )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700745 s6Result = False
746 if setS6Disallow:
Devin Lim142b5342017-07-20 15:22:39 -0700747 getS6 = utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg,
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700748 retValue=False,
749 kwargs={"subjectClass":"devices",
750 "subjectKey" : "of:0000000000000006",
751 "configKey" : "basic"},
752 sleep=main.retrysleep,
753 attempts=main.retrytimes )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700754 onosCfg = pprint( getS6 )
755 sentCfg = pprint( s6Json )
756 if onosCfg == sentCfg:
757 s6Result = True
758 else:
759 main.log.error( "ONOS NetCfg doesn't match what was sent" )
760 main.log.debug( "ONOS config: {}".format( onosCfg ) )
761 main.log.debug( "Sent config: {}".format( sentCfg ) )
Devin Lim142b5342017-07-20 15:22:39 -0700762 utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg,
763 retValue=False,
764 attempts=main.retrytimes,
765 sleep=main.retrysleep )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700766 utilities.assert_equals( expect=True, actual=s6Result,
767 onpass="Net Cfg added for devices s6",
768 onfail="Net Cfg for device s6 not correctly set" )