blob: ed4d978d827eec3f374a80fca7d0b7928f53946a [file] [log] [blame]
Devin Lim142b5342017-07-20 15:22:39 -07001"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002Copyright 2016 Open Networking Foundation ( ONF )
Devin Lim58046fa2017-07-05 16:55:00 -07003
Devin Lim142b5342017-07-20 15:22:39 -07004Please 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.
Devin Lim142b5342017-07-20 15:22:39 -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"""
Devin Lim58046fa2017-07-05 16:55:00 -070021import re
Devin Lim58046fa2017-07-05 16:55:00 -070022
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070023
Devin Lim58046fa2017-07-05 16:55:00 -070024class ONOSSetup:
25 main = None
Jon Hall4f360bc2017-09-07 10:19:52 -070026
Devin Lim58046fa2017-07-05 16:55:00 -070027 def __init__( self ):
28 self.default = ''
Jon Hall4f360bc2017-09-07 10:19:52 -070029
30 def envSetupDescription( self ):
Devin Lim142b5342017-07-20 15:22:39 -070031 """
32 Introduction part of the test. It will initialize some basic vairables.
33 """
Devin Lim58046fa2017-07-05 16:55:00 -070034 main.case( "Constructing test variables and building ONOS package" )
35 main.step( "Constructing test variables" )
36 main.caseExplanation = "For loading from params file, and pull" + \
37 " and build the latest ONOS package"
Devin Lim142b5342017-07-20 15:22:39 -070038 try:
39 from tests.dependencies.Cluster import Cluster
40 except ImportError:
41 main.log.error( "Cluster not found. exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070042 main.cleanAndExit()
Devin Lim142b5342017-07-20 15:22:39 -070043 try:
44 main.Cluster
45 except ( NameError, AttributeError ):
46 main.Cluster = Cluster( main.ONOScell.nodes )
47 main.ONOSbench = main.Cluster.controllers[ 0 ].Bench
Devin Lim58046fa2017-07-05 16:55:00 -070048 main.testOnDirectory = re.sub( "(/tests)$", "", main.testDir )
49
50 def gitPulling( self ):
Devin Lim142b5342017-07-20 15:22:39 -070051 """
52 it will do git checkout or pull if they are enabled from the params file.
53 """
Devin Lim58046fa2017-07-05 16:55:00 -070054 main.case( "Pull onos branch and build onos on Teststation." )
55 gitPull = main.params[ 'GIT' ][ 'pull' ]
56 gitBranch = main.params[ 'GIT' ][ 'branch' ]
57 if gitPull == 'True':
58 main.step( "Git Checkout ONOS branch: " + gitBranch )
59 stepResult = main.ONOSbench.gitCheckout( branch=gitBranch )
60 utilities.assert_equals( expect=main.TRUE,
61 actual=stepResult,
62 onpass="Successfully checkout onos branch.",
63 onfail="Failed to checkout onos branch. Exiting test..." )
Jon Hall4f360bc2017-09-07 10:19:52 -070064 if not stepResult:
65 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070066
67 main.step( "Git Pull on ONOS branch:" + gitBranch )
68 stepResult = main.ONOSbench.gitPull()
69 utilities.assert_equals( expect=main.TRUE,
70 actual=stepResult,
71 onpass="Successfully pull onos. ",
72 onfail="Failed to pull onos. Exiting test ..." )
Jon Hall4f360bc2017-09-07 10:19:52 -070073 if not stepResult:
74 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070075
76 else:
77 main.log.info( "Skipped git checkout and pull as they are disabled in params file" )
78
Devin Lim142b5342017-07-20 15:22:39 -070079 def envSetup( self, includeGitPull=True ):
80 """
81 Description:
82 some environment setup for the test.
83 Required:
84 * includeGitPull - if wish to git pulling function to be executed.
85 Returns:
86 Returns main.TRUE
87 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070088 if includeGitPull:
Devin Lim58046fa2017-07-05 16:55:00 -070089 self.gitPulling()
Jon Hallca319892017-06-15 15:25:22 -070090
Devin Lim142b5342017-07-20 15:22:39 -070091 try:
92 from tests.dependencies.Cluster import Cluster
93 except ImportError:
94 main.log.error( "Cluster not found. exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070095 main.cleanAndExit()
Devin Lim142b5342017-07-20 15:22:39 -070096 try:
97 main.Cluster
98 except ( NameError, AttributeError ):
99 main.Cluster = Cluster( main.ONOScell.nodes )
100
Devin Lim58046fa2017-07-05 16:55:00 -0700101 main.cellData = {} # For creating cell file
Devin Lim58046fa2017-07-05 16:55:00 -0700102
Jon Hallca319892017-06-15 15:25:22 -0700103 return main.TRUE
Devin Lim58046fa2017-07-05 16:55:00 -0700104
Jon Hallca319892017-06-15 15:25:22 -0700105 def envSetupException( self, e ):
Devin Lim142b5342017-07-20 15:22:39 -0700106 """
107 Description:
108 handles the exception that might occur from the environment setup.
109 Required:
110 * includeGitPull - exceeption code e.
111 """
Devin Lim58046fa2017-07-05 16:55:00 -0700112 main.log.exception( e )
Devin Lim44075962017-08-11 10:56:37 -0700113 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700114
Jon Hallca319892017-06-15 15:25:22 -0700115 def evnSetupConclusion( self, stepResult ):
Devin Lim142b5342017-07-20 15:22:39 -0700116 """
117 Description:
118 compare the result of the envSetup of the test.
119 Required:
120 * stepResult - Result of the envSetup.
121 """
Devin Lim58046fa2017-07-05 16:55:00 -0700122 utilities.assert_equals( expect=main.TRUE,
123 actual=stepResult,
124 onpass="Successfully construct " +
125 "test variables ",
126 onfail="Failed to construct test variables" )
127
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800128 url = self.generateGraphURL()
129 main.log.wiki( url )
130
Devin Lim58046fa2017-07-05 16:55:00 -0700131 main.commit = main.ONOSbench.getVersion( report=True )
132
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800133 def generateGraphURL( self, width=525, height=350 ):
134 """
135 Description:
136 Obtain the URL for the graph that corresponds to the test being run.
137 """
138
139 nodeCluster = main.params[ 'GRAPH' ][ 'nodeCluster' ]
140 testname = main.TEST
141 branch = main.ONOSbench.getBranchName()
142 maxBuildsToShow = main.params[ 'GRAPH' ][ 'builds' ]
143
144 return '<ac:structured-macro ac:name="html">\n' + \
145 '<ac:plain-text-body><![CDATA[\n' + \
146 '<img src="https://onos-jenkins.onlab.us/job/Pipeline_postjob_' + \
147 nodeCluster + \
148 '/lastSuccessfulBuild/artifact/' + \
149 testname + \
150 '_' + \
151 branch + \
152 '_' + \
153 maxBuildsToShow + \
154 '-builds_graph.jpg", alt="' + \
155 testname + \
156 '", style="width:' + \
157 str( width ) + \
158 'px;height:' + \
159 str( height ) + \
160 'px;border:0"' + \
161 '>' + \
162 ']]></ac:plain-text-body>\n' + \
163 '</ac:structured-macro>\n'
164
Devin Lim142b5342017-07-20 15:22:39 -0700165 def setNumCtrls( self, hasMultiNodeRounds ):
166 """
167 Description:
168 Set new number of controls if it uses different number of nodes.
169 different number of nodes should be pre-defined in main.scale.
170 Required:
171 * hasMultiNodeRouds - if the test is testing different number of nodes.
172 """
Devin Lim58046fa2017-07-05 16:55:00 -0700173 if hasMultiNodeRounds:
174 try:
175 main.cycle
176 except Exception:
177 main.cycle = 0
178 main.cycle += 1
179 # main.scale[ 0 ] determines the current number of ONOS controller
Devin Lim142b5342017-07-20 15:22:39 -0700180 main.Cluster.setRunningNode( int( main.scale.pop( 0 ) ) )
Devin Lim58046fa2017-07-05 16:55:00 -0700181
Devin Lim142b5342017-07-20 15:22:39 -0700182 def killingAllOnos( self, cluster, killRemoveMax, stopOnos ):
183 """
184 Description:
185 killing the onos. It will either kill the current runningnodes or
186 max number of the nodes.
187 Required:
188 * cluster - the cluster driver that will be used.
189 * killRemoveMax - The boolean that will decide either to kill
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700190 only running nodes ( False ) or max number of nodes ( True ).
Devin Lim142b5342017-07-20 15:22:39 -0700191 * stopOnos - If wish to stop onos before killing it. True for
192 enable stop , False for disable stop.
193 Returns:
194 Returns main.TRUE if successfully killing it.
195 """
196 main.log.info( "Safety check, killing all ONOS processes" )
Devin Lim58046fa2017-07-05 16:55:00 -0700197
Devin Lim142b5342017-07-20 15:22:39 -0700198 return cluster.kill( killRemoveMax, stopOnos )
Devin Lim58046fa2017-07-05 16:55:00 -0700199
Devin Lime9f0ccf2017-08-11 17:25:12 -0700200 def createApplyCell( self, cluster, newCell, cellName,
201 Mininet, useSSH, ips, installMax=False ):
Devin Lim142b5342017-07-20 15:22:39 -0700202 """
203 Description:
204 create new cell ( optional ) and apply it. It will also verify the
205 cell.
206 Required:
207 * cluster - the cluster driver that will be used.
208 * newCell - True for making a new cell and False for not making it.
209 * cellName - The name of the cell.
210 * Mininet - a mininet driver that will be used.
211 * useSSH - True for using ssh when creating a cell
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700212 * ips - ip( s ) of the node( s ).
Devin Lim142b5342017-07-20 15:22:39 -0700213 Returns:
214 Returns main.TRUE if it successfully executed.
215 """
Devin Lim58046fa2017-07-05 16:55:00 -0700216 if newCell:
Devin Lim142b5342017-07-20 15:22:39 -0700217 cluster.createCell( cellName, Mininet, useSSH, ips )
Devin Lim58046fa2017-07-05 16:55:00 -0700218 main.step( "Apply cell to environment" )
Devin Lim142b5342017-07-20 15:22:39 -0700219 stepResult = cluster.applyCell( cellName )
Devin Lim58046fa2017-07-05 16:55:00 -0700220 utilities.assert_equals( expect=main.TRUE,
221 actual=stepResult,
222 onpass="Successfully applied cell to " +
223 "environment",
Devin Lim142b5342017-07-20 15:22:39 -0700224 onfail="Failed to apply cell to environment" )
Devin Lim58046fa2017-07-05 16:55:00 -0700225 return stepResult
226
Devin Lim142b5342017-07-20 15:22:39 -0700227 def uninstallOnos( self, cluster, uninstallMax ):
228 """
229 Description:
230 uninstalling onos and verify the result.
231 Required:
232 * cluster - a cluster driver that will be used.
233 * uninstallMax - True for uninstalling max number of nodes
234 False for uninstalling the current running nodes.
235 Returns:
236 Returns main.TRUE if it successfully uninstalled.
237 """
Devin Lim58046fa2017-07-05 16:55:00 -0700238 main.step( "Uninstalling ONOS package" )
Devin Lim142b5342017-07-20 15:22:39 -0700239 onosUninstallResult = cluster.uninstall( uninstallMax )
Devin Lim58046fa2017-07-05 16:55:00 -0700240 utilities.assert_equals( expect=main.TRUE,
241 actual=onosUninstallResult,
242 onpass="Successfully uninstalled ONOS package",
243 onfail="Failed to uninstall ONOS package" )
244 return onosUninstallResult
245
Devin Lim142b5342017-07-20 15:22:39 -0700246 def buildOnos( self, cluster ):
247 """
248 Description:
249 build the onos using buck build onos and verify the result
250 Required:
251 * cluster - the cluster driver that will be used.
252 Returns:
253 Returns main.TRUE if it successfully built.
254 """
Devin Lim58046fa2017-07-05 16:55:00 -0700255 main.step( "Creating ONOS package" )
256 packageResult = main.ONOSbench.buckBuild()
257 utilities.assert_equals( expect=main.TRUE,
258 actual=packageResult,
259 onpass="Successfully created ONOS package",
260 onfail="Failed to create ONOS package" )
261 return packageResult
262
Devin Lime9f0ccf2017-08-11 17:25:12 -0700263 def installOnos( self, cluster, installMax, parallel=True ):
Devin Lim142b5342017-07-20 15:22:39 -0700264 """
265 Description:
266 Installing onos and verify the result
267 Required:
268 * cluster - the cluster driver that will be used.
269 * installMax - True for installing max number of nodes
270 False for installing current running nodes only.
271 Returns:
272 Returns main.TRUE if it successfully installed
273 """
Devin Lim58046fa2017-07-05 16:55:00 -0700274 main.step( "Installing ONOS package" )
275 onosInstallResult = main.TRUE
276
Devin Lime9f0ccf2017-08-11 17:25:12 -0700277 cluster.install( installMax, parallel )
Devin Lim58046fa2017-07-05 16:55:00 -0700278 utilities.assert_equals( expect=main.TRUE,
279 actual=onosInstallResult,
280 onpass="Successfully installed ONOS package",
281 onfail="Failed to install ONOS package" )
282 if not onosInstallResult:
Devin Lim44075962017-08-11 10:56:37 -0700283 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700284 return onosInstallResult
285
Devin Lim142b5342017-07-20 15:22:39 -0700286 def setupSsh( self, cluster ):
287 """
288 Description:
289 set up ssh to the onos and verify the result
290 Required:
291 * cluster - the cluster driver that will be used.
292 Returns:
293 Returns main.TRUE if it successfully setup the ssh to
294 the onos.
295 """
Devin Lim58046fa2017-07-05 16:55:00 -0700296 main.step( "Set up ONOS secure SSH" )
Devin Lim142b5342017-07-20 15:22:39 -0700297 secureSshResult = cluster.ssh()
Devin Lim58046fa2017-07-05 16:55:00 -0700298 utilities.assert_equals( expect=main.TRUE,
299 actual=secureSshResult,
300 onpass="Test step PASS",
301 onfail="Test step FAIL" )
302 return secureSshResult
303
Devin Lim142b5342017-07-20 15:22:39 -0700304 def checkOnosService( self, cluster ):
305 """
306 Description:
307 Checking if the onos service is up and verify the result
308 Required:
309 * cluster - the cluster driver that will be used.
310 Returns:
311 Returns main.TRUE if it successfully checked
312 """
313 main.step( "Checking ONOS service" )
314 stepResult = cluster.checkService()
Devin Lim58046fa2017-07-05 16:55:00 -0700315 utilities.assert_equals( expect=main.TRUE,
316 actual=stepResult,
317 onpass="ONOS service is ready on all nodes",
318 onfail="ONOS service did not start properly on all nodes" )
319 return stepResult
320
Jon Hallca319892017-06-15 15:25:22 -0700321 def startOnosClis( self, cluster ):
Devin Lim142b5342017-07-20 15:22:39 -0700322 """
323 Description:
324 starting Onos using onosCli driver and verify the result
325 Required:
326 * cluster - the cluster driver that will be used.
327 Returns:
328 Returns main.TRUE if it successfully started. It will exit
329 the test if not started properly.
330 """
Devin Lim58046fa2017-07-05 16:55:00 -0700331 main.step( "Starting ONOS CLI sessions" )
Jon Hallca319892017-06-15 15:25:22 -0700332 startCliResult = cluster.startCLIs()
Devin Lim58046fa2017-07-05 16:55:00 -0700333 if not startCliResult:
334 main.log.info( "ONOS CLI did not start up properly" )
Devin Lim44075962017-08-11 10:56:37 -0700335 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700336 else:
337 main.log.info( "Successful CLI startup" )
338 utilities.assert_equals( expect=main.TRUE,
339 actual=startCliResult,
340 onpass="Successfully start ONOS cli",
341 onfail="Failed to start ONOS cli" )
342 return startCliResult
343
Jon Hall4f360bc2017-09-07 10:19:52 -0700344 def processList( self, functions, args ):
345 if functions is not None:
346 if isinstance( functions, list ):
347 i = 0
348 for f in functions:
349 f( *( args[ i ] ) ) if args is not None and args[ i ] is not None else f()
350 i += 1
351 else:
352 functions( *args ) if args is not None else functions()
353
Devin Lim142b5342017-07-20 15:22:39 -0700354 def ONOSSetUp( self, Mininet, cluster, hasMultiNodeRounds=False, startOnos=True, newCell=True,
Jon Hall4f360bc2017-09-07 10:19:52 -0700355 cellName="temp", removeLog=False, extraApply=None, applyArgs=None, extraClean=None,
356 cleanArgs=None, skipPack=False, installMax=False, useSSH=True, killRemoveMax=True,
Devin Lime9f0ccf2017-08-11 17:25:12 -0700357 stopOnos=False, installParallel=True ):
Devin Lim142b5342017-07-20 15:22:39 -0700358 """
359 Description:
360 Initial ONOS setting up of the tests. It will also verify the result of each steps.
361 The procedures will be:
362 killing onos
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700363 creating ( optional ) /applying cell
364 removing raft logs ( optional )
Devin Lim142b5342017-07-20 15:22:39 -0700365 uninstalling onos
366 extra procedure to be applied( optional )
367 building onos
368 installing onos
369 extra cleanup to be applied ( optional )
370 setting up ssh to the onos
371 checking the onos service
372 starting onos
373 Required:
374 * Mininet - the mininet driver that will be used
375 * cluster - the cluster driver that will be used.
376 * hasMultiNodeRouds - True if the test is testing different set of nodes
377 * startOnos - True if wish to start onos.
378 * newCell - True for making a new cell and False for not making it.
379 * cellName - Name of the cell that will be used.
380 * removeLog - True if wish to remove raft logs
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700381 * extraApply - Function( s ) that will be called before building ONOS. Default to None.
382 * applyArgs - argument of the functon( s ) of the extraApply. Should be in list.
383 * extraClean - Function( s ) that will be called after building ONOS. Defaults to None.
384 * cleanArgs - argument of the functon( s ) of the extraClean. Should be in list.
Devin Lim142b5342017-07-20 15:22:39 -0700385 * skipPack - True if wish to skip some packing.
386 * installMax - True if wish to install onos max number of nodes
387 False if wish to install onos of running nodes only
388 * useSSH - True for using ssh when creating a cell
389 * killRemoveMax - True for removing/killing max number of nodes. False for
390 removing/killing running nodes only.
391 * stopOnos - True if wish to stop onos before killing it.
392 Returns:
393 Returns main.TRUE if it everything successfully proceeded.
394 """
395 self.setNumCtrls( hasMultiNodeRounds )
Devin Lim58046fa2017-07-05 16:55:00 -0700396
Devin Lim142b5342017-07-20 15:22:39 -0700397 main.case( "Starting up " + str( cluster.numCtrls ) +
Jon Hall4f360bc2017-09-07 10:19:52 -0700398 " node(s) ONOS cluster" )
Devin Lim142b5342017-07-20 15:22:39 -0700399 main.caseExplanation = "Set up ONOS with " + str( cluster.numCtrls ) + \
Devin Lim58046fa2017-07-05 16:55:00 -0700400 " node(s) ONOS cluster"
Devin Lim142b5342017-07-20 15:22:39 -0700401 killResult = self.killingAllOnos( cluster, killRemoveMax, stopOnos )
Devin Lim58046fa2017-07-05 16:55:00 -0700402
Devin Lim142b5342017-07-20 15:22:39 -0700403 main.log.info( "NODE COUNT = " + str( cluster.numCtrls ) )
404 cellResult = main.TRUE
405 packageResult = main.TRUE
406 onosUninstallResult = main.TRUE
407 onosCliResult = main.TRUE
Devin Lim58046fa2017-07-05 16:55:00 -0700408 if not skipPack:
Devin Lim142b5342017-07-20 15:22:39 -0700409 tempOnosIp = []
410 for ctrl in cluster.runningNodes:
411 tempOnosIp.append( ctrl.ipAddress )
412 cellResult = self.createApplyCell( cluster, newCell,
413 cellName, Mininet,
Devin Lime9f0ccf2017-08-11 17:25:12 -0700414 useSSH, tempOnosIp,
415 installMax )
Devin Lim58046fa2017-07-05 16:55:00 -0700416 if removeLog:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700417 main.log.info( "Removing raft logs" )
Devin Lim58046fa2017-07-05 16:55:00 -0700418 main.ONOSbench.onosRemoveRaftLogs()
419
Devin Lim142b5342017-07-20 15:22:39 -0700420 onosUninstallResult = self.uninstallOnos( cluster, killRemoveMax )
Jon Hall4f360bc2017-09-07 10:19:52 -0700421 self.processList( extraApply, applyArgs )
Devin Lim142b5342017-07-20 15:22:39 -0700422 packageResult = self.buildOnos( cluster )
423
Devin Lime9f0ccf2017-08-11 17:25:12 -0700424 onosInstallResult = self.installOnos( cluster, installMax, installParallel )
Devin Lim58046fa2017-07-05 16:55:00 -0700425
Jon Hall4f360bc2017-09-07 10:19:52 -0700426 self.processList( extraClean, cleanArgs )
Devin Lim142b5342017-07-20 15:22:39 -0700427 secureSshResult = self.setupSsh( cluster )
Devin Lim58046fa2017-07-05 16:55:00 -0700428
Devin Lim142b5342017-07-20 15:22:39 -0700429 onosServiceResult = self.checkOnosService( cluster )
Devin Lim58046fa2017-07-05 16:55:00 -0700430
Devin Lim142b5342017-07-20 15:22:39 -0700431 if startOnos:
Jon Hallca319892017-06-15 15:25:22 -0700432 onosCliResult = self.startOnosClis( cluster )
Devin Lim58046fa2017-07-05 16:55:00 -0700433
Devin Lim142b5342017-07-20 15:22:39 -0700434 return killResult and cellResult and packageResult and onosUninstallResult and \
Jon Hall4f360bc2017-09-07 10:19:52 -0700435 onosInstallResult and secureSshResult and onosServiceResult and onosCliResult