blob: aa9d1a44de4bd51fdb0b035032a261d39182aa30 [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 '''
You Wangba231e72018-03-01 13:18:21 -0800358 Verify connectivity between hosts according to the ping chart
359 acceptableFailed: max number of acceptable failed pings.
You Wangf19d9f42018-02-23 16:34:19 -0800360 basedOnIp: if True, run ping or ping6 based on suffix of host names
361 '''
You Wangba231e72018-03-01 13:18:21 -0800362 main.log.report( "Check host connectivity" )
363 main.log.debug( "Ping chart: %s" % main.pingChart )
Andreas Pantelopoulosf6ed5012018-02-08 21:26:01 -0800364 if tag == "":
365 tag = 'CASE%d' % main.CurrentTestCaseNumber
366 for entry in main.pingChart.itervalues():
You Wangba231e72018-03-01 13:18:21 -0800367 main.log.debug( "Entry in ping chart: %s" % entry )
368 expect = entry[ 'expect' ]
369 if expect == "Unidirectional":
370 # Verify ping from each src host to each dst host
371 src = entry[ 'src' ]
372 dst = entry[ 'dst' ]
373 expect = main.TRUE
374 main.step( "Verify unidirectional connectivity from %s to %s with tag %s" % ( str( src ), str( dst ), tag ) )
375 if basedOnIp:
376 if ("v4" in src[0]):
377 pa = main.Network.pingallHostsUnidirectional( src, dst, acceptableFailed=acceptableFailed )
378 utilities.assert_equals( expect=expect, actual=pa,
379 onpass="IPv4 connectivity successfully tested",
380 onfail="IPv4 connectivity failed" )
381 if ("v6" in src[0]):
382 pa = main.Network.pingallHostsUnidirectional( src, dst, ipv6=True, acceptableFailed=acceptableFailed )
383 utilities.assert_equals( expect=expect, actual=pa,
384 onpass="IPv6 connectivity successfully tested",
385 onfail="IPv6 connectivity failed" )
386 else:
387 pa = main.Network.pingallHostsUnidirectional( src, dst, acceptableFailed=acceptableFailed )
388 utilities.assert_equals( expect=expect, actual=pa,
389 onpass="IP connectivity successfully tested",
390 onfail="IP connectivity failed" )
391 else:
392 # Verify ping between each host pair
393 hosts = entry[ 'hosts' ]
394 try:
395 expect = main.TRUE if str(expect).lower() == 'true' else main.FALSE
396 except:
397 expect = main.FALSE
398 main.step( "Verify full connectivity for %s with tag %s" % ( str( hosts ), tag ) )
399 if basedOnIp:
400 if ("v4" in hosts[0]):
401 pa = main.Network.pingallHosts( hosts )
402 utilities.assert_equals( expect=expect, actual=pa,
403 onpass="IPv4 connectivity successfully tested",
404 onfail="IPv4 connectivity failed" )
405 if ("v6" in hosts[0]):
406 pa = main.Network.pingIpv6Hosts( hosts, acceptableFailed=acceptableFailed )
407 utilities.assert_equals( expect=expect, actual=pa,
408 onpass="IPv6 connectivity successfully tested",
409 onfail="IPv6 connectivity failed" )
410 else:
You Wangf19d9f42018-02-23 16:34:19 -0800411 pa = main.Network.pingallHosts( hosts )
412 utilities.assert_equals( expect=expect, actual=pa,
You Wangba231e72018-03-01 13:18:21 -0800413 onpass="IP connectivity successfully tested",
414 onfail="IP connectivity failed" )
Andreas Pantelopoulosf6ed5012018-02-08 21:26:01 -0800415
416 if dumpflows:
417 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
418 "flows",
419 main.logdir,
420 tag + "_FlowsOn" )
421 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
422 "groups",
423 main.logdir,
424 tag + "_GroupsOn" )
425
426 @staticmethod
Jon Hall1efcb3f2016-08-23 13:42:15 -0700427 def killLink( main, end1, end2, switches, links ):
428 """
429 end1,end2: identify the switches, ex.: 'leaf1', 'spine1'
430 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
431 Kill a link and verify ONOS can see the proper link change
432 """
433 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700434 main.step( "Kill link between %s and %s" % ( end1, end2 ) )
You Wangd5873482018-01-24 12:30:00 -0800435 LinkDown = main.Network.link( END1=end1, END2=end2, OPTION="down" )
436 LinkDown = main.Network.link( END2=end1, END1=end2, OPTION="down" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700437 main.log.info(
438 "Waiting %s seconds for link down to be discovered" % main.linkSleep )
439 time.sleep( main.linkSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700440 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700441 main.FALSE,
442 kwargs={ 'numoswitch': switches,
443 'numolink': links },
444 attempts=10,
445 sleep=main.linkSleep )
446 result = topology & LinkDown
447 utilities.assert_equals( expect=main.TRUE, actual=result,
448 onpass="Link down successful",
449 onfail="Failed to turn off link?" )
450
451 @staticmethod
452 def restoreLink( main, end1, end2, dpid1, dpid2, port1, port2, switches,
453 links ):
454 """
455 Params:
456 end1,end2: identify the end switches, ex.: 'leaf1', 'spine1'
457 dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002'
458 port1, port2: respective port of the end switches that connects to the link, ex.:'1'
459 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
460 Kill a link and verify ONOS can see the proper link change
461 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700462 main.step( "Restore link between %s and %s" % ( end1, end2 ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700463 result = False
464 count = 0
465 while True:
466 count += 1
You Wangd5873482018-01-24 12:30:00 -0800467 main.Network.link( END1=end1, END2=end2, OPTION="up" )
468 main.Network.link( END2=end1, END1=end2, OPTION="up" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700469 main.log.info(
470 "Waiting %s seconds for link up to be discovered" % main.linkSleep )
471 time.sleep( main.linkSleep )
Pierfb719b12016-09-19 14:51:44 -0700472
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700473 for i in range( 0, main.Cluster.numCtrls ):
Devin Lim142b5342017-07-20 15:22:39 -0700474 ctrl = main.Cluster.runningNodes[ i ]
475 onosIsUp = main.ONOSbench.isup( ctrl.ipAddress )
Pierfb719b12016-09-19 14:51:44 -0700476 if onosIsUp == main.TRUE:
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900477 ctrl.CLI.portstate( dpid=dpid1, port=port1, state='Enable' )
478 ctrl.CLI.portstate( dpid=dpid2, port=port2, state='Enable' )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700479 time.sleep( main.linkSleep )
480
Devin Lim142b5342017-07-20 15:22:39 -0700481 result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches,
482 numolink=links )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700483 if count > 5 or result:
484 break
485 utilities.assert_equals( expect=main.TRUE, actual=result,
486 onpass="Link up successful",
487 onfail="Failed to bring link up" )
488
489 @staticmethod
490 def killSwitch( main, switch, switches, links ):
491 """
492 Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6'
493 Completely kill a switch and verify ONOS can see the proper change
494 """
495 main.switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
496 main.step( "Kill " + switch )
497 main.log.info( "Stopping" + switch )
You Wangd5873482018-01-24 12:30:00 -0800498 main.Network.switch( SW=switch, OPTION="stop" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700499 # todo make this repeatable
500 main.log.info( "Waiting %s seconds for switch down to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700501 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700502 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700503 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700504 main.FALSE,
505 kwargs={ 'numoswitch': switches,
506 'numolink': links },
507 attempts=10,
508 sleep=main.switchSleep )
509 utilities.assert_equals( expect=main.TRUE, actual=topology,
510 onpass="Kill switch successful",
511 onfail="Failed to kill switch?" )
512
513 @staticmethod
514 def recoverSwitch( main, switch, switches, links ):
515 """
516 Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6'
517 Recover a switch and verify ONOS can see the proper change
518 """
519 # todo make this repeatable
520 main.step( "Recovering " + switch )
521 main.log.info( "Starting" + switch )
You Wangd5873482018-01-24 12:30:00 -0800522 main.Network.switch( SW=switch, OPTION="start" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700523 main.log.info( "Waiting %s seconds for switch up to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700524 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700525 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700526 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700527 main.FALSE,
528 kwargs={ 'numoswitch': switches,
529 'numolink': links },
530 attempts=10,
531 sleep=main.switchSleep )
532 utilities.assert_equals( expect=main.TRUE, actual=topology,
533 onpass="Switch recovery successful",
534 onfail="Failed to recover switch?" )
535
536 @staticmethod
537 def cleanup( main ):
538 """
539 Stop Onos-cluster.
540 Stops Mininet
541 Copies ONOS log
542 """
Devin Lim58046fa2017-07-05 16:55:00 -0700543 try:
544 from tests.dependencies.utils import Utils
545 except ImportError:
546 main.log.error( "Utils not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700547 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700548 try:
Devin Lim142b5342017-07-20 15:22:39 -0700549 main.utils
Devin Lim58046fa2017-07-05 16:55:00 -0700550 except ( NameError, AttributeError ):
Devin Lim142b5342017-07-20 15:22:39 -0700551 main.utils = Utils()
Devin Lim58046fa2017-07-05 16:55:00 -0700552
553 main.utils.mininetCleanup( main.Mininet1 )
554
Devin Lim0c972b72018-02-08 14:53:59 -0800555 main.utils.copyKarafLog( "CASE%d" % main.CurrentTestCaseNumber, before=True, includeCaseDesc=False )
Devin Lim58046fa2017-07-05 16:55:00 -0700556
Devin Lim142b5342017-07-20 15:22:39 -0700557 for ctrl in main.Cluster.active():
558 main.ONOSbench.onosStop( ctrl.ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700559
560 @staticmethod
561 def killOnos( main, nodes, switches, links, expNodes ):
562 """
563 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
564 switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6'
565 Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change
566 """
567 main.step( "Killing ONOS instance" )
Pier3b58c652016-09-26 12:03:31 -0700568
Jon Hall1efcb3f2016-08-23 13:42:15 -0700569 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700570 killResult = main.ONOSbench.onosDie( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700571 utilities.assert_equals( expect=main.TRUE, actual=killResult,
572 onpass="ONOS instance Killed",
573 onfail="Error killing ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700574 main.Cluster.runningNodes[ i ].active = False
Jon Hall1efcb3f2016-08-23 13:42:15 -0700575 time.sleep( 12 )
Pier3b58c652016-09-26 12:03:31 -0700576
Devin Lim142b5342017-07-20 15:22:39 -0700577 if len( nodes ) < main.Cluster.numCtrls:
Pier3b58c652016-09-26 12:03:31 -0700578
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700579 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700580 False,
Pier3b58c652016-09-26 12:03:31 -0700581 attempts=5,
582 sleep=10 )
583 utilities.assert_equals( expect=True, actual=nodeResults,
584 onpass="Nodes check successful",
585 onfail="Nodes check NOT successful" )
586
587 if not nodeResults:
588 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700589 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700590 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700591 ctrl.name,
592 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700593 main.log.error( "Failed to kill ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700594 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700595
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900596 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700597 main.FALSE,
598 kwargs={ 'numoswitch': switches,
599 'numolink': links,
600 'numoctrl': expNodes },
601 attempts=10,
602 sleep=12 )
603 utilities.assert_equals( expect=main.TRUE, actual=topology,
604 onpass="ONOS Instance down successful",
605 onfail="Failed to turn off ONOS Instance" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700606
607 @staticmethod
608 def recoverOnos( main, nodes, switches, links, expNodes ):
609 """
610 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
611 switches, links, nodes: number of expected switches, links and nodes after recoverOnos, ex.: '4', '6'
612 Recover an ONOS instance and verify the ONOS cluster can see the proper change
613 """
614 main.step( "Recovering ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700615 [ main.ONOSbench.onosStart( main.Cluster.runningNodes[ i ].ipAddress ) for i in nodes ]
Jon Hall1efcb3f2016-08-23 13:42:15 -0700616 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700617 isUp = main.ONOSbench.isup( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700618 utilities.assert_equals( expect=main.TRUE, actual=isUp,
619 onpass="ONOS service is ready",
620 onfail="ONOS service did not start properly" )
621 for i in nodes:
622 main.step( "Checking if ONOS CLI is ready" )
Devin Lim142b5342017-07-20 15:22:39 -0700623 ctrl = main.Cluster.runningNodes[ i ]
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900624 # ctrl.CLI.startCellCli()
Devin Lim142b5342017-07-20 15:22:39 -0700625 cliResult = ctrl.CLI.startOnosCli( ctrl.ipAddress,
626 commandlineTimeout=60,
627 onosStartTimeout=100 )
628 ctrl.active = True
Jon Hall1efcb3f2016-08-23 13:42:15 -0700629 utilities.assert_equals( expect=main.TRUE,
630 actual=cliResult,
631 onpass="ONOS CLI is ready",
632 onfail="ONOS CLI is not ready" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700633
Pier3b58c652016-09-26 12:03:31 -0700634 main.step( "Checking ONOS nodes" )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700635 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700636 False,
Pier3b58c652016-09-26 12:03:31 -0700637 attempts=5,
638 sleep=10 )
639 utilities.assert_equals( expect=True, actual=nodeResults,
640 onpass="Nodes check successful",
641 onfail="Nodes check NOT successful" )
642
643 if not nodeResults:
644 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700645 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700646 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700647 ctrl.name,
648 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700649 main.log.error( "Failed to start ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700650 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700651
Devin Lim142b5342017-07-20 15:22:39 -0700652 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700653 main.FALSE,
654 kwargs={ 'numoswitch': switches,
655 'numolink': links,
656 'numoctrl': expNodes },
657 attempts=10,
658 sleep=12 )
659 utilities.assert_equals( expect=main.TRUE, actual=topology,
660 onpass="ONOS Instance down successful",
661 onfail="Failed to turn off ONOS Instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700662 ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary,
663 main.FALSE,
664 attempts=10,
665 sleep=12 )
666 if ready:
667 ready = main.TRUE
668 utilities.assert_equals( expect=main.TRUE, actual=ready,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700669 onpass="ONOS summary command succeded",
670 onfail="ONOS summary command failed" )
671 if not ready:
672 main.log.error( "ONOS startup failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700673 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700674
675 @staticmethod
676 def addHostCfg( main ):
677 """
678 Adds Host Configuration to ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700679 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700680 """
681 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700682 hostCfg = {}
Devin Lim57221b02018-02-14 15:45:36 -0800683 with open( main.configPath + main.forJson + "extra.json" ) as template:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700684 hostCfg = json.load( template )
685 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ]
686 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700687 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700688 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
689 subjectClass="hosts",
690 subjectKey=urllib.quote( mac,
691 safe='' ),
692 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700693 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ]
694 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700695 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700696 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
697 subjectClass="hosts",
698 subjectKey=urllib.quote( mac,
699 safe='' ),
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700700 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700701 main.pingChart.update( { 'vlan1': { "expect": "True",
702 "hosts": [ "olt1", "vsg1" ] } } )
703 main.pingChart[ 'vlan5' ][ 'expect' ] = 0
704 main.pingChart[ 'vlan10' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700705 ports = "[%s,%s]" % ( 5, 6 )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700706 cfg = '{"of:0000000000000001":[{"vlan":1,"ports":%s,"name":"OLT 1"}]}' % ports
Devin Lim142b5342017-07-20 15:22:39 -0700707 main.Cluster.active( 0 ).REST.setNetCfg( json.loads( cfg ),
708 subjectClass="apps",
709 subjectKey="org.onosproject.segmentrouting",
710 configKey="xconnect" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700711
712 @staticmethod
713 def delHostCfg( main ):
714 """
715 Removest Host Configuration from ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700716 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700717 """
718 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700719 hostCfg = {}
Devin Lim57221b02018-02-14 15:45:36 -0800720 with open( main.configPath + main.forJson + "extra.json" ) as template:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700721 hostCfg = json.load( template )
722 main.step( "Removing host configuration" )
723 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700724 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700725 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
726 subjectKey=urllib.quote(
727 mac,
728 safe='' ),
729 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700730 main.step( "Removing configuration" )
731 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700732 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700733 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
734 subjectKey=urllib.quote(
735 mac,
736 safe='' ),
737 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700738 main.step( "Removing vlan configuration" )
739 main.pingChart[ 'vlan1' ][ 'expect' ] = 0
Devin Lim142b5342017-07-20 15:22:39 -0700740 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="apps",
741 subjectKey="org.onosproject.segmentrouting",
742 configKey="xconnect" )
You Wang53dba1e2018-02-02 17:45:44 -0800743
744 @staticmethod
745 def verifyNetworkHostIp( main, attempts=10, sleep=10 ):
746 """
747 Verifies IP address assignment from the hosts
748 """
749 main.step( "Verify IP address assignment from hosts" )
750 ipResult = main.TRUE
751 for hostName, ip in main.expectedHosts[ "network" ].items():
752 ipResult = ipResult and utilities.retry( main.Network.verifyHostIp,
753 main.FALSE,
754 kwargs={ 'hostList': [ hostName ],
755 'prefix': ip },
756 attempts=attempts,
757 sleep=sleep )
758 utilities.assert_equals( expect=main.TRUE, actual=ipResult,
759 onpass="Verify network host IP succeded",
760 onfail="Verify network host IP failed" )
761
762 @staticmethod
763 def verifyOnosHostIp( main, attempts=10, sleep=10 ):
764 """
765 Verifies host IP address assignment from ONOS
766 """
767 main.step( "Verify host IP address assignment in ONOS" )
768 ipResult = main.TRUE
769 for hostName, ip in main.expectedHosts[ "onos" ].items():
770 ipResult = ipResult and utilities.retry( main.Cluster.active( 0 ).verifyHostIp,
771 main.FALSE,
772 kwargs={ 'hostList': [ hostName ],
773 'prefix': ip },
774 attempts=attempts,
775 sleep=sleep )
776 utilities.assert_equals( expect=main.TRUE, actual=ipResult,
777 onpass="Verify ONOS host IP succeded",
778 onfail="Verify ONOS host IP failed" )