blob: 38dbaf69efea1a25128736dbc547bf620fec928f [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" )
50 main.exit()
51 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,
104 ip=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!" )
149 main.cleanup( )
150 main.exit( )
151
Devin Lim142b5342017-07-20 15:22:39 -0700152 for ctrl in main.Cluster.active():
153 ctrl.CLI.logSet( "DEBUG", "org.onosproject.segmentrouting" )
154 ctrl.CLI.logSet( "DEBUG", "org.onosproject.driver.pipeline" )
155 ctrl.CLI.logSet( "DEBUG", "org.onosproject.store.group.impl" )
156 ctrl.CLI.logSet( "DEBUG", "org.onosproject.net.flowobjective.impl" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700157
158 @staticmethod
159 def startMininet( main, topology, args="" ):
160 main.step( "Starting Mininet Topology" )
Devin Lim142b5342017-07-20 15:22:39 -0700161 arg = "--onos %d %s" % (main.Cluster.numCtrls, args)
Jon Hall1efcb3f2016-08-23 13:42:15 -0700162 main.topology = topology
163 topoResult = main.Mininet1.startNet(
164 topoFile=main.Mininet1.home + main.topology, args=arg )
165 stepResult = topoResult
166 utilities.assert_equals( expect=main.TRUE,
167 actual=stepResult,
168 onpass="Successfully loaded topology",
169 onfail="Failed to load topology" )
170 # Exit if topology did not load properly
171 if not topoResult:
172 main.cleanup( )
173 main.exit( )
174
175 @staticmethod
Devin Lim142b5342017-07-20 15:22:39 -0700176 def config( main, cfgName ):
Piera2a7e1b2016-10-04 11:51:43 -0700177 main.spines = []
178
179 main.failures = int(main.params[ 'failures' ])
180 main.cfgName = cfgName
Piera2a7e1b2016-10-04 11:51:43 -0700181
182 if main.cfgName == '2x2' :
183 spine = {}
184 spine[ 'name' ] = main.params['switches'][ 'spine1' ]
185 spine[ 'dpid' ] = main.params['switches'][ 'spinedpid1' ]
186 main.spines.append(spine)
187
188 spine = {}
189 spine[ 'name' ] = main.params['switches'][ 'spine2' ]
190 spine[ 'dpid' ] = main.params['switches'][ 'spinedpid2' ]
191 main.spines.append(spine)
192
193 elif main.cfgName == '4x4' :
194 spine = {}
195 spine[ 'name' ] = main.params['switches'][ 'spine1' ]
196 spine[ 'dpid' ] = main.params['switches'][ 'spinedpid1' ]
197 main.spines.append(spine)
198
199 spine = {}
200 spine[ 'name' ] = main.params['switches'][ 'spine2' ]
201 spine[ 'dpid' ] = main.params['switches'][ 'spinedpid2' ]
202 main.spines.append(spine)
203
204 spine = {}
205 spine[ 'name' ] = main.params['switches'][ 'spine3' ]
206 spine[ 'dpid' ] = main.params['switches'][ 'spinedpid3' ]
207 main.spines.append(spine)
208
209 spine = {}
210 spine[ 'name' ] = main.params['switches'][ 'spine4' ]
211 spine[ 'dpid' ] = main.params['switches'][ 'spinedpid4' ]
212 main.spines.append(spine)
213
214 else :
215 main.log.error( "Configuration failed!" )
216 main.cleanup( )
217 main.exit( )
218
219 @staticmethod
Jon Hall1efcb3f2016-08-23 13:42:15 -0700220 def checkFlows( main, minFlowCount, dumpflows=True ):
221 main.step(
222 " Check whether the flow count is bigger than %s" % minFlowCount )
Devin Lim142b5342017-07-20 15:22:39 -0700223 count = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowCount,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700224 main.FALSE,
225 kwargs={ 'min': minFlowCount },
226 attempts=10,
227 sleep=10 )
228 utilities.assertEquals( \
229 expect=True,
230 actual=(count > 0),
231 onpass="Flow count looks correct: " + str( count ),
232 onfail="Flow count looks wrong: " + str( count ) )
233
234 main.step( "Check whether all flow status are ADDED" )
Devin Lim142b5342017-07-20 15:22:39 -0700235 flowCheck = utilities.retry( main.Cluster.active( 0 ).CLI.checkFlowsState,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700236 main.FALSE,
237 kwargs={ 'isPENDING': False },
238 attempts=2,
239 sleep=10 )
240 utilities.assertEquals( \
241 expect=main.TRUE,
242 actual=flowCheck,
243 onpass="Flow status is correct!",
244 onfail="Flow status is wrong!" )
245 if dumpflows:
Devin Lim142b5342017-07-20 15:22:39 -0700246 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700247 "flows",
248 main.logdir,
249 "flowsBefore" + main.cfgName )
Devin Lim142b5342017-07-20 15:22:39 -0700250 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700251 "groups",
252 main.logdir,
253 "groupsBefore" + main.cfgName )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700254
255 @staticmethod
256 def pingAll( main, tag="", dumpflows=True ):
257 main.log.report( "Check full connectivity" )
258 print main.pingChart
259 for entry in main.pingChart.itervalues( ):
260 print entry
261 hosts, expect = entry[ 'hosts' ], entry[ 'expect' ]
262 expect = main.TRUE if expect else main.FALSE
263 main.step( "Connectivity for %s %s" % (str( hosts ), tag) )
264 pa = main.Mininet1.pingallHosts( hosts )
265 utilities.assert_equals( expect=expect, actual=pa,
266 onpass="IP connectivity successfully tested",
267 onfail="IP connectivity failed" )
268 if dumpflows:
Devin Lim142b5342017-07-20 15:22:39 -0700269 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700270 "flows",
271 main.logdir,
272 "flowsOn" + tag )
Devin Lim142b5342017-07-20 15:22:39 -0700273 main.ONOSbench.dumpONOSCmd( main.Cluster.active( 0 ).ipAddress,
Pier50f0bc62016-09-07 17:53:40 -0700274 "groups",
275 main.logdir,
276 "groupsOn" + tag )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700277
278 @staticmethod
279 def killLink( main, end1, end2, switches, links ):
280 """
281 end1,end2: identify the switches, ex.: 'leaf1', 'spine1'
282 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
283 Kill a link and verify ONOS can see the proper link change
284 """
285 main.linkSleep = float( main.params[ 'timers' ][ 'LinkDiscovery' ] )
286 main.step( "Kill link between %s and %s" % (end1, end2) )
287 LinkDown = main.Mininet1.link( END1=end1, END2=end2, OPTION="down" )
Pierfb719b12016-09-19 14:51:44 -0700288 LinkDown = main.Mininet1.link( END2=end1, END1=end2, OPTION="down" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700289 main.log.info(
290 "Waiting %s seconds for link down to be discovered" % main.linkSleep )
291 time.sleep( main.linkSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700292 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700293 main.FALSE,
294 kwargs={ 'numoswitch': switches,
295 'numolink': links },
296 attempts=10,
297 sleep=main.linkSleep )
298 result = topology & LinkDown
299 utilities.assert_equals( expect=main.TRUE, actual=result,
300 onpass="Link down successful",
301 onfail="Failed to turn off link?" )
302
303 @staticmethod
304 def restoreLink( main, end1, end2, dpid1, dpid2, port1, port2, switches,
305 links ):
306 """
307 Params:
308 end1,end2: identify the end switches, ex.: 'leaf1', 'spine1'
309 dpid1, dpid2: dpid of the end switches respectively, ex.: 'of:0000000000000002'
310 port1, port2: respective port of the end switches that connects to the link, ex.:'1'
311 switches, links: number of expected switches and links after linkDown, ex.: '4', '6'
312 Kill a link and verify ONOS can see the proper link change
313 """
314 main.step( "Restore link between %s and %s" % (end1, end2) )
315 result = False
316 count = 0
317 while True:
318 count += 1
319 main.Mininet1.link( END1=end1, END2=end2, OPTION="up" )
320 main.Mininet1.link( END2=end1, END1=end2, OPTION="up" )
321 main.log.info(
322 "Waiting %s seconds for link up to be discovered" % main.linkSleep )
323 time.sleep( main.linkSleep )
Pierfb719b12016-09-19 14:51:44 -0700324
Devin Lim142b5342017-07-20 15:22:39 -0700325 for i in range(0, main.Cluster.numCtrls):
326 ctrl = main.Cluster.runningNodes[ i ]
327 onosIsUp = main.ONOSbench.isup( ctrl.ipAddress )
Pierfb719b12016-09-19 14:51:44 -0700328 if onosIsUp == main.TRUE:
Devin Lim142b5342017-07-20 15:22:39 -0700329 ctrl.CLI.portstate( dpid=dpid1, port=port1 )
330 ctrl.CLI.portstate( dpid=dpid2, port=port2 )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700331 time.sleep( main.linkSleep )
332
Devin Lim142b5342017-07-20 15:22:39 -0700333 result = main.Cluster.active( 0 ).CLI.checkStatus( numoswitch=switches,
334 numolink=links )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700335 if count > 5 or result:
336 break
337 utilities.assert_equals( expect=main.TRUE, actual=result,
338 onpass="Link up successful",
339 onfail="Failed to bring link up" )
340
341 @staticmethod
342 def killSwitch( main, switch, switches, links ):
343 """
344 Params: switches, links: number of expected switches and links after SwitchDown, ex.: '4', '6'
345 Completely kill a switch and verify ONOS can see the proper change
346 """
347 main.switchSleep = float( main.params[ 'timers' ][ 'SwitchDiscovery' ] )
348 main.step( "Kill " + switch )
349 main.log.info( "Stopping" + switch )
350 main.Mininet1.switch( SW=switch, OPTION="stop" )
351 # todo make this repeatable
352 main.log.info( "Waiting %s seconds for switch down to be discovered" % (
353 main.switchSleep) )
354 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700355 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700356 main.FALSE,
357 kwargs={ 'numoswitch': switches,
358 'numolink': links },
359 attempts=10,
360 sleep=main.switchSleep )
361 utilities.assert_equals( expect=main.TRUE, actual=topology,
362 onpass="Kill switch successful",
363 onfail="Failed to kill switch?" )
364
365 @staticmethod
366 def recoverSwitch( main, switch, switches, links ):
367 """
368 Params: switches, links: number of expected switches and links after SwitchUp, ex.: '4', '6'
369 Recover a switch and verify ONOS can see the proper change
370 """
371 # todo make this repeatable
372 main.step( "Recovering " + switch )
373 main.log.info( "Starting" + switch )
374 main.Mininet1.switch( SW=switch, OPTION="start" )
375 main.log.info( "Waiting %s seconds for switch up to be discovered" % (
376 main.switchSleep) )
377 time.sleep( main.switchSleep )
Devin Lim142b5342017-07-20 15:22:39 -0700378 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700379 main.FALSE,
380 kwargs={ 'numoswitch': switches,
381 'numolink': links },
382 attempts=10,
383 sleep=main.switchSleep )
384 utilities.assert_equals( expect=main.TRUE, actual=topology,
385 onpass="Switch recovery successful",
386 onfail="Failed to recover switch?" )
387
388 @staticmethod
389 def cleanup( main ):
390 """
391 Stop Onos-cluster.
392 Stops Mininet
393 Copies ONOS log
394 """
Devin Lim58046fa2017-07-05 16:55:00 -0700395 try:
396 from tests.dependencies.utils import Utils
397 except ImportError:
398 main.log.error( "Utils not found exiting the test" )
399 main.exit()
400 try:
Devin Lim142b5342017-07-20 15:22:39 -0700401 main.utils
Devin Lim58046fa2017-07-05 16:55:00 -0700402 except ( NameError, AttributeError ):
Devin Lim142b5342017-07-20 15:22:39 -0700403 main.utils = Utils()
Devin Lim58046fa2017-07-05 16:55:00 -0700404
405 main.utils.mininetCleanup( main.Mininet1 )
406
Devin Lim142b5342017-07-20 15:22:39 -0700407 main.utils.copyKarafLog( main.cfgName )
Devin Lim58046fa2017-07-05 16:55:00 -0700408
Devin Lim142b5342017-07-20 15:22:39 -0700409 for ctrl in main.Cluster.active():
410 main.ONOSbench.onosStop( ctrl.ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700411
412 @staticmethod
413 def killOnos( main, nodes, switches, links, expNodes ):
414 """
415 Params: nodes, integer array with position of the ONOS nodes in the CLIs array
416 switches, links, nodes: number of expected switches, links and nodes after KillOnos, ex.: '4', '6'
417 Completely Kill an ONOS instance and verify the ONOS cluster can see the proper change
418 """
Pier3b58c652016-09-26 12:03:31 -0700419
Jon Hall1efcb3f2016-08-23 13:42:15 -0700420 main.step( "Killing ONOS instance" )
Pier3b58c652016-09-26 12:03:31 -0700421
Jon Hall1efcb3f2016-08-23 13:42:15 -0700422 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700423 killResult = main.ONOSbench.onosDie( main.Cluster.runningNodes[ i ].ipAddress )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700424 utilities.assert_equals( expect=main.TRUE, actual=killResult,
425 onpass="ONOS instance Killed",
426 onfail="Error killing ONOS instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700427 main.Cluster.runningNodes[ i ].active = False
Jon Hall1efcb3f2016-08-23 13:42:15 -0700428 time.sleep( 12 )
Pier3b58c652016-09-26 12:03:31 -0700429
Devin Lim142b5342017-07-20 15:22:39 -0700430 if len( nodes ) < main.Cluster.numCtrls:
Pier3b58c652016-09-26 12:03:31 -0700431
Pier3b58c652016-09-26 12:03:31 -0700432 nodeResults = utilities.retry( Testcaselib.nodesCheck,
433 False,
Pier3b58c652016-09-26 12:03:31 -0700434 attempts=5,
435 sleep=10 )
436 utilities.assert_equals( expect=True, actual=nodeResults,
437 onpass="Nodes check successful",
438 onfail="Nodes check NOT successful" )
439
440 if not nodeResults:
441 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700442 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700443 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700444 ctrl.name,
445 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700446 main.log.error( "Failed to kill ONOS, stopping test" )
447 main.cleanup()
448 main.exit()
449
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" )
489 nodeResults = utilities.retry( Testcaselib.nodesCheck,
490 False,
491 args=[nodes],
492 attempts=5,
493 sleep=10 )
494 utilities.assert_equals( expect=True, actual=nodeResults,
495 onpass="Nodes check successful",
496 onfail="Nodes check NOT successful" )
497
498 if not nodeResults:
499 for i in nodes:
Devin Lim142b5342017-07-20 15:22:39 -0700500 ctrl = main.Cluster.runningNodes[ i ]
Pier3b58c652016-09-26 12:03:31 -0700501 main.log.debug( "{} components not ACTIVE: \n{}".format(
Devin Lim142b5342017-07-20 15:22:39 -0700502 ctrl.name,
503 ctrl.CLI.sendline( "scr:list | grep -v ACTIVE" ) ) )
Pier3b58c652016-09-26 12:03:31 -0700504 main.log.error( "Failed to start ONOS, stopping test" )
505 main.cleanup()
506 main.exit()
507
Devin Lim142b5342017-07-20 15:22:39 -0700508 topology = utilities.retry( main.Cluster.active( 0 ).CLI.checkStatus,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700509 main.FALSE,
510 kwargs={ 'numoswitch': switches,
511 'numolink': links,
512 'numoctrl': expNodes },
513 attempts=10,
514 sleep=12 )
515 utilities.assert_equals( expect=main.TRUE, actual=topology,
516 onpass="ONOS Instance down successful",
517 onfail="Failed to turn off ONOS Instance" )
Devin Lim142b5342017-07-20 15:22:39 -0700518 ready = utilities.retry( main.Cluster.active( 0 ).CLI.summary,
519 main.FALSE,
520 attempts=10,
521 sleep=12 )
522 if ready:
523 ready = main.TRUE
524 utilities.assert_equals( expect=main.TRUE, actual=ready,
Jon Hall1efcb3f2016-08-23 13:42:15 -0700525 onpass="ONOS summary command succeded",
526 onfail="ONOS summary command failed" )
527 if not ready:
528 main.log.error( "ONOS startup failed!" )
529 main.cleanup( )
530 main.exit( )
531
532 @staticmethod
533 def addHostCfg( main ):
534 """
535 Adds Host Configuration to ONOS
536 Updates expected state of the network (pingChart)
537 """
538 import json
539 hostCfg = { }
540 with open( main.dependencyPath + "/json/extra.json" ) as template:
541 hostCfg = json.load( template )
542 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'in1' ]
543 main.step( "Pushing new configuration" )
544 mac, cfg = hostCfg[ 'hosts' ].popitem( )
Devin Lim142b5342017-07-20 15:22:39 -0700545 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
546 subjectClass="hosts",
547 subjectKey=urllib.quote( mac,
548 safe='' ),
549 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700550 main.pingChart[ 'ip' ][ 'hosts' ] += [ 'out1' ]
551 main.step( "Pushing new configuration" )
552 mac, cfg = hostCfg[ 'hosts' ].popitem( )
Devin Lim142b5342017-07-20 15:22:39 -0700553 main.Cluster.active( 0 ).REST.setNetCfg( cfg[ 'basic' ],
554 subjectClass="hosts",
555 subjectKey=urllib.quote( mac,
556 safe='' ),
Jon Hall1efcb3f2016-08-23 13:42:15 -0700557 configKey="basic" )
558 main.pingChart.update( { 'vlan1': { "expect": "True",
559 "hosts": [ "olt1", "vsg1" ] } } )
560 main.pingChart[ 'vlan5' ][ 'expect' ] = 0
561 main.pingChart[ 'vlan10' ][ 'expect' ] = 0
562 ports = "[%s,%s]" % (5, 6)
563 cfg = '{"of:0000000000000001":[{"vlan":1,"ports":%s,"name":"OLT 1"}]}' % ports
Devin Lim142b5342017-07-20 15:22:39 -0700564 main.Cluster.active( 0 ).REST.setNetCfg( json.loads( cfg ),
565 subjectClass="apps",
566 subjectKey="org.onosproject.segmentrouting",
567 configKey="xconnect" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700568
569 @staticmethod
570 def delHostCfg( main ):
571 """
572 Removest Host Configuration from ONOS
573 Updates expected state of the network (pingChart)
574 """
575 import json
576 hostCfg = { }
577 with open( main.dependencyPath + "/json/extra.json" ) as template:
578 hostCfg = json.load( template )
579 main.step( "Removing host configuration" )
580 main.pingChart[ 'ip' ][ 'expect' ] = 0
581 mac, cfg = hostCfg[ 'hosts' ].popitem( )
Devin Lim142b5342017-07-20 15:22:39 -0700582 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
583 subjectKey=urllib.quote(
584 mac,
585 safe='' ),
586 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700587 main.step( "Removing configuration" )
588 main.pingChart[ 'ip' ][ 'expect' ] = 0
589 mac, cfg = hostCfg[ 'hosts' ].popitem( )
Devin Lim142b5342017-07-20 15:22:39 -0700590 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="hosts",
591 subjectKey=urllib.quote(
592 mac,
593 safe='' ),
594 configKey="basic" )
Jon Hall1efcb3f2016-08-23 13:42:15 -0700595 main.step( "Removing vlan configuration" )
596 main.pingChart[ 'vlan1' ][ 'expect' ] = 0
Devin Lim142b5342017-07-20 15:22:39 -0700597 main.Cluster.active( 0 ).REST.removeNetCfg( subjectClass="apps",
598 subjectKey="org.onosproject.segmentrouting",
599 configKey="xconnect" )
Pier3b58c652016-09-26 12:03:31 -0700600 @staticmethod
601 def nodesCheck( nodes ):
Pier3b58c652016-09-26 12:03:31 -0700602 results = True
Devin Lim142b5342017-07-20 15:22:39 -0700603 nodesOutput = main.Cluster.command( "nodes", specificDriver=2 )
604 ips = main.Cluster.getIps( activeOnly=True )
Pier3b58c652016-09-26 12:03:31 -0700605 ips.sort()
606 for i in nodesOutput:
607 try:
608 current = json.loads( i )
609 activeIps = []
610 currentResult = False
611 for node in current:
612 if node['state'] == 'READY':
613 activeIps.append( node['ip'] )
614 currentResult = True
615 for ip in ips:
616 if ip not in activeIps:
617 currentResult = False
618 break
619 except ( ValueError, TypeError ):
620 main.log.error( "Error parsing nodes output" )
621 main.log.warn( repr( i ) )
622 currentResult = False
623 results = results and currentResult
624 return results