blob: cf0d9a98469bd75985c441c7a43d6c1c356afd1f [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 Hyun98fb40a2018-01-04 16:16:28 -0800223 attempts=5,
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
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800241 def checkFlowsByDpid( main, dpid, minFlowCount, sleep=10 ):
242 main.step(
243 " Check whether the flow count of device %s is bigger than %s" % ( dpid, minFlowCount ) )
244 count = utilities.retry( main.Cluster.active( 0 ).CLI.flowAddedCount,
245 None,
246 args=( dpid, ),
247 attempts=5,
248 sleep=sleep )
249 utilities.assertEquals(
250 expect=True,
251 actual=( int( count ) > minFlowCount ),
252 onpass="Flow count looks correct: " + count ,
253 onfail="Flow count looks wrong: " + count )
254
255 @staticmethod
Jon Hall1efcb3f2016-08-23 13:42:15 -0700256 def pingAll( main, tag="", dumpflows=True ):
257 main.log.report( "Check full connectivity" )
258 print main.pingChart
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700259 for entry in main.pingChart.itervalues():
Jon Hall1efcb3f2016-08-23 13:42:15 -0700260 print entry
261 hosts, expect = entry[ 'hosts' ], entry[ 'expect' ]
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700262 try:
263 expect = main.TRUE if str(expect).lower() == 'true' else main.FALSE
264 except:
265 expect = main.FALSE
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700266 main.step( "Connectivity for %s %s" % ( str( hosts ), tag ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700267 pa = main.Mininet1.pingallHosts( hosts )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700268
Jon Hall1efcb3f2016-08-23 13:42:15 -0700269 utilities.assert_equals( expect=expect, actual=pa,
270 onpass="IP connectivity successfully tested",
271 onfail="IP connectivity failed" )
272 if dumpflows:
Devin Lim142b5342017-07-20 15:22:39 -0700273 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700274 "flows",
275 main.logdir,
276 "flowsOn" + tag )
Devin Lim142b5342017-07-20 15:22:39 -0700277 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700278 "groups",
279 main.logdir,
280 "groupsOn" + tag )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700281
282 @staticmethod
283 def killLink( main, end1, end2, switches, links ):
284 """
285 end1,end2: identify the switches, ex.: 'leaf1', 'spine1'
286 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
287 Kill a link and verify ONOS can see the proper link change
288 """
289 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700290 main.step( "Kill link between %s and %s" % ( end1, end2 ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700291 LinkDown = main.Mininet1.link( END1=end1, END2=end2, OPTION="down" )
Pierfb719b12016-09-19 14:51:44 -0700292 LinkDown = main.Mininet1.link( END2=end1, END1=end2, OPTION="down" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700293 main.log.info(
294 "Waiting %s seconds for link down to be discovered" % main.linkSleep )
295 time.sleep( main.linkSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700296 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700297 main.FALSE,
298 kwargs={ 'numoswitch': switches,
299 'numolink': links },
300 attempts=10,
301 sleep=main.linkSleep )
302 result = topology & LinkDown
303 utilities.assert_equals( expect=main.TRUE, actual=result,
304 onpass="Link down successful",
305 onfail="Failed to turn off link?" )
306
307 @staticmethod
308 def restoreLink( main, end1, end2, dpid1, dpid2, port1, port2, switches,
309 links ):
310 """
311 Params:
312 end1,end2: identify the end switches, ex.: 'leaf1', 'spine1'
313 dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002'
314 port1, port2: respective port of the end switches that connects to the link, ex.:'1'
315 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
316 Kill a link and verify ONOS can see the proper link change
317 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700318 main.step( "Restore link between %s and %s" % ( end1, end2 ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700319 result = False
320 count = 0
321 while True:
322 count += 1
323 main.Mininet1.link( END1=end1, END2=end2, OPTION="up" )
324 main.Mininet1.link( END2=end1, END1=end2, OPTION="up" )
325 main.log.info(
326 "Waiting %s seconds for link up to be discovered" % main.linkSleep )
327 time.sleep( main.linkSleep )
Pierfb719b12016-09-19 14:51:44 -0700328
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700329 for i in range( 0, main.Cluster.numCtrls ):
Devin Lim142b5342017-07-20 15:22:39 -0700330 ctrl = main.Cluster.runningNodes[ i ]
331 onosIsUp = main.ONOSbench.isup( ctrl.ipAddress )
Pierfb719b12016-09-19 14:51:44 -0700332 if onosIsUp == main.TRUE:
Devin Lim142b5342017-07-20 15:22:39 -0700333 ctrl.CLI.portstate( dpid=dpid1, port=port1 )
334 ctrl.CLI.portstate( dpid=dpid2, port=port2 )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700335 time.sleep( main.linkSleep )
336
Devin Lim142b5342017-07-20 15:22:39 -0700337 result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches,
338 numolink=links )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700339 if count > 5 or result:
340 break
341 utilities.assert_equals( expect=main.TRUE, actual=result,
342 onpass="Link up successful",
343 onfail="Failed to bring link up" )
344
345 @staticmethod
346 def killSwitch( main, switch, switches, links ):
347 """
348 Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6'
349 Completely kill a switch and verify ONOS can see the proper change
350 """
351 main.switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
352 main.step( "Kill " + switch )
353 main.log.info( "Stopping" + switch )
354 main.Mininet1.switch( SW=switch, OPTION="stop" )
355 # todo make this repeatable
356 main.log.info( "Waiting %s seconds for switch down to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700357 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700358 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700359 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700360 main.FALSE,
361 kwargs={ 'numoswitch': switches,
362 'numolink': links },
363 attempts=10,
364 sleep=main.switchSleep )
365 utilities.assert_equals( expect=main.TRUE, actual=topology,
366 onpass="Kill switch successful",
367 onfail="Failed to kill switch?" )
368
369 @staticmethod
370 def recoverSwitch( main, switch, switches, links ):
371 """
372 Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6'
373 Recover a switch and verify ONOS can see the proper change
374 """
375 # todo make this repeatable
376 main.step( "Recovering " + switch )
377 main.log.info( "Starting" + switch )
378 main.Mininet1.switch( SW=switch, OPTION="start" )
379 main.log.info( "Waiting %s seconds for switch up to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700380 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700381 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700382 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700383 main.FALSE,
384 kwargs={ 'numoswitch': switches,
385 'numolink': links },
386 attempts=10,
387 sleep=main.switchSleep )
388 utilities.assert_equals( expect=main.TRUE, actual=topology,
389 onpass="Switch recovery successful",
390 onfail="Failed to recover switch?" )
391
392 @staticmethod
393 def cleanup( main ):
394 """
395 Stop Onos-cluster.
396 Stops Mininet
397 Copies ONOS log
398 """
Devin Lim58046fa2017-07-05 16:55:00 -0700399 try:
400 from tests.dependencies.utils import Utils
401 except ImportError:
402 main.log.error( "Utils not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700403 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700404 try:
Devin Lim142b5342017-07-20 15:22:39 -0700405 main.utils
Devin Lim58046fa2017-07-05 16:55:00 -0700406 except ( NameError, AttributeError ):
Devin Lim142b5342017-07-20 15:22:39 -0700407 main.utils = Utils()
Devin Lim58046fa2017-07-05 16:55:00 -0700408
409 main.utils.mininetCleanup( main.Mininet1 )
410
Devin Lim142b5342017-07-20 15:22:39 -0700411 main.utils.copyKarafLog( main.cfgName )
Devin Lim58046fa2017-07-05 16:55:00 -0700412
Devin Lim142b5342017-07-20 15:22:39 -0700413 for ctrl in main.Cluster.active():
414 main.ONOSbench.onosStop( ctrl.ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700415
416 @staticmethod
417 def killOnos( main, nodes, switches, links, expNodes ):
418 """
419 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
420 switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6'
421 Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change
422 """
423 main.step( "Killing ONOS instance" )
Pier3b58c652016-09-26 12:03:31 -0700424
Jon Hall1efcb3f2016-08-23 13:42:15 -0700425 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700426 killResult = main.ONOSbench.onosDie( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700427 utilities.assert_equals( expect=main.TRUE, actual=killResult,
428 onpass="ONOS instance Killed",
429 onfail="Error killing ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700430 main.Cluster.runningNodes[ i ].active = False
Jon Hall1efcb3f2016-08-23 13:42:15 -0700431 time.sleep( 12 )
Pier3b58c652016-09-26 12:03:31 -0700432
Devin Lim142b5342017-07-20 15:22:39 -0700433 if len( nodes ) < main.Cluster.numCtrls:
Pier3b58c652016-09-26 12:03:31 -0700434
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700435 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700436 False,
Pier3b58c652016-09-26 12:03:31 -0700437 attempts=5,
438 sleep=10 )
439 utilities.assert_equals( expect=True, actual=nodeResults,
440 onpass="Nodes check successful",
441 onfail="Nodes check NOT successful" )
442
443 if not nodeResults:
444 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700445 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700446 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700447 ctrl.name,
448 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700449 main.log.error( "Failed to kill ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700450 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700451
Devin Lim142b5342017-07-20 15:22:39 -0700452 topology = utilities.retry( main.Cluster.active( 0 ).checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700453 main.FALSE,
454 kwargs={ 'numoswitch': switches,
455 'numolink': links,
456 'numoctrl': expNodes },
457 attempts=10,
458 sleep=12 )
459 utilities.assert_equals( expect=main.TRUE, actual=topology,
460 onpass="ONOS Instance down successful",
461 onfail="Failed to turn off ONOS Instance" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700462
463 @staticmethod
464 def recoverOnos( main, nodes, switches, links, expNodes ):
465 """
466 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
467 switches, links, nodes: number of expected switches, links and nodes after recoverOnos, ex.: '4', '6'
468 Recover an ONOS instance and verify the ONOS cluster can see the proper change
469 """
470 main.step( "Recovering ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700471 [ main.ONOSbench.onosStart( main.Cluster.runningNodes[ i ].ipAddress ) for i in nodes ]
Jon Hall1efcb3f2016-08-23 13:42:15 -0700472 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700473 isUp = main.ONOSbench.isup( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700474 utilities.assert_equals( expect=main.TRUE, actual=isUp,
475 onpass="ONOS service is ready",
476 onfail="ONOS service did not start properly" )
477 for i in nodes:
478 main.step( "Checking if ONOS CLI is ready" )
Devin Lim142b5342017-07-20 15:22:39 -0700479 ctrl = main.Cluster.runningNodes[ i ]
480 ctrl.CLI.startCellCli()
481 cliResult = ctrl.CLI.startOnosCli( ctrl.ipAddress,
482 commandlineTimeout=60,
483 onosStartTimeout=100 )
484 ctrl.active = True
Jon Hall1efcb3f2016-08-23 13:42:15 -0700485 utilities.assert_equals( expect=main.TRUE,
486 actual=cliResult,
487 onpass="ONOS CLI is ready",
488 onfail="ONOS CLI is not ready" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700489
Pier3b58c652016-09-26 12:03:31 -0700490 main.step( "Checking ONOS nodes" )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700491 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700492 False,
Pier3b58c652016-09-26 12:03:31 -0700493 attempts=5,
494 sleep=10 )
495 utilities.assert_equals( expect=True, actual=nodeResults,
496 onpass="Nodes check successful",
497 onfail="Nodes check NOT successful" )
498
499 if not nodeResults:
500 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700501 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700502 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700503 ctrl.name,
504 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700505 main.log.error( "Failed to start ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700506 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700507
Devin Lim142b5342017-07-20 15:22:39 -0700508 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700509 main.FALSE,
510 kwargs={ 'numoswitch': switches,
511 'numolink': links,
512 'numoctrl': expNodes },
513 attempts=10,
514 sleep=12 )
515 utilities.assert_equals( expect=main.TRUE, actual=topology,
516 onpass="ONOS Instance down successful",
517 onfail="Failed to turn off ONOS Instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700518 ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary,
519 main.FALSE,
520 attempts=10,
521 sleep=12 )
522 if ready:
523 ready = main.TRUE
524 utilities.assert_equals( expect=main.TRUE, actual=ready,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700525 onpass="ONOS summary command succeded",
526 onfail="ONOS summary command failed" )
527 if not ready:
528 main.log.error( "ONOS startup failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700529 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700530
531 @staticmethod
532 def addHostCfg( main ):
533 """
534 Adds Host Configuration to ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700535 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700536 """
537 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700538 hostCfg = {}
Jon Hall1efcb3f2016-08-23 13:42:15 -0700539 with open( main.dependencyPath + "/json/extra.json" ) as template:
540 hostCfg = json.load( template )
541 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ]
542 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700543 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700544 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
545 subjectClass="hosts",
546 subjectKey=urllib.quote( mac,
547 safe='' ),
548 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700549 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ]
550 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700551 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700552 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
553 subjectClass="hosts",
554 subjectKey=urllib.quote( mac,
555 safe='' ),
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700556 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700557 main.pingChart.update( { 'vlan1': { "expect": "True",
558 "hosts": [ "olt1", "vsg1" ] } } )
559 main.pingChart[ 'vlan5' ][ 'expect' ] = 0
560 main.pingChart[ 'vlan10' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700561 ports = "[%s,%s]" % ( 5, 6 )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700562 cfg = '{"of:0000000000000001":[{"vlan":1,"ports":%s,"name":"OLT 1"}]}' % ports
Devin Lim142b5342017-07-20 15:22:39 -0700563 main.Cluster.active( 0 ).REST.setNetCfg( json.loads( cfg ),
564 subjectClass="apps",
565 subjectKey="org.onosproject.segmentrouting",
566 configKey="xconnect" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700567
568 @staticmethod
569 def delHostCfg( main ):
570 """
571 Removest Host Configuration from ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700572 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700573 """
574 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700575 hostCfg = {}
Jon Hall1efcb3f2016-08-23 13:42:15 -0700576 with open( main.dependencyPath + "/json/extra.json" ) as template:
577 hostCfg = json.load( template )
578 main.step( "Removing host configuration" )
579 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700580 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700581 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
582 subjectKey=urllib.quote(
583 mac,
584 safe='' ),
585 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700586 main.step( "Removing configuration" )
587 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700588 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700589 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
590 subjectKey=urllib.quote(
591 mac,
592 safe='' ),
593 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700594 main.step( "Removing vlan configuration" )
595 main.pingChart[ 'vlan1' ][ 'expect' ] = 0
Devin Lim142b5342017-07-20 15:22:39 -0700596 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="apps",
597 subjectKey="org.onosproject.segmentrouting",
598 configKey="xconnect" )