blob: f3350aa17962663b40a6c94f771a5043a0f0c627 [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()
You Wangd5873482018-01-24 12:30:00 -080050 from tests.dependencies.Network import Network
51 main.Network = Network()
Devin Lim0c972b72018-02-08 14:53:59 -080052 main.testSetUp.envSetupDescription( False )
Devin Lim58046fa2017-07-05 16:55:00 -070053 stepResult = main.FALSE
54 try:
55 main.step( "Constructing test variables" )
56 # Test variables
57 main.cellName = main.params[ 'ENV' ][ 'cellName' ]
58 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
Devin Lim58046fa2017-07-05 16:55:00 -070059 main.path = os.path.dirname( main.testFile )
You Wangac02b142018-01-26 14:57:28 -080060 main.topoPath = main.path + "/../dependencies/"
61 main.configPath = main.path + "/../dependencies/"
Devin Lim58046fa2017-07-05 16:55:00 -070062 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
You Wangd87b2312018-01-30 12:47:17 -080063 main.topologyLib = main.params[ 'DEPENDENCY' ][ 'lib' ] if 'lib' in main.params[ 'DEPENDENCY' ] else None
64 main.topologyConf = main.params[ 'DEPENDENCY' ][ 'conf' ] if 'conf' in main.params[ 'DEPENDENCY' ] else None
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070065 main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," )
Devin Lim58046fa2017-07-05 16:55:00 -070066 main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
Devin Lim58046fa2017-07-05 16:55:00 -070067 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
Jon Hall1efcb3f2016-08-23 13:42:15 -070068
Devin Lim0c972b72018-02-08 14:53:59 -080069 stepResult = main.testSetUp.envSetup( False )
Devin Lim58046fa2017-07-05 16:55:00 -070070 except Exception as e:
71 main.testSetUp.envSetupException( e )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -070072
Devin Lim58046fa2017-07-05 16:55:00 -070073 main.testSetUp.evnSetupConclusion( stepResult )
Jon Hall1efcb3f2016-08-23 13:42:15 -070074
Jon Hall1efcb3f2016-08-23 13:42:15 -070075 @staticmethod
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -080076 def installOnos( main, vlanCfg=True, skipPackage=False, cliSleep=10,
77 parallel=True ):
Jon Hall1efcb3f2016-08-23 13:42:15 -070078 """
79 - Set up cell
80 - Create cell file
81 - Set cell file
82 - Verify cell file
83 - Kill ONOS process
84 - Uninstall ONOS cluster
85 - Verify ONOS start up
86 - Install ONOS cluster
87 - Connect to cli
88 """
89 # main.scale[ 0 ] determines the current number of ONOS controller
You Wangd87b2312018-01-30 12:47:17 -080090 if not main.apps:
Jon Hall1efcb3f2016-08-23 13:42:15 -070091 main.log.error( "App list is empty" )
Devin Lim142b5342017-07-20 15:22:39 -070092 main.log.info( "NODE COUNT = " + str( main.Cluster.numCtrls ) )
93 main.log.info( ''.join( main.Cluster.getIps() ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -070094 main.dynamicHosts = [ 'in1', 'out1' ]
You Wanga0f6ff62018-01-11 15:46:30 -080095 main.testSetUp.ONOSSetUp( main.Cluster, newCell=True, cellName=main.cellName,
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -080096 skipPack=skipPackage,
97 useSSH=Testcaselib.useSSH,
Devin Lim0c972b72018-02-08 14:53:59 -080098 installParallel=parallel, includeCaseDesc=False )
Devin Lim142b5342017-07-20 15:22:39 -070099 ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary,
100 main.FALSE,
You Wang1cdc5f52017-12-19 16:47:51 -0800101 sleep=cliSleep,
Devin Lim142b5342017-07-20 15:22:39 -0700102 attempts=10 )
103 if ready:
104 ready = main.TRUE
105 utilities.assert_equals( expect=main.TRUE, actual=ready,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700106 onpass="ONOS summary command succeded",
107 onfail="ONOS summary command failed" )
108
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -0800109 with open( "%s/json/%s.json" % (main.configPath, main.cfgName)) as cfg:
110 main.Cluster.active( 0 ).REST.setNetCfg(json.load(cfg))
111 with open("%s/json/%s.chart" % (main.configPath, main.cfgName)) as chart:
112 main.pingChart = json.load(chart)
Jon Hall1efcb3f2016-08-23 13:42:15 -0700113 if not ready:
114 main.log.error( "ONOS startup failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700115 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700116
Devin Lim142b5342017-07-20 15:22:39 -0700117 for ctrl in main.Cluster.active():
118 ctrl.CLI.logSet( "DEBUG", "org.onosproject.segmentrouting" )
119 ctrl.CLI.logSet( "DEBUG", "org.onosproject.driver.pipeline" )
120 ctrl.CLI.logSet( "DEBUG", "org.onosproject.store.group.impl" )
121 ctrl.CLI.logSet( "DEBUG", "org.onosproject.net.flowobjective.impl" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700122
123 @staticmethod
124 def startMininet( main, topology, args="" ):
You Wangd87b2312018-01-30 12:47:17 -0800125 copyResult = main.ONOSbench.scp( main.Mininet1,
126 main.topoPath + main.topology,
127 main.Mininet1.home,
128 direction="to" )
129 if main.topologyLib:
130 for lib in main.topologyLib.split(","):
131 copyResult = copyResult and main.ONOSbench.scp( main.Mininet1,
132 main.topoPath + lib,
133 main.Mininet1.home,
134 direction="to" )
135 if main.topologyConf:
136 for conf in main.topologyConf.split(","):
137 copyResult = copyResult and main.ONOSbench.scp( main.Mininet1,
138 main.topoPath + "conf/" + conf,
139 "~/",
140 direction="to" )
141 stepResult = copyResult
142 utilities.assert_equals( expect=main.TRUE,
143 actual=stepResult,
144 onpass="Successfully copied topo files",
145 onfail="Failed to copy topo files" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700146 main.step( "Starting Mininet Topology" )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700147 arg = "--onos-ip=%s %s" % (",".join([ctrl.ipAddress for ctrl in main.Cluster.runningNodes]), args)
Jon Hall1efcb3f2016-08-23 13:42:15 -0700148 main.topology = topology
149 topoResult = main.Mininet1.startNet(
150 topoFile=main.Mininet1.home + main.topology, args=arg )
151 stepResult = topoResult
152 utilities.assert_equals( expect=main.TRUE,
153 actual=stepResult,
154 onpass="Successfully loaded topology",
155 onfail="Failed to load topology" )
156 # Exit if topology did not load properly
157 if not topoResult:
Devin Lim44075962017-08-11 10:56:37 -0700158 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700159
160 @staticmethod
Devin Lim142b5342017-07-20 15:22:39 -0700161 def config( main, cfgName ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700162 main.spines = []
Piera2a7e1b2016-10-04 11:51:43 -0700163
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700164 main.failures = int( main.params[ 'failures' ] )
165 main.cfgName = cfgName
Piera2a7e1b2016-10-04 11:51:43 -0700166
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700167 if main.cfgName == '2x2':
168 spine = {}
169 spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ]
170 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ]
171 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700172
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700173 spine = {}
174 spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ]
175 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ]
176 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700177
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700178 elif main.cfgName == '4x4':
179 spine = {}
180 spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ]
181 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ]
182 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700183
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700184 spine = {}
185 spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ]
186 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ]
187 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700188
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700189 spine = {}
190 spine[ 'name' ] = main.params[ 'switches' ][ 'spine3' ]
191 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid3' ]
192 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700193
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700194 spine = {}
195 spine[ 'name' ] = main.params[ 'switches' ][ 'spine4' ]
196 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid4' ]
197 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700198
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700199 else:
Piera2a7e1b2016-10-04 11:51:43 -0700200 main.log.error( "Configuration failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700201 main.cleanAndExit()
Piera2a7e1b2016-10-04 11:51:43 -0700202
203 @staticmethod
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900204 def checkFlows( main, minFlowCount, tag="", dumpflows=True, sleep=10 ):
Jon Hall1efcb3f2016-08-23 13:42:15 -0700205 main.step(
206 " Check whether the flow count is bigger than %s" % minFlowCount )
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900207 if tag == "":
208 tag = 'CASE%d' % main.CurrentTestCaseNumber
Devin Lim142b5342017-07-20 15:22:39 -0700209 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowCount,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700210 main.FALSE,
211 kwargs={ 'min': minFlowCount },
212 attempts=10,
You Wang1cdc5f52017-12-19 16:47:51 -0800213 sleep=sleep )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700214 utilities.assertEquals(
Jon Hall1efcb3f2016-08-23 13:42:15 -0700215 expect=True,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700216 actual=( count > 0 ),
Jon Hall1efcb3f2016-08-23 13:42:15 -0700217 onpass="Flow count looks correct: " + str( count ),
218 onfail="Flow count looks wrong: " + str( count ) )
219
220 main.step( "Check whether all flow status are ADDED" )
Devin Lim142b5342017-07-20 15:22:39 -0700221 flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700222 main.FALSE,
223 kwargs={ 'isPENDING': False },
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800224 attempts=5,
You Wang1cdc5f52017-12-19 16:47:51 -0800225 sleep=sleep )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700226 utilities.assertEquals(
Jon Hall1efcb3f2016-08-23 13:42:15 -0700227 expect=main.TRUE,
228 actual=flowCheck,
229 onpass="Flow status is correct!",
230 onfail="Flow status is wrong!" )
231 if dumpflows:
Devin Lim142b5342017-07-20 15:22:39 -0700232 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700233 "flows",
234 main.logdir,
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900235 tag + "_FlowsBefore" )
Devin Lim142b5342017-07-20 15:22:39 -0700236 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700237 "groups",
238 main.logdir,
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900239 tag + "_GroupsBefore" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700240
241 @staticmethod
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800242 def checkFlowsByDpid( main, dpid, minFlowCount, sleep=10 ):
243 main.step(
244 " Check whether the flow count of device %s is bigger than %s" % ( dpid, minFlowCount ) )
245 count = utilities.retry( main.Cluster.active( 0 ).CLI.flowAddedCount,
246 None,
247 args=( dpid, ),
248 attempts=5,
249 sleep=sleep )
250 utilities.assertEquals(
251 expect=True,
252 actual=( int( count ) > minFlowCount ),
253 onpass="Flow count looks correct: " + count ,
254 onfail="Flow count looks wrong: " + count )
255
256 @staticmethod
Jon Hall1efcb3f2016-08-23 13:42:15 -0700257 def pingAll( main, tag="", dumpflows=True ):
258 main.log.report( "Check full connectivity" )
259 print main.pingChart
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900260 if tag == "":
261 tag = 'CASE%d' % main.CurrentTestCaseNumber
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700262 for entry in main.pingChart.itervalues():
Jon Hall1efcb3f2016-08-23 13:42:15 -0700263 print entry
264 hosts, expect = entry[ 'hosts' ], entry[ 'expect' ]
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700265 try:
266 expect = main.TRUE if str(expect).lower() == 'true' else main.FALSE
267 except:
268 expect = main.FALSE
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700269 main.step( "Connectivity for %s %s" % ( str( hosts ), tag ) )
You Wangd5873482018-01-24 12:30:00 -0800270 pa = main.Network.pingallHosts( hosts )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700271
Jon Hall1efcb3f2016-08-23 13:42:15 -0700272 utilities.assert_equals( expect=expect, actual=pa,
273 onpass="IP connectivity successfully tested",
274 onfail="IP connectivity failed" )
275 if dumpflows:
Devin Lim142b5342017-07-20 15:22:39 -0700276 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700277 "flows",
278 main.logdir,
Devin Lim97b6b862018-01-23 22:51:25 -0800279 tag + "_FlowsOn" )
Devin Lim142b5342017-07-20 15:22:39 -0700280 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700281 "groups",
282 main.logdir,
Devin Lim97b6b862018-01-23 22:51:25 -0800283 tag + "_GroupsOn" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700284
285 @staticmethod
286 def killLink( main, end1, end2, switches, links ):
287 """
288 end1,end2: identify the switches, ex.: 'leaf1', 'spine1'
289 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
290 Kill a link and verify ONOS can see the proper link change
291 """
292 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700293 main.step( "Kill link between %s and %s" % ( end1, end2 ) )
You Wangd5873482018-01-24 12:30:00 -0800294 LinkDown = main.Network.link( END1=end1, END2=end2, OPTION="down" )
295 LinkDown = main.Network.link( END2=end1, END1=end2, OPTION="down" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700296 main.log.info(
297 "Waiting %s seconds for link down to be discovered" % main.linkSleep )
298 time.sleep( main.linkSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700299 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700300 main.FALSE,
301 kwargs={ 'numoswitch': switches,
302 'numolink': links },
303 attempts=10,
304 sleep=main.linkSleep )
305 result = topology & LinkDown
306 utilities.assert_equals( expect=main.TRUE, actual=result,
307 onpass="Link down successful",
308 onfail="Failed to turn off link?" )
309
310 @staticmethod
311 def restoreLink( main, end1, end2, dpid1, dpid2, port1, port2, switches,
312 links ):
313 """
314 Params:
315 end1,end2: identify the end switches, ex.: 'leaf1', 'spine1'
316 dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002'
317 port1, port2: respective port of the end switches that connects to the link, ex.:'1'
318 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
319 Kill a link and verify ONOS can see the proper link change
320 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700321 main.step( "Restore link between %s and %s" % ( end1, end2 ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700322 result = False
323 count = 0
324 while True:
325 count += 1
You Wangd5873482018-01-24 12:30:00 -0800326 main.Network.link( END1=end1, END2=end2, OPTION="up" )
327 main.Network.link( END2=end1, END1=end2, OPTION="up" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700328 main.log.info(
329 "Waiting %s seconds for link up to be discovered" % main.linkSleep )
330 time.sleep( main.linkSleep )
Pierfb719b12016-09-19 14:51:44 -0700331
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700332 for i in range( 0, main.Cluster.numCtrls ):
Devin Lim142b5342017-07-20 15:22:39 -0700333 ctrl = main.Cluster.runningNodes[ i ]
334 onosIsUp = main.ONOSbench.isup( ctrl.ipAddress )
Pierfb719b12016-09-19 14:51:44 -0700335 if onosIsUp == main.TRUE:
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900336 ctrl.CLI.portstate( dpid=dpid1, port=port1, state='Enable' )
337 ctrl.CLI.portstate( dpid=dpid2, port=port2, state='Enable' )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700338 time.sleep( main.linkSleep )
339
Devin Lim142b5342017-07-20 15:22:39 -0700340 result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches,
341 numolink=links )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700342 if count > 5 or result:
343 break
344 utilities.assert_equals( expect=main.TRUE, actual=result,
345 onpass="Link up successful",
346 onfail="Failed to bring link up" )
347
348 @staticmethod
349 def killSwitch( main, switch, switches, links ):
350 """
351 Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6'
352 Completely kill a switch and verify ONOS can see the proper change
353 """
354 main.switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
355 main.step( "Kill " + switch )
356 main.log.info( "Stopping" + switch )
You Wangd5873482018-01-24 12:30:00 -0800357 main.Network.switch( SW=switch, OPTION="stop" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700358 # todo make this repeatable
359 main.log.info( "Waiting %s seconds for switch down to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700360 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700361 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700362 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700363 main.FALSE,
364 kwargs={ 'numoswitch': switches,
365 'numolink': links },
366 attempts=10,
367 sleep=main.switchSleep )
368 utilities.assert_equals( expect=main.TRUE, actual=topology,
369 onpass="Kill switch successful",
370 onfail="Failed to kill switch?" )
371
372 @staticmethod
373 def recoverSwitch( main, switch, switches, links ):
374 """
375 Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6'
376 Recover a switch and verify ONOS can see the proper change
377 """
378 # todo make this repeatable
379 main.step( "Recovering " + switch )
380 main.log.info( "Starting" + switch )
You Wangd5873482018-01-24 12:30:00 -0800381 main.Network.switch( SW=switch, OPTION="start" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700382 main.log.info( "Waiting %s seconds for switch up to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700383 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700384 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700385 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700386 main.FALSE,
387 kwargs={ 'numoswitch': switches,
388 'numolink': links },
389 attempts=10,
390 sleep=main.switchSleep )
391 utilities.assert_equals( expect=main.TRUE, actual=topology,
392 onpass="Switch recovery successful",
393 onfail="Failed to recover switch?" )
394
395 @staticmethod
396 def cleanup( main ):
397 """
398 Stop Onos-cluster.
399 Stops Mininet
400 Copies ONOS log
401 """
Devin Lim58046fa2017-07-05 16:55:00 -0700402 try:
403 from tests.dependencies.utils import Utils
404 except ImportError:
405 main.log.error( "Utils not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700406 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700407 try:
Devin Lim142b5342017-07-20 15:22:39 -0700408 main.utils
Devin Lim58046fa2017-07-05 16:55:00 -0700409 except ( NameError, AttributeError ):
Devin Lim142b5342017-07-20 15:22:39 -0700410 main.utils = Utils()
Devin Lim58046fa2017-07-05 16:55:00 -0700411
412 main.utils.mininetCleanup( main.Mininet1 )
413
Devin Lim0c972b72018-02-08 14:53:59 -0800414 main.utils.copyKarafLog( "CASE%d" % main.CurrentTestCaseNumber, before=True, includeCaseDesc=False )
Devin Lim58046fa2017-07-05 16:55:00 -0700415
Devin Lim142b5342017-07-20 15:22:39 -0700416 for ctrl in main.Cluster.active():
417 main.ONOSbench.onosStop( ctrl.ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700418
419 @staticmethod
420 def killOnos( main, nodes, switches, links, expNodes ):
421 """
422 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
423 switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6'
424 Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change
425 """
426 main.step( "Killing ONOS instance" )
Pier3b58c652016-09-26 12:03:31 -0700427
Jon Hall1efcb3f2016-08-23 13:42:15 -0700428 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700429 killResult = main.ONOSbench.onosDie( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700430 utilities.assert_equals( expect=main.TRUE, actual=killResult,
431 onpass="ONOS instance Killed",
432 onfail="Error killing ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700433 main.Cluster.runningNodes[ i ].active = False
Jon Hall1efcb3f2016-08-23 13:42:15 -0700434 time.sleep( 12 )
Pier3b58c652016-09-26 12:03:31 -0700435
Devin Lim142b5342017-07-20 15:22:39 -0700436 if len( nodes ) < main.Cluster.numCtrls:
Pier3b58c652016-09-26 12:03:31 -0700437
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700438 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700439 False,
Pier3b58c652016-09-26 12:03:31 -0700440 attempts=5,
441 sleep=10 )
442 utilities.assert_equals( expect=True, actual=nodeResults,
443 onpass="Nodes check successful",
444 onfail="Nodes check NOT successful" )
445
446 if not nodeResults:
447 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700448 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700449 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700450 ctrl.name,
451 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700452 main.log.error( "Failed to kill ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700453 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700454
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900455 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700456 main.FALSE,
457 kwargs={ 'numoswitch': switches,
458 'numolink': links,
459 'numoctrl': expNodes },
460 attempts=10,
461 sleep=12 )
462 utilities.assert_equals( expect=main.TRUE, actual=topology,
463 onpass="ONOS Instance down successful",
464 onfail="Failed to turn off ONOS Instance" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700465
466 @staticmethod
467 def recoverOnos( main, nodes, switches, links, expNodes ):
468 """
469 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
470 switches, links, nodes: number of expected switches, links and nodes after recoverOnos, ex.: '4', '6'
471 Recover an ONOS instance and verify the ONOS cluster can see the proper change
472 """
473 main.step( "Recovering ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700474 [ main.ONOSbench.onosStart( main.Cluster.runningNodes[ i ].ipAddress ) for i in nodes ]
Jon Hall1efcb3f2016-08-23 13:42:15 -0700475 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700476 isUp = main.ONOSbench.isup( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700477 utilities.assert_equals( expect=main.TRUE, actual=isUp,
478 onpass="ONOS service is ready",
479 onfail="ONOS service did not start properly" )
480 for i in nodes:
481 main.step( "Checking if ONOS CLI is ready" )
Devin Lim142b5342017-07-20 15:22:39 -0700482 ctrl = main.Cluster.runningNodes[ i ]
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900483 # ctrl.CLI.startCellCli()
Devin Lim142b5342017-07-20 15:22:39 -0700484 cliResult = ctrl.CLI.startOnosCli( ctrl.ipAddress,
485 commandlineTimeout=60,
486 onosStartTimeout=100 )
487 ctrl.active = True
Jon Hall1efcb3f2016-08-23 13:42:15 -0700488 utilities.assert_equals( expect=main.TRUE,
489 actual=cliResult,
490 onpass="ONOS CLI is ready",
491 onfail="ONOS CLI is not ready" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700492
Pier3b58c652016-09-26 12:03:31 -0700493 main.step( "Checking ONOS nodes" )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700494 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700495 False,
Pier3b58c652016-09-26 12:03:31 -0700496 attempts=5,
497 sleep=10 )
498 utilities.assert_equals( expect=True, actual=nodeResults,
499 onpass="Nodes check successful",
500 onfail="Nodes check NOT successful" )
501
502 if not nodeResults:
503 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700504 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700505 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700506 ctrl.name,
507 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700508 main.log.error( "Failed to start ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700509 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700510
Devin Lim142b5342017-07-20 15:22:39 -0700511 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700512 main.FALSE,
513 kwargs={ 'numoswitch': switches,
514 'numolink': links,
515 'numoctrl': expNodes },
516 attempts=10,
517 sleep=12 )
518 utilities.assert_equals( expect=main.TRUE, actual=topology,
519 onpass="ONOS Instance down successful",
520 onfail="Failed to turn off ONOS Instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700521 ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary,
522 main.FALSE,
523 attempts=10,
524 sleep=12 )
525 if ready:
526 ready = main.TRUE
527 utilities.assert_equals( expect=main.TRUE, actual=ready,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700528 onpass="ONOS summary command succeded",
529 onfail="ONOS summary command failed" )
530 if not ready:
531 main.log.error( "ONOS startup failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700532 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700533
534 @staticmethod
535 def addHostCfg( main ):
536 """
537 Adds Host Configuration to ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700538 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700539 """
540 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700541 hostCfg = {}
You Wangac02b142018-01-26 14:57:28 -0800542 with open( main.configPath + "/json/extra.json" ) as template:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700543 hostCfg = json.load( template )
544 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ]
545 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700546 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700547 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
548 subjectClass="hosts",
549 subjectKey=urllib.quote( mac,
550 safe='' ),
551 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700552 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ]
553 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700554 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700555 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
556 subjectClass="hosts",
557 subjectKey=urllib.quote( mac,
558 safe='' ),
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700559 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700560 main.pingChart.update( { 'vlan1': { "expect": "True",
561 "hosts": [ "olt1", "vsg1" ] } } )
562 main.pingChart[ 'vlan5' ][ 'expect' ] = 0
563 main.pingChart[ 'vlan10' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700564 ports = "[%s,%s]" % ( 5, 6 )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700565 cfg = '{"of:0000000000000001":[{"vlan":1,"ports":%s,"name":"OLT 1"}]}' % ports
Devin Lim142b5342017-07-20 15:22:39 -0700566 main.Cluster.active( 0 ).REST.setNetCfg( json.loads( cfg ),
567 subjectClass="apps",
568 subjectKey="org.onosproject.segmentrouting",
569 configKey="xconnect" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700570
571 @staticmethod
572 def delHostCfg( main ):
573 """
574 Removest Host Configuration from ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700575 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700576 """
577 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700578 hostCfg = {}
You Wangac02b142018-01-26 14:57:28 -0800579 with open( main.configPath + "/json/extra.json" ) as template:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700580 hostCfg = json.load( template )
581 main.step( "Removing host configuration" )
582 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700583 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700584 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
585 subjectKey=urllib.quote(
586 mac,
587 safe='' ),
588 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700589 main.step( "Removing configuration" )
590 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700591 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700592 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
593 subjectKey=urllib.quote(
594 mac,
595 safe='' ),
596 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700597 main.step( "Removing vlan configuration" )
598 main.pingChart[ 'vlan1' ][ 'expect' ] = 0
Devin Lim142b5342017-07-20 15:22:39 -0700599 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="apps",
600 subjectKey="org.onosproject.segmentrouting",
601 configKey="xconnect" )