blob: dd93fe4dd9ed7072a82fa66cc13fbdb6d665d0e9 [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 )
Devin Lim57221b02018-02-14 15:45:36 -080060 main.useCommonTopo = main.params[ 'DEPENDENCY' ][ 'useCommonTopo' ] == 'True'
61 main.topoPath = main.path + ( "/.." if main.useCommonTopo else "" ) + "/dependencies/"
62 main.useCommonConf = main.params[ 'DEPENDENCY' ][ 'useCommonConf' ] == 'True'
63 main.configPath = main.path + ( "/.." if main.useCommonConf else "" ) + "/dependencies/"
64 main.forJson = "json/"
65 main.forChart = "chart/"
66 main.forConfig = "conf/"
67 main.forHost = "host/"
Devin Lim58046fa2017-07-05 16:55:00 -070068 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
You Wangd87b2312018-01-30 12:47:17 -080069 main.topologyLib = main.params[ 'DEPENDENCY' ][ 'lib' ] if 'lib' in main.params[ 'DEPENDENCY' ] else None
70 main.topologyConf = main.params[ 'DEPENDENCY' ][ 'conf' ] if 'conf' in main.params[ 'DEPENDENCY' ] else None
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070071 main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," )
Devin Lim58046fa2017-07-05 16:55:00 -070072 main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
Devin Lim58046fa2017-07-05 16:55:00 -070073 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
Jon Hall1efcb3f2016-08-23 13:42:15 -070074
Devin Lim0c972b72018-02-08 14:53:59 -080075 stepResult = main.testSetUp.envSetup( False )
Devin Lim58046fa2017-07-05 16:55:00 -070076 except Exception as e:
77 main.testSetUp.envSetupException( e )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -070078
Devin Lim58046fa2017-07-05 16:55:00 -070079 main.testSetUp.evnSetupConclusion( stepResult )
Jon Hall1efcb3f2016-08-23 13:42:15 -070080
Jon Hall1efcb3f2016-08-23 13:42:15 -070081 @staticmethod
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -080082 def installOnos( main, vlanCfg=True, skipPackage=False, cliSleep=10,
83 parallel=True ):
Jon Hall1efcb3f2016-08-23 13:42:15 -070084 """
85 - Set up cell
86 - Create cell file
87 - Set cell file
88 - Verify cell file
89 - Kill ONOS process
90 - Uninstall ONOS cluster
91 - Verify ONOS start up
92 - Install ONOS cluster
93 - Connect to cli
94 """
95 # main.scale[ 0 ] determines the current number of ONOS controller
You Wangd87b2312018-01-30 12:47:17 -080096 if not main.apps:
Jon Hall1efcb3f2016-08-23 13:42:15 -070097 main.log.error( "App list is empty" )
Devin Lim142b5342017-07-20 15:22:39 -070098 main.log.info( "NODE COUNT = " + str( main.Cluster.numCtrls ) )
99 main.log.info( ''.join( main.Cluster.getIps() ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700100 main.dynamicHosts = [ 'in1', 'out1' ]
You Wanga0f6ff62018-01-11 15:46:30 -0800101 main.testSetUp.ONOSSetUp( main.Cluster, newCell=True, cellName=main.cellName,
Andreas Pantelopoulos90f0b102018-02-01 13:21:45 -0800102 skipPack=skipPackage,
103 useSSH=Testcaselib.useSSH,
Devin Lim0c972b72018-02-08 14:53:59 -0800104 installParallel=parallel, includeCaseDesc=False )
Devin Lim142b5342017-07-20 15:22:39 -0700105 ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary,
106 main.FALSE,
You Wang1cdc5f52017-12-19 16:47:51 -0800107 sleep=cliSleep,
Devin Lim142b5342017-07-20 15:22:39 -0700108 attempts=10 )
109 if ready:
110 ready = main.TRUE
111 utilities.assert_equals( expect=main.TRUE, actual=ready,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700112 onpass="ONOS summary command succeded",
113 onfail="ONOS summary command failed" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700114 if not ready:
115 main.log.error( "ONOS startup failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700116 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700117
Devin Lim142b5342017-07-20 15:22:39 -0700118 for ctrl in main.Cluster.active():
119 ctrl.CLI.logSet( "DEBUG", "org.onosproject.segmentrouting" )
120 ctrl.CLI.logSet( "DEBUG", "org.onosproject.driver.pipeline" )
121 ctrl.CLI.logSet( "DEBUG", "org.onosproject.store.group.impl" )
122 ctrl.CLI.logSet( "DEBUG", "org.onosproject.net.flowobjective.impl" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700123
124 @staticmethod
Andreas Pantelopoulos9173d442018-03-01 17:07:37 -0800125 def loadCount( main ):
126 with open("%s/count/%s.count" % (main.configPath, main.cfgName)) as count:
127 main.count = json.load(count)
128
129 @staticmethod
Devin Lim57221b02018-02-14 15:45:36 -0800130 def loadJson( main ):
131 with open( "%s%s.json" % ( main.configPath + main.forJson,
132 main.cfgName ) ) as cfg:
133 main.Cluster.active( 0 ).REST.setNetCfg( json.load( cfg ) )
134
135 @staticmethod
136 def loadChart( main ):
137 try:
138 with open( "%s%s.chart" % ( main.configPath + main.forChart,
139 main.cfgName ) ) as chart:
140 main.pingChart = json.load(chart)
141 except IOError:
142 main.log.warn( "No chart file found." )
143
144 @staticmethod
145 def loadHost( main ):
146 with open( "%s%s.host" % ( main.configPath + main.forHost,
147 main.cfgName ) ) as host:
148 main.expectedHosts = json.load( host )
149
150 @staticmethod
Jon Hall1efcb3f2016-08-23 13:42:15 -0700151 def startMininet( main, topology, args="" ):
You Wangd87b2312018-01-30 12:47:17 -0800152 copyResult = main.ONOSbench.scp( main.Mininet1,
153 main.topoPath + main.topology,
154 main.Mininet1.home,
155 direction="to" )
156 if main.topologyLib:
157 for lib in main.topologyLib.split(","):
158 copyResult = copyResult and main.ONOSbench.scp( main.Mininet1,
159 main.topoPath + lib,
160 main.Mininet1.home,
161 direction="to" )
162 if main.topologyConf:
163 for conf in main.topologyConf.split(","):
164 copyResult = copyResult and main.ONOSbench.scp( main.Mininet1,
Devin Lim57221b02018-02-14 15:45:36 -0800165 main.configPath + main.forConfig + conf,
You Wangd87b2312018-01-30 12:47:17 -0800166 "~/",
167 direction="to" )
168 stepResult = copyResult
169 utilities.assert_equals( expect=main.TRUE,
170 actual=stepResult,
171 onpass="Successfully copied topo files",
172 onfail="Failed to copy topo files" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700173 main.step( "Starting Mininet Topology" )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700174 arg = "--onos-ip=%s %s" % (",".join([ctrl.ipAddress for ctrl in main.Cluster.runningNodes]), args)
Jon Hall1efcb3f2016-08-23 13:42:15 -0700175 main.topology = topology
176 topoResult = main.Mininet1.startNet(
177 topoFile=main.Mininet1.home + main.topology, args=arg )
178 stepResult = topoResult
179 utilities.assert_equals( expect=main.TRUE,
180 actual=stepResult,
181 onpass="Successfully loaded topology",
182 onfail="Failed to load topology" )
183 # Exit if topology did not load properly
184 if not topoResult:
Devin Lim44075962017-08-11 10:56:37 -0700185 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700186
187 @staticmethod
You Wang84f981d2018-01-12 16:11:50 -0800188 def connectToPhysicalNetwork( main, switchNames ):
189 main.step( "Connecting to physical netowrk" )
190 topoResult = main.NetworkBench.connectToNet()
191 stepResult = topoResult
192 utilities.assert_equals( expect=main.TRUE,
193 actual=stepResult,
194 onpass="Successfully loaded topology",
195 onfail="Failed to load topology" )
196 # Exit if topology did not load properly
197 if not topoResult:
198 main.cleanAndExit()
199
200 main.step( "Assign switches to controllers." )
201 assignResult = main.TRUE
202 for name in switchNames:
203 assignResult = assignResult & main.NetworkBench.assignSwController( sw=name,
204 ip=main.Cluster.getIps(),
205 port='6653' )
206 utilities.assert_equals( expect=main.TRUE,
207 actual=stepResult,
208 onpass="Successfully assign switches to controllers",
209 onfail="Failed to assign switches to controllers" )
210
211 @staticmethod
Devin Lim142b5342017-07-20 15:22:39 -0700212 def config( main, cfgName ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700213 main.spines = []
Piera2a7e1b2016-10-04 11:51:43 -0700214
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700215 main.failures = int( main.params[ 'failures' ] )
216 main.cfgName = cfgName
Piera2a7e1b2016-10-04 11:51:43 -0700217
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700218 if main.cfgName == '2x2':
219 spine = {}
220 spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ]
221 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ]
222 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700223
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700224 spine = {}
225 spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ]
226 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ]
227 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700228
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700229 elif main.cfgName == '4x4':
230 spine = {}
231 spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ]
232 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ]
233 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700234
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700235 spine = {}
236 spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ]
237 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ]
238 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700239
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700240 spine = {}
241 spine[ 'name' ] = main.params[ 'switches' ][ 'spine3' ]
242 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid3' ]
243 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700244
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700245 spine = {}
246 spine[ 'name' ] = main.params[ 'switches' ][ 'spine4' ]
247 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid4' ]
248 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700249
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700250 else:
Piera2a7e1b2016-10-04 11:51:43 -0700251 main.log.error( "Configuration failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700252 main.cleanAndExit()
Piera2a7e1b2016-10-04 11:51:43 -0700253
254 @staticmethod
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900255 def checkFlows( main, minFlowCount, tag="", dumpflows=True, sleep=10 ):
Jon Hall1efcb3f2016-08-23 13:42:15 -0700256 main.step(
257 " Check whether the flow count is bigger than %s" % minFlowCount )
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900258 if tag == "":
259 tag = 'CASE%d' % main.CurrentTestCaseNumber
Devin Lim142b5342017-07-20 15:22:39 -0700260 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowCount,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700261 main.FALSE,
262 kwargs={ 'min': minFlowCount },
263 attempts=10,
You Wang1cdc5f52017-12-19 16:47:51 -0800264 sleep=sleep )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700265 utilities.assertEquals(
Jon Hall1efcb3f2016-08-23 13:42:15 -0700266 expect=True,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700267 actual=( count > 0 ),
Jon Hall1efcb3f2016-08-23 13:42:15 -0700268 onpass="Flow count looks correct: " + str( count ),
269 onfail="Flow count looks wrong: " + str( count ) )
270
271 main.step( "Check whether all flow status are ADDED" )
Devin Lim142b5342017-07-20 15:22:39 -0700272 flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700273 main.FALSE,
274 kwargs={ 'isPENDING': False },
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800275 attempts=5,
You Wang1cdc5f52017-12-19 16:47:51 -0800276 sleep=sleep )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700277 utilities.assertEquals(
Jon Hall1efcb3f2016-08-23 13:42:15 -0700278 expect=main.TRUE,
279 actual=flowCheck,
280 onpass="Flow status is correct!",
281 onfail="Flow status is wrong!" )
282 if dumpflows:
Devin Lim142b5342017-07-20 15:22:39 -0700283 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700284 "flows",
285 main.logdir,
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900286 tag + "_FlowsBefore" )
Devin Lim142b5342017-07-20 15:22:39 -0700287 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700288 "groups",
289 main.logdir,
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900290 tag + "_GroupsBefore" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700291
292 @staticmethod
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800293 def checkFlowsByDpid( main, dpid, minFlowCount, sleep=10 ):
294 main.step(
Jonghwan Hyuncf2345c2018-02-26 11:07:54 -0800295 " Check whether the flow count of device %s is bigger than %s" % ( dpid, minFlowCount ) )
296 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowAddedCount,
297 main.FALSE,
298 args=( dpid, minFlowCount ),
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800299 attempts=5,
300 sleep=sleep )
301 utilities.assertEquals(
Jonghwan Hyuncf2345c2018-02-26 11:07:54 -0800302 expect=True,
303 actual=( count > minFlowCount ),
304 onpass="Flow count looks correct: " + str( count ),
305 onfail="Flow count looks wrong. " )
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800306
307 @staticmethod
Andreas Pantelopoulos9173d442018-03-01 17:07:37 -0800308 def checkFlowEqualityByDpid( main, dpid, flowCount, sleep=10):
309 main.step(
310 " Check whether the flow count of device %s is equal to %s" % ( dpid, flowCount ) )
311 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowAddedCount,
312 main.FALSE,
313 args=( dpid, flowCount, False, 1),
314 attempts=5,
315 sleep=sleep )
316
317 utilities.assertEquals(
318 expect=True,
319 actual=( int( count ) == flowCount ),
320 onpass="Flow count looks correct: " + str(count) ,
321 onfail="Flow count looks wrong, should be " + str(flowCount))
322
323 @staticmethod
324 def checkGroupEqualityByDpid( main, dpid, groupCount, sleep=10):
325 main.step(
326 " Check whether the group count of device %s is equal to %s" % ( dpid, groupCount ) )
327 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkGroupAddedCount,
328 main.FALSE,
329 args=( dpid, groupCount, False, 1),
330 attempts=5,
331 sleep=sleep )
332
333 utilities.assertEquals(
334 expect=True,
335 actual=( count == groupCount ),
336 onpass="Group count looks correct: " + str(count) ,
337 onfail="Group count looks wrong: should be " + str(groupCount))
338
339 @staticmethod
340 def checkFlowsGroupsFromFile(main):
341
342 for dpid, values in main.count.items():
343 flowCount = values["flows"]
344 groupCount = values["groups"]
345 main.log.report( "Check flow count for dpid " + str(dpid) +
346 ", should be " + str(flowCount))
347 Testcaselib.checkFlowEqualityByDpid(main, dpid, flowCount)
348
349 main.log.report( "Check group count for dpid " + str(dpid) +
350 ", should be " + str(groupCount))
351 Testcaselib.checkGroupEqualityByDpid(main, dpid, groupCount)
352
353 return
354
355 @staticmethod
You Wangf19d9f42018-02-23 16:34:19 -0800356 def pingAll( main, tag="", dumpflows=True, acceptableFailed=0, basedOnIp=False ):
357 '''
358 acceptableFailed: max number of acceptable failed pings. Only works for ping6
359 basedOnIp: if True, run ping or ping6 based on suffix of host names
360 '''
Andreas Pantelopoulosf6ed5012018-02-08 21:26:01 -0800361 main.log.report( "Check full connectivity" )
362 print main.pingChart
363 if tag == "":
364 tag = 'CASE%d' % main.CurrentTestCaseNumber
365 for entry in main.pingChart.itervalues():
366 print entry
367 hosts, expect = entry[ 'hosts' ], entry[ 'expect' ]
368 try:
369 expect = main.TRUE if str(expect).lower() == 'true' else main.FALSE
370 except:
371 expect = main.FALSE
372 main.step( "Connectivity for %s %s" % ( str( hosts ), tag ) )
373
You Wangf19d9f42018-02-23 16:34:19 -0800374 if basedOnIp:
375 if ("v4" in hosts[0]):
376 pa = main.Network.pingallHosts( hosts )
377 utilities.assert_equals( expect=expect, actual=pa,
378 onpass="IPv4 connectivity successfully tested",
379 onfail="IPv4 connectivity failed" )
380 if ("v6" in hosts[0]):
381 pa = main.Network.pingIpv6Hosts( hosts, acceptableFailed=acceptableFailed )
382 utilities.assert_equals( expect=expect, actual=pa,
383 onpass="IPv6 connectivity successfully tested",
384 onfail="IPv6 connectivity failed" )
385 else:
Andreas Pantelopoulosf6ed5012018-02-08 21:26:01 -0800386 pa = main.Network.pingallHosts( hosts )
387 utilities.assert_equals( expect=expect, actual=pa,
You Wangf19d9f42018-02-23 16:34:19 -0800388 onpass="IP connectivity successfully tested",
389 onfail="IP connectivity failed" )
Andreas Pantelopoulosf6ed5012018-02-08 21:26:01 -0800390
391 if dumpflows:
392 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
393 "flows",
394 main.logdir,
395 tag + "_FlowsOn" )
396 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
397 "groups",
398 main.logdir,
399 tag + "_GroupsOn" )
400
401 @staticmethod
Jon Hall1efcb3f2016-08-23 13:42:15 -0700402 def killLink( main, end1, end2, switches, links ):
403 """
404 end1,end2: identify the switches, ex.: 'leaf1', 'spine1'
405 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
406 Kill a link and verify ONOS can see the proper link change
407 """
408 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700409 main.step( "Kill link between %s and %s" % ( end1, end2 ) )
You Wangd5873482018-01-24 12:30:00 -0800410 LinkDown = main.Network.link( END1=end1, END2=end2, OPTION="down" )
411 LinkDown = main.Network.link( END2=end1, END1=end2, OPTION="down" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700412 main.log.info(
413 "Waiting %s seconds for link down to be discovered" % main.linkSleep )
414 time.sleep( main.linkSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700415 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700416 main.FALSE,
417 kwargs={ 'numoswitch': switches,
418 'numolink': links },
419 attempts=10,
420 sleep=main.linkSleep )
421 result = topology & LinkDown
422 utilities.assert_equals( expect=main.TRUE, actual=result,
423 onpass="Link down successful",
424 onfail="Failed to turn off link?" )
425
426 @staticmethod
427 def restoreLink( main, end1, end2, dpid1, dpid2, port1, port2, switches,
428 links ):
429 """
430 Params:
431 end1,end2: identify the end switches, ex.: 'leaf1', 'spine1'
432 dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002'
433 port1, port2: respective port of the end switches that connects to the link, ex.:'1'
434 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
435 Kill a link and verify ONOS can see the proper link change
436 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700437 main.step( "Restore link between %s and %s" % ( end1, end2 ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700438 result = False
439 count = 0
440 while True:
441 count += 1
You Wangd5873482018-01-24 12:30:00 -0800442 main.Network.link( END1=end1, END2=end2, OPTION="up" )
443 main.Network.link( END2=end1, END1=end2, OPTION="up" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700444 main.log.info(
445 "Waiting %s seconds for link up to be discovered" % main.linkSleep )
446 time.sleep( main.linkSleep )
Pierfb719b12016-09-19 14:51:44 -0700447
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700448 for i in range( 0, main.Cluster.numCtrls ):
Devin Lim142b5342017-07-20 15:22:39 -0700449 ctrl = main.Cluster.runningNodes[ i ]
450 onosIsUp = main.ONOSbench.isup( ctrl.ipAddress )
Pierfb719b12016-09-19 14:51:44 -0700451 if onosIsUp == main.TRUE:
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900452 ctrl.CLI.portstate( dpid=dpid1, port=port1, state='Enable' )
453 ctrl.CLI.portstate( dpid=dpid2, port=port2, state='Enable' )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700454 time.sleep( main.linkSleep )
455
Devin Lim142b5342017-07-20 15:22:39 -0700456 result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches,
457 numolink=links )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700458 if count > 5 or result:
459 break
460 utilities.assert_equals( expect=main.TRUE, actual=result,
461 onpass="Link up successful",
462 onfail="Failed to bring link up" )
463
464 @staticmethod
465 def killSwitch( main, switch, switches, links ):
466 """
467 Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6'
468 Completely kill a switch and verify ONOS can see the proper change
469 """
470 main.switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
471 main.step( "Kill " + switch )
472 main.log.info( "Stopping" + switch )
You Wangd5873482018-01-24 12:30:00 -0800473 main.Network.switch( SW=switch, OPTION="stop" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700474 # todo make this repeatable
475 main.log.info( "Waiting %s seconds for switch down to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700476 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700477 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700478 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700479 main.FALSE,
480 kwargs={ 'numoswitch': switches,
481 'numolink': links },
482 attempts=10,
483 sleep=main.switchSleep )
484 utilities.assert_equals( expect=main.TRUE, actual=topology,
485 onpass="Kill switch successful",
486 onfail="Failed to kill switch?" )
487
488 @staticmethod
489 def recoverSwitch( main, switch, switches, links ):
490 """
491 Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6'
492 Recover a switch and verify ONOS can see the proper change
493 """
494 # todo make this repeatable
495 main.step( "Recovering " + switch )
496 main.log.info( "Starting" + switch )
You Wangd5873482018-01-24 12:30:00 -0800497 main.Network.switch( SW=switch, OPTION="start" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700498 main.log.info( "Waiting %s seconds for switch up to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700499 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700500 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700501 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700502 main.FALSE,
503 kwargs={ 'numoswitch': switches,
504 'numolink': links },
505 attempts=10,
506 sleep=main.switchSleep )
507 utilities.assert_equals( expect=main.TRUE, actual=topology,
508 onpass="Switch recovery successful",
509 onfail="Failed to recover switch?" )
510
511 @staticmethod
512 def cleanup( main ):
513 """
514 Stop Onos-cluster.
515 Stops Mininet
516 Copies ONOS log
517 """
Devin Lim58046fa2017-07-05 16:55:00 -0700518 try:
519 from tests.dependencies.utils import Utils
520 except ImportError:
521 main.log.error( "Utils not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700522 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700523 try:
Devin Lim142b5342017-07-20 15:22:39 -0700524 main.utils
Devin Lim58046fa2017-07-05 16:55:00 -0700525 except ( NameError, AttributeError ):
Devin Lim142b5342017-07-20 15:22:39 -0700526 main.utils = Utils()
Devin Lim58046fa2017-07-05 16:55:00 -0700527
528 main.utils.mininetCleanup( main.Mininet1 )
529
Devin Lim0c972b72018-02-08 14:53:59 -0800530 main.utils.copyKarafLog( "CASE%d" % main.CurrentTestCaseNumber, before=True, includeCaseDesc=False )
Devin Lim58046fa2017-07-05 16:55:00 -0700531
Devin Lim142b5342017-07-20 15:22:39 -0700532 for ctrl in main.Cluster.active():
533 main.ONOSbench.onosStop( ctrl.ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700534
535 @staticmethod
536 def killOnos( main, nodes, switches, links, expNodes ):
537 """
538 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
539 switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6'
540 Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change
541 """
542 main.step( "Killing ONOS instance" )
Pier3b58c652016-09-26 12:03:31 -0700543
Jon Hall1efcb3f2016-08-23 13:42:15 -0700544 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700545 killResult = main.ONOSbench.onosDie( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700546 utilities.assert_equals( expect=main.TRUE, actual=killResult,
547 onpass="ONOS instance Killed",
548 onfail="Error killing ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700549 main.Cluster.runningNodes[ i ].active = False
Jon Hall1efcb3f2016-08-23 13:42:15 -0700550 time.sleep( 12 )
Pier3b58c652016-09-26 12:03:31 -0700551
Devin Lim142b5342017-07-20 15:22:39 -0700552 if len( nodes ) < main.Cluster.numCtrls:
Pier3b58c652016-09-26 12:03:31 -0700553
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700554 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700555 False,
Pier3b58c652016-09-26 12:03:31 -0700556 attempts=5,
557 sleep=10 )
558 utilities.assert_equals( expect=True, actual=nodeResults,
559 onpass="Nodes check successful",
560 onfail="Nodes check NOT successful" )
561
562 if not nodeResults:
563 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700564 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700565 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700566 ctrl.name,
567 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700568 main.log.error( "Failed to kill ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700569 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700570
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900571 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700572 main.FALSE,
573 kwargs={ 'numoswitch': switches,
574 'numolink': links,
575 'numoctrl': expNodes },
576 attempts=10,
577 sleep=12 )
578 utilities.assert_equals( expect=main.TRUE, actual=topology,
579 onpass="ONOS Instance down successful",
580 onfail="Failed to turn off ONOS Instance" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700581
582 @staticmethod
583 def recoverOnos( main, nodes, switches, links, expNodes ):
584 """
585 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
586 switches, links, nodes: number of expected switches, links and nodes after recoverOnos, ex.: '4', '6'
587 Recover an ONOS instance and verify the ONOS cluster can see the proper change
588 """
589 main.step( "Recovering ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700590 [ main.ONOSbench.onosStart( main.Cluster.runningNodes[ i ].ipAddress ) for i in nodes ]
Jon Hall1efcb3f2016-08-23 13:42:15 -0700591 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700592 isUp = main.ONOSbench.isup( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700593 utilities.assert_equals( expect=main.TRUE, actual=isUp,
594 onpass="ONOS service is ready",
595 onfail="ONOS service did not start properly" )
596 for i in nodes:
597 main.step( "Checking if ONOS CLI is ready" )
Devin Lim142b5342017-07-20 15:22:39 -0700598 ctrl = main.Cluster.runningNodes[ i ]
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900599 # ctrl.CLI.startCellCli()
Devin Lim142b5342017-07-20 15:22:39 -0700600 cliResult = ctrl.CLI.startOnosCli( ctrl.ipAddress,
601 commandlineTimeout=60,
602 onosStartTimeout=100 )
603 ctrl.active = True
Jon Hall1efcb3f2016-08-23 13:42:15 -0700604 utilities.assert_equals( expect=main.TRUE,
605 actual=cliResult,
606 onpass="ONOS CLI is ready",
607 onfail="ONOS CLI is not ready" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700608
Pier3b58c652016-09-26 12:03:31 -0700609 main.step( "Checking ONOS nodes" )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700610 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700611 False,
Pier3b58c652016-09-26 12:03:31 -0700612 attempts=5,
613 sleep=10 )
614 utilities.assert_equals( expect=True, actual=nodeResults,
615 onpass="Nodes check successful",
616 onfail="Nodes check NOT successful" )
617
618 if not nodeResults:
619 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700620 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700621 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700622 ctrl.name,
623 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700624 main.log.error( "Failed to start ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700625 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700626
Devin Lim142b5342017-07-20 15:22:39 -0700627 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700628 main.FALSE,
629 kwargs={ 'numoswitch': switches,
630 'numolink': links,
631 'numoctrl': expNodes },
632 attempts=10,
633 sleep=12 )
634 utilities.assert_equals( expect=main.TRUE, actual=topology,
635 onpass="ONOS Instance down successful",
636 onfail="Failed to turn off ONOS Instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700637 ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary,
638 main.FALSE,
639 attempts=10,
640 sleep=12 )
641 if ready:
642 ready = main.TRUE
643 utilities.assert_equals( expect=main.TRUE, actual=ready,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700644 onpass="ONOS summary command succeded",
645 onfail="ONOS summary command failed" )
646 if not ready:
647 main.log.error( "ONOS startup failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700648 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700649
650 @staticmethod
651 def addHostCfg( main ):
652 """
653 Adds Host Configuration to ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700654 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700655 """
656 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700657 hostCfg = {}
Devin Lim57221b02018-02-14 15:45:36 -0800658 with open( main.configPath + main.forJson + "extra.json" ) as template:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700659 hostCfg = json.load( template )
660 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ]
661 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700662 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700663 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
664 subjectClass="hosts",
665 subjectKey=urllib.quote( mac,
666 safe='' ),
667 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700668 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ]
669 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700670 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700671 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
672 subjectClass="hosts",
673 subjectKey=urllib.quote( mac,
674 safe='' ),
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700675 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700676 main.pingChart.update( { 'vlan1': { "expect": "True",
677 "hosts": [ "olt1", "vsg1" ] } } )
678 main.pingChart[ 'vlan5' ][ 'expect' ] = 0
679 main.pingChart[ 'vlan10' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700680 ports = "[%s,%s]" % ( 5, 6 )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700681 cfg = '{"of:0000000000000001":[{"vlan":1,"ports":%s,"name":"OLT 1"}]}' % ports
Devin Lim142b5342017-07-20 15:22:39 -0700682 main.Cluster.active( 0 ).REST.setNetCfg( json.loads( cfg ),
683 subjectClass="apps",
684 subjectKey="org.onosproject.segmentrouting",
685 configKey="xconnect" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700686
687 @staticmethod
688 def delHostCfg( main ):
689 """
690 Removest Host Configuration from ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700691 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700692 """
693 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700694 hostCfg = {}
Devin Lim57221b02018-02-14 15:45:36 -0800695 with open( main.configPath + main.forJson + "extra.json" ) as template:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700696 hostCfg = json.load( template )
697 main.step( "Removing host configuration" )
698 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700699 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700700 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
701 subjectKey=urllib.quote(
702 mac,
703 safe='' ),
704 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700705 main.step( "Removing configuration" )
706 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700707 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700708 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
709 subjectKey=urllib.quote(
710 mac,
711 safe='' ),
712 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700713 main.step( "Removing vlan configuration" )
714 main.pingChart[ 'vlan1' ][ 'expect' ] = 0
Devin Lim142b5342017-07-20 15:22:39 -0700715 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="apps",
716 subjectKey="org.onosproject.segmentrouting",
717 configKey="xconnect" )
You Wang53dba1e2018-02-02 17:45:44 -0800718
719 @staticmethod
720 def verifyNetworkHostIp( main, attempts=10, sleep=10 ):
721 """
722 Verifies IP address assignment from the hosts
723 """
724 main.step( "Verify IP address assignment from hosts" )
725 ipResult = main.TRUE
726 for hostName, ip in main.expectedHosts[ "network" ].items():
727 ipResult = ipResult and utilities.retry( main.Network.verifyHostIp,
728 main.FALSE,
729 kwargs={ 'hostList': [ hostName ],
730 'prefix': ip },
731 attempts=attempts,
732 sleep=sleep )
733 utilities.assert_equals( expect=main.TRUE, actual=ipResult,
734 onpass="Verify network host IP succeded",
735 onfail="Verify network host IP failed" )
736
737 @staticmethod
738 def verifyOnosHostIp( main, attempts=10, sleep=10 ):
739 """
740 Verifies host IP address assignment from ONOS
741 """
742 main.step( "Verify host IP address assignment in ONOS" )
743 ipResult = main.TRUE
744 for hostName, ip in main.expectedHosts[ "onos" ].items():
745 ipResult = ipResult and utilities.retry( main.Cluster.active( 0 ).verifyHostIp,
746 main.FALSE,
747 kwargs={ 'hostList': [ hostName ],
748 'prefix': ip },
749 attempts=attempts,
750 sleep=sleep )
751 utilities.assert_equals( expect=main.TRUE, actual=ipResult,
752 onpass="Verify ONOS host IP succeded",
753 onfail="Verify ONOS host IP failed" )