blob: d83585a0ef392ee4ca502a56de4aa1510f07c723 [file] [log] [blame]
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07001"""
2Copyright 2016 Open Networking Foundation (ONF)
3
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
11 (at your option) any later version.
12
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"""
21
Jon Hall1efcb3f2016-08-23 13:42:15 -070022import os
23import imp
24import time
25import json
26import urllib
27from core import utilities
28
29
30class Testcaselib:
Pierfb719b12016-09-19 14:51:44 -070031
You Wangf5de25b2017-01-06 15:13:01 -080032 useSSH=True
Pierfb719b12016-09-19 14:51:44 -070033
Jon Hall1efcb3f2016-08-23 13:42:15 -070034 @staticmethod
35 def initTest( main ):
36 """
37 - Construct tests variables
38 - GIT ( optional )
39 - Checkout ONOS master branch
40 - Pull latest ONOS code
41 - Building ONOS ( optional )
42 - Install ONOS package
43 - Build ONOS package
44 """
Devin Lim58046fa2017-07-05 16:55:00 -070045 try:
46 from tests.dependencies.ONOSSetup import ONOSSetup
47 main.testSetUp = ONOSSetup()
48 except ImportError:
49 main.log.error( "ONOSSetup not found. exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070050 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070051 main.testSetUp.envSetupDescription()
52 stepResult = main.FALSE
53 try:
54 main.step( "Constructing test variables" )
55 # Test variables
56 main.cellName = main.params[ 'ENV' ][ 'cellName' ]
57 main.apps = main.params[ 'ENV' ][ 'cellApps' ]
58 main.diff = main.params[ 'ENV' ][ 'diffApps' ]
59 main.path = os.path.dirname( main.testFile )
60 main.dependencyPath = main.path + "/../dependencies/"
61 main.topology = main.params[ 'DEPENDENCY' ][ 'topology' ]
62 wrapperFile1 = main.params[ 'DEPENDENCY' ][ 'wrapper1' ]
63 main.scale = (main.params[ 'SCALE' ][ 'size' ]).split( "," )
64 main.maxNodes = int( main.params[ 'SCALE' ][ 'max' ] )
65 # main.ONOSport = main.params[ 'CTRL' ][ 'port' ]
66 main.startUpSleep = int( main.params[ 'SLEEP' ][ 'startup' ] )
67 # -- INIT SECTION, ONLY RUNS ONCE -- #
Jon Hall1efcb3f2016-08-23 13:42:15 -070068
Devin Lim58046fa2017-07-05 16:55:00 -070069 copyResult1 = main.ONOSbench.scp( main.Mininet1,
70 main.dependencyPath +
71 main.topology,
72 main.Mininet1.home,
73 direction="to" )
Devin Lim142b5342017-07-20 15:22:39 -070074 stepResult = main.testSetUp.envSetup()
Devin Lim58046fa2017-07-05 16:55:00 -070075 except Exception as e:
76 main.testSetUp.envSetupException( e )
77 main.testSetUp.evnSetupConclusion( stepResult )
Jon Hall1efcb3f2016-08-23 13:42:15 -070078
Jon Hall1efcb3f2016-08-23 13:42:15 -070079
Jon Hall1efcb3f2016-08-23 13:42:15 -070080
81 @staticmethod
82 def installOnos( main, vlanCfg=True ):
83 """
84 - Set up cell
85 - Create cell file
86 - Set cell file
87 - Verify cell file
88 - Kill ONOS process
89 - Uninstall ONOS cluster
90 - Verify ONOS start up
91 - Install ONOS cluster
92 - Connect to cli
93 """
94 # main.scale[ 0 ] determines the current number of ONOS controller
Jon Hall1efcb3f2016-08-23 13:42:15 -070095 if main.diff:
Devin Lim58046fa2017-07-05 16:55:00 -070096 main.apps = main.apps + "," + main.diff
Jon Hall1efcb3f2016-08-23 13:42:15 -070097 else:
98 main.log.error( "App list is empty" )
Devin Lim142b5342017-07-20 15:22:39 -070099 main.log.info( "NODE COUNT = " + str( main.Cluster.numCtrls ) )
100 main.log.info( ''.join( main.Cluster.getIps() ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700101 main.dynamicHosts = [ 'in1', 'out1' ]
Devin Lim142b5342017-07-20 15:22:39 -0700102 main.testSetUp.createApplyCell( main.Cluster, newCell=True, cellName=main.cellName,
103 Mininet=main.Mininet1, useSSH=Testcaselib.useSSH,
Devin Lim6301b742017-08-07 11:00:21 -0700104 ips=main.Cluster.getIps() )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700105 # kill off all onos processes
106 main.log.info( "Safety check, killing all ONOS processes" +
107 " before initiating environment setup" )
Devin Lim142b5342017-07-20 15:22:39 -0700108 for ctrl in main.Cluster.runningNodes:
109 main.ONOSbench.onosDie( ctrl.ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700110
Devin Lim142b5342017-07-20 15:22:39 -0700111 main.testSetUp.buildOnos( main.Cluster )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700112
Devin Lim142b5342017-07-20 15:22:39 -0700113 main.testSetUp.installOnos( main.Cluster, False )
Devin Lim58046fa2017-07-05 16:55:00 -0700114
Devin Lim142b5342017-07-20 15:22:39 -0700115 main.testSetUp.setupSsh( main.Cluster )
Devin Lim58046fa2017-07-05 16:55:00 -0700116
Devin Lim142b5342017-07-20 15:22:39 -0700117 main.testSetUp.checkOnosService( main.Cluster )
Devin Lim58046fa2017-07-05 16:55:00 -0700118
Devin Lim142b5342017-07-20 15:22:39 -0700119 cliResult = main.TRUE
Jon Hall1efcb3f2016-08-23 13:42:15 -0700120 main.step( "Checking if ONOS CLI is ready" )
Devin Lim142b5342017-07-20 15:22:39 -0700121 for ctrl in main.Cluster.runningNodes:
122 ctrl.CLI.startCellCli( )
123 cliResult = cliResult and ctrl.CLI.startOnosCli( ctrl.ipAddress,
124 commandlineTimeout=60,
125 onosStartTimeout=100 )
126 ctrl.active = True
Jon Hall1efcb3f2016-08-23 13:42:15 -0700127 utilities.assert_equals( expect=main.TRUE,
128 actual=cliResult,
129 onpass="ONOS CLI is ready",
130 onfail="ONOS CLI is not ready" )
Devin Lim142b5342017-07-20 15:22:39 -0700131 ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary,
132 main.FALSE,
133 sleep=10,
134 attempts=10 )
135 if ready:
136 ready = main.TRUE
137 utilities.assert_equals( expect=main.TRUE, actual=ready,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700138 onpass="ONOS summary command succeded",
139 onfail="ONOS summary command failed" )
140
141 with open( "%s/json/%s.json" % (
142 main.dependencyPath, main.cfgName) ) as cfg:
Devin Lim142b5342017-07-20 15:22:39 -0700143 main.Cluster.active( 0 ).REST.setNetCfg( json.load( cfg ) )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700144 with open( "%s/json/%s.chart" % (
145 main.dependencyPath, main.cfgName) ) as chart:
146 main.pingChart = json.load( chart )
147 if not ready:
148 main.log.error( "ONOS startup failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700149 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700150
Devin Lim142b5342017-07-20 15:22:39 -0700151 for ctrl in main.Cluster.active():
152 ctrl.CLI.logSet( "DEBUG", "org.onosproject.segmentrouting" )
153 ctrl.CLI.logSet( "DEBUG", "org.onosproject.driver.pipeline" )
154 ctrl.CLI.logSet( "DEBUG", "org.onosproject.store.group.impl" )
155 ctrl.CLI.logSet( "DEBUG", "org.onosproject.net.flowobjective.impl" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700156
157 @staticmethod
158 def startMininet( main, topology, args="" ):
159 main.step( "Starting Mininet Topology" )
Devin Lim142b5342017-07-20 15:22:39 -0700160 arg = "--onos %d %s" % (main.Cluster.numCtrls, args)
Jon Hall1efcb3f2016-08-23 13:42:15 -0700161 main.topology = topology
162 topoResult = main.Mininet1.startNet(
163 topoFile=main.Mininet1.home + main.topology, args=arg )
164 stepResult = topoResult
165 utilities.assert_equals( expect=main.TRUE,
166 actual=stepResult,
167 onpass="Successfully loaded topology",
168 onfail="Failed to load topology" )
169 # Exit if topology did not load properly
170 if not topoResult:
Devin Lim44075962017-08-11 10:56:37 -0700171 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700172
173 @staticmethod
Devin Lim142b5342017-07-20 15:22:39 -0700174 def config( main, cfgName ):
Piera2a7e1b2016-10-04 11:51:43 -0700175 main.spines = []
176
177 main.failures = int(main.params[ 'failures' ])
178 main.cfgName = cfgName
Piera2a7e1b2016-10-04 11:51:43 -0700179
180 if main.cfgName == '2x2' :
181 spine = {}
182 spine[ 'name' ] = main.params['switches'][ 'spine1' ]
183 spine[ 'dpid' ] = main.params['switches'][ 'spinedpid1' ]
184 main.spines.append(spine)
185
186 spine = {}
187 spine[ 'name' ] = main.params['switches'][ 'spine2' ]
188 spine[ 'dpid' ] = main.params['switches'][ 'spinedpid2' ]
189 main.spines.append(spine)
190
191 elif main.cfgName == '4x4' :
192 spine = {}
193 spine[ 'name' ] = main.params['switches'][ 'spine1' ]
194 spine[ 'dpid' ] = main.params['switches'][ 'spinedpid1' ]
195 main.spines.append(spine)
196
197 spine = {}
198 spine[ 'name' ] = main.params['switches'][ 'spine2' ]
199 spine[ 'dpid' ] = main.params['switches'][ 'spinedpid2' ]
200 main.spines.append(spine)
201
202 spine = {}
203 spine[ 'name' ] = main.params['switches'][ 'spine3' ]
204 spine[ 'dpid' ] = main.params['switches'][ 'spinedpid3' ]
205 main.spines.append(spine)
206
207 spine = {}
208 spine[ 'name' ] = main.params['switches'][ 'spine4' ]
209 spine[ 'dpid' ] = main.params['switches'][ 'spinedpid4' ]
210 main.spines.append(spine)
211
212 else :
213 main.log.error( "Configuration failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700214 main.cleanAndExit()
Piera2a7e1b2016-10-04 11:51:43 -0700215
216 @staticmethod
Jon Hall1efcb3f2016-08-23 13:42:15 -0700217 def checkFlows( main, minFlowCount, dumpflows=True ):
218 main.step(
219 " Check whether the flow count is bigger than %s" % minFlowCount )
Devin Lim142b5342017-07-20 15:22:39 -0700220 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowCount,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700221 main.FALSE,
222 kwargs={ 'min': minFlowCount },
223 attempts=10,
224 sleep=10 )
225 utilities.assertEquals( \
226 expect=True,
227 actual=(count > 0),
228 onpass="Flow count looks correct: " + str( count ),
229 onfail="Flow count looks wrong: " + str( count ) )
230
231 main.step( "Check whether all flow status are ADDED" )
Devin Lim142b5342017-07-20 15:22:39 -0700232 flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700233 main.FALSE,
234 kwargs={ 'isPENDING': False },
235 attempts=2,
236 sleep=10 )
237 utilities.assertEquals( \
238 expect=main.TRUE,
239 actual=flowCheck,
240 onpass="Flow status is correct!",
241 onfail="Flow status is wrong!" )
242 if dumpflows:
Devin Lim142b5342017-07-20 15:22:39 -0700243 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700244 "flows",
245 main.logdir,
246 "flowsBefore" + main.cfgName )
Devin Lim142b5342017-07-20 15:22:39 -0700247 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700248 "groups",
249 main.logdir,
250 "groupsBefore" + main.cfgName )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700251
252 @staticmethod
253 def pingAll( main, tag="", dumpflows=True ):
254 main.log.report( "Check full connectivity" )
255 print main.pingChart
256 for entry in main.pingChart.itervalues( ):
257 print entry
258 hosts, expect = entry[ 'hosts' ], entry[ 'expect' ]
259 expect = main.TRUE if expect else main.FALSE
260 main.step( "Connectivity for %s %s" % (str( hosts ), tag) )
261 pa = main.Mininet1.pingallHosts( hosts )
262 utilities.assert_equals( expect=expect, actual=pa,
263 onpass="IP connectivity successfully tested",
264 onfail="IP connectivity failed" )
265 if dumpflows:
Devin Lim142b5342017-07-20 15:22:39 -0700266 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700267 "flows",
268 main.logdir,
269 "flowsOn" + tag )
Devin Lim142b5342017-07-20 15:22:39 -0700270 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700271 "groups",
272 main.logdir,
273 "groupsOn" + tag )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700274
275 @staticmethod
276 def killLink( main, end1, end2, switches, links ):
277 """
278 end1,end2: identify the switches, ex.: 'leaf1', 'spine1'
279 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
280 Kill a link and verify ONOS can see the proper link change
281 """
282 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
283 main.step( "Kill link between %s and %s" % (end1, end2) )
284 LinkDown = main.Mininet1.link( END1=end1, END2=end2, OPTION="down" )
Pierfb719b12016-09-19 14:51:44 -0700285 LinkDown = main.Mininet1.link( END2=end1, END1=end2, OPTION="down" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700286 main.log.info(
287 "Waiting %s seconds for link down to be discovered" % main.linkSleep )
288 time.sleep( main.linkSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700289 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700290 main.FALSE,
291 kwargs={ 'numoswitch': switches,
292 'numolink': links },
293 attempts=10,
294 sleep=main.linkSleep )
295 result = topology & LinkDown
296 utilities.assert_equals( expect=main.TRUE, actual=result,
297 onpass="Link down successful",
298 onfail="Failed to turn off link?" )
299
300 @staticmethod
301 def restoreLink( main, end1, end2, dpid1, dpid2, port1, port2, switches,
302 links ):
303 """
304 Params:
305 end1,end2: identify the end switches, ex.: 'leaf1', 'spine1'
306 dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002'
307 port1, port2: respective port of the end switches that connects to the link, ex.:'1'
308 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
309 Kill a link and verify ONOS can see the proper link change
310 """
311 main.step( "Restore link between %s and %s" % (end1, end2) )
312 result = False
313 count = 0
314 while True:
315 count += 1
316 main.Mininet1.link( END1=end1, END2=end2, OPTION="up" )
317 main.Mininet1.link( END2=end1, END1=end2, OPTION="up" )
318 main.log.info(
319 "Waiting %s seconds for link up to be discovered" % main.linkSleep )
320 time.sleep( main.linkSleep )
Pierfb719b12016-09-19 14:51:44 -0700321
Devin Lim142b5342017-07-20 15:22:39 -0700322 for i in range(0, main.Cluster.numCtrls):
323 ctrl = main.Cluster.runningNodes[ i ]
324 onosIsUp = main.ONOSbench.isup( ctrl.ipAddress )
Pierfb719b12016-09-19 14:51:44 -0700325 if onosIsUp == main.TRUE:
Devin Lim142b5342017-07-20 15:22:39 -0700326 ctrl.CLI.portstate( dpid=dpid1, port=port1 )
327 ctrl.CLI.portstate( dpid=dpid2, port=port2 )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700328 time.sleep( main.linkSleep )
329
Devin Lim142b5342017-07-20 15:22:39 -0700330 result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches,
331 numolink=links )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700332 if count > 5 or result:
333 break
334 utilities.assert_equals( expect=main.TRUE, actual=result,
335 onpass="Link up successful",
336 onfail="Failed to bring link up" )
337
338 @staticmethod
339 def killSwitch( main, switch, switches, links ):
340 """
341 Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6'
342 Completely kill a switch and verify ONOS can see the proper change
343 """
344 main.switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
345 main.step( "Kill " + switch )
346 main.log.info( "Stopping" + switch )
347 main.Mininet1.switch( SW=switch, OPTION="stop" )
348 # todo make this repeatable
349 main.log.info( "Waiting %s seconds for switch down to be discovered" % (
350 main.switchSleep) )
351 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700352 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700353 main.FALSE,
354 kwargs={ 'numoswitch': switches,
355 'numolink': links },
356 attempts=10,
357 sleep=main.switchSleep )
358 utilities.assert_equals( expect=main.TRUE, actual=topology,
359 onpass="Kill switch successful",
360 onfail="Failed to kill switch?" )
361
362 @staticmethod
363 def recoverSwitch( main, switch, switches, links ):
364 """
365 Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6'
366 Recover a switch and verify ONOS can see the proper change
367 """
368 # todo make this repeatable
369 main.step( "Recovering " + switch )
370 main.log.info( "Starting" + switch )
371 main.Mininet1.switch( SW=switch, OPTION="start" )
372 main.log.info( "Waiting %s seconds for switch up to be discovered" % (
373 main.switchSleep) )
374 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700375 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700376 main.FALSE,
377 kwargs={ 'numoswitch': switches,
378 'numolink': links },
379 attempts=10,
380 sleep=main.switchSleep )
381 utilities.assert_equals( expect=main.TRUE, actual=topology,
382 onpass="Switch recovery successful",
383 onfail="Failed to recover switch?" )
384
385 @staticmethod
386 def cleanup( main ):
387 """
388 Stop Onos-cluster.
389 Stops Mininet
390 Copies ONOS log
391 """
Devin Lim58046fa2017-07-05 16:55:00 -0700392 try:
393 from tests.dependencies.utils import Utils
394 except ImportError:
395 main.log.error( "Utils not found exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700396 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700397 try:
Devin Lim142b5342017-07-20 15:22:39 -0700398 main.utils
Devin Lim58046fa2017-07-05 16:55:00 -0700399 except ( NameError, AttributeError ):
Devin Lim142b5342017-07-20 15:22:39 -0700400 main.utils = Utils()
Devin Lim58046fa2017-07-05 16:55:00 -0700401
402 main.utils.mininetCleanup( main.Mininet1 )
403
Devin Lim142b5342017-07-20 15:22:39 -0700404 main.utils.copyKarafLog( main.cfgName )
Devin Lim58046fa2017-07-05 16:55:00 -0700405
Devin Lim142b5342017-07-20 15:22:39 -0700406 for ctrl in main.Cluster.active():
407 main.ONOSbench.onosStop( ctrl.ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700408
409 @staticmethod
410 def killOnos( main, nodes, switches, links, expNodes ):
411 """
412 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
413 switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6'
414 Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change
415 """
Pier3b58c652016-09-26 12:03:31 -0700416
Jon Hall1efcb3f2016-08-23 13:42:15 -0700417 main.step( "Killing ONOS instance" )
Pier3b58c652016-09-26 12:03:31 -0700418
Jon Hall1efcb3f2016-08-23 13:42:15 -0700419 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700420 killResult = main.ONOSbench.onosDie( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700421 utilities.assert_equals( expect=main.TRUE, actual=killResult,
422 onpass="ONOS instance Killed",
423 onfail="Error killing ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700424 main.Cluster.runningNodes[ i ].active = False
Jon Hall1efcb3f2016-08-23 13:42:15 -0700425 time.sleep( 12 )
Pier3b58c652016-09-26 12:03:31 -0700426
Devin Lim142b5342017-07-20 15:22:39 -0700427 if len( nodes ) < main.Cluster.numCtrls:
Pier3b58c652016-09-26 12:03:31 -0700428
Pier3b58c652016-09-26 12:03:31 -0700429 nodeResults = utilities.retry( Testcaselib.nodesCheck,
430 False,
Pier3b58c652016-09-26 12:03:31 -0700431 attempts=5,
432 sleep=10 )
433 utilities.assert_equals( expect=True, actual=nodeResults,
434 onpass="Nodes check successful",
435 onfail="Nodes check NOT successful" )
436
437 if not nodeResults:
438 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700439 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700440 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700441 ctrl.name,
442 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700443 main.log.error( "Failed to kill ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700444 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700445
Devin Lim142b5342017-07-20 15:22:39 -0700446 topology = utilities.retry( main.Cluster.active( 0 ).checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700447 main.FALSE,
448 kwargs={ 'numoswitch': switches,
449 'numolink': links,
450 'numoctrl': expNodes },
451 attempts=10,
452 sleep=12 )
453 utilities.assert_equals( expect=main.TRUE, actual=topology,
454 onpass="ONOS Instance down successful",
455 onfail="Failed to turn off ONOS Instance" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700456
457 @staticmethod
458 def recoverOnos( main, nodes, switches, links, expNodes ):
459 """
460 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
461 switches, links, nodes: number of expected switches, links and nodes after recoverOnos, ex.: '4', '6'
462 Recover an ONOS instance and verify the ONOS cluster can see the proper change
463 """
464 main.step( "Recovering ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700465 [ main.ONOSbench.onosStart( main.Cluster.runningNodes[ i ].ipAddress ) for i in nodes ]
Jon Hall1efcb3f2016-08-23 13:42:15 -0700466 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700467 isUp = main.ONOSbench.isup( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700468 utilities.assert_equals( expect=main.TRUE, actual=isUp,
469 onpass="ONOS service is ready",
470 onfail="ONOS service did not start properly" )
471 for i in nodes:
472 main.step( "Checking if ONOS CLI is ready" )
Devin Lim142b5342017-07-20 15:22:39 -0700473 ctrl = main.Cluster.runningNodes[ i ]
474 ctrl.CLI.startCellCli()
475 cliResult = ctrl.CLI.startOnosCli( ctrl.ipAddress,
476 commandlineTimeout=60,
477 onosStartTimeout=100 )
478 ctrl.active = True
Jon Hall1efcb3f2016-08-23 13:42:15 -0700479 utilities.assert_equals( expect=main.TRUE,
480 actual=cliResult,
481 onpass="ONOS CLI is ready",
482 onfail="ONOS CLI is not ready" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700483
Pier3b58c652016-09-26 12:03:31 -0700484 main.step( "Checking ONOS nodes" )
485 nodeResults = utilities.retry( Testcaselib.nodesCheck,
486 False,
487 args=[nodes],
488 attempts=5,
489 sleep=10 )
490 utilities.assert_equals( expect=True, actual=nodeResults,
491 onpass="Nodes check successful",
492 onfail="Nodes check NOT successful" )
493
494 if not nodeResults:
495 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700496 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700497 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700498 ctrl.name,
499 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700500 main.log.error( "Failed to start ONOS, stopping test" )
Devin Lim44075962017-08-11 10:56:37 -0700501 main.cleanAndExit()
Pier3b58c652016-09-26 12:03:31 -0700502
Devin Lim142b5342017-07-20 15:22:39 -0700503 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700504 main.FALSE,
505 kwargs={ 'numoswitch': switches,
506 'numolink': links,
507 'numoctrl': expNodes },
508 attempts=10,
509 sleep=12 )
510 utilities.assert_equals( expect=main.TRUE, actual=topology,
511 onpass="ONOS Instance down successful",
512 onfail="Failed to turn off ONOS Instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700513 ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary,
514 main.FALSE,
515 attempts=10,
516 sleep=12 )
517 if ready:
518 ready = main.TRUE
519 utilities.assert_equals( expect=main.TRUE, actual=ready,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700520 onpass="ONOS summary command succeded",
521 onfail="ONOS summary command failed" )
522 if not ready:
523 main.log.error( "ONOS startup failed!" )
Devin Lim44075962017-08-11 10:56:37 -0700524 main.cleanAndExit()
Jon Hall1efcb3f2016-08-23 13:42:15 -0700525
526 @staticmethod
527 def addHostCfg( main ):
528 """
529 Adds Host Configuration to ONOS
530 Updates expected state of the network (pingChart)
531 """
532 import json
533 hostCfg = { }
534 with open( main.dependencyPath + "/json/extra.json" ) as template:
535 hostCfg = json.load( template )
536 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ]
537 main.step( "Pushing new configuration" )
538 mac, cfg = hostCfg[ 'hosts' ].popitem( )
Devin Lim142b5342017-07-20 15:22:39 -0700539 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
540 subjectClass="hosts",
541 subjectKey=urllib.quote( mac,
542 safe='' ),
543 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700544 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ]
545 main.step( "Pushing new configuration" )
546 mac, cfg = hostCfg[ 'hosts' ].popitem( )
Devin Lim142b5342017-07-20 15:22:39 -0700547 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
548 subjectClass="hosts",
549 subjectKey=urllib.quote( mac,
550 safe='' ),
Jon Hall1efcb3f2016-08-23 13:42:15 -0700551 configKey="basic" )
552 main.pingChart.update( { 'vlan1': { "expect": "True",
553 "hosts": [ "olt1", "vsg1" ] } } )
554 main.pingChart[ 'vlan5' ][ 'expect' ] = 0
555 main.pingChart[ 'vlan10' ][ 'expect' ] = 0
556 ports = "[%s,%s]" % (5, 6)
557 cfg = '{"of:0000000000000001":[{"vlan":1,"ports":%s,"name":"OLT 1"}]}' % ports
Devin Lim142b5342017-07-20 15:22:39 -0700558 main.Cluster.active( 0 ).REST.setNetCfg( json.loads( cfg ),
559 subjectClass="apps",
560 subjectKey="org.onosproject.segmentrouting",
561 configKey="xconnect" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700562
563 @staticmethod
564 def delHostCfg( main ):
565 """
566 Removest Host Configuration from ONOS
567 Updates expected state of the network (pingChart)
568 """
569 import json
570 hostCfg = { }
571 with open( main.dependencyPath + "/json/extra.json" ) as template:
572 hostCfg = json.load( template )
573 main.step( "Removing host configuration" )
574 main.pingChart[ 'ip' ][ 'expect' ] = 0
575 mac, cfg = hostCfg[ 'hosts' ].popitem( )
Devin Lim142b5342017-07-20 15:22:39 -0700576 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
577 subjectKey=urllib.quote(
578 mac,
579 safe='' ),
580 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700581 main.step( "Removing configuration" )
582 main.pingChart[ 'ip' ][ 'expect' ] = 0
583 mac, cfg = hostCfg[ 'hosts' ].popitem( )
Devin Lim142b5342017-07-20 15:22:39 -0700584 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
585 subjectKey=urllib.quote(
586 mac,
587 safe='' ),
588 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700589 main.step( "Removing vlan configuration" )
590 main.pingChart[ 'vlan1' ][ 'expect' ] = 0
Devin Lim142b5342017-07-20 15:22:39 -0700591 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="apps",
592 subjectKey="org.onosproject.segmentrouting",
593 configKey="xconnect" )
Pier3b58c652016-09-26 12:03:31 -0700594 @staticmethod
595 def nodesCheck( nodes ):
Pier3b58c652016-09-26 12:03:31 -0700596 results = True
Devin Lim142b5342017-07-20 15:22:39 -0700597 nodesOutput = main.Cluster.command( "nodes", specificDriver=2 )
598 ips = main.Cluster.getIps( activeOnly=True )
Pier3b58c652016-09-26 12:03:31 -0700599 ips.sort()
600 for i in nodesOutput:
601 try:
602 current = json.loads( i )
603 activeIps = []
604 currentResult = False
605 for node in current:
606 if node['state'] == 'READY':
607 activeIps.append( node['ip'] )
608 currentResult = True
609 for ip in ips:
610 if ip not in activeIps:
611 currentResult = False
612 break
613 except ( ValueError, TypeError ):
614 main.log.error( "Error parsing nodes output" )
615 main.log.warn( repr( i ) )
616 currentResult = False
617 results = results and currentResult
618 return results