blob: ba4e0d7ff78b1b3f9d55b22932fe16fea3ccd256 [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 Lim58046fa2017-07-05 16:55:00 -070052 main.testSetUp.envSetupDescription()
53 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' ]
59 main.diff = main.params[ 'ENV' ][ 'diffApps' ]
60 main.path = os.path.dirname( main.testFile )
61 main.dependencyPath = main.path + "/../dependencies/"
62 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
63 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070064 main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," )
Devin Lim58046fa2017-07-05 16:55:00 -070065 main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
66 # main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
67 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
Jon Hall1efcb3f2016-08-23 13:42:15 -070068
Devin Lim142b5342017-07-20 15:22:39 -070069 stepResult = main.testSetUp.envSetup()
Devin Lim58046fa2017-07-05 16:55:00 -070070 except Exception as e:
71 main.testSetUp.envSetupException( e )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -070072
73 # Additional files for topology building
74 try:
75 main.topologyLib1 = main.params[ 'DEPENDENCY' ][ 'lib1' ]
76 main.topologyLib2 = main.params[ 'DEPENDENCY' ][ 'lib2' ]
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -070077 except:
78 pass
79
Devin Lim58046fa2017-07-05 16:55:00 -070080 main.testSetUp.evnSetupConclusion( stepResult )
Jon Hall1efcb3f2016-08-23 13:42:15 -070081
Jon Hall1efcb3f2016-08-23 13:42:15 -070082 @staticmethod
You Wang1cdc5f52017-12-19 16:47:51 -080083 def installOnos( main, vlanCfg=True, skipPackage=False, cliSleep=10 ):
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
Jon Hall1efcb3f2016-08-23 13:42:15 -070096 if main.diff:
Devin Lim58046fa2017-07-05 16:55:00 -070097 main.apps = main.apps + "," + main.diff
Jon Hall1efcb3f2016-08-23 13:42:15 -070098 else:
99 main.log.error( "App list is empty" )
Devin Lim142b5342017-07-20 15:22:39 -0700100 main.log.info( "NODE COUNT = " + str( main.Cluster.numCtrls ) )
101 main.log.info( ''.join( main.Cluster.getIps() ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700102 main.dynamicHosts = [ 'in1', 'out1' ]
You Wanga0f6ff62018-01-11 15:46:30 -0800103 main.testSetUp.ONOSSetUp( main.Cluster, newCell=True, cellName=main.cellName,
You Wang1cdc5f52017-12-19 16:47:51 -0800104 skipPack=skipPackage, useSSH=Testcaselib.useSSH )
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" )
114
115 with open( "%s/json/%s.json" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700116 main.dependencyPath, main.cfgName ) ) as cfg:
Devin Lim142b5342017-07-20 15:22:39 -0700117 main.Cluster.active( 0 ).REST.setNetCfg( json.load( cfg ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700118 with open( "%s/json/%s.chart" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700119 main.dependencyPath, main.cfgName ) ) as chart:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700120 main.pingChart = json.load( chart )
121 if not ready:
122 main.log.error( "ONOS startup failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700123 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700124
Devin Lim142b5342017-07-20 15:22:39 -0700125 for ctrl in main.Cluster.active():
126 ctrl.CLI.logSet( "DEBUG", "org.onosproject.segmentrouting" )
127 ctrl.CLI.logSet( "DEBUG", "org.onosproject.driver.pipeline" )
128 ctrl.CLI.logSet( "DEBUG", "org.onosproject.store.group.impl" )
129 ctrl.CLI.logSet( "DEBUG", "org.onosproject.net.flowobjective.impl" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700130
131 @staticmethod
132 def startMininet( main, topology, args="" ):
You Wangd5873482018-01-24 12:30:00 -0800133 try:
134 copyResult1 = main.ONOSbench.scp( main.Mininet1,
135 main.dependencyPath +
136 main.topology,
137 main.Mininet1.home,
138 direction="to" )
139 copyResult2 = main.ONOSbench.scp( main.Mininet1,
140 main.dependencyPath +
141 main.topologyLib1,
142 main.Mininet1.home,
143 direction="to" )
144 copyResult3 = main.ONOSbench.scp( main.Mininet1,
145 main.dependencyPath +
146 main.topologyLib2,
147 main.Mininet1.home,
148 direction="to" )
149 except:
150 pass
Jon Hall1efcb3f2016-08-23 13:42:15 -0700151 main.step( "Starting Mininet Topology" )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700152 arg = "--onos-ip=%s %s" % (",".join([ctrl.ipAddress for ctrl in main.Cluster.runningNodes]), args)
Jon Hall1efcb3f2016-08-23 13:42:15 -0700153 main.topology = topology
154 topoResult = main.Mininet1.startNet(
155 topoFile=main.Mininet1.home + main.topology, args=arg )
156 stepResult = topoResult
157 utilities.assert_equals( expect=main.TRUE,
158 actual=stepResult,
159 onpass="Successfully loaded topology",
160 onfail="Failed to load topology" )
161 # Exit if topology did not load properly
162 if not topoResult:
Devin Lim44075962017-08-11 10:56:37 -0700163 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700164
165 @staticmethod
Devin Lim142b5342017-07-20 15:22:39 -0700166 def config( main, cfgName ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700167 main.spines = []
Piera2a7e1b2016-10-04 11:51:43 -0700168
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700169 main.failures = int( main.params[ 'failures' ] )
170 main.cfgName = cfgName
Piera2a7e1b2016-10-04 11:51:43 -0700171
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700172 if main.cfgName == '2x2':
173 spine = {}
174 spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ]
175 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ]
176 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700177
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700178 spine = {}
179 spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ]
180 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ]
181 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700182
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700183 elif main.cfgName == '4x4':
184 spine = {}
185 spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ]
186 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ]
187 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700188
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700189 spine = {}
190 spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ]
191 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ]
192 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700193
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700194 spine = {}
195 spine[ 'name' ] = main.params[ 'switches' ][ 'spine3' ]
196 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid3' ]
197 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700198
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700199 spine = {}
200 spine[ 'name' ] = main.params[ 'switches' ][ 'spine4' ]
201 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid4' ]
202 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700203
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700204 else:
Piera2a7e1b2016-10-04 11:51:43 -0700205 main.log.error( "Configuration failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700206 main.cleanAndExit()
Piera2a7e1b2016-10-04 11:51:43 -0700207
208 @staticmethod
You Wang1cdc5f52017-12-19 16:47:51 -0800209 def checkFlows( main, minFlowCount, dumpflows=True, sleep=10 ):
Jon Hall1efcb3f2016-08-23 13:42:15 -0700210 main.step(
211 " Check whether the flow count is bigger than %s" % minFlowCount )
Devin Lim142b5342017-07-20 15:22:39 -0700212 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowCount,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700213 main.FALSE,
214 kwargs={ 'min': minFlowCount },
215 attempts=10,
You Wang1cdc5f52017-12-19 16:47:51 -0800216 sleep=sleep )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700217 utilities.assertEquals(
Jon Hall1efcb3f2016-08-23 13:42:15 -0700218 expect=True,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700219 actual=( count > 0 ),
Jon Hall1efcb3f2016-08-23 13:42:15 -0700220 onpass="Flow count looks correct: " + str( count ),
221 onfail="Flow count looks wrong: " + str( count ) )
222
223 main.step( "Check whether all flow status are ADDED" )
Devin Lim142b5342017-07-20 15:22:39 -0700224 flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700225 main.FALSE,
226 kwargs={ 'isPENDING': False },
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800227 attempts=5,
You Wang1cdc5f52017-12-19 16:47:51 -0800228 sleep=sleep )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700229 utilities.assertEquals(
Jon Hall1efcb3f2016-08-23 13:42:15 -0700230 expect=main.TRUE,
231 actual=flowCheck,
232 onpass="Flow status is correct!",
233 onfail="Flow status is wrong!" )
234 if dumpflows:
Devin Lim142b5342017-07-20 15:22:39 -0700235 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700236 "flows",
237 main.logdir,
Devin Lim97b6b862018-01-23 22:51:25 -0800238 main.resultFileName + "_FlowsBefore" )
Devin Lim142b5342017-07-20 15:22:39 -0700239 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700240 "groups",
241 main.logdir,
Devin Lim97b6b862018-01-23 22:51:25 -0800242 main.resultFileName + "_GroupsBefore" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700243
244 @staticmethod
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800245 def checkFlowsByDpid( main, dpid, minFlowCount, sleep=10 ):
246 main.step(
247 " Check whether the flow count of device %s is bigger than %s" % ( dpid, minFlowCount ) )
248 count = utilities.retry( main.Cluster.active( 0 ).CLI.flowAddedCount,
249 None,
250 args=( dpid, ),
251 attempts=5,
252 sleep=sleep )
253 utilities.assertEquals(
254 expect=True,
255 actual=( int( count ) > minFlowCount ),
256 onpass="Flow count looks correct: " + count ,
257 onfail="Flow count looks wrong: " + count )
258
259 @staticmethod
Jon Hall1efcb3f2016-08-23 13:42:15 -0700260 def pingAll( main, tag="", dumpflows=True ):
261 main.log.report( "Check full connectivity" )
262 print main.pingChart
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700263 for entry in main.pingChart.itervalues():
Jon Hall1efcb3f2016-08-23 13:42:15 -0700264 print entry
265 hosts, expect = entry[ 'hosts' ], entry[ 'expect' ]
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700266 try:
267 expect = main.TRUE if str(expect).lower() == 'true' else main.FALSE
268 except:
269 expect = main.FALSE
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700270 main.step( "Connectivity for %s %s" % ( str( hosts ), tag ) )
You Wangd5873482018-01-24 12:30:00 -0800271 pa = main.Network.pingallHosts( hosts )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700272
Jon Hall1efcb3f2016-08-23 13:42:15 -0700273 utilities.assert_equals( expect=expect, actual=pa,
274 onpass="IP connectivity successfully tested",
275 onfail="IP connectivity failed" )
276 if dumpflows:
Devin Lim142b5342017-07-20 15:22:39 -0700277 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700278 "flows",
279 main.logdir,
Devin Lim97b6b862018-01-23 22:51:25 -0800280 tag + "_FlowsOn" )
Devin Lim142b5342017-07-20 15:22:39 -0700281 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700282 "groups",
283 main.logdir,
Devin Lim97b6b862018-01-23 22:51:25 -0800284 tag + "_GroupsOn" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700285
286 @staticmethod
287 def killLink( main, end1, end2, switches, links ):
288 """
289 end1,end2: identify the switches, ex.: 'leaf1', 'spine1'
290 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
291 Kill a link and verify ONOS can see the proper link change
292 """
293 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700294 main.step( "Kill link between %s and %s" % ( end1, end2 ) )
You Wangd5873482018-01-24 12:30:00 -0800295 LinkDown = main.Network.link( END1=end1, END2=end2, OPTION="down" )
296 LinkDown = main.Network.link( END2=end1, END1=end2, OPTION="down" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700297 main.log.info(
298 "Waiting %s seconds for link down to be discovered" % main.linkSleep )
299 time.sleep( main.linkSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700300 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700301 main.FALSE,
302 kwargs={ 'numoswitch': switches,
303 'numolink': links },
304 attempts=10,
305 sleep=main.linkSleep )
306 result = topology & LinkDown
307 utilities.assert_equals( expect=main.TRUE, actual=result,
308 onpass="Link down successful",
309 onfail="Failed to turn off link?" )
310
311 @staticmethod
312 def restoreLink( main, end1, end2, dpid1, dpid2, port1, port2, switches,
313 links ):
314 """
315 Params:
316 end1,end2: identify the end switches, ex.: 'leaf1', 'spine1'
317 dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002'
318 port1, port2: respective port of the end switches that connects to the link, ex.:'1'
319 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
320 Kill a link and verify ONOS can see the proper link change
321 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700322 main.step( "Restore link between %s and %s" % ( end1, end2 ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700323 result = False
324 count = 0
325 while True:
326 count += 1
You Wangd5873482018-01-24 12:30:00 -0800327 main.Network.link( END1=end1, END2=end2, OPTION="up" )
328 main.Network.link( END2=end1, END1=end2, OPTION="up" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700329 main.log.info(
330 "Waiting %s seconds for link up to be discovered" % main.linkSleep )
331 time.sleep( main.linkSleep )
Pierfb719b12016-09-19 14:51:44 -0700332
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700333 for i in range( 0, main.Cluster.numCtrls ):
Devin Lim142b5342017-07-20 15:22:39 -0700334 ctrl = main.Cluster.runningNodes[ i ]
335 onosIsUp = main.ONOSbench.isup( ctrl.ipAddress )
Pierfb719b12016-09-19 14:51:44 -0700336 if onosIsUp == main.TRUE:
Devin Lim142b5342017-07-20 15:22:39 -0700337 ctrl.CLI.portstate( dpid=dpid1, port=port1 )
338 ctrl.CLI.portstate( dpid=dpid2, port=port2 )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700339 time.sleep( main.linkSleep )
340
Devin Lim142b5342017-07-20 15:22:39 -0700341 result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches,
342 numolink=links )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700343 if count > 5 or result:
344 break
345 utilities.assert_equals( expect=main.TRUE, actual=result,
346 onpass="Link up successful",
347 onfail="Failed to bring link up" )
348
349 @staticmethod
350 def killSwitch( main, switch, switches, links ):
351 """
352 Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6'
353 Completely kill a switch and verify ONOS can see the proper change
354 """
355 main.switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
356 main.step( "Kill " + switch )
357 main.log.info( "Stopping" + switch )
You Wangd5873482018-01-24 12:30:00 -0800358 main.Network.switch( SW=switch, OPTION="stop" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700359 # todo make this repeatable
360 main.log.info( "Waiting %s seconds for switch down to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700361 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700362 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700363 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700364 main.FALSE,
365 kwargs={ 'numoswitch': switches,
366 'numolink': links },
367 attempts=10,
368 sleep=main.switchSleep )
369 utilities.assert_equals( expect=main.TRUE, actual=topology,
370 onpass="Kill switch successful",
371 onfail="Failed to kill switch?" )
372
373 @staticmethod
374 def recoverSwitch( main, switch, switches, links ):
375 """
376 Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6'
377 Recover a switch and verify ONOS can see the proper change
378 """
379 # todo make this repeatable
380 main.step( "Recovering " + switch )
381 main.log.info( "Starting" + switch )
You Wangd5873482018-01-24 12:30:00 -0800382 main.Network.switch( SW=switch, OPTION="start" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700383 main.log.info( "Waiting %s seconds for switch up to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700384 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700385 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700386 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700387 main.FALSE,
388 kwargs={ 'numoswitch': switches,
389 'numolink': links },
390 attempts=10,
391 sleep=main.switchSleep )
392 utilities.assert_equals( expect=main.TRUE, actual=topology,
393 onpass="Switch recovery successful",
394 onfail="Failed to recover switch?" )
395
396 @staticmethod
397 def cleanup( main ):
398 """
399 Stop Onos-cluster.
400 Stops Mininet
401 Copies ONOS log
402 """
Devin Lim58046fa2017-07-05 16:55:00 -0700403 try:
404 from tests.dependencies.utils import Utils
405 except ImportError:
406 main.log.error( "Utils not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700407 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700408 try:
Devin Lim142b5342017-07-20 15:22:39 -0700409 main.utils
Devin Lim58046fa2017-07-05 16:55:00 -0700410 except ( NameError, AttributeError ):
Devin Lim142b5342017-07-20 15:22:39 -0700411 main.utils = Utils()
Devin Lim58046fa2017-07-05 16:55:00 -0700412
413 main.utils.mininetCleanup( main.Mininet1 )
414
Devin Lim97b6b862018-01-23 22:51:25 -0800415 main.utils.copyKarafLog( main.resultFileName, before=True )
Devin Lim58046fa2017-07-05 16:55:00 -0700416
Devin Lim142b5342017-07-20 15:22:39 -0700417 for ctrl in main.Cluster.active():
418 main.ONOSbench.onosStop( ctrl.ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700419
420 @staticmethod
421 def killOnos( main, nodes, switches, links, expNodes ):
422 """
423 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
424 switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6'
425 Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change
426 """
427 main.step( "Killing ONOS instance" )
Pier3b58c652016-09-26 12:03:31 -0700428
Jon Hall1efcb3f2016-08-23 13:42:15 -0700429 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700430 killResult = main.ONOSbench.onosDie( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700431 utilities.assert_equals( expect=main.TRUE, actual=killResult,
432 onpass="ONOS instance Killed",
433 onfail="Error killing ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700434 main.Cluster.runningNodes[ i ].active = False
Jon Hall1efcb3f2016-08-23 13:42:15 -0700435 time.sleep( 12 )
Pier3b58c652016-09-26 12:03:31 -0700436
Devin Lim142b5342017-07-20 15:22:39 -0700437 if len( nodes ) < main.Cluster.numCtrls:
Pier3b58c652016-09-26 12:03:31 -0700438
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700439 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700440 False,
Pier3b58c652016-09-26 12:03:31 -0700441 attempts=5,
442 sleep=10 )
443 utilities.assert_equals( expect=True, actual=nodeResults,
444 onpass="Nodes check successful",
445 onfail="Nodes check NOT successful" )
446
447 if not nodeResults:
448 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700449 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700450 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700451 ctrl.name,
452 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700453 main.log.error( "Failed to kill ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700454 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700455
Devin Lim142b5342017-07-20 15:22:39 -0700456 topology = utilities.retry( main.Cluster.active( 0 ).checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700457 main.FALSE,
458 kwargs={ 'numoswitch': switches,
459 'numolink': links,
460 'numoctrl': expNodes },
461 attempts=10,
462 sleep=12 )
463 utilities.assert_equals( expect=main.TRUE, actual=topology,
464 onpass="ONOS Instance down successful",
465 onfail="Failed to turn off ONOS Instance" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700466
467 @staticmethod
468 def recoverOnos( main, nodes, switches, links, expNodes ):
469 """
470 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
471 switches, links, nodes: number of expected switches, links and nodes after recoverOnos, ex.: '4', '6'
472 Recover an ONOS instance and verify the ONOS cluster can see the proper change
473 """
474 main.step( "Recovering ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700475 [ main.ONOSbench.onosStart( main.Cluster.runningNodes[ i ].ipAddress ) for i in nodes ]
Jon Hall1efcb3f2016-08-23 13:42:15 -0700476 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700477 isUp = main.ONOSbench.isup( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700478 utilities.assert_equals( expect=main.TRUE, actual=isUp,
479 onpass="ONOS service is ready",
480 onfail="ONOS service did not start properly" )
481 for i in nodes:
482 main.step( "Checking if ONOS CLI is ready" )
Devin Lim142b5342017-07-20 15:22:39 -0700483 ctrl = main.Cluster.runningNodes[ i ]
484 ctrl.CLI.startCellCli()
485 cliResult = ctrl.CLI.startOnosCli( ctrl.ipAddress,
486 commandlineTimeout=60,
487 onosStartTimeout=100 )
488 ctrl.active = True
Jon Hall1efcb3f2016-08-23 13:42:15 -0700489 utilities.assert_equals( expect=main.TRUE,
490 actual=cliResult,
491 onpass="ONOS CLI is ready",
492 onfail="ONOS CLI is not ready" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700493
Pier3b58c652016-09-26 12:03:31 -0700494 main.step( "Checking ONOS nodes" )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700495 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700496 False,
Pier3b58c652016-09-26 12:03:31 -0700497 attempts=5,
498 sleep=10 )
499 utilities.assert_equals( expect=True, actual=nodeResults,
500 onpass="Nodes check successful",
501 onfail="Nodes check NOT successful" )
502
503 if not nodeResults:
504 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700505 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700506 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700507 ctrl.name,
508 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700509 main.log.error( "Failed to start ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700510 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700511
Devin Lim142b5342017-07-20 15:22:39 -0700512 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700513 main.FALSE,
514 kwargs={ 'numoswitch': switches,
515 'numolink': links,
516 'numoctrl': expNodes },
517 attempts=10,
518 sleep=12 )
519 utilities.assert_equals( expect=main.TRUE, actual=topology,
520 onpass="ONOS Instance down successful",
521 onfail="Failed to turn off ONOS Instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700522 ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary,
523 main.FALSE,
524 attempts=10,
525 sleep=12 )
526 if ready:
527 ready = main.TRUE
528 utilities.assert_equals( expect=main.TRUE, actual=ready,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700529 onpass="ONOS summary command succeded",
530 onfail="ONOS summary command failed" )
531 if not ready:
532 main.log.error( "ONOS startup failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700533 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700534
535 @staticmethod
536 def addHostCfg( main ):
537 """
538 Adds Host Configuration to ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700539 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700540 """
541 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700542 hostCfg = {}
Jon Hall1efcb3f2016-08-23 13:42:15 -0700543 with open( main.dependencyPath + "/json/extra.json" ) as template:
544 hostCfg = json.load( template )
545 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ]
546 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700547 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700548 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
549 subjectClass="hosts",
550 subjectKey=urllib.quote( mac,
551 safe='' ),
552 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700553 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ]
554 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700555 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700556 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
557 subjectClass="hosts",
558 subjectKey=urllib.quote( mac,
559 safe='' ),
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700560 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700561 main.pingChart.update( { 'vlan1': { "expect": "True",
562 "hosts": [ "olt1", "vsg1" ] } } )
563 main.pingChart[ 'vlan5' ][ 'expect' ] = 0
564 main.pingChart[ 'vlan10' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700565 ports = "[%s,%s]" % ( 5, 6 )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700566 cfg = '{"of:0000000000000001":[{"vlan":1,"ports":%s,"name":"OLT 1"}]}' % ports
Devin Lim142b5342017-07-20 15:22:39 -0700567 main.Cluster.active( 0 ).REST.setNetCfg( json.loads( cfg ),
568 subjectClass="apps",
569 subjectKey="org.onosproject.segmentrouting",
570 configKey="xconnect" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700571
572 @staticmethod
573 def delHostCfg( main ):
574 """
575 Removest Host Configuration from ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700576 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700577 """
578 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700579 hostCfg = {}
Jon Hall1efcb3f2016-08-23 13:42:15 -0700580 with open( main.dependencyPath + "/json/extra.json" ) as template:
581 hostCfg = json.load( template )
582 main.step( "Removing host configuration" )
583 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700584 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700585 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
586 subjectKey=urllib.quote(
587 mac,
588 safe='' ),
589 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700590 main.step( "Removing configuration" )
591 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700592 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700593 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
594 subjectKey=urllib.quote(
595 mac,
596 safe='' ),
597 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700598 main.step( "Removing vlan configuration" )
599 main.pingChart[ 'vlan1' ][ 'expect' ] = 0
Devin Lim142b5342017-07-20 15:22:39 -0700600 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="apps",
601 subjectKey="org.onosproject.segmentrouting",
602 configKey="xconnect" )