blob: bb868df8280f804061608efff16dbbad882aa253 [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
Devin Lim57221b02018-02-14 15:45:36 -0800125 def loadJson( main ):
126 with open( "%s%s.json" % ( main.configPath + main.forJson,
127 main.cfgName ) ) as cfg:
128 main.Cluster.active( 0 ).REST.setNetCfg( json.load( cfg ) )
129
130 @staticmethod
131 def loadChart( main ):
132 try:
133 with open( "%s%s.chart" % ( main.configPath + main.forChart,
134 main.cfgName ) ) as chart:
135 main.pingChart = json.load(chart)
136 except IOError:
137 main.log.warn( "No chart file found." )
138
139 @staticmethod
140 def loadHost( main ):
141 with open( "%s%s.host" % ( main.configPath + main.forHost,
142 main.cfgName ) ) as host:
143 main.expectedHosts = json.load( host )
144
145 @staticmethod
Jon Hall1efcb3f2016-08-23 13:42:15 -0700146 def startMininet( main, topology, args="" ):
You Wangd87b2312018-01-30 12:47:17 -0800147 copyResult = main.ONOSbench.scp( main.Mininet1,
148 main.topoPath + main.topology,
149 main.Mininet1.home,
150 direction="to" )
151 if main.topologyLib:
152 for lib in main.topologyLib.split(","):
153 copyResult = copyResult and main.ONOSbench.scp( main.Mininet1,
154 main.topoPath + lib,
155 main.Mininet1.home,
156 direction="to" )
157 if main.topologyConf:
158 for conf in main.topologyConf.split(","):
159 copyResult = copyResult and main.ONOSbench.scp( main.Mininet1,
Devin Lim57221b02018-02-14 15:45:36 -0800160 main.configPath + main.forConfig + conf,
You Wangd87b2312018-01-30 12:47:17 -0800161 "~/",
162 direction="to" )
163 stepResult = copyResult
164 utilities.assert_equals( expect=main.TRUE,
165 actual=stepResult,
166 onpass="Successfully copied topo files",
167 onfail="Failed to copy topo files" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700168 main.step( "Starting Mininet Topology" )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700169 arg = "--onos-ip=%s %s" % (",".join([ctrl.ipAddress for ctrl in main.Cluster.runningNodes]), args)
Jon Hall1efcb3f2016-08-23 13:42:15 -0700170 main.topology = topology
171 topoResult = main.Mininet1.startNet(
172 topoFile=main.Mininet1.home + main.topology, args=arg )
173 stepResult = topoResult
174 utilities.assert_equals( expect=main.TRUE,
175 actual=stepResult,
176 onpass="Successfully loaded topology",
177 onfail="Failed to load topology" )
178 # Exit if topology did not load properly
179 if not topoResult:
Devin Lim44075962017-08-11 10:56:37 -0700180 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700181
182 @staticmethod
You Wang84f981d2018-01-12 16:11:50 -0800183 def connectToPhysicalNetwork( main, switchNames ):
184 main.step( "Connecting to physical netowrk" )
185 topoResult = main.NetworkBench.connectToNet()
186 stepResult = topoResult
187 utilities.assert_equals( expect=main.TRUE,
188 actual=stepResult,
189 onpass="Successfully loaded topology",
190 onfail="Failed to load topology" )
191 # Exit if topology did not load properly
192 if not topoResult:
193 main.cleanAndExit()
194
195 main.step( "Assign switches to controllers." )
196 assignResult = main.TRUE
197 for name in switchNames:
198 assignResult = assignResult & main.NetworkBench.assignSwController( sw=name,
199 ip=main.Cluster.getIps(),
200 port='6653' )
201 utilities.assert_equals( expect=main.TRUE,
202 actual=stepResult,
203 onpass="Successfully assign switches to controllers",
204 onfail="Failed to assign switches to controllers" )
205
206 @staticmethod
Devin Lim142b5342017-07-20 15:22:39 -0700207 def config( main, cfgName ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700208 main.spines = []
Piera2a7e1b2016-10-04 11:51:43 -0700209
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700210 main.failures = int( main.params[ 'failures' ] )
211 main.cfgName = cfgName
Piera2a7e1b2016-10-04 11:51:43 -0700212
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700213 if main.cfgName == '2x2':
214 spine = {}
215 spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ]
216 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ]
217 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700218
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700219 spine = {}
220 spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ]
221 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ]
222 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700223
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700224 elif main.cfgName == '4x4':
225 spine = {}
226 spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ]
227 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ]
228 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700229
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700230 spine = {}
231 spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ]
232 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ]
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' ][ 'spine3' ]
237 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid3' ]
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' ][ 'spine4' ]
242 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid4' ]
243 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700244
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700245 else:
Piera2a7e1b2016-10-04 11:51:43 -0700246 main.log.error( "Configuration failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700247 main.cleanAndExit()
Piera2a7e1b2016-10-04 11:51:43 -0700248
249 @staticmethod
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900250 def checkFlows( main, minFlowCount, tag="", dumpflows=True, sleep=10 ):
Jon Hall1efcb3f2016-08-23 13:42:15 -0700251 main.step(
252 " Check whether the flow count is bigger than %s" % minFlowCount )
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900253 if tag == "":
254 tag = 'CASE%d' % main.CurrentTestCaseNumber
Devin Lim142b5342017-07-20 15:22:39 -0700255 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowCount,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700256 main.FALSE,
257 kwargs={ 'min': minFlowCount },
258 attempts=10,
You Wang1cdc5f52017-12-19 16:47:51 -0800259 sleep=sleep )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700260 utilities.assertEquals(
Jon Hall1efcb3f2016-08-23 13:42:15 -0700261 expect=True,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700262 actual=( count > 0 ),
Jon Hall1efcb3f2016-08-23 13:42:15 -0700263 onpass="Flow count looks correct: " + str( count ),
264 onfail="Flow count looks wrong: " + str( count ) )
265
266 main.step( "Check whether all flow status are ADDED" )
Devin Lim142b5342017-07-20 15:22:39 -0700267 flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700268 main.FALSE,
269 kwargs={ 'isPENDING': False },
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800270 attempts=5,
You Wang1cdc5f52017-12-19 16:47:51 -0800271 sleep=sleep )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700272 utilities.assertEquals(
Jon Hall1efcb3f2016-08-23 13:42:15 -0700273 expect=main.TRUE,
274 actual=flowCheck,
275 onpass="Flow status is correct!",
276 onfail="Flow status is wrong!" )
277 if dumpflows:
Devin Lim142b5342017-07-20 15:22:39 -0700278 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700279 "flows",
280 main.logdir,
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900281 tag + "_FlowsBefore" )
Devin Lim142b5342017-07-20 15:22:39 -0700282 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700283 "groups",
284 main.logdir,
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900285 tag + "_GroupsBefore" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700286
287 @staticmethod
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800288 def checkFlowsByDpid( main, dpid, minFlowCount, sleep=10 ):
289 main.step(
Jonghwan Hyuncf2345c2018-02-26 11:07:54 -0800290 " Check whether the flow count of device %s is bigger than %s" % ( dpid, minFlowCount ) )
291 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowAddedCount,
292 main.FALSE,
293 args=( dpid, minFlowCount ),
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800294 attempts=5,
295 sleep=sleep )
296 utilities.assertEquals(
Jonghwan Hyuncf2345c2018-02-26 11:07:54 -0800297 expect=True,
298 actual=( count > minFlowCount ),
299 onpass="Flow count looks correct: " + str( count ),
300 onfail="Flow count looks wrong. " )
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800301
302 @staticmethod
You Wangf19d9f42018-02-23 16:34:19 -0800303 def pingAll( main, tag="", dumpflows=True, acceptableFailed=0, basedOnIp=False ):
304 '''
305 acceptableFailed: max number of acceptable failed pings. Only works for ping6
306 basedOnIp: if True, run ping or ping6 based on suffix of host names
307 '''
Andreas Pantelopoulosf6ed5012018-02-08 21:26:01 -0800308 main.log.report( "Check full connectivity" )
309 print main.pingChart
310 if tag == "":
311 tag = 'CASE%d' % main.CurrentTestCaseNumber
312 for entry in main.pingChart.itervalues():
313 print entry
314 hosts, expect = entry[ 'hosts' ], entry[ 'expect' ]
315 try:
316 expect = main.TRUE if str(expect).lower() == 'true' else main.FALSE
317 except:
318 expect = main.FALSE
319 main.step( "Connectivity for %s %s" % ( str( hosts ), tag ) )
320
You Wangf19d9f42018-02-23 16:34:19 -0800321 if basedOnIp:
322 if ("v4" in hosts[0]):
323 pa = main.Network.pingallHosts( hosts )
324 utilities.assert_equals( expect=expect, actual=pa,
325 onpass="IPv4 connectivity successfully tested",
326 onfail="IPv4 connectivity failed" )
327 if ("v6" in hosts[0]):
328 pa = main.Network.pingIpv6Hosts( hosts, acceptableFailed=acceptableFailed )
329 utilities.assert_equals( expect=expect, actual=pa,
330 onpass="IPv6 connectivity successfully tested",
331 onfail="IPv6 connectivity failed" )
332 else:
Andreas Pantelopoulosf6ed5012018-02-08 21:26:01 -0800333 pa = main.Network.pingallHosts( hosts )
334 utilities.assert_equals( expect=expect, actual=pa,
You Wangf19d9f42018-02-23 16:34:19 -0800335 onpass="IP connectivity successfully tested",
336 onfail="IP connectivity failed" )
Andreas Pantelopoulosf6ed5012018-02-08 21:26:01 -0800337
338 if dumpflows:
339 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
340 "flows",
341 main.logdir,
342 tag + "_FlowsOn" )
343 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
344 "groups",
345 main.logdir,
346 tag + "_GroupsOn" )
347
348 @staticmethod
Jon Hall1efcb3f2016-08-23 13:42:15 -0700349 def killLink( main, end1, end2, switches, links ):
350 """
351 end1,end2: identify the switches, ex.: 'leaf1', 'spine1'
352 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
353 Kill a link and verify ONOS can see the proper link change
354 """
355 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700356 main.step( "Kill link between %s and %s" % ( end1, end2 ) )
You Wangd5873482018-01-24 12:30:00 -0800357 LinkDown = main.Network.link( END1=end1, END2=end2, OPTION="down" )
358 LinkDown = main.Network.link( END2=end1, END1=end2, OPTION="down" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700359 main.log.info(
360 "Waiting %s seconds for link down to be discovered" % main.linkSleep )
361 time.sleep( main.linkSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700362 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700363 main.FALSE,
364 kwargs={ 'numoswitch': switches,
365 'numolink': links },
366 attempts=10,
367 sleep=main.linkSleep )
368 result = topology & LinkDown
369 utilities.assert_equals( expect=main.TRUE, actual=result,
370 onpass="Link down successful",
371 onfail="Failed to turn off link?" )
372
373 @staticmethod
374 def restoreLink( main, end1, end2, dpid1, dpid2, port1, port2, switches,
375 links ):
376 """
377 Params:
378 end1,end2: identify the end switches, ex.: 'leaf1', 'spine1'
379 dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002'
380 port1, port2: respective port of the end switches that connects to the link, ex.:'1'
381 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
382 Kill a link and verify ONOS can see the proper link change
383 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700384 main.step( "Restore link between %s and %s" % ( end1, end2 ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700385 result = False
386 count = 0
387 while True:
388 count += 1
You Wangd5873482018-01-24 12:30:00 -0800389 main.Network.link( END1=end1, END2=end2, OPTION="up" )
390 main.Network.link( END2=end1, END1=end2, OPTION="up" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700391 main.log.info(
392 "Waiting %s seconds for link up to be discovered" % main.linkSleep )
393 time.sleep( main.linkSleep )
Pierfb719b12016-09-19 14:51:44 -0700394
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700395 for i in range( 0, main.Cluster.numCtrls ):
Devin Lim142b5342017-07-20 15:22:39 -0700396 ctrl = main.Cluster.runningNodes[ i ]
397 onosIsUp = main.ONOSbench.isup( ctrl.ipAddress )
Pierfb719b12016-09-19 14:51:44 -0700398 if onosIsUp == main.TRUE:
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900399 ctrl.CLI.portstate( dpid=dpid1, port=port1, state='Enable' )
400 ctrl.CLI.portstate( dpid=dpid2, port=port2, state='Enable' )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700401 time.sleep( main.linkSleep )
402
Devin Lim142b5342017-07-20 15:22:39 -0700403 result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches,
404 numolink=links )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700405 if count > 5 or result:
406 break
407 utilities.assert_equals( expect=main.TRUE, actual=result,
408 onpass="Link up successful",
409 onfail="Failed to bring link up" )
410
411 @staticmethod
412 def killSwitch( main, switch, switches, links ):
413 """
414 Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6'
415 Completely kill a switch and verify ONOS can see the proper change
416 """
417 main.switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
418 main.step( "Kill " + switch )
419 main.log.info( "Stopping" + switch )
You Wangd5873482018-01-24 12:30:00 -0800420 main.Network.switch( SW=switch, OPTION="stop" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700421 # todo make this repeatable
422 main.log.info( "Waiting %s seconds for switch down to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700423 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700424 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700425 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700426 main.FALSE,
427 kwargs={ 'numoswitch': switches,
428 'numolink': links },
429 attempts=10,
430 sleep=main.switchSleep )
431 utilities.assert_equals( expect=main.TRUE, actual=topology,
432 onpass="Kill switch successful",
433 onfail="Failed to kill switch?" )
434
435 @staticmethod
436 def recoverSwitch( main, switch, switches, links ):
437 """
438 Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6'
439 Recover a switch and verify ONOS can see the proper change
440 """
441 # todo make this repeatable
442 main.step( "Recovering " + switch )
443 main.log.info( "Starting" + switch )
You Wangd5873482018-01-24 12:30:00 -0800444 main.Network.switch( SW=switch, OPTION="start" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700445 main.log.info( "Waiting %s seconds for switch up to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700446 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700447 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700448 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700449 main.FALSE,
450 kwargs={ 'numoswitch': switches,
451 'numolink': links },
452 attempts=10,
453 sleep=main.switchSleep )
454 utilities.assert_equals( expect=main.TRUE, actual=topology,
455 onpass="Switch recovery successful",
456 onfail="Failed to recover switch?" )
457
458 @staticmethod
459 def cleanup( main ):
460 """
461 Stop Onos-cluster.
462 Stops Mininet
463 Copies ONOS log
464 """
Devin Lim58046fa2017-07-05 16:55:00 -0700465 try:
466 from tests.dependencies.utils import Utils
467 except ImportError:
468 main.log.error( "Utils not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700469 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700470 try:
Devin Lim142b5342017-07-20 15:22:39 -0700471 main.utils
Devin Lim58046fa2017-07-05 16:55:00 -0700472 except ( NameError, AttributeError ):
Devin Lim142b5342017-07-20 15:22:39 -0700473 main.utils = Utils()
Devin Lim58046fa2017-07-05 16:55:00 -0700474
475 main.utils.mininetCleanup( main.Mininet1 )
476
Devin Lim0c972b72018-02-08 14:53:59 -0800477 main.utils.copyKarafLog( "CASE%d" % main.CurrentTestCaseNumber, before=True, includeCaseDesc=False )
Devin Lim58046fa2017-07-05 16:55:00 -0700478
Devin Lim142b5342017-07-20 15:22:39 -0700479 for ctrl in main.Cluster.active():
480 main.ONOSbench.onosStop( ctrl.ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700481
482 @staticmethod
483 def killOnos( main, nodes, switches, links, expNodes ):
484 """
485 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
486 switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6'
487 Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change
488 """
489 main.step( "Killing ONOS instance" )
Pier3b58c652016-09-26 12:03:31 -0700490
Jon Hall1efcb3f2016-08-23 13:42:15 -0700491 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700492 killResult = main.ONOSbench.onosDie( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700493 utilities.assert_equals( expect=main.TRUE, actual=killResult,
494 onpass="ONOS instance Killed",
495 onfail="Error killing ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700496 main.Cluster.runningNodes[ i ].active = False
Jon Hall1efcb3f2016-08-23 13:42:15 -0700497 time.sleep( 12 )
Pier3b58c652016-09-26 12:03:31 -0700498
Devin Lim142b5342017-07-20 15:22:39 -0700499 if len( nodes ) < main.Cluster.numCtrls:
Pier3b58c652016-09-26 12:03:31 -0700500
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700501 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700502 False,
Pier3b58c652016-09-26 12:03:31 -0700503 attempts=5,
504 sleep=10 )
505 utilities.assert_equals( expect=True, actual=nodeResults,
506 onpass="Nodes check successful",
507 onfail="Nodes check NOT successful" )
508
509 if not nodeResults:
510 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700511 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700512 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700513 ctrl.name,
514 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700515 main.log.error( "Failed to kill ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700516 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700517
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900518 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700519 main.FALSE,
520 kwargs={ 'numoswitch': switches,
521 'numolink': links,
522 'numoctrl': expNodes },
523 attempts=10,
524 sleep=12 )
525 utilities.assert_equals( expect=main.TRUE, actual=topology,
526 onpass="ONOS Instance down successful",
527 onfail="Failed to turn off ONOS Instance" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700528
529 @staticmethod
530 def recoverOnos( main, nodes, switches, links, expNodes ):
531 """
532 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
533 switches, links, nodes: number of expected switches, links and nodes after recoverOnos, ex.: '4', '6'
534 Recover an ONOS instance and verify the ONOS cluster can see the proper change
535 """
536 main.step( "Recovering ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700537 [ main.ONOSbench.onosStart( main.Cluster.runningNodes[ i ].ipAddress ) for i in nodes ]
Jon Hall1efcb3f2016-08-23 13:42:15 -0700538 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700539 isUp = main.ONOSbench.isup( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700540 utilities.assert_equals( expect=main.TRUE, actual=isUp,
541 onpass="ONOS service is ready",
542 onfail="ONOS service did not start properly" )
543 for i in nodes:
544 main.step( "Checking if ONOS CLI is ready" )
Devin Lim142b5342017-07-20 15:22:39 -0700545 ctrl = main.Cluster.runningNodes[ i ]
Jonghwan Hyun76a02b72018-01-30 16:40:48 +0900546 # ctrl.CLI.startCellCli()
Devin Lim142b5342017-07-20 15:22:39 -0700547 cliResult = ctrl.CLI.startOnosCli( ctrl.ipAddress,
548 commandlineTimeout=60,
549 onosStartTimeout=100 )
550 ctrl.active = True
Jon Hall1efcb3f2016-08-23 13:42:15 -0700551 utilities.assert_equals( expect=main.TRUE,
552 actual=cliResult,
553 onpass="ONOS CLI is ready",
554 onfail="ONOS CLI is not ready" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700555
Pier3b58c652016-09-26 12:03:31 -0700556 main.step( "Checking ONOS nodes" )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700557 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700558 False,
Pier3b58c652016-09-26 12:03:31 -0700559 attempts=5,
560 sleep=10 )
561 utilities.assert_equals( expect=True, actual=nodeResults,
562 onpass="Nodes check successful",
563 onfail="Nodes check NOT successful" )
564
565 if not nodeResults:
566 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700567 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700568 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700569 ctrl.name,
570 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700571 main.log.error( "Failed to start ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700572 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700573
Devin Lim142b5342017-07-20 15:22:39 -0700574 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700575 main.FALSE,
576 kwargs={ 'numoswitch': switches,
577 'numolink': links,
578 'numoctrl': expNodes },
579 attempts=10,
580 sleep=12 )
581 utilities.assert_equals( expect=main.TRUE, actual=topology,
582 onpass="ONOS Instance down successful",
583 onfail="Failed to turn off ONOS Instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700584 ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary,
585 main.FALSE,
586 attempts=10,
587 sleep=12 )
588 if ready:
589 ready = main.TRUE
590 utilities.assert_equals( expect=main.TRUE, actual=ready,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700591 onpass="ONOS summary command succeded",
592 onfail="ONOS summary command failed" )
593 if not ready:
594 main.log.error( "ONOS startup failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700595 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700596
597 @staticmethod
598 def addHostCfg( main ):
599 """
600 Adds Host Configuration to ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700601 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700602 """
603 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700604 hostCfg = {}
Devin Lim57221b02018-02-14 15:45:36 -0800605 with open( main.configPath + main.forJson + "extra.json" ) as template:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700606 hostCfg = json.load( template )
607 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ]
608 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700609 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700610 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
611 subjectClass="hosts",
612 subjectKey=urllib.quote( mac,
613 safe='' ),
614 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700615 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ]
616 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700617 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700618 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
619 subjectClass="hosts",
620 subjectKey=urllib.quote( mac,
621 safe='' ),
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700622 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700623 main.pingChart.update( { 'vlan1': { "expect": "True",
624 "hosts": [ "olt1", "vsg1" ] } } )
625 main.pingChart[ 'vlan5' ][ 'expect' ] = 0
626 main.pingChart[ 'vlan10' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700627 ports = "[%s,%s]" % ( 5, 6 )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700628 cfg = '{"of:0000000000000001":[{"vlan":1,"ports":%s,"name":"OLT 1"}]}' % ports
Devin Lim142b5342017-07-20 15:22:39 -0700629 main.Cluster.active( 0 ).REST.setNetCfg( json.loads( cfg ),
630 subjectClass="apps",
631 subjectKey="org.onosproject.segmentrouting",
632 configKey="xconnect" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700633
634 @staticmethod
635 def delHostCfg( main ):
636 """
637 Removest Host Configuration from ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700638 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700639 """
640 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700641 hostCfg = {}
Devin Lim57221b02018-02-14 15:45:36 -0800642 with open( main.configPath + main.forJson + "extra.json" ) as template:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700643 hostCfg = json.load( template )
644 main.step( "Removing host configuration" )
645 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700646 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700647 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
648 subjectKey=urllib.quote(
649 mac,
650 safe='' ),
651 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700652 main.step( "Removing configuration" )
653 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700654 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700655 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
656 subjectKey=urllib.quote(
657 mac,
658 safe='' ),
659 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700660 main.step( "Removing vlan configuration" )
661 main.pingChart[ 'vlan1' ][ 'expect' ] = 0
Devin Lim142b5342017-07-20 15:22:39 -0700662 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="apps",
663 subjectKey="org.onosproject.segmentrouting",
664 configKey="xconnect" )
You Wang53dba1e2018-02-02 17:45:44 -0800665
666 @staticmethod
667 def verifyNetworkHostIp( main, attempts=10, sleep=10 ):
668 """
669 Verifies IP address assignment from the hosts
670 """
671 main.step( "Verify IP address assignment from hosts" )
672 ipResult = main.TRUE
673 for hostName, ip in main.expectedHosts[ "network" ].items():
674 ipResult = ipResult and utilities.retry( main.Network.verifyHostIp,
675 main.FALSE,
676 kwargs={ 'hostList': [ hostName ],
677 'prefix': ip },
678 attempts=attempts,
679 sleep=sleep )
680 utilities.assert_equals( expect=main.TRUE, actual=ipResult,
681 onpass="Verify network host IP succeded",
682 onfail="Verify network host IP failed" )
683
684 @staticmethod
685 def verifyOnosHostIp( main, attempts=10, sleep=10 ):
686 """
687 Verifies host IP address assignment from ONOS
688 """
689 main.step( "Verify host IP address assignment in ONOS" )
690 ipResult = main.TRUE
691 for hostName, ip in main.expectedHosts[ "onos" ].items():
692 ipResult = ipResult and utilities.retry( main.Cluster.active( 0 ).verifyHostIp,
693 main.FALSE,
694 kwargs={ 'hostList': [ hostName ],
695 'prefix': ip },
696 attempts=attempts,
697 sleep=sleep )
698 utilities.assert_equals( expect=main.TRUE, actual=ipResult,
699 onpass="Verify ONOS host IP succeded",
700 onfail="Verify ONOS host IP failed" )