blob: c5271f56aaadd405703e9fc44593fb9651353c06 [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/"
You Wang69362682018-02-12 13:35:54 -080061 main.configPath = main.path + "/../dependencies/conf/"
62 main.testConfPath = main.path + "/dependencies/conf/"
Devin Lim58046fa2017-07-05 16:55:00 -070063 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
You Wangd87b2312018-01-30 12:47:17 -080064 main.topologyLib = main.params[ 'DEPENDENCY' ][ 'lib' ] if 'lib' in main.params[ 'DEPENDENCY' ] else None
65 main.topologyConf = main.params[ 'DEPENDENCY' ][ 'conf' ] if 'conf' in main.params[ 'DEPENDENCY' ] else None
You Wang69362682018-02-12 13:35:54 -080066 main.testConf = main.params[ 'DEPENDENCY' ][ 'testConf' ] if 'testConf' in main.params[ 'DEPENDENCY' ] else None
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070067 main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," )
Devin Lim58046fa2017-07-05 16:55:00 -070068 main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
Devin Lim58046fa2017-07-05 16:55:00 -070069 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
Jon Hall1efcb3f2016-08-23 13:42:15 -070070
Devin Lim0c972b72018-02-08 14:53:59 -080071 stepResult = main.testSetUp.envSetup( False )
Devin Lim58046fa2017-07-05 16:55:00 -070072 except Exception as e:
73 main.testSetUp.envSetupException( e )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -070074
Devin Lim58046fa2017-07-05 16:55:00 -070075 main.testSetUp.evnSetupConclusion( stepResult )
Jon Hall1efcb3f2016-08-23 13:42:15 -070076
Jon Hall1efcb3f2016-08-23 13:42:15 -070077 @staticmethod
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -080078 def installOnos( main, vlanCfg=True, skipPackage=False, cliSleep=10,
79 parallel=True ):
Jon Hall1efcb3f2016-08-23 13:42:15 -070080 """
81 - Set up cell
82 - Create cell file
83 - Set cell file
84 - Verify cell file
85 - Kill ONOS process
86 - Uninstall ONOS cluster
87 - Verify ONOS start up
88 - Install ONOS cluster
89 - Connect to cli
90 """
91 # main.scale[ 0 ] determines the current number of ONOS controller
You Wangd87b2312018-01-30 12:47:17 -080092 if not main.apps:
Jon Hall1efcb3f2016-08-23 13:42:15 -070093 main.log.error( "App list is empty" )
Devin Lim142b5342017-07-20 15:22:39 -070094 main.log.info( "NODE COUNT = " + str( main.Cluster.numCtrls ) )
95 main.log.info( ''.join( main.Cluster.getIps() ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -070096 main.dynamicHosts = [ 'in1', 'out1' ]
You Wanga0f6ff62018-01-11 15:46:30 -080097 main.testSetUp.ONOSSetUp( main.Cluster, newCell=True, cellName=main.cellName,
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -080098 skipPack=skipPackage,
99 useSSH=Testcaselib.useSSH,
Devin Lim0c972b72018-02-08 14:53:59 -0800100 installParallel=parallel, includeCaseDesc=False )
Devin Lim142b5342017-07-20 15:22:39 -0700101 ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary,
102 main.FALSE,
You Wang1cdc5f52017-12-19 16:47:51 -0800103 sleep=cliSleep,
Devin Lim142b5342017-07-20 15:22:39 -0700104 attempts=10 )
105 if ready:
106 ready = main.TRUE
107 utilities.assert_equals( expect=main.TRUE, actual=ready,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700108 onpass="ONOS summary command succeded",
109 onfail="ONOS summary command failed" )
110
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -0800111 with open( "%s/json/%s.json" % (main.configPath, main.cfgName)) as cfg:
112 main.Cluster.active( 0 ).REST.setNetCfg(json.load(cfg))
113 with open("%s/json/%s.chart" % (main.configPath, main.cfgName)) as chart:
114 main.pingChart = json.load(chart)
Jon Hall1efcb3f2016-08-23 13:42:15 -0700115 if not ready:
116 main.log.error( "ONOS startup failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700117 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700118
Devin Lim142b5342017-07-20 15:22:39 -0700119 for ctrl in main.Cluster.active():
120 ctrl.CLI.logSet( "DEBUG", "org.onosproject.segmentrouting" )
121 ctrl.CLI.logSet( "DEBUG", "org.onosproject.driver.pipeline" )
122 ctrl.CLI.logSet( "DEBUG", "org.onosproject.store.group.impl" )
123 ctrl.CLI.logSet( "DEBUG", "org.onosproject.net.flowobjective.impl" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700124
125 @staticmethod
126 def startMininet( main, topology, args="" ):
You Wangd87b2312018-01-30 12:47:17 -0800127 copyResult = main.ONOSbench.scp( main.Mininet1,
128 main.topoPath + main.topology,
129 main.Mininet1.home,
130 direction="to" )
131 if main.topologyLib:
132 for lib in main.topologyLib.split(","):
133 copyResult = copyResult and main.ONOSbench.scp( main.Mininet1,
134 main.topoPath + lib,
135 main.Mininet1.home,
136 direction="to" )
137 if main.topologyConf:
138 for conf in main.topologyConf.split(","):
139 copyResult = copyResult and main.ONOSbench.scp( main.Mininet1,
You Wang69362682018-02-12 13:35:54 -0800140 main.configPath + conf,
141 "~/",
142 direction="to" )
143 if main.testConf:
144 for conf in main.testConf.split(","):
145 copyResult = copyResult and main.ONOSbench.scp( main.Mininet1,
146 main.testConfPath + conf,
You Wangd87b2312018-01-30 12:47:17 -0800147 "~/",
148 direction="to" )
149 stepResult = copyResult
150 utilities.assert_equals( expect=main.TRUE,
151 actual=stepResult,
152 onpass="Successfully copied topo files",
153 onfail="Failed to copy topo files" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700154 main.step( "Starting Mininet Topology" )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700155 arg = "--onos-ip=%s %s" % (",".join([ctrl.ipAddress for ctrl in main.Cluster.runningNodes]), args)
Jon Hall1efcb3f2016-08-23 13:42:15 -0700156 main.topology = topology
157 topoResult = main.Mininet1.startNet(
158 topoFile=main.Mininet1.home + main.topology, args=arg )
159 stepResult = topoResult
160 utilities.assert_equals( expect=main.TRUE,
161 actual=stepResult,
162 onpass="Successfully loaded topology",
163 onfail="Failed to load topology" )
164 # Exit if topology did not load properly
165 if not topoResult:
Devin Lim44075962017-08-11 10:56:37 -0700166 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700167
168 @staticmethod
You Wang84f981d2018-01-12 16:11:50 -0800169 def connectToPhysicalNetwork( main, switchNames ):
170 main.step( "Connecting to physical netowrk" )
171 topoResult = main.NetworkBench.connectToNet()
172 stepResult = topoResult
173 utilities.assert_equals( expect=main.TRUE,
174 actual=stepResult,
175 onpass="Successfully loaded topology",
176 onfail="Failed to load topology" )
177 # Exit if topology did not load properly
178 if not topoResult:
179 main.cleanAndExit()
180
181 main.step( "Assign switches to controllers." )
182 assignResult = main.TRUE
183 for name in switchNames:
184 assignResult = assignResult & main.NetworkBench.assignSwController( sw=name,
185 ip=main.Cluster.getIps(),
186 port='6653' )
187 utilities.assert_equals( expect=main.TRUE,
188 actual=stepResult,
189 onpass="Successfully assign switches to controllers",
190 onfail="Failed to assign switches to controllers" )
191
192 @staticmethod
Devin Lim142b5342017-07-20 15:22:39 -0700193 def config( main, cfgName ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700194 main.spines = []
Piera2a7e1b2016-10-04 11:51:43 -0700195
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700196 main.failures = int( main.params[ 'failures' ] )
197 main.cfgName = cfgName
Piera2a7e1b2016-10-04 11:51:43 -0700198
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700199 if main.cfgName == '2x2':
200 spine = {}
201 spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ]
202 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ]
203 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700204
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700205 spine = {}
206 spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ]
207 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ]
208 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700209
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700210 elif main.cfgName == '4x4':
211 spine = {}
212 spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ]
213 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ]
214 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700215
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700216 spine = {}
217 spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ]
218 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ]
219 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700220
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700221 spine = {}
222 spine[ 'name' ] = main.params[ 'switches' ][ 'spine3' ]
223 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid3' ]
224 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700225
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700226 spine = {}
227 spine[ 'name' ] = main.params[ 'switches' ][ 'spine4' ]
228 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid4' ]
229 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700230
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700231 else:
Piera2a7e1b2016-10-04 11:51:43 -0700232 main.log.error( "Configuration failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700233 main.cleanAndExit()
Piera2a7e1b2016-10-04 11:51:43 -0700234
235 @staticmethod
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900236 def checkFlows( main, minFlowCount, tag="", dumpflows=True, sleep=10 ):
Jon Hall1efcb3f2016-08-23 13:42:15 -0700237 main.step(
238 " Check whether the flow count is bigger than %s" % minFlowCount )
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900239 if tag == "":
240 tag = 'CASE%d' % main.CurrentTestCaseNumber
Devin Lim142b5342017-07-20 15:22:39 -0700241 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowCount,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700242 main.FALSE,
243 kwargs={ 'min': minFlowCount },
244 attempts=10,
You Wang1cdc5f52017-12-19 16:47:51 -0800245 sleep=sleep )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700246 utilities.assertEquals(
Jon Hall1efcb3f2016-08-23 13:42:15 -0700247 expect=True,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700248 actual=( count > 0 ),
Jon Hall1efcb3f2016-08-23 13:42:15 -0700249 onpass="Flow count looks correct: " + str( count ),
250 onfail="Flow count looks wrong: " + str( count ) )
251
252 main.step( "Check whether all flow status are ADDED" )
Devin Lim142b5342017-07-20 15:22:39 -0700253 flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700254 main.FALSE,
255 kwargs={ 'isPENDING': False },
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800256 attempts=5,
You Wang1cdc5f52017-12-19 16:47:51 -0800257 sleep=sleep )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700258 utilities.assertEquals(
Jon Hall1efcb3f2016-08-23 13:42:15 -0700259 expect=main.TRUE,
260 actual=flowCheck,
261 onpass="Flow status is correct!",
262 onfail="Flow status is wrong!" )
263 if dumpflows:
Devin Lim142b5342017-07-20 15:22:39 -0700264 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700265 "flows",
266 main.logdir,
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900267 tag + "_FlowsBefore" )
Devin Lim142b5342017-07-20 15:22:39 -0700268 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700269 "groups",
270 main.logdir,
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900271 tag + "_GroupsBefore" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700272
273 @staticmethod
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800274 def checkFlowsByDpid( main, dpid, minFlowCount, sleep=10 ):
275 main.step(
276 " Check whether the flow count of device %s is bigger than %s" % ( dpid, minFlowCount ) )
277 count = utilities.retry( main.Cluster.active( 0 ).CLI.flowAddedCount,
278 None,
279 args=( dpid, ),
280 attempts=5,
281 sleep=sleep )
282 utilities.assertEquals(
283 expect=True,
284 actual=( int( count ) > minFlowCount ),
285 onpass="Flow count looks correct: " + count ,
286 onfail="Flow count looks wrong: " + count )
287
288 @staticmethod
You Wangf19d9f42018-02-23 16:34:19 -0800289 def pingAll( main, tag="", dumpflows=True, acceptableFailed=0, basedOnIp=False ):
290 '''
291 acceptableFailed: max number of acceptable failed pings. Only works for ping6
292 basedOnIp: if True, run ping or ping6 based on suffix of host names
293 '''
Andreas Pantelopoulosf6ed5012018-02-08 21:26:01 -0800294 main.log.report( "Check full connectivity" )
295 print main.pingChart
296 if tag == "":
297 tag = 'CASE%d' % main.CurrentTestCaseNumber
298 for entry in main.pingChart.itervalues():
299 print entry
300 hosts, expect = entry[ 'hosts' ], entry[ 'expect' ]
301 try:
302 expect = main.TRUE if str(expect).lower() == 'true' else main.FALSE
303 except:
304 expect = main.FALSE
305 main.step( "Connectivity for %s %s" % ( str( hosts ), tag ) )
306
You Wangf19d9f42018-02-23 16:34:19 -0800307 if basedOnIp:
308 if ("v4" in hosts[0]):
309 pa = main.Network.pingallHosts( hosts )
310 utilities.assert_equals( expect=expect, actual=pa,
311 onpass="IPv4 connectivity successfully tested",
312 onfail="IPv4 connectivity failed" )
313 if ("v6" in hosts[0]):
314 pa = main.Network.pingIpv6Hosts( hosts, acceptableFailed=acceptableFailed )
315 utilities.assert_equals( expect=expect, actual=pa,
316 onpass="IPv6 connectivity successfully tested",
317 onfail="IPv6 connectivity failed" )
318 else:
Andreas Pantelopoulosf6ed5012018-02-08 21:26:01 -0800319 pa = main.Network.pingallHosts( hosts )
320 utilities.assert_equals( expect=expect, actual=pa,
You Wangf19d9f42018-02-23 16:34:19 -0800321 onpass="IP connectivity successfully tested",
322 onfail="IP connectivity failed" )
Andreas Pantelopoulosf6ed5012018-02-08 21:26:01 -0800323
324 if dumpflows:
325 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
326 "flows",
327 main.logdir,
328 tag + "_FlowsOn" )
329 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
330 "groups",
331 main.logdir,
332 tag + "_GroupsOn" )
333
334 @staticmethod
Jon Hall1efcb3f2016-08-23 13:42:15 -0700335 def killLink( main, end1, end2, switches, links ):
336 """
337 end1,end2: identify the switches, ex.: 'leaf1', 'spine1'
338 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
339 Kill a link and verify ONOS can see the proper link change
340 """
341 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700342 main.step( "Kill link between %s and %s" % ( end1, end2 ) )
You Wangd5873482018-01-24 12:30:00 -0800343 LinkDown = main.Network.link( END1=end1, END2=end2, OPTION="down" )
344 LinkDown = main.Network.link( END2=end1, END1=end2, OPTION="down" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700345 main.log.info(
346 "Waiting %s seconds for link down to be discovered" % main.linkSleep )
347 time.sleep( main.linkSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700348 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700349 main.FALSE,
350 kwargs={ 'numoswitch': switches,
351 'numolink': links },
352 attempts=10,
353 sleep=main.linkSleep )
354 result = topology & LinkDown
355 utilities.assert_equals( expect=main.TRUE, actual=result,
356 onpass="Link down successful",
357 onfail="Failed to turn off link?" )
358
359 @staticmethod
360 def restoreLink( main, end1, end2, dpid1, dpid2, port1, port2, switches,
361 links ):
362 """
363 Params:
364 end1,end2: identify the end switches, ex.: 'leaf1', 'spine1'
365 dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002'
366 port1, port2: respective port of the end switches that connects to the link, ex.:'1'
367 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
368 Kill a link and verify ONOS can see the proper link change
369 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700370 main.step( "Restore link between %s and %s" % ( end1, end2 ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700371 result = False
372 count = 0
373 while True:
374 count += 1
You Wangd5873482018-01-24 12:30:00 -0800375 main.Network.link( END1=end1, END2=end2, OPTION="up" )
376 main.Network.link( END2=end1, END1=end2, OPTION="up" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700377 main.log.info(
378 "Waiting %s seconds for link up to be discovered" % main.linkSleep )
379 time.sleep( main.linkSleep )
Pierfb719b12016-09-19 14:51:44 -0700380
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700381 for i in range( 0, main.Cluster.numCtrls ):
Devin Lim142b5342017-07-20 15:22:39 -0700382 ctrl = main.Cluster.runningNodes[ i ]
383 onosIsUp = main.ONOSbench.isup( ctrl.ipAddress )
Pierfb719b12016-09-19 14:51:44 -0700384 if onosIsUp == main.TRUE:
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900385 ctrl.CLI.portstate( dpid=dpid1, port=port1, state='Enable' )
386 ctrl.CLI.portstate( dpid=dpid2, port=port2, state='Enable' )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700387 time.sleep( main.linkSleep )
388
Devin Lim142b5342017-07-20 15:22:39 -0700389 result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches,
390 numolink=links )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700391 if count > 5 or result:
392 break
393 utilities.assert_equals( expect=main.TRUE, actual=result,
394 onpass="Link up successful",
395 onfail="Failed to bring link up" )
396
397 @staticmethod
398 def killSwitch( main, switch, switches, links ):
399 """
400 Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6'
401 Completely kill a switch and verify ONOS can see the proper change
402 """
403 main.switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
404 main.step( "Kill " + switch )
405 main.log.info( "Stopping" + switch )
You Wangd5873482018-01-24 12:30:00 -0800406 main.Network.switch( SW=switch, OPTION="stop" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700407 # todo make this repeatable
408 main.log.info( "Waiting %s seconds for switch down to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700409 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700410 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700411 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700412 main.FALSE,
413 kwargs={ 'numoswitch': switches,
414 'numolink': links },
415 attempts=10,
416 sleep=main.switchSleep )
417 utilities.assert_equals( expect=main.TRUE, actual=topology,
418 onpass="Kill switch successful",
419 onfail="Failed to kill switch?" )
420
421 @staticmethod
422 def recoverSwitch( main, switch, switches, links ):
423 """
424 Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6'
425 Recover a switch and verify ONOS can see the proper change
426 """
427 # todo make this repeatable
428 main.step( "Recovering " + switch )
429 main.log.info( "Starting" + switch )
You Wangd5873482018-01-24 12:30:00 -0800430 main.Network.switch( SW=switch, OPTION="start" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700431 main.log.info( "Waiting %s seconds for switch up to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700432 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700433 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700434 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700435 main.FALSE,
436 kwargs={ 'numoswitch': switches,
437 'numolink': links },
438 attempts=10,
439 sleep=main.switchSleep )
440 utilities.assert_equals( expect=main.TRUE, actual=topology,
441 onpass="Switch recovery successful",
442 onfail="Failed to recover switch?" )
443
444 @staticmethod
445 def cleanup( main ):
446 """
447 Stop Onos-cluster.
448 Stops Mininet
449 Copies ONOS log
450 """
Devin Lim58046fa2017-07-05 16:55:00 -0700451 try:
452 from tests.dependencies.utils import Utils
453 except ImportError:
454 main.log.error( "Utils not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700455 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700456 try:
Devin Lim142b5342017-07-20 15:22:39 -0700457 main.utils
Devin Lim58046fa2017-07-05 16:55:00 -0700458 except ( NameError, AttributeError ):
Devin Lim142b5342017-07-20 15:22:39 -0700459 main.utils = Utils()
Devin Lim58046fa2017-07-05 16:55:00 -0700460
461 main.utils.mininetCleanup( main.Mininet1 )
462
Devin Lim0c972b72018-02-08 14:53:59 -0800463 main.utils.copyKarafLog( "CASE%d" % main.CurrentTestCaseNumber, before=True, includeCaseDesc=False )
Devin Lim58046fa2017-07-05 16:55:00 -0700464
Devin Lim142b5342017-07-20 15:22:39 -0700465 for ctrl in main.Cluster.active():
466 main.ONOSbench.onosStop( ctrl.ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700467
468 @staticmethod
469 def killOnos( main, nodes, switches, links, expNodes ):
470 """
471 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
472 switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6'
473 Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change
474 """
475 main.step( "Killing ONOS instance" )
Pier3b58c652016-09-26 12:03:31 -0700476
Jon Hall1efcb3f2016-08-23 13:42:15 -0700477 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700478 killResult = main.ONOSbench.onosDie( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700479 utilities.assert_equals( expect=main.TRUE, actual=killResult,
480 onpass="ONOS instance Killed",
481 onfail="Error killing ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700482 main.Cluster.runningNodes[ i ].active = False
Jon Hall1efcb3f2016-08-23 13:42:15 -0700483 time.sleep( 12 )
Pier3b58c652016-09-26 12:03:31 -0700484
Devin Lim142b5342017-07-20 15:22:39 -0700485 if len( nodes ) < main.Cluster.numCtrls:
Pier3b58c652016-09-26 12:03:31 -0700486
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700487 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700488 False,
Pier3b58c652016-09-26 12:03:31 -0700489 attempts=5,
490 sleep=10 )
491 utilities.assert_equals( expect=True, actual=nodeResults,
492 onpass="Nodes check successful",
493 onfail="Nodes check NOT successful" )
494
495 if not nodeResults:
496 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700497 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700498 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700499 ctrl.name,
500 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700501 main.log.error( "Failed to kill ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700502 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700503
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900504 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700505 main.FALSE,
506 kwargs={ 'numoswitch': switches,
507 'numolink': links,
508 'numoctrl': expNodes },
509 attempts=10,
510 sleep=12 )
511 utilities.assert_equals( expect=main.TRUE, actual=topology,
512 onpass="ONOS Instance down successful",
513 onfail="Failed to turn off ONOS Instance" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700514
515 @staticmethod
516 def recoverOnos( main, nodes, switches, links, expNodes ):
517 """
518 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
519 switches, links, nodes: number of expected switches, links and nodes after recoverOnos, ex.: '4', '6'
520 Recover an ONOS instance and verify the ONOS cluster can see the proper change
521 """
522 main.step( "Recovering ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700523 [ main.ONOSbench.onosStart( main.Cluster.runningNodes[ i ].ipAddress ) for i in nodes ]
Jon Hall1efcb3f2016-08-23 13:42:15 -0700524 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700525 isUp = main.ONOSbench.isup( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700526 utilities.assert_equals( expect=main.TRUE, actual=isUp,
527 onpass="ONOS service is ready",
528 onfail="ONOS service did not start properly" )
529 for i in nodes:
530 main.step( "Checking if ONOS CLI is ready" )
Devin Lim142b5342017-07-20 15:22:39 -0700531 ctrl = main.Cluster.runningNodes[ i ]
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900532 # ctrl.CLI.startCellCli()
Devin Lim142b5342017-07-20 15:22:39 -0700533 cliResult = ctrl.CLI.startOnosCli( ctrl.ipAddress,
534 commandlineTimeout=60,
535 onosStartTimeout=100 )
536 ctrl.active = True
Jon Hall1efcb3f2016-08-23 13:42:15 -0700537 utilities.assert_equals( expect=main.TRUE,
538 actual=cliResult,
539 onpass="ONOS CLI is ready",
540 onfail="ONOS CLI is not ready" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700541
Pier3b58c652016-09-26 12:03:31 -0700542 main.step( "Checking ONOS nodes" )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700543 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700544 False,
Pier3b58c652016-09-26 12:03:31 -0700545 attempts=5,
546 sleep=10 )
547 utilities.assert_equals( expect=True, actual=nodeResults,
548 onpass="Nodes check successful",
549 onfail="Nodes check NOT successful" )
550
551 if not nodeResults:
552 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700553 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700554 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700555 ctrl.name,
556 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700557 main.log.error( "Failed to start ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700558 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700559
Devin Lim142b5342017-07-20 15:22:39 -0700560 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700561 main.FALSE,
562 kwargs={ 'numoswitch': switches,
563 'numolink': links,
564 'numoctrl': expNodes },
565 attempts=10,
566 sleep=12 )
567 utilities.assert_equals( expect=main.TRUE, actual=topology,
568 onpass="ONOS Instance down successful",
569 onfail="Failed to turn off ONOS Instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700570 ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary,
571 main.FALSE,
572 attempts=10,
573 sleep=12 )
574 if ready:
575 ready = main.TRUE
576 utilities.assert_equals( expect=main.TRUE, actual=ready,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700577 onpass="ONOS summary command succeded",
578 onfail="ONOS summary command failed" )
579 if not ready:
580 main.log.error( "ONOS startup failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700581 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700582
583 @staticmethod
584 def addHostCfg( main ):
585 """
586 Adds Host Configuration to ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700587 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700588 """
589 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700590 hostCfg = {}
You Wangac02b142018-01-26 14:57:28 -0800591 with open( main.configPath + "/json/extra.json" ) as template:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700592 hostCfg = json.load( template )
593 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ]
594 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700595 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700596 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
597 subjectClass="hosts",
598 subjectKey=urllib.quote( mac,
599 safe='' ),
600 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700601 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ]
602 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700603 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700604 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
605 subjectClass="hosts",
606 subjectKey=urllib.quote( mac,
607 safe='' ),
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700608 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700609 main.pingChart.update( { 'vlan1': { "expect": "True",
610 "hosts": [ "olt1", "vsg1" ] } } )
611 main.pingChart[ 'vlan5' ][ 'expect' ] = 0
612 main.pingChart[ 'vlan10' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700613 ports = "[%s,%s]" % ( 5, 6 )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700614 cfg = '{"of:0000000000000001":[{"vlan":1,"ports":%s,"name":"OLT 1"}]}' % ports
Devin Lim142b5342017-07-20 15:22:39 -0700615 main.Cluster.active( 0 ).REST.setNetCfg( json.loads( cfg ),
616 subjectClass="apps",
617 subjectKey="org.onosproject.segmentrouting",
618 configKey="xconnect" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700619
620 @staticmethod
621 def delHostCfg( main ):
622 """
623 Removest Host Configuration from ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700624 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700625 """
626 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700627 hostCfg = {}
You Wangac02b142018-01-26 14:57:28 -0800628 with open( main.configPath + "/json/extra.json" ) as template:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700629 hostCfg = json.load( template )
630 main.step( "Removing host configuration" )
631 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700632 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700633 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
634 subjectKey=urllib.quote(
635 mac,
636 safe='' ),
637 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700638 main.step( "Removing configuration" )
639 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700640 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700641 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
642 subjectKey=urllib.quote(
643 mac,
644 safe='' ),
645 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700646 main.step( "Removing vlan configuration" )
647 main.pingChart[ 'vlan1' ][ 'expect' ] = 0
Devin Lim142b5342017-07-20 15:22:39 -0700648 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="apps",
649 subjectKey="org.onosproject.segmentrouting",
650 configKey="xconnect" )