blob: 78c96ccfe2e3a2968ed85e31486314e2f15b3035 [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' ]
Devin Lim58046fa2017-07-05 16:55:00 -070059 main.path = os.path.dirname( main.testFile )
You Wangac02b142018-01-26 14:57:28 -080060 main.topoPath = main.path + "/../dependencies/"
61 main.configPath = main.path + "/../dependencies/"
Devin Lim58046fa2017-07-05 16:55:00 -070062 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
You Wangd87b2312018-01-30 12:47:17 -080063 main.topologyLib = main.params[ 'DEPENDENCY' ][ 'lib' ] if 'lib' in main.params[ 'DEPENDENCY' ] else None
64 main.topologyConf = main.params[ 'DEPENDENCY' ][ 'conf' ] if 'conf' in main.params[ 'DEPENDENCY' ] else None
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' ] )
Devin Lim58046fa2017-07-05 16:55:00 -070067 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
Devin Lim58046fa2017-07-05 16:55:00 -070073 main.testSetUp.evnSetupConclusion( stepResult )
Jon Hall1efcb3f2016-08-23 13:42:15 -070074
Jon Hall1efcb3f2016-08-23 13:42:15 -070075 @staticmethod
You Wang1cdc5f52017-12-19 16:47:51 -080076 def installOnos( main, vlanCfg=True, skipPackage=False, cliSleep=10 ):
Jon Hall1efcb3f2016-08-23 13:42:15 -070077 """
78 - Set up cell
79 - Create cell file
80 - Set cell file
81 - Verify cell file
82 - Kill ONOS process
83 - Uninstall ONOS cluster
84 - Verify ONOS start up
85 - Install ONOS cluster
86 - Connect to cli
87 """
88 # main.scale[ 0 ] determines the current number of ONOS controller
You Wangd87b2312018-01-30 12:47:17 -080089 if not main.apps:
Jon Hall1efcb3f2016-08-23 13:42:15 -070090 main.log.error( "App list is empty" )
Devin Lim142b5342017-07-20 15:22:39 -070091 main.log.info( "NODE COUNT = " + str( main.Cluster.numCtrls ) )
92 main.log.info( ''.join( main.Cluster.getIps() ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -070093 main.dynamicHosts = [ 'in1', 'out1' ]
You Wanga0f6ff62018-01-11 15:46:30 -080094 main.testSetUp.ONOSSetUp( main.Cluster, newCell=True, cellName=main.cellName,
You Wang1cdc5f52017-12-19 16:47:51 -080095 skipPack=skipPackage, useSSH=Testcaselib.useSSH )
Devin Lim142b5342017-07-20 15:22:39 -070096 ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary,
97 main.FALSE,
You Wang1cdc5f52017-12-19 16:47:51 -080098 sleep=cliSleep,
Devin Lim142b5342017-07-20 15:22:39 -070099 attempts=10 )
100 if ready:
101 ready = main.TRUE
102 utilities.assert_equals( expect=main.TRUE, actual=ready,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700103 onpass="ONOS summary command succeded",
104 onfail="ONOS summary command failed" )
105
106 with open( "%s/json/%s.json" % (
You Wangac02b142018-01-26 14:57:28 -0800107 main.configPath, main.cfgName ) ) as cfg:
Devin Lim142b5342017-07-20 15:22:39 -0700108 main.Cluster.active( 0 ).REST.setNetCfg( json.load( cfg ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700109 with open( "%s/json/%s.chart" % (
You Wangac02b142018-01-26 14:57:28 -0800110 main.configPath, main.cfgName ) ) as chart:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700111 main.pingChart = json.load( chart )
112 if not ready:
113 main.log.error( "ONOS startup failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700114 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700115
Devin Lim142b5342017-07-20 15:22:39 -0700116 for ctrl in main.Cluster.active():
117 ctrl.CLI.logSet( "DEBUG", "org.onosproject.segmentrouting" )
118 ctrl.CLI.logSet( "DEBUG", "org.onosproject.driver.pipeline" )
119 ctrl.CLI.logSet( "DEBUG", "org.onosproject.store.group.impl" )
120 ctrl.CLI.logSet( "DEBUG", "org.onosproject.net.flowobjective.impl" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700121
122 @staticmethod
123 def startMininet( main, topology, args="" ):
You Wangd87b2312018-01-30 12:47:17 -0800124 copyResult = main.ONOSbench.scp( main.Mininet1,
125 main.topoPath + main.topology,
126 main.Mininet1.home,
127 direction="to" )
128 if main.topologyLib:
129 for lib in main.topologyLib.split(","):
130 copyResult = copyResult and main.ONOSbench.scp( main.Mininet1,
131 main.topoPath + lib,
132 main.Mininet1.home,
133 direction="to" )
134 if main.topologyConf:
135 for conf in main.topologyConf.split(","):
136 copyResult = copyResult and main.ONOSbench.scp( main.Mininet1,
137 main.topoPath + "conf/" + conf,
138 "~/",
139 direction="to" )
140 stepResult = copyResult
141 utilities.assert_equals( expect=main.TRUE,
142 actual=stepResult,
143 onpass="Successfully copied topo files",
144 onfail="Failed to copy topo files" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700145 main.step( "Starting Mininet Topology" )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700146 arg = "--onos-ip=%s %s" % (",".join([ctrl.ipAddress for ctrl in main.Cluster.runningNodes]), args)
Jon Hall1efcb3f2016-08-23 13:42:15 -0700147 main.topology = topology
148 topoResult = main.Mininet1.startNet(
149 topoFile=main.Mininet1.home + main.topology, args=arg )
150 stepResult = topoResult
151 utilities.assert_equals( expect=main.TRUE,
152 actual=stepResult,
153 onpass="Successfully loaded topology",
154 onfail="Failed to load topology" )
155 # Exit if topology did not load properly
156 if not topoResult:
Devin Lim44075962017-08-11 10:56:37 -0700157 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700158
159 @staticmethod
Devin Lim142b5342017-07-20 15:22:39 -0700160 def config( main, cfgName ):
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700161 main.spines = []
Piera2a7e1b2016-10-04 11:51:43 -0700162
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700163 main.failures = int( main.params[ 'failures' ] )
164 main.cfgName = cfgName
Piera2a7e1b2016-10-04 11:51:43 -0700165
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700166 if main.cfgName == '2x2':
167 spine = {}
168 spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ]
169 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ]
170 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700171
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700172 spine = {}
173 spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ]
174 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ]
175 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700176
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700177 elif main.cfgName == '4x4':
178 spine = {}
179 spine[ 'name' ] = main.params[ 'switches' ][ 'spine1' ]
180 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid1' ]
181 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700182
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700183 spine = {}
184 spine[ 'name' ] = main.params[ 'switches' ][ 'spine2' ]
185 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid2' ]
186 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700187
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700188 spine = {}
189 spine[ 'name' ] = main.params[ 'switches' ][ 'spine3' ]
190 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid3' ]
191 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700192
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700193 spine = {}
194 spine[ 'name' ] = main.params[ 'switches' ][ 'spine4' ]
195 spine[ 'dpid' ] = main.params[ 'switches' ][ 'spinedpid4' ]
196 main.spines.append( spine )
Piera2a7e1b2016-10-04 11:51:43 -0700197
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700198 else:
Piera2a7e1b2016-10-04 11:51:43 -0700199 main.log.error( "Configuration failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700200 main.cleanAndExit()
Piera2a7e1b2016-10-04 11:51:43 -0700201
202 @staticmethod
You Wang1cdc5f52017-12-19 16:47:51 -0800203 def checkFlows( main, minFlowCount, dumpflows=True, sleep=10 ):
Jon Hall1efcb3f2016-08-23 13:42:15 -0700204 main.step(
205 " Check whether the flow count is bigger than %s" % minFlowCount )
Devin Lim142b5342017-07-20 15:22:39 -0700206 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowCount,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700207 main.FALSE,
208 kwargs={ 'min': minFlowCount },
209 attempts=10,
You Wang1cdc5f52017-12-19 16:47:51 -0800210 sleep=sleep )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700211 utilities.assertEquals(
Jon Hall1efcb3f2016-08-23 13:42:15 -0700212 expect=True,
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700213 actual=( count > 0 ),
Jon Hall1efcb3f2016-08-23 13:42:15 -0700214 onpass="Flow count looks correct: " + str( count ),
215 onfail="Flow count looks wrong: " + str( count ) )
216
217 main.step( "Check whether all flow status are ADDED" )
Devin Lim142b5342017-07-20 15:22:39 -0700218 flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700219 main.FALSE,
220 kwargs={ 'isPENDING': False },
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800221 attempts=5,
You Wang1cdc5f52017-12-19 16:47:51 -0800222 sleep=sleep )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700223 utilities.assertEquals(
Jon Hall1efcb3f2016-08-23 13:42:15 -0700224 expect=main.TRUE,
225 actual=flowCheck,
226 onpass="Flow status is correct!",
227 onfail="Flow status is wrong!" )
228 if dumpflows:
Devin Lim142b5342017-07-20 15:22:39 -0700229 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700230 "flows",
231 main.logdir,
Devin Lim97b6b862018-01-23 22:51:25 -0800232 main.resultFileName + "_FlowsBefore" )
Devin Lim142b5342017-07-20 15:22:39 -0700233 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700234 "groups",
235 main.logdir,
Devin Lim97b6b862018-01-23 22:51:25 -0800236 main.resultFileName + "_GroupsBefore" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700237
238 @staticmethod
Jonghwan Hyun98fb40a2018-01-04 16:16:28 -0800239 def checkFlowsByDpid( main, dpid, minFlowCount, sleep=10 ):
240 main.step(
241 " Check whether the flow count of device %s is bigger than %s" % ( dpid, minFlowCount ) )
242 count = utilities.retry( main.Cluster.active( 0 ).CLI.flowAddedCount,
243 None,
244 args=( dpid, ),
245 attempts=5,
246 sleep=sleep )
247 utilities.assertEquals(
248 expect=True,
249 actual=( int( count ) > minFlowCount ),
250 onpass="Flow count looks correct: " + count ,
251 onfail="Flow count looks wrong: " + count )
252
253 @staticmethod
Jon Hall1efcb3f2016-08-23 13:42:15 -0700254 def pingAll( main, tag="", dumpflows=True ):
255 main.log.report( "Check full connectivity" )
256 print main.pingChart
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700257 for entry in main.pingChart.itervalues():
Jon Hall1efcb3f2016-08-23 13:42:15 -0700258 print entry
259 hosts, expect = entry[ 'hosts' ], entry[ 'expect' ]
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700260 try:
261 expect = main.TRUE if str(expect).lower() == 'true' else main.FALSE
262 except:
263 expect = main.FALSE
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700264 main.step( "Connectivity for %s %s" % ( str( hosts ), tag ) )
You Wangd5873482018-01-24 12:30:00 -0800265 pa = main.Network.pingallHosts( hosts )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700266
Jon Hall1efcb3f2016-08-23 13:42:15 -0700267 utilities.assert_equals( expect=expect, actual=pa,
268 onpass="IP connectivity successfully tested",
269 onfail="IP connectivity failed" )
270 if dumpflows:
Devin Lim142b5342017-07-20 15:22:39 -0700271 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700272 "flows",
273 main.logdir,
Devin Lim97b6b862018-01-23 22:51:25 -0800274 tag + "_FlowsOn" )
Devin Lim142b5342017-07-20 15:22:39 -0700275 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700276 "groups",
277 main.logdir,
Devin Lim97b6b862018-01-23 22:51:25 -0800278 tag + "_GroupsOn" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700279
280 @staticmethod
281 def killLink( main, end1, end2, switches, links ):
282 """
283 end1,end2: identify the switches, ex.: 'leaf1', 'spine1'
284 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
285 Kill a link and verify ONOS can see the proper link change
286 """
287 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700288 main.step( "Kill link between %s and %s" % ( end1, end2 ) )
You Wangd5873482018-01-24 12:30:00 -0800289 LinkDown = main.Network.link( END1=end1, END2=end2, OPTION="down" )
290 LinkDown = main.Network.link( END2=end1, END1=end2, OPTION="down" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700291 main.log.info(
292 "Waiting %s seconds for link down to be discovered" % main.linkSleep )
293 time.sleep( main.linkSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700294 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700295 main.FALSE,
296 kwargs={ 'numoswitch': switches,
297 'numolink': links },
298 attempts=10,
299 sleep=main.linkSleep )
300 result = topology & LinkDown
301 utilities.assert_equals( expect=main.TRUE, actual=result,
302 onpass="Link down successful",
303 onfail="Failed to turn off link?" )
304
305 @staticmethod
306 def restoreLink( main, end1, end2, dpid1, dpid2, port1, port2, switches,
307 links ):
308 """
309 Params:
310 end1,end2: identify the end switches, ex.: 'leaf1', 'spine1'
311 dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002'
312 port1, port2: respective port of the end switches that connects to the link, ex.:'1'
313 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
314 Kill a link and verify ONOS can see the proper link change
315 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700316 main.step( "Restore link between %s and %s" % ( end1, end2 ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700317 result = False
318 count = 0
319 while True:
320 count += 1
You Wangd5873482018-01-24 12:30:00 -0800321 main.Network.link( END1=end1, END2=end2, OPTION="up" )
322 main.Network.link( END2=end1, END1=end2, OPTION="up" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700323 main.log.info(
324 "Waiting %s seconds for link up to be discovered" % main.linkSleep )
325 time.sleep( main.linkSleep )
Pierfb719b12016-09-19 14:51:44 -0700326
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700327 for i in range( 0, main.Cluster.numCtrls ):
Devin Lim142b5342017-07-20 15:22:39 -0700328 ctrl = main.Cluster.runningNodes[ i ]
329 onosIsUp = main.ONOSbench.isup( ctrl.ipAddress )
Pierfb719b12016-09-19 14:51:44 -0700330 if onosIsUp == main.TRUE:
Devin Lim142b5342017-07-20 15:22:39 -0700331 ctrl.CLI.portstate( dpid=dpid1, port=port1 )
332 ctrl.CLI.portstate( dpid=dpid2, port=port2 )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700333 time.sleep( main.linkSleep )
334
Devin Lim142b5342017-07-20 15:22:39 -0700335 result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches,
336 numolink=links )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700337 if count > 5 or result:
338 break
339 utilities.assert_equals( expect=main.TRUE, actual=result,
340 onpass="Link up successful",
341 onfail="Failed to bring link up" )
342
343 @staticmethod
344 def killSwitch( main, switch, switches, links ):
345 """
346 Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6'
347 Completely kill a switch and verify ONOS can see the proper change
348 """
349 main.switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
350 main.step( "Kill " + switch )
351 main.log.info( "Stopping" + switch )
You Wangd5873482018-01-24 12:30:00 -0800352 main.Network.switch( SW=switch, OPTION="stop" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700353 # todo make this repeatable
354 main.log.info( "Waiting %s seconds for switch down to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700355 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700356 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700357 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700358 main.FALSE,
359 kwargs={ 'numoswitch': switches,
360 'numolink': links },
361 attempts=10,
362 sleep=main.switchSleep )
363 utilities.assert_equals( expect=main.TRUE, actual=topology,
364 onpass="Kill switch successful",
365 onfail="Failed to kill switch?" )
366
367 @staticmethod
368 def recoverSwitch( main, switch, switches, links ):
369 """
370 Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6'
371 Recover a switch and verify ONOS can see the proper change
372 """
373 # todo make this repeatable
374 main.step( "Recovering " + switch )
375 main.log.info( "Starting" + switch )
You Wangd5873482018-01-24 12:30:00 -0800376 main.Network.switch( SW=switch, OPTION="start" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700377 main.log.info( "Waiting %s seconds for switch up to be discovered" % (
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700378 main.switchSleep ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700379 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700380 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700381 main.FALSE,
382 kwargs={ 'numoswitch': switches,
383 'numolink': links },
384 attempts=10,
385 sleep=main.switchSleep )
386 utilities.assert_equals( expect=main.TRUE, actual=topology,
387 onpass="Switch recovery successful",
388 onfail="Failed to recover switch?" )
389
390 @staticmethod
391 def cleanup( main ):
392 """
393 Stop Onos-cluster.
394 Stops Mininet
395 Copies ONOS log
396 """
Devin Lim58046fa2017-07-05 16:55:00 -0700397 try:
398 from tests.dependencies.utils import Utils
399 except ImportError:
400 main.log.error( "Utils not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700401 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700402 try:
Devin Lim142b5342017-07-20 15:22:39 -0700403 main.utils
Devin Lim58046fa2017-07-05 16:55:00 -0700404 except ( NameError, AttributeError ):
Devin Lim142b5342017-07-20 15:22:39 -0700405 main.utils = Utils()
Devin Lim58046fa2017-07-05 16:55:00 -0700406
407 main.utils.mininetCleanup( main.Mininet1 )
408
Devin Lim97b6b862018-01-23 22:51:25 -0800409 main.utils.copyKarafLog( main.resultFileName, before=True )
Devin Lim58046fa2017-07-05 16:55:00 -0700410
Devin Lim142b5342017-07-20 15:22:39 -0700411 for ctrl in main.Cluster.active():
412 main.ONOSbench.onosStop( ctrl.ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700413
414 @staticmethod
415 def killOnos( main, nodes, switches, links, expNodes ):
416 """
417 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
418 switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6'
419 Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change
420 """
421 main.step( "Killing ONOS instance" )
Pier3b58c652016-09-26 12:03:31 -0700422
Jon Hall1efcb3f2016-08-23 13:42:15 -0700423 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700424 killResult = main.ONOSbench.onosDie( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700425 utilities.assert_equals( expect=main.TRUE, actual=killResult,
426 onpass="ONOS instance Killed",
427 onfail="Error killing ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700428 main.Cluster.runningNodes[ i ].active = False
Jon Hall1efcb3f2016-08-23 13:42:15 -0700429 time.sleep( 12 )
Pier3b58c652016-09-26 12:03:31 -0700430
Devin Lim142b5342017-07-20 15:22:39 -0700431 if len( nodes ) < main.Cluster.numCtrls:
Pier3b58c652016-09-26 12:03:31 -0700432
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700433 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700434 False,
Pier3b58c652016-09-26 12:03:31 -0700435 attempts=5,
436 sleep=10 )
437 utilities.assert_equals( expect=True, actual=nodeResults,
438 onpass="Nodes check successful",
439 onfail="Nodes check NOT successful" )
440
441 if not nodeResults:
442 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700443 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700444 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700445 ctrl.name,
446 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700447 main.log.error( "Failed to kill ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700448 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700449
Devin Lim142b5342017-07-20 15:22:39 -0700450 topology = utilities.retry( main.Cluster.active( 0 ).checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700451 main.FALSE,
452 kwargs={ 'numoswitch': switches,
453 'numolink': links,
454 'numoctrl': expNodes },
455 attempts=10,
456 sleep=12 )
457 utilities.assert_equals( expect=main.TRUE, actual=topology,
458 onpass="ONOS Instance down successful",
459 onfail="Failed to turn off ONOS Instance" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700460
461 @staticmethod
462 def recoverOnos( main, nodes, switches, links, expNodes ):
463 """
464 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
465 switches, links, nodes: number of expected switches, links and nodes after recoverOnos, ex.: '4', '6'
466 Recover an ONOS instance and verify the ONOS cluster can see the proper change
467 """
468 main.step( "Recovering ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700469 [ main.ONOSbench.onosStart( main.Cluster.runningNodes[ i ].ipAddress ) for i in nodes ]
Jon Hall1efcb3f2016-08-23 13:42:15 -0700470 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700471 isUp = main.ONOSbench.isup( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700472 utilities.assert_equals( expect=main.TRUE, actual=isUp,
473 onpass="ONOS service is ready",
474 onfail="ONOS service did not start properly" )
475 for i in nodes:
476 main.step( "Checking if ONOS CLI is ready" )
Devin Lim142b5342017-07-20 15:22:39 -0700477 ctrl = main.Cluster.runningNodes[ i ]
478 ctrl.CLI.startCellCli()
479 cliResult = ctrl.CLI.startOnosCli( ctrl.ipAddress,
480 commandlineTimeout=60,
481 onosStartTimeout=100 )
482 ctrl.active = True
Jon Hall1efcb3f2016-08-23 13:42:15 -0700483 utilities.assert_equals( expect=main.TRUE,
484 actual=cliResult,
485 onpass="ONOS CLI is ready",
486 onfail="ONOS CLI is not ready" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700487
Pier3b58c652016-09-26 12:03:31 -0700488 main.step( "Checking ONOS nodes" )
Jonghwan Hyun3731d6a2017-10-19 11:59:31 -0700489 nodeResults = utilities.retry( main.Cluster.nodesCheck,
Pier3b58c652016-09-26 12:03:31 -0700490 False,
Pier3b58c652016-09-26 12:03:31 -0700491 attempts=5,
492 sleep=10 )
493 utilities.assert_equals( expect=True, actual=nodeResults,
494 onpass="Nodes check successful",
495 onfail="Nodes check NOT successful" )
496
497 if not nodeResults:
498 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700499 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700500 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700501 ctrl.name,
502 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700503 main.log.error( "Failed to start ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700504 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700505
Devin Lim142b5342017-07-20 15:22:39 -0700506 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700507 main.FALSE,
508 kwargs={ 'numoswitch': switches,
509 'numolink': links,
510 'numoctrl': expNodes },
511 attempts=10,
512 sleep=12 )
513 utilities.assert_equals( expect=main.TRUE, actual=topology,
514 onpass="ONOS Instance down successful",
515 onfail="Failed to turn off ONOS Instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700516 ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary,
517 main.FALSE,
518 attempts=10,
519 sleep=12 )
520 if ready:
521 ready = main.TRUE
522 utilities.assert_equals( expect=main.TRUE, actual=ready,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700523 onpass="ONOS summary command succeded",
524 onfail="ONOS summary command failed" )
525 if not ready:
526 main.log.error( "ONOS startup failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700527 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700528
529 @staticmethod
530 def addHostCfg( main ):
531 """
532 Adds Host Configuration to ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700533 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700534 """
535 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700536 hostCfg = {}
You Wangac02b142018-01-26 14:57:28 -0800537 with open( main.configPath + "/json/extra.json" ) as template:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700538 hostCfg = json.load( template )
539 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ]
540 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700541 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700542 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
543 subjectClass="hosts",
544 subjectKey=urllib.quote( mac,
545 safe='' ),
546 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700547 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ]
548 main.step( "Pushing new configuration" )
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700549 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700550 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
551 subjectClass="hosts",
552 subjectKey=urllib.quote( mac,
553 safe='' ),
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700554 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700555 main.pingChart.update( { 'vlan1': { "expect": "True",
556 "hosts": [ "olt1", "vsg1" ] } } )
557 main.pingChart[ 'vlan5' ][ 'expect' ] = 0
558 main.pingChart[ 'vlan10' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700559 ports = "[%s,%s]" % ( 5, 6 )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700560 cfg = '{"of:0000000000000001":[{"vlan":1,"ports":%s,"name":"OLT 1"}]}' % ports
Devin Lim142b5342017-07-20 15:22:39 -0700561 main.Cluster.active( 0 ).REST.setNetCfg( json.loads( cfg ),
562 subjectClass="apps",
563 subjectKey="org.onosproject.segmentrouting",
564 configKey="xconnect" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700565
566 @staticmethod
567 def delHostCfg( main ):
568 """
569 Removest Host Configuration from ONOS
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700570 Updates expected state of the network ( pingChart )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700571 """
572 import json
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700573 hostCfg = {}
You Wangac02b142018-01-26 14:57:28 -0800574 with open( main.configPath + "/json/extra.json" ) as template:
Jon Hall1efcb3f2016-08-23 13:42:15 -0700575 hostCfg = json.load( template )
576 main.step( "Removing host configuration" )
577 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700578 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700579 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
580 subjectKey=urllib.quote(
581 mac,
582 safe='' ),
583 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700584 main.step( "Removing configuration" )
585 main.pingChart[ 'ip' ][ 'expect' ] = 0
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700586 mac, cfg = hostCfg[ 'hosts' ].popitem()
Devin Lim142b5342017-07-20 15:22:39 -0700587 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
588 subjectKey=urllib.quote(
589 mac,
590 safe='' ),
591 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700592 main.step( "Removing vlan configuration" )
593 main.pingChart[ 'vlan1' ][ 'expect' ] = 0
Devin Lim142b5342017-07-20 15:22:39 -0700594 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="apps",
595 subjectKey="org.onosproject.segmentrouting",
596 configKey="xconnect" )