blob: 4845974df051d3afe4ad044337380d2bbcf7176a [file] [log] [blame]
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07001"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002Copyright 2015 Open Networking Foundation ( ONF )
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07003
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
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070011 ( at your option ) any later version.
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070012
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# Testing the basic intent functionality of ONOS
22
Jon Hallbc080f92017-05-24 16:29:55 -070023
Jon Hall66e001c2015-11-12 09:45:10 -080024class FUNCnetCfg:
25
26 def __init__( self ):
27 self.default = ''
28
29 def CASE1( self, main ):
30 import imp
31 import re
Jon Hall66e001c2015-11-12 09:45:10 -080032 """
33 - Construct tests variables
34 - GIT ( optional )
35 - Checkout ONOS master branch
36 - Pull latest ONOS code
Jon Hall66e001c2015-11-12 09:45:10 -080037 """
Devin Lim58046fa2017-07-05 16:55:00 -070038 try:
39 from tests.dependencies.ONOSSetup import ONOSSetup
40 main.testSetUp = ONOSSetup()
41 except ImportError:
42 main.log.error( "ONOSSetup not found. exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070043 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070044 main.testSetUp.envSetupDescription()
Jon Hall66e001c2015-11-12 09:45:10 -080045 stepResult = main.FALSE
46
47 # Test variables
48 try:
Jon Hall66e001c2015-11-12 09:45:10 -080049 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
Jon Hall66e001c2015-11-12 09:45:10 -080050 main.dependencyPath = main.testOnDirectory + \
51 main.params[ 'DEPENDENCY' ][ 'path' ]
Jon Hall66e001c2015-11-12 09:45:10 -080052 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
53 wrapperFile2 = main.params[ 'DEPENDENCY' ][ 'wrapper2' ]
54 wrapperFile3 = main.params[ 'DEPENDENCY' ][ 'wrapper3' ]
55 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
Jon Hallbc080f92017-05-24 16:29:55 -070056 main.gossipTime = int( main.params[ 'SLEEP' ][ 'cfgGossip' ] )
alison15124df2016-10-06 12:04:51 -070057 main.SetNetCfgSleep = int( main.params[ 'SLEEP' ][ 'SetNetCfgSleep' ] )
Jon Hall66e001c2015-11-12 09:45:10 -080058 main.hostsData = {}
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -070059 main.retrytimes = int( main.params[ 'RETRY' ] )
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -070060 main.retrysleep = int( main.params[ 'RetrySleep' ] )
Jon Hall66e001c2015-11-12 09:45:10 -080061
62 # -- INIT SECTION, SHOULD ONLY BE RUN ONCE -- #
Jon Hall66e001c2015-11-12 09:45:10 -080063 main.netCfg = imp.load_source( wrapperFile2,
64 main.dependencyPath +
65 wrapperFile2 +
66 ".py" )
67
Devin Lim142b5342017-07-20 15:22:39 -070068 stepResult = main.testSetUp.envSetup()
Jon Hall66e001c2015-11-12 09:45:10 -080069 except Exception as e:
Devin Lim58046fa2017-07-05 16:55:00 -070070 main.testSetUp.envSetupException( e )
Jon Hallaa1d9b82020-07-30 13:49:42 -070071 main.testSetUp.envSetupConclusion( stepResult )
Jon Hall66e001c2015-11-12 09:45:10 -080072
73 def CASE2( self, main ):
74 """
75 - Set up cell
76 - Create cell file
77 - Set cell file
78 - Verify cell file
79 - Kill ONOS process
80 - Uninstall ONOS cluster
Jon Hall66e001c2015-11-12 09:45:10 -080081 - Install ONOS cluster
Jon Hall72ecaa02017-06-06 09:41:48 -070082 - Verify ONOS start up
Jon Hall66e001c2015-11-12 09:45:10 -080083 - Connect to cli
84 """
85 import time
You Wanga0f6ff62018-01-11 15:46:30 -080086 main.testSetUp.ONOSSetUp( main.Cluster )
Jon Hall66e001c2015-11-12 09:45:10 -080087
88 def CASE8( self, main ):
89 """
90 Compare Topo
91 """
Devin Lim58046fa2017-07-05 16:55:00 -070092 try:
93 from tests.dependencies.topology import Topology
94 except ImportError:
95 main.log.error( "Topology not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070096 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070097 try:
98 main.topoRelated
99 except ( NameError, AttributeError ):
100 main.topoRelated = Topology()
101 main.topoRelated.compareTopos( main.Mininet1 )
Jon Hall66e001c2015-11-12 09:45:10 -0800102
103 def CASE9( self, main ):
Jon Hallbc080f92017-05-24 16:29:55 -0700104 """
Jon Hall66e001c2015-11-12 09:45:10 -0800105 Report errors/warnings/exceptions
Jon Hallbc080f92017-05-24 16:29:55 -0700106 """
Jon Hall66e001c2015-11-12 09:45:10 -0800107 main.log.info( "Error report: \n" )
108 main.ONOSbench.logReport(
Devin Lim142b5342017-07-20 15:22:39 -0700109 main.Cluster.active( 0 ).ipAddress,
Jon Hallbc080f92017-05-24 16:29:55 -0700110 [ "INFO", "WARN", "ERROR", "Except" ],
Jon Hall66e001c2015-11-12 09:45:10 -0800111 "s" )
Jon Hallbc080f92017-05-24 16:29:55 -0700112 # main.ONOSbench.logReport( globalONOSip[ 1 ], [ "INFO" ], "d" )
Jon Hall66e001c2015-11-12 09:45:10 -0800113
114 def CASE10( self, main ):
115 """
116 Start Mininet topology with OF 1.0 switches
117 """
118 main.OFProtocol = "1.0"
119 main.log.report( "Start Mininet topology with OF 1.0 switches" )
120 main.case( "Start Mininet topology with OF 1.0 switches" )
121 main.caseExplanation = "Start mininet topology with OF 1.0 " +\
122 "switches to test intents, exits out if " +\
123 "topology did not start correctly"
124
125 main.step( "Starting Mininet topology with OF 1.0 switches" )
Jon Hall53c5e662016-04-13 16:06:56 -0700126 args = "--controller none --switch ovs,protocols=OpenFlow10"
Jon Hallbc080f92017-05-24 16:29:55 -0700127 switches = int( main.params[ 'MININET' ][ 'switch' ] )
Jon Hall66e001c2015-11-12 09:45:10 -0800128 cmd = "mn --topo linear,{} {}".format( switches, args )
Jon Hallbc080f92017-05-24 16:29:55 -0700129 topoResult = main.Mininet1.startNet( mnCmd=cmd )
Jon Hall66e001c2015-11-12 09:45:10 -0800130 stepResult = topoResult
131 utilities.assert_equals( expect=main.TRUE,
132 actual=stepResult,
133 onpass="Successfully loaded topology",
134 onfail="Failed to load topology" )
135 # Exit if topology did not load properly
136 if not topoResult:
Devin Lim44075962017-08-11 10:56:37 -0700137 main.cleanAndExit()
Jon Hall66e001c2015-11-12 09:45:10 -0800138
139 def CASE11( self, main ):
140 """
141 Start Mininet topology with OF 1.3 switches
142 """
143 import re
144 main.OFProtocol = "1.3"
145 main.log.report( "Start Mininet topology with OF 1.3 switches" )
146 main.case( "Start Mininet topology with OF 1.3 switches" )
147 main.caseExplanation = "Start mininet topology with OF 1.3 " +\
148 "switches to test intents, exits out if " +\
149 "topology did not start correctly"
150
151 main.step( "Starting Mininet topology with OF 1.3 switches" )
Jon Hall53c5e662016-04-13 16:06:56 -0700152 args = "--controller none --switch ovs,protocols=OpenFlow13"
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700153 switches = int( main.params[ 'MININET' ][ 'switch' ] )
Jon Hall66e001c2015-11-12 09:45:10 -0800154 cmd = "mn --topo linear,{} {}".format( switches, args )
Jon Hallbc080f92017-05-24 16:29:55 -0700155 topoResult = main.Mininet1.startNet( mnCmd=cmd )
Jon Hall66e001c2015-11-12 09:45:10 -0800156 stepResult = topoResult
157 utilities.assert_equals( expect=main.TRUE,
158 actual=stepResult,
159 onpass="Successfully loaded topology",
160 onfail="Failed to load topology" )
161 # Exit if topology did not load properly
162 if not topoResult:
Devin Lim44075962017-08-11 10:56:37 -0700163 main.cleanAndExit()
Jon Hall66e001c2015-11-12 09:45:10 -0800164
Devin Lim142b5342017-07-20 15:22:39 -0700165 tempONOSip = main.Cluster.getIps()
Jon Hall66e001c2015-11-12 09:45:10 -0800166
167 swList = [ "s" + str( i ) for i in range( 1, switches + 1 ) ]
168 assignResult = main.Mininet1.assignSwController( sw=swList,
169 ip=tempONOSip,
170 port='6653' )
171 if not assignResult:
Devin Lim44075962017-08-11 10:56:37 -0700172 main.cleanAndExit()
Jon Hall66e001c2015-11-12 09:45:10 -0800173
174 assignResult = main.TRUE
175 for sw in swList:
176 response = main.Mininet1.getSwController( "s" + str( i ) )
177 main.log.info( "Response is " + str( response ) )
178 for ip in tempONOSip:
179 if re.search( "tcp:" + ip, response ):
180 assignResult = assignResult and main.TRUE
181 else:
182 assignResult = assignResult and main.FALSE
183 stepResult = assignResult
184 utilities.assert_equals( expect=main.TRUE,
185 actual=stepResult,
186 onpass="Successfully assigned switches" +
187 "to controller",
188 onfail="Failed to assign switches to " +
189 "controller" )
190
191 def CASE14( self, main ):
192 """
193 Stop mininet
194 """
Devin Lim58046fa2017-07-05 16:55:00 -0700195 try:
196 from tests.dependencies.utils import Utils
197 except ImportError:
198 main.log.error( "Utils not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700199 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700200 try:
201 main.Utils
202 except ( NameError, AttributeError ):
203 main.Utils = Utils()
204 main.Utils.mininetCleanIntro()
205 topoResult = main.Utils.mininetCleanup( main.Mininet1 )
Jon Hall66e001c2015-11-12 09:45:10 -0800206 # Exit if topology did not load properly
207 if not topoResult:
Devin Lim44075962017-08-11 10:56:37 -0700208 main.cleanAndExit()
Jon Hall66e001c2015-11-12 09:45:10 -0800209
210 def CASE20( self, main ):
211 """
212 Add some device configurations and then check they are distributed
213 to all nodes
214 """
alison15124df2016-10-06 12:04:51 -0700215 import time
Pratik Parabc6083c22017-04-27 13:24:41 -0700216 import json
217 import os
Jon Hall66e001c2015-11-12 09:45:10 -0800218 main.case( "Add Network configurations to the cluster" )
219 main.caseExplanation = "Add Network Configurations for devices" +\
220 " not discovered yet. One device is allowed" +\
221 ", the other disallowed."
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -0700222
Devin Lim142b5342017-07-20 15:22:39 -0700223 pprint = main.Cluster.active( 0 ).REST.pprint
Jon Hall66e001c2015-11-12 09:45:10 -0800224
225 main.step( "Add Net Cfg for switch1" )
Pratik Parab6f418632017-04-25 17:05:50 -0700226
Pratik Parab6f418632017-04-25 17:05:50 -0700227 try:
228 with open( os.path.dirname( main.testFile ) + '/dependencies/s1Json', 'r' ) as s1Jsondata:
229 s1Json = json.load( s1Jsondata )
230 except IOError:
231 main.log.exception( "s1Json File not found." )
Devin Lim44075962017-08-11 10:56:37 -0700232 main.cleanAndExit()
Pratik Parab6f418632017-04-25 17:05:50 -0700233 main.log.info( "s1Json:" + str( s1Json ) )
234
Jon Hall66e001c2015-11-12 09:45:10 -0800235 main.s1Json = s1Json
Devin Lim142b5342017-07-20 15:22:39 -0700236 setS1Allow = main.Cluster.active( 0 ).REST.setNetCfg( s1Json,
237 subjectClass="devices",
238 subjectKey="of:0000000000000001",
239 configKey="basic" )
Jon Hall66e001c2015-11-12 09:45:10 -0800240 s1Result = False
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700241 # Wait 5 secs after set up netCfg
alison15124df2016-10-06 12:04:51 -0700242 time.sleep( main.SetNetCfgSleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800243 if setS1Allow:
Devin Lim142b5342017-07-20 15:22:39 -0700244 getS1 = utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg,
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700245 retValue=False,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700246 kwargs={ "subjectClass": "devices",
247 "subjectKey": "of:0000000000000001",
248 "configKey": "basic" },
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700249 attempts=main.retrytimes,
250 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800251 onosCfg = pprint( getS1 )
252 sentCfg = pprint( s1Json )
253 if onosCfg == sentCfg:
alison15124df2016-10-06 12:04:51 -0700254 main.log.info( "ONOS NetCfg match what was sent" )
Jon Hall66e001c2015-11-12 09:45:10 -0800255 s1Result = True
256 else:
257 main.log.error( "ONOS NetCfg doesn't match what was sent" )
258 main.log.debug( "ONOS config: {}".format( onosCfg ) )
259 main.log.debug( "Sent config: {}".format( sentCfg ) )
Devin Lim142b5342017-07-20 15:22:39 -0700260 utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg,
261 retValue=False,
262 attempts=main.retrytimes,
263 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800264 utilities.assert_equals( expect=True,
265 actual=s1Result,
266 onpass="Net Cfg added for device s1",
267 onfail="Net Cfg for device s1 not correctly set" )
268
269 main.step( "Add Net Cfg for switch3" )
Pratik Parab6f418632017-04-25 17:05:50 -0700270
271 try:
272 with open( os.path.dirname( main.testFile ) + '/dependencies/s3Json', 'r' ) as s3Jsondata:
273 s3Json = json.load( s3Jsondata )
274 except IOError:
275 main.log.exception( "s3Json File not found" )
Devin Lim44075962017-08-11 10:56:37 -0700276 main.cleanAndExit()
Jon Hallbc080f92017-05-24 16:29:55 -0700277 main.log.info( "s3Json:" + str( s3Json ) )
Pratik Parab6f418632017-04-25 17:05:50 -0700278
Jon Hall66e001c2015-11-12 09:45:10 -0800279 main.s3Json = s3Json
Devin Lim142b5342017-07-20 15:22:39 -0700280 setS3Disallow = main.Cluster.active( 0 ).REST.setNetCfg( s3Json,
281 subjectClass="devices",
282 subjectKey="of:0000000000000003",
283 configKey="basic" )
Jon Hall66e001c2015-11-12 09:45:10 -0800284 s3Result = False
alison15124df2016-10-06 12:04:51 -0700285 time.sleep( main.SetNetCfgSleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800286 if setS3Disallow:
287 # Check what we set is what is in ONOS
Devin Lim142b5342017-07-20 15:22:39 -0700288 getS3 = utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg,
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700289 retValue=False,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700290 kwargs={ "subjectClass": "devices",
291 "subjectKey": "of:0000000000000003",
292 "configKey": "basic" },
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700293 attempts=main.retrytimes,
294 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800295 onosCfg = pprint( getS3 )
296 sentCfg = pprint( s3Json )
297 if onosCfg == sentCfg:
Jon Hallbc080f92017-05-24 16:29:55 -0700298 main.log.info( "ONOS NetCfg match what was sent" )
Jon Hall66e001c2015-11-12 09:45:10 -0800299 s3Result = True
300 else:
301 main.log.error( "ONOS NetCfg doesn't match what was sent" )
302 main.log.debug( "ONOS config: {}".format( onosCfg ) )
303 main.log.debug( "Sent config: {}".format( sentCfg ) )
Devin Lim142b5342017-07-20 15:22:39 -0700304 utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg,
305 retValue=False,
306 attempts=main.retrytimes,
307 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800308 utilities.assert_equals( expect=True,
309 actual=s3Result,
310 onpass="Net Cfg added for device s3",
311 onfail="Net Cfg for device s3 not correctly set" )
312 main.netCfg.compareCfg( main, main.gossipTime )
313
314 def CASE21( self, main ):
315 """
316 Initial check of devices
317 """
318 import json
319 try:
320 assert main.s1Json, "s1Json not defined"
321 except AssertionError:
322 main.log.exception( "Case Prerequisites not set: " )
Devin Lim44075962017-08-11 10:56:37 -0700323 main.cleanAndExit()
Jon Hall66e001c2015-11-12 09:45:10 -0800324 main.case( "Check Devices After they initially connect to ONOS" )
325
326 main.netCfg.compareCfg( main )
327
328 main.step( "ONOS should only show devices S1, S2, and S4" )
Devin Lim142b5342017-07-20 15:22:39 -0700329 devices = main.Cluster.active( 0 ).REST.devices()
330 main.log.debug( main.Cluster.active( 0 ).REST.pprint( devices ) )
Jon Hall66e001c2015-11-12 09:45:10 -0800331 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4 ] ]
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700332 main.log.debug( allowedDevices )
Jon Hall66e001c2015-11-12 09:45:10 -0800333 onosDevices = []
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700334 try:
335 for sw in json.loads( devices ):
Jon Hallbc080f92017-05-24 16:29:55 -0700336 onosDevices.append( str( sw[ 'id' ] ) )
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700337 onosDevices.sort()
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700338 main.log.debug( onosDevices )
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700339 except( TypeError, ValueError ):
340 main.log.error( "Problem loading devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800341 utilities.assert_equals( expect=allowedDevices,
342 actual=onosDevices,
343 onpass="Only allowed devices are in ONOS",
344 onfail="ONOS devices doesn't match the list" +
345 " of allowed devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800346 main.step( "Check device annotations" )
347 keys = [ 'name', 'owner', 'rackAddress' ]
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700348 try:
349 for sw in json.loads( devices ):
Jon Hallbc080f92017-05-24 16:29:55 -0700350 if "of:0000000000000001" in sw[ 'id' ]:
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700351 s1Correct = True
352 for k in keys:
Jon Hallbc080f92017-05-24 16:29:55 -0700353 if str( sw.get( 'annotations', {} ).get( k ) ) != str( main.s1Json[ k ] ):
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700354 s1Correct = False
355 main.log.debug( "{} is wrong on s1".format( k ) )
356 if not s1Correct:
357 main.log.error( "Annotations for s1 are incorrect: {}".format( sw ) )
358 except( TypeError, ValueError ):
359 main.log.error( "Problem loading devices" )
360 s1Correct = False
Jon Hall66e001c2015-11-12 09:45:10 -0800361 try:
362 stepResult = s1Correct
363 except NameError:
364 stepResult = False
365 main.log.error( "s1 not found in devices" )
366 utilities.assert_equals( expect=True,
367 actual=stepResult,
368 onpass="Configured device's annotations are correct",
369 onfail="Incorrect annotations for configured devices." )
370
371 def CASE22( self, main ):
372 """
373 Add some device configurations for connected devices and then check
374 they are distributed to all nodes
375 """
376 main.case( "Add Network configurations for connected devices to the cluster" )
377 main.caseExplanation = "Add Network Configurations for discovered " +\
378 "devices. One device is allowed" +\
379 ", the other disallowed."
Devin Lim142b5342017-07-20 15:22:39 -0700380 pprint = main.Cluster.active( 0 ).REST.pprint
Jon Hall66e001c2015-11-12 09:45:10 -0800381
382 main.step( "Add Net Cfg for switch2" )
Pratik Parab6f418632017-04-25 17:05:50 -0700383 try:
384 with open( os.path.dirname( main.testFile ) + '/dependencies/s2Json', 'r' ) as s2Jsondata:
385 s2Json = json.load( s2Jsondata )
386 except IOError:
387 main.log.exception( "s2Json File not found" )
Devin Lim44075962017-08-11 10:56:37 -0700388 main.cleanAndExit()
Pratik Parab6f418632017-04-25 17:05:50 -0700389 main.log.info( "s2Json:" + str( s2Json ) )
Jon Hall66e001c2015-11-12 09:45:10 -0800390 main.s2Json = s2Json
Devin Lim142b5342017-07-20 15:22:39 -0700391 setS2Allow = main.Cluster.active( 1 ).REST.setNetCfg( s2Json,
392 subjectClass="devices",
393 subjectKey="of:0000000000000002",
394 configKey="basic" )
Jon Hall66e001c2015-11-12 09:45:10 -0800395 s2Result = False
396 if setS2Allow:
397 # Check what we set is what is in ONOS
Devin Lim142b5342017-07-20 15:22:39 -0700398 getS2 = utilities.retry( f=main.Cluster.active( 1 ).REST.getNetCfg,
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700399 retValue=False,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700400 kwargs={ "subjectClass": "devices",
401 "subjectKey": "of:0000000000000002",
402 "configKey": "basic" },
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700403 attempts=main.retrytimes,
404 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800405 onosCfg = pprint( getS2 )
406 sentCfg = pprint( s2Json )
407 if onosCfg == sentCfg:
408 s2Result = True
409 else:
410 main.log.error( "ONOS NetCfg doesn't match what was sent" )
411 main.log.debug( "ONOS config: {}".format( onosCfg ) )
412 main.log.debug( "Sent config: {}".format( sentCfg ) )
Devin Lim142b5342017-07-20 15:22:39 -0700413 utilities.retry( f=main.Cluster.active( 1 ).REST.getNetCfg,
414 retValue=False,
415 attempts=main.retrytimes,
416 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800417 utilities.assert_equals( expect=True,
418 actual=s2Result,
419 onpass="Net Cfg added for device s2",
420 onfail="Net Cfg for device s2 not correctly set" )
Jon Hall66e001c2015-11-12 09:45:10 -0800421 main.step( "Add Net Cfg for switch4" )
Pratik Parab6f418632017-04-25 17:05:50 -0700422
423 try:
424 with open( os.path.dirname( main.testFile ) + '/dependencies/s4Json', 'r' ) as s4Jsondata:
425 s4Json = json.load( s4Jsondata )
426 except IOError:
427 main.log.exception( "s4Json File not found" )
Devin Lim44075962017-08-11 10:56:37 -0700428 main.cleanAndExit()
Pratik Parab6f418632017-04-25 17:05:50 -0700429 main.log.info( "s4Json:" + str( s4Json ) )
Jon Hall66e001c2015-11-12 09:45:10 -0800430 main.s4Json = s4Json
Devin Lim142b5342017-07-20 15:22:39 -0700431 setS4Disallow = main.Cluster.active( 2 ).REST.setNetCfg( s4Json,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700432 subjectClass="devices",
433 subjectKey="of:0000000000000004",
434 configKey="basic" )
Jon Hall66e001c2015-11-12 09:45:10 -0800435 s4Result = False
436 if setS4Disallow:
437 # Check what we set is what is in ONOS
Devin Lim142b5342017-07-20 15:22:39 -0700438 getS4 = utilities.retry( f=main.Cluster.active( 2 ).REST.getNetCfg,
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700439 retValue=False,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700440 kwargs={ "subjectClass": "devices",
441 "subjectKey": "of:0000000000000004",
442 "configKey": "basic" },
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700443 attempts=main.retrytimes,
444 sleep=main.retrysleep )
445
Jon Hall66e001c2015-11-12 09:45:10 -0800446 onosCfg = pprint( getS4 )
447 sentCfg = pprint( s4Json )
448 if onosCfg == sentCfg:
449 s4Result = True
450 else:
451 main.log.error( "ONOS NetCfg doesn't match what was sent" )
452 main.log.debug( "ONOS config: {}".format( onosCfg ) )
453 main.log.debug( "Sent config: {}".format( sentCfg ) )
Devin Lim142b5342017-07-20 15:22:39 -0700454 main.step( "Retrying main.Cluster.active( 2 ).REST.getNetCfg" )
455 utilities.retry( f=main.Cluster.active( 2 ).REST.getNetCfg,
456 retValue=False,
457 attempts=main.retrytimes,
458 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800459 utilities.assert_equals( expect=True,
460 actual=s4Result,
461 onpass="Net Cfg added for device s4",
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700462 onfail="Net Cfg for device s4 not correctly set" )
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -0700463
Jon Hall66e001c2015-11-12 09:45:10 -0800464 main.netCfg.compareCfg( main, main.gossipTime )
465
466 def CASE23( self, main ):
467 """
468 Check of devices after all Network Configurations are set
469 """
470 import json
471 try:
472 assert main.s1Json, "s1Json not defined"
473 assert main.s2Json, "s2Json not defined"
474 except AssertionError:
475 main.log.exception( "Case Prerequisites not set: " )
Devin Lim44075962017-08-11 10:56:37 -0700476 main.cleanAndExit()
Jon Hall66e001c2015-11-12 09:45:10 -0800477 main.case( "Check Devices after all configurations are set" )
478
479 main.netCfg.compareCfg( main )
480
481 main.step( "ONOS should only show devices S1 and S2" )
Devin Lim142b5342017-07-20 15:22:39 -0700482 devices = main.Cluster.active( 0 ).REST.devices()
483 main.log.debug( main.Cluster.active( 0 ).REST.pprint( devices ) )
Jon Hall66e001c2015-11-12 09:45:10 -0800484 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2 ] ]
485 onosDevices = []
Jeremy Songster5c3fdb42016-04-27 12:19:27 -0700486 try:
487 for sw in json.loads( devices ):
488 onosDevices.append( str( sw.get( 'id' ) ) )
489 onosDevices.sort()
490 failMsg = "ONOS devices doesn't match the list of allowed devices.\n"
491 failMsg += "Expected devices: {}\nActual devices: {}".format( allowedDevices,
492 onosDevices )
493 except( TypeError, ValueError ):
494 main.log.error( "Problem loading devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800495 utilities.assert_equals( expect=allowedDevices,
496 actual=onosDevices,
497 onpass="Only allowed devices are in ONOS",
498 onfail=failMsg )
499
500 main.step( "Check device annotations" )
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -0700501 stepResult = utilities.retry( f=main.netCfg.checkAllDeviceAnnotations,
502 args=( main, json ),
503 retValue=False,
504 attempts=main.retrytimes,
505 sleep=main.retrysleep )
Jon Hall66e001c2015-11-12 09:45:10 -0800506 utilities.assert_equals( expect=True,
507 actual=stepResult,
Jeremy Ronquillo4cf537d2017-06-26 11:20:52 -0700508 onpass="Configured devices' annotations are correct",
Jon Hall66e001c2015-11-12 09:45:10 -0800509 onfail="Incorrect annotations for configured devices." )
510
511 def CASE24( self, main ):
512 """
513 Testing removal of configurations
514 """
Jon Hall541b8e02015-12-14 19:29:01 -0800515 import time
Jon Hall66e001c2015-11-12 09:45:10 -0800516 try:
517 assert main.s1Json, "s1Json not defined"
518 assert main.s2Json, "s2Json not defined"
519 assert main.s3Json, "s3Json not defined"
520 assert main.s4Json, "s4Json not defined"
521 except AssertionError:
522 main.log.exception( "Case Prerequisites not set: " )
Devin Lim44075962017-08-11 10:56:37 -0700523 main.cleanAndExit()
Jon Hall66e001c2015-11-12 09:45:10 -0800524 main.case( "Testing removal of configurations" )
525 main.step( "Remove 'allowed' configuration from all devices" )
526
527 s1Json = main.s1Json # NOTE: This is a reference
528 try:
Jon Hallbc080f92017-05-24 16:29:55 -0700529 del s1Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800530 except KeyError:
531 main.log.exception( "Key not found" )
Devin Lim142b5342017-07-20 15:22:39 -0700532 setS1 = main.Cluster.active( 0 ).REST.setNetCfg( s1Json,
533 subjectClass="devices",
534 subjectKey="of:0000000000000001",
535 configKey="basic" )
Jon Hall66e001c2015-11-12 09:45:10 -0800536
537 s2Json = main.s2Json # NOTE: This is a reference
538 try:
Jon Hall541b8e02015-12-14 19:29:01 -0800539 time.sleep( main.gossipTime )
Jon Hallbc080f92017-05-24 16:29:55 -0700540 del s2Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800541 except KeyError:
542 main.log.exception( "Key not found" )
Devin Lim142b5342017-07-20 15:22:39 -0700543 setS2 = main.Cluster.active( 1 ).REST.setNetCfg( s2Json,
544 subjectClass="devices",
545 subjectKey="of:0000000000000002",
546 configKey="basic" )
Jon Hall66e001c2015-11-12 09:45:10 -0800547
548 s3Json = main.s3Json # NOTE: This is a reference
549 try:
Jon Hall541b8e02015-12-14 19:29:01 -0800550 time.sleep( main.gossipTime )
Jon Hallbc080f92017-05-24 16:29:55 -0700551 del s3Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800552 except KeyError:
553 main.log.exception( "Key not found" )
Devin Lim142b5342017-07-20 15:22:39 -0700554 setS3 = main.Cluster.active( 2 ).REST.setNetCfg( s3Json,
555 subjectClass="devices",
556 subjectKey="of:0000000000000003",
557 configKey="basic" )
Jon Hall66e001c2015-11-12 09:45:10 -0800558
559 s4Json = main.s4Json # NOTE: This is a reference
560 try:
Jon Hall541b8e02015-12-14 19:29:01 -0800561 time.sleep( main.gossipTime )
Jon Hallbc080f92017-05-24 16:29:55 -0700562 del s4Json[ 'allowed' ]
Jon Hall66e001c2015-11-12 09:45:10 -0800563 except KeyError:
564 main.log.exception( "Key not found" )
Devin Lim142b5342017-07-20 15:22:39 -0700565 setS4 = main.Cluster.active( 2 ).REST.setNetCfg( s4Json,
566 subjectClass="devices",
567 subjectKey="of:0000000000000004",
568 configKey="basic" )
Jon Hall66e001c2015-11-12 09:45:10 -0800569 removeAllowed = setS1 and setS2 and setS3 and setS4
570 utilities.assert_equals( expect=main.TRUE,
571 actual=removeAllowed,
572 onpass="Successfully removed 'allowed' config from devices",
573 onfail="Failed to remove the 'allowed' config key." )
574
575 main.netCfg.compareCfg( main, main.gossipTime )
576
577 main.step( "Delete basic config for s1 and s2" )
Devin Lim142b5342017-07-20 15:22:39 -0700578 removeS1 = main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="devices",
579 subjectKey="of:0000000000000001",
580 configKey="basic" )
581 removeS2 = main.Cluster.active( 1 ).REST.removeNetCfg( subjectClass="devices",
582 subjectKey="of:0000000000000002",
583 configKey="basic" )
Jon Hall66e001c2015-11-12 09:45:10 -0800584 removeSingles = removeS1 and removeS2
585 utilities.assert_equals( expect=main.TRUE,
586 actual=removeSingles,
587 onpass="Successfully removed S1 and S2 basic config",
588 onfail="Failed to removed S1 and S2 basic config" )
589
590 main.netCfg.compareCfg( main, main.gossipTime )
591
592 main.step( "Delete the net config for S3" )
Devin Lim142b5342017-07-20 15:22:39 -0700593 removeS3 = main.Cluster.active( 2 ).REST.removeNetCfg( subjectClass="devices",
594 subjectKey="of:0000000000000003" )
Jon Hall66e001c2015-11-12 09:45:10 -0800595 utilities.assert_equals( expect=main.TRUE,
596 actual=removeS3,
597 onpass="Successfully removed S3's config",
598 onfail="Failed to removed S3's config" )
599
600 main.netCfg.compareCfg( main, main.gossipTime )
601
602 main.step( "Delete the net config for all devices" )
Devin Lim142b5342017-07-20 15:22:39 -0700603 remove = main.Cluster.active( 2 ).REST.removeNetCfg( subjectClass="devices" )
Jon Hall66e001c2015-11-12 09:45:10 -0800604 utilities.assert_equals( expect=main.TRUE,
605 actual=remove,
606 onpass="Successfully removed device config",
607 onfail="Failed to remove device config" )
608
609 main.netCfg.compareCfg( main, main.gossipTime )
610
611 main.step( "Assert the net config for devices is empty" )
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700612
Devin Lim142b5342017-07-20 15:22:39 -0700613 get = utilities.retry( f=main.Cluster.active( 2 ).REST.getNetCfg,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700614 retValue=False,
615 kwargs={ "subjectClass": "devices" },
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700616 sleep=main.retrysleep,
617 attempts=main.retrytimes )
618
Jon Hall66e001c2015-11-12 09:45:10 -0800619 utilities.assert_equals( expect='{}',
620 actual=get,
621 onpass="Successfully removed device config",
622 onfail="Failed to remove device config" )
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700623
624 def CASE25( self, main ):
625 """
626 Use network-cfg.json to configure devices during ONOS startup
627 """
628 main.case( "Preparing network-cfg.json to load configurations" )
629 main.step( "Moving network-cfg.json to $ONOS_ROOT/tools/package/config/" )
630 prestartResult = main.TRUE
631 srcPath = "~/OnosSystemTest/TestON/tests/FUNC/FUNCnetCfg/dependencies/network-cfg.json"
632 dstPath = "~/onos/tools/package/config/network-cfg.json"
633 prestartResult = main.ONOSbench.scp( main.ONOSbench, srcPath, dstPath, direction="to" )
634 utilities.assert_equals( expect=main.TRUE,
635 actual=prestartResult,
636 onpass="Successfully copied network-cfg.json to target directory",
637 onfail="Failed to copy network-cfg.json to target directory" )
638
639 def CASE26( self, main ):
640 """
641 Check to see that pre-startup configurations were set correctly
642 """
643 import json
644 main.case( "Check to see if the pre-startup configurations were set, then remove their allowed status" )
645 main.step( "Checking configurations for Switches 5 and 6" )
Jon Hallbc080f92017-05-24 16:29:55 -0700646 main.step( "ONOS should only show devices S1, S2, S4, and S5" ) # and S6
Devin Lim142b5342017-07-20 15:22:39 -0700647 devices = main.Cluster.active( 0 ).REST.devices()
648 main.log.debug( main.Cluster.active( 0 ).REST.pprint( devices ) )
Jon Hallbc080f92017-05-24 16:29:55 -0700649 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4, 5 ] ] # 6
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700650 main.log.debug( allowedDevices )
651 onosDevices = []
652 try:
653 for sw in json.loads( devices ):
Jon Hallbc080f92017-05-24 16:29:55 -0700654 onosDevices.append( str( sw[ 'id' ] ) )
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700655 onosDevices.sort()
656 main.log.debug( onosDevices )
657 except( TypeError, ValueError ):
658 main.log.error( "Problem loading devices" )
659 utilities.assert_equals( expect=allowedDevices,
660 actual=onosDevices,
661 onpass="Only allowed devices are in ONOS",
662 onfail="ONOS devices doesn't match the list" +
663 " of allowed devices" )
664
665 main.step( "Removing allowed status from Switches 5 and 6" )
Pratik Parab6f418632017-04-25 17:05:50 -0700666 try:
667 with open( os.path.dirname( main.testFile ) + '/dependencies/s5Json', 'r' ) as s5Jsondata:
668 main.s5Json = json.load( s5Jsondata )
669 except IOError:
670 main.log.exception( "s5Json File not found" )
Devin Lim44075962017-08-11 10:56:37 -0700671 main.cleanAndExit()
Pratik Parab6f418632017-04-25 17:05:50 -0700672 main.log.info( "s5Json:" + str( main.s5Json ) )
673
674 try:
675 with open( os.path.dirname( main.testFile ) + '/dependencies/s6Json', 'r' ) as s6Jsondata:
676 main.s6Json = json.load( s6Jsondata )
677 except IOError:
678 main.log.exception( "s6Json File not found" )
Devin Lim44075962017-08-11 10:56:37 -0700679 main.cleanAndExit()
Pratik Parab6f418632017-04-25 17:05:50 -0700680 main.log.info( "s6Json:" + str( main.s6Json ) )
681
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700682 s5Json = main.s5Json
Devin Lim142b5342017-07-20 15:22:39 -0700683 setS1 = main.Cluster.active( 0 ).REST.setNetCfg( s5Json,
684 subjectClass="devices",
685 subjectKey="of:0000000000000005",
686 configKey="basic" )
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700687
Jeremy Ronquillo9865a4d2017-12-07 13:08:27 -0800688 # Wait 5 secs after set up netCfg
689 time.sleep( main.SetNetCfgSleep )
690
Jeremy Songster2baa44e2016-06-10 10:18:40 -0700691 s6Json = main.s6Json
Devin Lim142b5342017-07-20 15:22:39 -0700692 setS1 = main.Cluster.active( 0 ).REST.setNetCfg( s6Json,
693 subjectClass="devices",
694 subjectKey="of:0000000000000006",
695 configKey="basic" )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700696
Jeremy Ronquillo9865a4d2017-12-07 13:08:27 -0800697 # Wait 5 secs after set up netCfg
698 time.sleep( main.SetNetCfgSleep )
699
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700700 def CASE27( self, main ):
701 """
Jon Hallbc080f92017-05-24 16:29:55 -0700702 1 ) A = get /network/configuration
703 2 ) Post A
704 3 ) Compare A with ONOS
705 4 ) Modify A so S6 is disallowed
706 5 ) Check
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700707
708 """
709 import json
Devin Lim142b5342017-07-20 15:22:39 -0700710 pprint = main.Cluster.active( 0 ).REST.pprint
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700711 main.case( "Posting network configurations to the top level web resource" )
712 main.step( "Get json object from Net Cfg" )
Devin Lim142b5342017-07-20 15:22:39 -0700713 getinfo = utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg,
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700714 retValue=False,
715 sleep=main.retrysleep,
716 attempts=main.retrytimes )
717
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700718 main.log.debug( getinfo )
719 main.step( "Posting json object to Net Cfg" )
Devin Lim142b5342017-07-20 15:22:39 -0700720 postinfo = main.Cluster.active( 0 ).REST.setNetCfg( json.loads( getinfo ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700721 main.step( "Compare device with ONOS" )
722 main.netCfg.compareCfg( main )
Jon Hallbc080f92017-05-24 16:29:55 -0700723 main.step( "ONOS should only show devices S1, S2, S4, S5 and S6" )
Devin Lim142b5342017-07-20 15:22:39 -0700724 devices = main.Cluster.active( 0 ).REST.devices()
725 main.log.debug( main.Cluster.active( 0 ).REST.pprint( devices ) )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700726 allowedDevices = [ "of:{}".format( str( i ).zfill( 16 ) ) for i in [ 1, 2, 4, 5, 6 ] ]
727 onosDevices = []
728 try:
729 for sw in json.loads( devices ):
730 onosDevices.append( str( sw.get( 'id' ) ) )
Jon Hallbc080f92017-05-24 16:29:55 -0700731 onosDevices.sort()
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700732 failMsg = "ONOS devices doesn't match the list of allowed devices. \n"
733 failMsg += "Expected devices: {}\nActual devices: {}".format( allowedDevices, onosDevices )
734 except( TypeError, ValueError ):
735 main.log.error( "Problem loading devices" )
736 utilities.assert_equals( expect=allowedDevices, actual=onosDevices,
737 onpass="Only allowed devices are in ONOS", onfail=failMsg )
738
739 main.step( "Modify json object so S6 is disallowed" )
740 main.s6Json = { "allowed": False }
741 s6Json = main.s6Json
Devin Lim142b5342017-07-20 15:22:39 -0700742 setS6Disallow = main.Cluster.active( 0 ).REST.setNetCfg( s6Json,
743 subjectClass="devices",
744 subjectKey="of:0000000000000006",
745 configKey="basic" )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700746 s6Result = False
747 if setS6Disallow:
Devin Lim142b5342017-07-20 15:22:39 -0700748 getS6 = utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg,
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700749 retValue=False,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700750 kwargs={ "subjectClass": "devices",
751 "subjectKey": "of:0000000000000006",
752 "configKey": "basic" },
Jeremy Ronquillo4a30ffe2017-06-07 11:36:35 -0700753 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 ) )
Devin Lim142b5342017-07-20 15:22:39 -0700763 utilities.retry( f=main.Cluster.active( 0 ).REST.getNetCfg,
764 retValue=False,
765 attempts=main.retrytimes,
766 sleep=main.retrysleep )
Ming Yan Shudb74bf22016-06-23 14:56:22 -0700767 utilities.assert_equals( expect=True, actual=s6Result,
768 onpass="Net Cfg added for devices s6",
769 onfail="Net Cfg for device s6 not correctly set" )