blob: 5198dbed206a7606325816106b8f20e8a867b196 [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 )
You Wangac02b142018-01-26 14:57:28 -080061 main.topoPath = main.path + "/../dependencies/"
62 main.configPath = main.path + "/../dependencies/"
Devin Lim58046fa2017-07-05 16:55:00 -070063 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
64 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070065 main.scale = ( main.params[ 'SCALE' ][ 'size' ] ).split( "," )
Devin Lim58046fa2017-07-05 16:55:00 -070066 main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
67 # main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
68 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
Jon Hall1efcb3f2016-08-23 13:42:15 -070069
Devin Lim142b5342017-07-20 15:22:39 -070070 stepResult = main.testSetUp.envSetup()
Devin Lim58046fa2017-07-05 16:55:00 -070071 except Exception as e:
72 main.testSetUp.envSetupException( e )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -070073
74 # Additional files for topology building
75 try:
76 main.topologyLib1 = main.params[ 'DEPENDENCY' ][ 'lib1' ]
77 main.topologyLib2 = main.params[ 'DEPENDENCY' ][ 'lib2' ]
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -070078 except:
79 pass
80
Devin Lim58046fa2017-07-05 16:55:00 -070081 main.testSetUp.evnSetupConclusion( stepResult )
Jon Hall1efcb3f2016-08-23 13:42:15 -070082
Jon Hall1efcb3f2016-08-23 13:42:15 -070083 @staticmethod
You Wang1cdc5f52017-12-19 16:47:51 -080084 def installOnos( main, vlanCfg=True, skipPackage=False, cliSleep=10 ):
Jon Hall1efcb3f2016-08-23 13:42:15 -070085 """
86 - Set up cell
87 - Create cell file
88 - Set cell file
89 - Verify cell file
90 - Kill ONOS process
91 - Uninstall ONOS cluster
92 - Verify ONOS start up
93 - Install ONOS cluster
94 - Connect to cli
95 """
96 # main.scale[ 0 ] determines the current number of ONOS controller
Jon Hall1efcb3f2016-08-23 13:42:15 -070097 if main.diff:
Devin Lim58046fa2017-07-05 16:55:00 -070098 main.apps = main.apps + "," + main.diff
Jon Hall1efcb3f2016-08-23 13:42:15 -070099 else:
100 main.log.error( "App list is empty" )
Devin Lim142b5342017-07-20 15:22:39 -0700101 main.log.info( "NODE COUNT = " + str( main.Cluster.numCtrls ) )
102 main.log.info( ''.join( main.Cluster.getIps() ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700103 main.dynamicHosts = [ 'in1', 'out1' ]
You Wanga0f6ff62018-01-11 15:46:30 -0800104 main.testSetUp.ONOSSetUp( main.Cluster, newCell=True, cellName=main.cellName,
You Wang1cdc5f52017-12-19 16:47:51 -0800105 skipPack=skipPackage, useSSH=Testcaselib.useSSH )
Devin Lim142b5342017-07-20 15:22:39 -0700106 ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary,
107 main.FALSE,
You Wang1cdc5f52017-12-19 16:47:51 -0800108 sleep=cliSleep,
Devin Lim142b5342017-07-20 15:22:39 -0700109 attempts=10 )
110 if ready:
111 ready = main.TRUE
112 utilities.assert_equals( expect=main.TRUE, actual=ready,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700113 onpass="ONOS summary command succeded",
114 onfail="ONOS summary command failed" )
115
116 with open( "%s/json/%s.json" % (
You Wangac02b142018-01-26 14:57:28 -0800117 main.configPath, main.cfgName ) ) as cfg:
Devin Lim142b5342017-07-20 15:22:39 -0700118 main.Cluster.active( 0 ).REST.setNetCfg( json.load( cfg ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700119 with open( "%s/json/%s.chart" % (
You Wangac02b142018-01-26 14:57:28 -0800120 main.configPath, main.cfgName ) ) as chart:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700121 main.pingChart = json.load( chart )
122 if not ready:
123 main.log.error( "ONOS startup failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700124 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700125
Devin Lim142b5342017-07-20 15:22:39 -0700126 for ctrl in main.Cluster.active():
127 ctrl.CLI.logSet( "DEBUG", "org.onosproject.segmentrouting" )
128 ctrl.CLI.logSet( "DEBUG", "org.onosproject.driver.pipeline" )
129 ctrl.CLI.logSet( "DEBUG", "org.onosproject.store.group.impl" )
130 ctrl.CLI.logSet( "DEBUG", "org.onosproject.net.flowobjective.impl" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700131
132 @staticmethod
133 def startMininet( main, topology, args="" ):
You Wangd5873482018-01-24 12:30:00 -0800134 try:
135 copyResult1 = main.ONOSbench.scp( main.Mininet1,
You Wangac02b142018-01-26 14:57:28 -0800136 main.topoPath +
You Wangd5873482018-01-24 12:30:00 -0800137 main.topology,
138 main.Mininet1.home,
139 direction="to" )
140 copyResult2 = main.ONOSbench.scp( main.Mininet1,
You Wangac02b142018-01-26 14:57:28 -0800141 main.topoPath +
You Wangd5873482018-01-24 12:30:00 -0800142 main.topologyLib1,
143 main.Mininet1.home,
144 direction="to" )
145 copyResult3 = main.ONOSbench.scp( main.Mininet1,
You Wangac02b142018-01-26 14:57:28 -0800146 main.topoPath +
You Wangd5873482018-01-24 12:30:00 -0800147 main.topologyLib2,
148 main.Mininet1.home,
149 direction="to" )
150 except:
151 pass
Jon Hall1efcb3f2016-08-23 13:42:15 -0700152 main.step( "Starting Mininet Topology" )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700153 arg = "--onos-ip=%s %s" % (",".join([ctrl.ipAddress for ctrl in main.Cluster.runningNodes]), args)
Jon Hall1efcb3f2016-08-23 13:42:15 -0700154 main.topology = topology
155 topoResult = main.Mininet1.startNet(
156 topoFile=main.Mininet1.home + main.topology, args=arg )
157 stepResult = topoResult
158 utilities.assert_equals( expect=main.TRUE,
159 actual=stepResult,
160 onpass="Successfully loaded topology",
161 onfail="Failed to load topology" )
162 # Exit if topology did not load properly
163 if not topoResult:
Devin Lim44075962017-08-11 10:56:37 -0700164 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700165
166 @staticmethod
Devin Lim142b5342017-07-20 15:22:39 -0700167 def config( main, cfgName ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700168 main.spines = []
Piera2a7e1b2016-10-04 11:51:43 -0700169
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700170 main.failures = int( main.params[ 'failures' ] )
171 main.cfgName = cfgName
Piera2a7e1b2016-10-04 11:51:43 -0700172
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700173 if main.cfgName == '2x2':
174 spine = {}
175 spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ]
176 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ]
177 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700178
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700179 spine = {}
180 spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ]
181 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ]
182 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700183
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700184 elif main.cfgName == '4x4':
185 spine = {}
186 spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ]
187 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ]
188 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700189
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700190 spine = {}
191 spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ]
192 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ]
193 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700194
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700195 spine = {}
196 spine[ 'name' ] = main.params[ 'switches' ][ 'spine3' ]
197 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid3' ]
198 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700199
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700200 spine = {}
201 spine[ 'name' ] = main.params[ 'switches' ][ 'spine4' ]
202 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid4' ]
203 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700204
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700205 else:
Piera2a7e1b2016-10-04 11:51:43 -0700206 main.log.error( "Configuration failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700207 main.cleanAndExit()
Piera2a7e1b2016-10-04 11:51:43 -0700208
209 @staticmethod
You Wang1cdc5f52017-12-19 16:47:51 -0800210 def checkFlows( main, minFlowCount, dumpflows=True, sleep=10 ):
Jon Hall1efcb3f2016-08-23 13:42:15 -0700211 main.step(
212 " Check whether the flow count is bigger than %s" % minFlowCount )
Devin Lim142b5342017-07-20 15:22:39 -0700213 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowCount,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700214 main.FALSE,
215 kwargs={ 'min': minFlowCount },
216 attempts=10,
You Wang1cdc5f52017-12-19 16:47:51 -0800217 sleep=sleep )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700218 utilities.assertEquals(
Jon Hall1efcb3f2016-08-23 13:42:15 -0700219 expect=True,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700220 actual=( count > 0 ),
Jon Hall1efcb3f2016-08-23 13:42:15 -0700221 onpass="Flow count looks correct: " + str( count ),
222 onfail="Flow count looks wrong: " + str( count ) )
223
224 main.step( "Check whether all flow status are ADDED" )
Devin Lim142b5342017-07-20 15:22:39 -0700225 flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700226 main.FALSE,
227 kwargs={ 'isPENDING': False },
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800228 attempts=5,
You Wang1cdc5f52017-12-19 16:47:51 -0800229 sleep=sleep )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700230 utilities.assertEquals(
Jon Hall1efcb3f2016-08-23 13:42:15 -0700231 expect=main.TRUE,
232 actual=flowCheck,
233 onpass="Flow status is correct!",
234 onfail="Flow status is wrong!" )
235 if dumpflows:
Devin Lim142b5342017-07-20 15:22:39 -0700236 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700237 "flows",
238 main.logdir,
Devin Lim97b6b862018-01-23 22:51:25 -0800239 main.resultFileName + "_FlowsBefore" )
Devin Lim142b5342017-07-20 15:22:39 -0700240 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700241 "groups",
242 main.logdir,
Devin Lim97b6b862018-01-23 22:51:25 -0800243 main.resultFileName + "_GroupsBefore" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700244
245 @staticmethod
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800246 def checkFlowsByDpid( main, dpid, minFlowCount, sleep=10 ):
247 main.step(
248 " Check whether the flow count of device %s is bigger than %s" % ( dpid, minFlowCount ) )
249 count = utilities.retry( main.Cluster.active( 0 ).CLI.flowAddedCount,
250 None,
251 args=( dpid, ),
252 attempts=5,
253 sleep=sleep )
254 utilities.assertEquals(
255 expect=True,
256 actual=( int( count ) > minFlowCount ),
257 onpass="Flow count looks correct: " + count ,
258 onfail="Flow count looks wrong: " + count )
259
260 @staticmethod
Jon Hall1efcb3f2016-08-23 13:42:15 -0700261 def pingAll( main, tag="", dumpflows=True ):
262 main.log.report( "Check full connectivity" )
263 print main.pingChart
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700264 for entry in main.pingChart.itervalues():
Jon Hall1efcb3f2016-08-23 13:42:15 -0700265 print entry
266 hosts, expect = entry[ 'hosts' ], entry[ 'expect' ]
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700267 try:
268 expect = main.TRUE if str(expect).lower() == 'true' else main.FALSE
269 except:
270 expect = main.FALSE
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700271 main.step( "Connectivity for %s %s" % ( str( hosts ), tag ) )
You Wangd5873482018-01-24 12:30:00 -0800272 pa = main.Network.pingallHosts( hosts )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700273
Jon Hall1efcb3f2016-08-23 13:42:15 -0700274 utilities.assert_equals( expect=expect, actual=pa,
275 onpass="IP connectivity successfully tested",
276 onfail="IP connectivity failed" )
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,
Devin Lim97b6b862018-01-23 22:51:25 -0800281 tag + "_FlowsOn" )
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,
Devin Lim97b6b862018-01-23 22:51:25 -0800285 tag + "_GroupsOn" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700286
287 @staticmethod
288 def killLink( main, end1, end2, switches, links ):
289 """
290 end1,end2: identify the switches, ex.: 'leaf1', 'spine1'
291 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
292 Kill a link and verify ONOS can see the proper link change
293 """
294 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700295 main.step( "Kill link between %s and %s" % ( end1, end2 ) )
You Wangd5873482018-01-24 12:30:00 -0800296 LinkDown = main.Network.link( END1=end1, END2=end2, OPTION="down" )
297 LinkDown = main.Network.link( END2=end1, END1=end2, OPTION="down" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700298 main.log.info(
299 "Waiting %s seconds for link down to be discovered" % main.linkSleep )
300 time.sleep( main.linkSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700301 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700302 main.FALSE,
303 kwargs={ 'numoswitch': switches,
304 'numolink': links },
305 attempts=10,
306 sleep=main.linkSleep )
307 result = topology & LinkDown
308 utilities.assert_equals( expect=main.TRUE, actual=result,
309 onpass="Link down successful",
310 onfail="Failed to turn off link?" )
311
312 @staticmethod
313 def restoreLink( main, end1, end2, dpid1, dpid2, port1, port2, switches,
314 links ):
315 """
316 Params:
317 end1,end2: identify the end switches, ex.: 'leaf1', 'spine1'
318 dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002'
319 port1, port2: respective port of the end switches that connects to the link, ex.:'1'
320 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
321 Kill a link and verify ONOS can see the proper link change
322 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700323 main.step( "Restore link between %s and %s" % ( end1, end2 ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700324 result = False
325 count = 0
326 while True:
327 count += 1
You Wangd5873482018-01-24 12:30:00 -0800328 main.Network.link( END1=end1, END2=end2, OPTION="up" )
329 main.Network.link( END2=end1, END1=end2, OPTION="up" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700330 main.log.info(
331 "Waiting %s seconds for link up to be discovered" % main.linkSleep )
332 time.sleep( main.linkSleep )
Pierfb719b12016-09-19 14:51:44 -0700333
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700334 for i in range( 0, main.Cluster.numCtrls ):
Devin Lim142b5342017-07-20 15:22:39 -0700335 ctrl = main.Cluster.runningNodes[ i ]
336 onosIsUp = main.ONOSbench.isup( ctrl.ipAddress )
Pierfb719b12016-09-19 14:51:44 -0700337 if onosIsUp == main.TRUE:
Devin Lim142b5342017-07-20 15:22:39 -0700338 ctrl.CLI.portstate( dpid=dpid1, port=port1 )
339 ctrl.CLI.portstate( dpid=dpid2, port=port2 )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700340 time.sleep( main.linkSleep )
341
Devin Lim142b5342017-07-20 15:22:39 -0700342 result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches,
343 numolink=links )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700344 if count > 5 or result:
345 break
346 utilities.assert_equals( expect=main.TRUE, actual=result,
347 onpass="Link up successful",
348 onfail="Failed to bring link up" )
349
350 @staticmethod
351 def killSwitch( main, switch, switches, links ):
352 """
353 Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6'
354 Completely kill a switch and verify ONOS can see the proper change
355 """
356 main.switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
357 main.step( "Kill " + switch )
358 main.log.info( "Stopping" + switch )
You Wangd5873482018-01-24 12:30:00 -0800359 main.Network.switch( SW=switch, OPTION="stop" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700360 # todo make this repeatable
361 main.log.info( "Waiting %s seconds for switch down to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700362 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700363 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700364 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700365 main.FALSE,
366 kwargs={ 'numoswitch': switches,
367 'numolink': links },
368 attempts=10,
369 sleep=main.switchSleep )
370 utilities.assert_equals( expect=main.TRUE, actual=topology,
371 onpass="Kill switch successful",
372 onfail="Failed to kill switch?" )
373
374 @staticmethod
375 def recoverSwitch( main, switch, switches, links ):
376 """
377 Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6'
378 Recover a switch and verify ONOS can see the proper change
379 """
380 # todo make this repeatable
381 main.step( "Recovering " + switch )
382 main.log.info( "Starting" + switch )
You Wangd5873482018-01-24 12:30:00 -0800383 main.Network.switch( SW=switch, OPTION="start" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700384 main.log.info( "Waiting %s seconds for switch up to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700385 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700386 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700387 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700388 main.FALSE,
389 kwargs={ 'numoswitch': switches,
390 'numolink': links },
391 attempts=10,
392 sleep=main.switchSleep )
393 utilities.assert_equals( expect=main.TRUE, actual=topology,
394 onpass="Switch recovery successful",
395 onfail="Failed to recover switch?" )
396
397 @staticmethod
398 def cleanup( main ):
399 """
400 Stop Onos-cluster.
401 Stops Mininet
402 Copies ONOS log
403 """
Devin Lim58046fa2017-07-05 16:55:00 -0700404 try:
405 from tests.dependencies.utils import Utils
406 except ImportError:
407 main.log.error( "Utils not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700408 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700409 try:
Devin Lim142b5342017-07-20 15:22:39 -0700410 main.utils
Devin Lim58046fa2017-07-05 16:55:00 -0700411 except ( NameError, AttributeError ):
Devin Lim142b5342017-07-20 15:22:39 -0700412 main.utils = Utils()
Devin Lim58046fa2017-07-05 16:55:00 -0700413
414 main.utils.mininetCleanup( main.Mininet1 )
415
Devin Lim97b6b862018-01-23 22:51:25 -0800416 main.utils.copyKarafLog( main.resultFileName, before=True )
Devin Lim58046fa2017-07-05 16:55:00 -0700417
Devin Lim142b5342017-07-20 15:22:39 -0700418 for ctrl in main.Cluster.active():
419 main.ONOSbench.onosStop( ctrl.ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700420
421 @staticmethod
422 def killOnos( main, nodes, switches, links, expNodes ):
423 """
424 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
425 switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6'
426 Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change
427 """
428 main.step( "Killing ONOS instance" )
Pier3b58c652016-09-26 12:03:31 -0700429
Jon Hall1efcb3f2016-08-23 13:42:15 -0700430 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700431 killResult = main.ONOSbench.onosDie( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700432 utilities.assert_equals( expect=main.TRUE, actual=killResult,
433 onpass="ONOS instance Killed",
434 onfail="Error killing ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700435 main.Cluster.runningNodes[ i ].active = False
Jon Hall1efcb3f2016-08-23 13:42:15 -0700436 time.sleep( 12 )
Pier3b58c652016-09-26 12:03:31 -0700437
Devin Lim142b5342017-07-20 15:22:39 -0700438 if len( nodes ) < main.Cluster.numCtrls:
Pier3b58c652016-09-26 12:03:31 -0700439
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700440 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700441 False,
Pier3b58c652016-09-26 12:03:31 -0700442 attempts=5,
443 sleep=10 )
444 utilities.assert_equals( expect=True, actual=nodeResults,
445 onpass="Nodes check successful",
446 onfail="Nodes check NOT successful" )
447
448 if not nodeResults:
449 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700450 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700451 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700452 ctrl.name,
453 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700454 main.log.error( "Failed to kill ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700455 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700456
Devin Lim142b5342017-07-20 15:22:39 -0700457 topology = utilities.retry( main.Cluster.active( 0 ).checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700458 main.FALSE,
459 kwargs={ 'numoswitch': switches,
460 'numolink': links,
461 'numoctrl': expNodes },
462 attempts=10,
463 sleep=12 )
464 utilities.assert_equals( expect=main.TRUE, actual=topology,
465 onpass="ONOS Instance down successful",
466 onfail="Failed to turn off ONOS Instance" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700467
468 @staticmethod
469 def recoverOnos( main, nodes, switches, links, expNodes ):
470 """
471 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
472 switches, links, nodes: number of expected switches, links and nodes after recoverOnos, ex.: '4', '6'
473 Recover an ONOS instance and verify the ONOS cluster can see the proper change
474 """
475 main.step( "Recovering ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700476 [ main.ONOSbench.onosStart( main.Cluster.runningNodes[ i ].ipAddress ) for i in nodes ]
Jon Hall1efcb3f2016-08-23 13:42:15 -0700477 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700478 isUp = main.ONOSbench.isup( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700479 utilities.assert_equals( expect=main.TRUE, actual=isUp,
480 onpass="ONOS service is ready",
481 onfail="ONOS service did not start properly" )
482 for i in nodes:
483 main.step( "Checking if ONOS CLI is ready" )
Devin Lim142b5342017-07-20 15:22:39 -0700484 ctrl = main.Cluster.runningNodes[ i ]
485 ctrl.CLI.startCellCli()
486 cliResult = ctrl.CLI.startOnosCli( ctrl.ipAddress,
487 commandlineTimeout=60,
488 onosStartTimeout=100 )
489 ctrl.active = True
Jon Hall1efcb3f2016-08-23 13:42:15 -0700490 utilities.assert_equals( expect=main.TRUE,
491 actual=cliResult,
492 onpass="ONOS CLI is ready",
493 onfail="ONOS CLI is not ready" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700494
Pier3b58c652016-09-26 12:03:31 -0700495 main.step( "Checking ONOS nodes" )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700496 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700497 False,
Pier3b58c652016-09-26 12:03:31 -0700498 attempts=5,
499 sleep=10 )
500 utilities.assert_equals( expect=True, actual=nodeResults,
501 onpass="Nodes check successful",
502 onfail="Nodes check NOT successful" )
503
504 if not nodeResults:
505 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700506 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700507 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700508 ctrl.name,
509 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700510 main.log.error( "Failed to start ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700511 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700512
Devin Lim142b5342017-07-20 15:22:39 -0700513 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700514 main.FALSE,
515 kwargs={ 'numoswitch': switches,
516 'numolink': links,
517 'numoctrl': expNodes },
518 attempts=10,
519 sleep=12 )
520 utilities.assert_equals( expect=main.TRUE, actual=topology,
521 onpass="ONOS Instance down successful",
522 onfail="Failed to turn off ONOS Instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700523 ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary,
524 main.FALSE,
525 attempts=10,
526 sleep=12 )
527 if ready:
528 ready = main.TRUE
529 utilities.assert_equals( expect=main.TRUE, actual=ready,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700530 onpass="ONOS summary command succeded",
531 onfail="ONOS summary command failed" )
532 if not ready:
533 main.log.error( "ONOS startup failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700534 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700535
536 @staticmethod
537 def addHostCfg( main ):
538 """
539 Adds Host Configuration to ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700540 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700541 """
542 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700543 hostCfg = {}
You Wangac02b142018-01-26 14:57:28 -0800544 with open( main.configPath + "/json/extra.json" ) as template:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700545 hostCfg = json.load( template )
546 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ]
547 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700548 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700549 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
550 subjectClass="hosts",
551 subjectKey=urllib.quote( mac,
552 safe='' ),
553 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700554 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ]
555 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700556 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700557 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
558 subjectClass="hosts",
559 subjectKey=urllib.quote( mac,
560 safe='' ),
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700561 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700562 main.pingChart.update( { 'vlan1': { "expect": "True",
563 "hosts": [ "olt1", "vsg1" ] } } )
564 main.pingChart[ 'vlan5' ][ 'expect' ] = 0
565 main.pingChart[ 'vlan10' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700566 ports = "[%s,%s]" % ( 5, 6 )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700567 cfg = '{"of:0000000000000001":[{"vlan":1,"ports":%s,"name":"OLT 1"}]}' % ports
Devin Lim142b5342017-07-20 15:22:39 -0700568 main.Cluster.active( 0 ).REST.setNetCfg( json.loads( cfg ),
569 subjectClass="apps",
570 subjectKey="org.onosproject.segmentrouting",
571 configKey="xconnect" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700572
573 @staticmethod
574 def delHostCfg( main ):
575 """
576 Removest Host Configuration from ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700577 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700578 """
579 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700580 hostCfg = {}
You Wangac02b142018-01-26 14:57:28 -0800581 with open( main.configPath + "/json/extra.json" ) as template:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700582 hostCfg = json.load( template )
583 main.step( "Removing host configuration" )
584 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700585 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700586 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
587 subjectKey=urllib.quote(
588 mac,
589 safe='' ),
590 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700591 main.step( "Removing configuration" )
592 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700593 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700594 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
595 subjectKey=urllib.quote(
596 mac,
597 safe='' ),
598 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700599 main.step( "Removing vlan configuration" )
600 main.pingChart[ 'vlan1' ][ 'expect' ] = 0
Devin Lim142b5342017-07-20 15:22:39 -0700601 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="apps",
602 subjectKey="org.onosproject.segmentrouting",
603 configKey="xconnect" )