blob: 5ffed7c3cfcc032a01162c375aa0dc5eb36e95d2 [file] [log] [blame]
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07001"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002Copyright 2016 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 Hall1efcb3f2016-08-23 13:42:15 -070021import os
22import imp
23import time
24import json
25import urllib
26from core import utilities
27
28
29class Testcaselib:
Pierfb719b12016-09-19 14:51:44 -070030
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070031 useSSH = True
Pierfb719b12016-09-19 14:51:44 -070032
Jon Hall1efcb3f2016-08-23 13:42:15 -070033 @staticmethod
34 def initTest( main ):
35 """
36 - Construct tests variables
37 - GIT ( optional )
38 - Checkout ONOS master branch
39 - Pull latest ONOS code
40 - Building ONOS ( optional )
41 - Install ONOS package
42 - Build ONOS package
43 """
Devin Lim58046fa2017-07-05 16:55:00 -070044 try:
45 from tests.dependencies.ONOSSetup import ONOSSetup
46 main.testSetUp = ONOSSetup()
47 except ImportError:
48 main.log.error( "ONOSSetup not found. exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070049 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070050 main.testSetUp.envSetupDescription()
51 stepResult = main.FALSE
52 try:
53 main.step( "Constructing test variables" )
54 # Test variables
55 main.cellName = main.params[ 'ENV' ][ 'cellName' ]
56 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
57 main.diff = main.params[ 'ENV' ][ 'diffApps' ]
58 main.path = os.path.dirname( main.testFile )
59 main.dependencyPath = main.path + "/../dependencies/"
60 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
61 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070062 main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," )
Devin Lim58046fa2017-07-05 16:55:00 -070063 main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
64 # main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
65 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
66 # -- INIT SECTION, ONLY RUNS ONCE -- #
Jon Hall1efcb3f2016-08-23 13:42:15 -070067
Devin Lim58046fa2017-07-05 16:55:00 -070068 copyResult1 = main.ONOSbench.scp( main.Mininet1,
69 main.dependencyPath +
70 main.topology,
71 main.Mininet1.home,
72 direction="to" )
Devin Lim142b5342017-07-20 15:22:39 -070073 stepResult = main.testSetUp.envSetup()
Devin Lim58046fa2017-07-05 16:55:00 -070074 except Exception as e:
75 main.testSetUp.envSetupException( e )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -070076
77 # Additional files for topology building
78 try:
79 main.topologyLib1 = main.params[ 'DEPENDENCY' ][ 'lib1' ]
80 main.topologyLib2 = main.params[ 'DEPENDENCY' ][ 'lib2' ]
81 copyResult2 = main.ONOSbench.scp(main.Mininet1,
82 main.dependencyPath +
83 main.topologyLib1,
84 main.Mininet1.home,
85 direction="to")
86 copyResult3 = main.ONOSbench.scp(main.Mininet1,
87 main.dependencyPath +
88 main.topologyLib2,
89 main.Mininet1.home,
90 direction="to")
91 except:
92 pass
93
Devin Lim58046fa2017-07-05 16:55:00 -070094 main.testSetUp.evnSetupConclusion( stepResult )
Jon Hall1efcb3f2016-08-23 13:42:15 -070095
Jon Hall1efcb3f2016-08-23 13:42:15 -070096 @staticmethod
You Wang1cdc5f52017-12-19 16:47:51 -080097 def installOnos( main, vlanCfg=True, skipPackage=False, cliSleep=10 ):
Jon Hall1efcb3f2016-08-23 13:42:15 -070098 """
99 - Set up cell
100 - Create cell file
101 - Set cell file
102 - Verify cell file
103 - Kill ONOS process
104 - Uninstall ONOS cluster
105 - Verify ONOS start up
106 - Install ONOS cluster
107 - Connect to cli
108 """
109 # main.scale[ 0 ] determines the current number of ONOS controller
Jon Hall1efcb3f2016-08-23 13:42:15 -0700110 if main.diff:
Devin Lim58046fa2017-07-05 16:55:00 -0700111 main.apps = main.apps + "," + main.diff
Jon Hall1efcb3f2016-08-23 13:42:15 -0700112 else:
113 main.log.error( "App list is empty" )
Devin Lim142b5342017-07-20 15:22:39 -0700114 main.log.info( "NODE COUNT = " + str( main.Cluster.numCtrls ) )
115 main.log.info( ''.join( main.Cluster.getIps() ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700116 main.dynamicHosts = [ 'in1', 'out1' ]
You Wang1cdc5f52017-12-19 16:47:51 -0800117 main.testSetUp.ONOSSetUp( main.Mininet1, main.Cluster, newCell=True, cellName=main.cellName,
118 skipPack=skipPackage, useSSH=Testcaselib.useSSH )
Devin Lim142b5342017-07-20 15:22:39 -0700119 ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary,
120 main.FALSE,
You Wang1cdc5f52017-12-19 16:47:51 -0800121 sleep=cliSleep,
Devin Lim142b5342017-07-20 15:22:39 -0700122 attempts=10 )
123 if ready:
124 ready = main.TRUE
125 utilities.assert_equals( expect=main.TRUE, actual=ready,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700126 onpass="ONOS summary command succeded",
127 onfail="ONOS summary command failed" )
128
129 with open( "%s/json/%s.json" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700130 main.dependencyPath, main.cfgName ) ) as cfg:
Devin Lim142b5342017-07-20 15:22:39 -0700131 main.Cluster.active( 0 ).REST.setNetCfg( json.load( cfg ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700132 with open( "%s/json/%s.chart" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700133 main.dependencyPath, main.cfgName ) ) as chart:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700134 main.pingChart = json.load( chart )
135 if not ready:
136 main.log.error( "ONOS startup failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700137 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700138
Devin Lim142b5342017-07-20 15:22:39 -0700139 for ctrl in main.Cluster.active():
140 ctrl.CLI.logSet( "DEBUG", "org.onosproject.segmentrouting" )
141 ctrl.CLI.logSet( "DEBUG", "org.onosproject.driver.pipeline" )
142 ctrl.CLI.logSet( "DEBUG", "org.onosproject.store.group.impl" )
143 ctrl.CLI.logSet( "DEBUG", "org.onosproject.net.flowobjective.impl" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700144
145 @staticmethod
146 def startMininet( main, topology, args="" ):
147 main.step( "Starting Mininet Topology" )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700148 arg = "--onos-ip=%s %s" % (",".join([ctrl.ipAddress for ctrl in main.Cluster.runningNodes]), args)
Jon Hall1efcb3f2016-08-23 13:42:15 -0700149 main.topology = topology
150 topoResult = main.Mininet1.startNet(
151 topoFile=main.Mininet1.home + main.topology, args=arg )
152 stepResult = topoResult
153 utilities.assert_equals( expect=main.TRUE,
154 actual=stepResult,
155 onpass="Successfully loaded topology",
156 onfail="Failed to load topology" )
157 # Exit if topology did not load properly
158 if not topoResult:
Devin Lim44075962017-08-11 10:56:37 -0700159 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700160
161 @staticmethod
Devin Lim142b5342017-07-20 15:22:39 -0700162 def config( main, cfgName ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700163 main.spines = []
Piera2a7e1b2016-10-04 11:51:43 -0700164
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700165 main.failures = int( main.params[ 'failures' ] )
166 main.cfgName = cfgName
Piera2a7e1b2016-10-04 11:51:43 -0700167
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700168 if main.cfgName == '2x2':
169 spine = {}
170 spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ]
171 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ]
172 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700173
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700174 spine = {}
175 spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ]
176 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ]
177 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700178
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700179 elif main.cfgName == '4x4':
180 spine = {}
181 spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ]
182 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ]
183 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700184
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700185 spine = {}
186 spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ]
187 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ]
188 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700189
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700190 spine = {}
191 spine[ 'name' ] = main.params[ 'switches' ][ 'spine3' ]
192 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid3' ]
193 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700194
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700195 spine = {}
196 spine[ 'name' ] = main.params[ 'switches' ][ 'spine4' ]
197 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid4' ]
198 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700199
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700200 else:
Piera2a7e1b2016-10-04 11:51:43 -0700201 main.log.error( "Configuration failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700202 main.cleanAndExit()
Piera2a7e1b2016-10-04 11:51:43 -0700203
204 @staticmethod
You Wang1cdc5f52017-12-19 16:47:51 -0800205 def checkFlows( main, minFlowCount, dumpflows=True, sleep=10 ):
Jon Hall1efcb3f2016-08-23 13:42:15 -0700206 main.step(
207 " Check whether the flow count is bigger than %s" % minFlowCount )
Devin Lim142b5342017-07-20 15:22:39 -0700208 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowCount,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700209 main.FALSE,
210 kwargs={ 'min': minFlowCount },
211 attempts=10,
You Wang1cdc5f52017-12-19 16:47:51 -0800212 sleep=sleep )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700213 utilities.assertEquals(
Jon Hall1efcb3f2016-08-23 13:42:15 -0700214 expect=True,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700215 actual=( count > 0 ),
Jon Hall1efcb3f2016-08-23 13:42:15 -0700216 onpass="Flow count looks correct: " + str( count ),
217 onfail="Flow count looks wrong: " + str( count ) )
218
219 main.step( "Check whether all flow status are ADDED" )
Devin Lim142b5342017-07-20 15:22:39 -0700220 flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700221 main.FALSE,
222 kwargs={ 'isPENDING': False },
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700223 attempts=4,
You Wang1cdc5f52017-12-19 16:47:51 -0800224 sleep=sleep )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700225 utilities.assertEquals(
Jon Hall1efcb3f2016-08-23 13:42:15 -0700226 expect=main.TRUE,
227 actual=flowCheck,
228 onpass="Flow status is correct!",
229 onfail="Flow status is wrong!" )
230 if dumpflows:
Devin Lim142b5342017-07-20 15:22:39 -0700231 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700232 "flows",
233 main.logdir,
234 "flowsBefore" + main.cfgName )
Devin Lim142b5342017-07-20 15:22:39 -0700235 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700236 "groups",
237 main.logdir,
238 "groupsBefore" + main.cfgName )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700239
240 @staticmethod
241 def pingAll( main, tag="", dumpflows=True ):
242 main.log.report( "Check full connectivity" )
243 print main.pingChart
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700244 for entry in main.pingChart.itervalues():
Jon Hall1efcb3f2016-08-23 13:42:15 -0700245 print entry
246 hosts, expect = entry[ 'hosts' ], entry[ 'expect' ]
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700247 try:
248 expect = main.TRUE if str(expect).lower() == 'true' else main.FALSE
249 except:
250 expect = main.FALSE
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700251 main.step( "Connectivity for %s %s" % ( str( hosts ), tag ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700252 pa = main.Mininet1.pingallHosts( hosts )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700253
Jon Hall1efcb3f2016-08-23 13:42:15 -0700254 utilities.assert_equals( expect=expect, actual=pa,
255 onpass="IP connectivity successfully tested",
256 onfail="IP connectivity failed" )
257 if dumpflows:
Devin Lim142b5342017-07-20 15:22:39 -0700258 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700259 "flows",
260 main.logdir,
261 "flowsOn" + tag )
Devin Lim142b5342017-07-20 15:22:39 -0700262 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700263 "groups",
264 main.logdir,
265 "groupsOn" + tag )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700266
267 @staticmethod
268 def killLink( main, end1, end2, switches, links ):
269 """
270 end1,end2: identify the switches, ex.: 'leaf1', 'spine1'
271 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
272 Kill a link and verify ONOS can see the proper link change
273 """
274 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700275 main.step( "Kill link between %s and %s" % ( end1, end2 ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700276 LinkDown = main.Mininet1.link( END1=end1, END2=end2, OPTION="down" )
Pierfb719b12016-09-19 14:51:44 -0700277 LinkDown = main.Mininet1.link( END2=end1, END1=end2, OPTION="down" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700278 main.log.info(
279 "Waiting %s seconds for link down to be discovered" % main.linkSleep )
280 time.sleep( main.linkSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700281 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700282 main.FALSE,
283 kwargs={ 'numoswitch': switches,
284 'numolink': links },
285 attempts=10,
286 sleep=main.linkSleep )
287 result = topology & LinkDown
288 utilities.assert_equals( expect=main.TRUE, actual=result,
289 onpass="Link down successful",
290 onfail="Failed to turn off link?" )
291
292 @staticmethod
293 def restoreLink( main, end1, end2, dpid1, dpid2, port1, port2, switches,
294 links ):
295 """
296 Params:
297 end1,end2: identify the end switches, ex.: 'leaf1', 'spine1'
298 dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002'
299 port1, port2: respective port of the end switches that connects to the link, ex.:'1'
300 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
301 Kill a link and verify ONOS can see the proper link change
302 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700303 main.step( "Restore link between %s and %s" % ( end1, end2 ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700304 result = False
305 count = 0
306 while True:
307 count += 1
308 main.Mininet1.link( END1=end1, END2=end2, OPTION="up" )
309 main.Mininet1.link( END2=end1, END1=end2, OPTION="up" )
310 main.log.info(
311 "Waiting %s seconds for link up to be discovered" % main.linkSleep )
312 time.sleep( main.linkSleep )
Pierfb719b12016-09-19 14:51:44 -0700313
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700314 for i in range( 0, main.Cluster.numCtrls ):
Devin Lim142b5342017-07-20 15:22:39 -0700315 ctrl = main.Cluster.runningNodes[ i ]
316 onosIsUp = main.ONOSbench.isup( ctrl.ipAddress )
Pierfb719b12016-09-19 14:51:44 -0700317 if onosIsUp == main.TRUE:
Devin Lim142b5342017-07-20 15:22:39 -0700318 ctrl.CLI.portstate( dpid=dpid1, port=port1 )
319 ctrl.CLI.portstate( dpid=dpid2, port=port2 )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700320 time.sleep( main.linkSleep )
321
Devin Lim142b5342017-07-20 15:22:39 -0700322 result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches,
323 numolink=links )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700324 if count > 5 or result:
325 break
326 utilities.assert_equals( expect=main.TRUE, actual=result,
327 onpass="Link up successful",
328 onfail="Failed to bring link up" )
329
330 @staticmethod
331 def killSwitch( main, switch, switches, links ):
332 """
333 Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6'
334 Completely kill a switch and verify ONOS can see the proper change
335 """
336 main.switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
337 main.step( "Kill " + switch )
338 main.log.info( "Stopping" + switch )
339 main.Mininet1.switch( SW=switch, OPTION="stop" )
340 # todo make this repeatable
341 main.log.info( "Waiting %s seconds for switch down to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700342 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700343 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700344 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700345 main.FALSE,
346 kwargs={ 'numoswitch': switches,
347 'numolink': links },
348 attempts=10,
349 sleep=main.switchSleep )
350 utilities.assert_equals( expect=main.TRUE, actual=topology,
351 onpass="Kill switch successful",
352 onfail="Failed to kill switch?" )
353
354 @staticmethod
355 def recoverSwitch( main, switch, switches, links ):
356 """
357 Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6'
358 Recover a switch and verify ONOS can see the proper change
359 """
360 # todo make this repeatable
361 main.step( "Recovering " + switch )
362 main.log.info( "Starting" + switch )
363 main.Mininet1.switch( SW=switch, OPTION="start" )
364 main.log.info( "Waiting %s seconds for switch up to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700365 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700366 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700367 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700368 main.FALSE,
369 kwargs={ 'numoswitch': switches,
370 'numolink': links },
371 attempts=10,
372 sleep=main.switchSleep )
373 utilities.assert_equals( expect=main.TRUE, actual=topology,
374 onpass="Switch recovery successful",
375 onfail="Failed to recover switch?" )
376
377 @staticmethod
378 def cleanup( main ):
379 """
380 Stop Onos-cluster.
381 Stops Mininet
382 Copies ONOS log
383 """
Devin Lim58046fa2017-07-05 16:55:00 -0700384 try:
385 from tests.dependencies.utils import Utils
386 except ImportError:
387 main.log.error( "Utils not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700388 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700389 try:
Devin Lim142b5342017-07-20 15:22:39 -0700390 main.utils
Devin Lim58046fa2017-07-05 16:55:00 -0700391 except ( NameError, AttributeError ):
Devin Lim142b5342017-07-20 15:22:39 -0700392 main.utils = Utils()
Devin Lim58046fa2017-07-05 16:55:00 -0700393
394 main.utils.mininetCleanup( main.Mininet1 )
395
Devin Lim142b5342017-07-20 15:22:39 -0700396 main.utils.copyKarafLog( main.cfgName )
Devin Lim58046fa2017-07-05 16:55:00 -0700397
Devin Lim142b5342017-07-20 15:22:39 -0700398 for ctrl in main.Cluster.active():
399 main.ONOSbench.onosStop( ctrl.ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700400
401 @staticmethod
402 def killOnos( main, nodes, switches, links, expNodes ):
403 """
404 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
405 switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6'
406 Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change
407 """
408 main.step( "Killing ONOS instance" )
Pier3b58c652016-09-26 12:03:31 -0700409
Jon Hall1efcb3f2016-08-23 13:42:15 -0700410 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700411 killResult = main.ONOSbench.onosDie( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700412 utilities.assert_equals( expect=main.TRUE, actual=killResult,
413 onpass="ONOS instance Killed",
414 onfail="Error killing ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700415 main.Cluster.runningNodes[ i ].active = False
Jon Hall1efcb3f2016-08-23 13:42:15 -0700416 time.sleep( 12 )
Pier3b58c652016-09-26 12:03:31 -0700417
Devin Lim142b5342017-07-20 15:22:39 -0700418 if len( nodes ) < main.Cluster.numCtrls:
Pier3b58c652016-09-26 12:03:31 -0700419
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700420 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700421 False,
Pier3b58c652016-09-26 12:03:31 -0700422 attempts=5,
423 sleep=10 )
424 utilities.assert_equals( expect=True, actual=nodeResults,
425 onpass="Nodes check successful",
426 onfail="Nodes check NOT successful" )
427
428 if not nodeResults:
429 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700430 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700431 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700432 ctrl.name,
433 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700434 main.log.error( "Failed to kill ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700435 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700436
Devin Lim142b5342017-07-20 15:22:39 -0700437 topology = utilities.retry( main.Cluster.active( 0 ).checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700438 main.FALSE,
439 kwargs={ 'numoswitch': switches,
440 'numolink': links,
441 'numoctrl': expNodes },
442 attempts=10,
443 sleep=12 )
444 utilities.assert_equals( expect=main.TRUE, actual=topology,
445 onpass="ONOS Instance down successful",
446 onfail="Failed to turn off ONOS Instance" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700447
448 @staticmethod
449 def recoverOnos( main, nodes, switches, links, expNodes ):
450 """
451 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
452 switches, links, nodes: number of expected switches, links and nodes after recoverOnos, ex.: '4', '6'
453 Recover an ONOS instance and verify the ONOS cluster can see the proper change
454 """
455 main.step( "Recovering ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700456 [ main.ONOSbench.onosStart( main.Cluster.runningNodes[ i ].ipAddress ) for i in nodes ]
Jon Hall1efcb3f2016-08-23 13:42:15 -0700457 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700458 isUp = main.ONOSbench.isup( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700459 utilities.assert_equals( expect=main.TRUE, actual=isUp,
460 onpass="ONOS service is ready",
461 onfail="ONOS service did not start properly" )
462 for i in nodes:
463 main.step( "Checking if ONOS CLI is ready" )
Devin Lim142b5342017-07-20 15:22:39 -0700464 ctrl = main.Cluster.runningNodes[ i ]
465 ctrl.CLI.startCellCli()
466 cliResult = ctrl.CLI.startOnosCli( ctrl.ipAddress,
467 commandlineTimeout=60,
468 onosStartTimeout=100 )
469 ctrl.active = True
Jon Hall1efcb3f2016-08-23 13:42:15 -0700470 utilities.assert_equals( expect=main.TRUE,
471 actual=cliResult,
472 onpass="ONOS CLI is ready",
473 onfail="ONOS CLI is not ready" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700474
Pier3b58c652016-09-26 12:03:31 -0700475 main.step( "Checking ONOS nodes" )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700476 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700477 False,
Pier3b58c652016-09-26 12:03:31 -0700478 attempts=5,
479 sleep=10 )
480 utilities.assert_equals( expect=True, actual=nodeResults,
481 onpass="Nodes check successful",
482 onfail="Nodes check NOT successful" )
483
484 if not nodeResults:
485 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700486 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700487 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700488 ctrl.name,
489 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700490 main.log.error( "Failed to start ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700491 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700492
Devin Lim142b5342017-07-20 15:22:39 -0700493 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700494 main.FALSE,
495 kwargs={ 'numoswitch': switches,
496 'numolink': links,
497 'numoctrl': expNodes },
498 attempts=10,
499 sleep=12 )
500 utilities.assert_equals( expect=main.TRUE, actual=topology,
501 onpass="ONOS Instance down successful",
502 onfail="Failed to turn off ONOS Instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700503 ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary,
504 main.FALSE,
505 attempts=10,
506 sleep=12 )
507 if ready:
508 ready = main.TRUE
509 utilities.assert_equals( expect=main.TRUE, actual=ready,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700510 onpass="ONOS summary command succeded",
511 onfail="ONOS summary command failed" )
512 if not ready:
513 main.log.error( "ONOS startup failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700514 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700515
516 @staticmethod
517 def addHostCfg( main ):
518 """
519 Adds Host Configuration to ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700520 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700521 """
522 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700523 hostCfg = {}
Jon Hall1efcb3f2016-08-23 13:42:15 -0700524 with open( main.dependencyPath + "/json/extra.json" ) as template:
525 hostCfg = json.load( template )
526 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ]
527 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700528 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700529 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
530 subjectClass="hosts",
531 subjectKey=urllib.quote( mac,
532 safe='' ),
533 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700534 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ]
535 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700536 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700537 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
538 subjectClass="hosts",
539 subjectKey=urllib.quote( mac,
540 safe='' ),
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700541 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700542 main.pingChart.update( { 'vlan1': { "expect": "True",
543 "hosts": [ "olt1", "vsg1" ] } } )
544 main.pingChart[ 'vlan5' ][ 'expect' ] = 0
545 main.pingChart[ 'vlan10' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700546 ports = "[%s,%s]" % ( 5, 6 )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700547 cfg = '{"of:0000000000000001":[{"vlan":1,"ports":%s,"name":"OLT 1"}]}' % ports
Devin Lim142b5342017-07-20 15:22:39 -0700548 main.Cluster.active( 0 ).REST.setNetCfg( json.loads( cfg ),
549 subjectClass="apps",
550 subjectKey="org.onosproject.segmentrouting",
551 configKey="xconnect" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700552
553 @staticmethod
554 def delHostCfg( main ):
555 """
556 Removest Host Configuration from ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700557 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700558 """
559 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700560 hostCfg = {}
Jon Hall1efcb3f2016-08-23 13:42:15 -0700561 with open( main.dependencyPath + "/json/extra.json" ) as template:
562 hostCfg = json.load( template )
563 main.step( "Removing host configuration" )
564 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700565 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700566 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
567 subjectKey=urllib.quote(
568 mac,
569 safe='' ),
570 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700571 main.step( "Removing configuration" )
572 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700573 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700574 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
575 subjectKey=urllib.quote(
576 mac,
577 safe='' ),
578 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700579 main.step( "Removing vlan configuration" )
580 main.pingChart[ 'vlan1' ][ 'expect' ] = 0
Devin Lim142b5342017-07-20 15:22:39 -0700581 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="apps",
582 subjectKey="org.onosproject.segmentrouting",
583 configKey="xconnect" )