blob: 8a73e324757404ef751a6475d022b02ba9a8ca91 [file] [log] [blame]
Devin Lim142b5342017-07-20 15:22:39 -07001"""
2Copyright 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
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"""
Devin Lim58046fa2017-07-05 16:55:00 -070021import re
Devin Lim58046fa2017-07-05 16:55:00 -070022
23class ONOSSetup:
24 main = None
Jon Hall4f360bc2017-09-07 10:19:52 -070025
Devin Lim58046fa2017-07-05 16:55:00 -070026 def __init__( self ):
27 self.default = ''
Jon Hall4f360bc2017-09-07 10:19:52 -070028
29 def envSetupDescription( self ):
Devin Lim142b5342017-07-20 15:22:39 -070030 """
31 Introduction part of the test. It will initialize some basic vairables.
32 """
Devin Lim58046fa2017-07-05 16:55:00 -070033 main.case( "Constructing test variables and building ONOS package" )
34 main.step( "Constructing test variables" )
35 main.caseExplanation = "For loading from params file, and pull" + \
36 " and build the latest ONOS package"
Devin Lim142b5342017-07-20 15:22:39 -070037 try:
38 from tests.dependencies.Cluster import Cluster
39 except ImportError:
40 main.log.error( "Cluster not found. exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070041 main.cleanAndExit()
Devin Lim142b5342017-07-20 15:22:39 -070042 try:
43 main.Cluster
44 except ( NameError, AttributeError ):
45 main.Cluster = Cluster( main.ONOScell.nodes )
46 main.ONOSbench = main.Cluster.controllers[ 0 ].Bench
Devin Lim58046fa2017-07-05 16:55:00 -070047 main.testOnDirectory = re.sub( "(/tests)$", "", main.testDir )
48
49 def gitPulling( self ):
Devin Lim142b5342017-07-20 15:22:39 -070050 """
51 it will do git checkout or pull if they are enabled from the params file.
52 """
Devin Lim58046fa2017-07-05 16:55:00 -070053 main.case( "Pull onos branch and build onos on Teststation." )
54 gitPull = main.params[ 'GIT' ][ 'pull' ]
55 gitBranch = main.params[ 'GIT' ][ 'branch' ]
56 if gitPull == 'True':
57 main.step( "Git Checkout ONOS branch: " + gitBranch )
58 stepResult = main.ONOSbench.gitCheckout( branch=gitBranch )
59 utilities.assert_equals( expect=main.TRUE,
60 actual=stepResult,
61 onpass="Successfully checkout onos branch.",
62 onfail="Failed to checkout onos branch. Exiting test..." )
Jon Hall4f360bc2017-09-07 10:19:52 -070063 if not stepResult:
64 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070065
66 main.step( "Git Pull on ONOS branch:" + gitBranch )
67 stepResult = main.ONOSbench.gitPull()
68 utilities.assert_equals( expect=main.TRUE,
69 actual=stepResult,
70 onpass="Successfully pull onos. ",
71 onfail="Failed to pull onos. Exiting test ..." )
Jon Hall4f360bc2017-09-07 10:19:52 -070072 if not stepResult:
73 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070074
75 else:
76 main.log.info( "Skipped git checkout and pull as they are disabled in params file" )
77
Devin Lim142b5342017-07-20 15:22:39 -070078 def envSetup( self, includeGitPull=True ):
79 """
80 Description:
81 some environment setup for the test.
82 Required:
83 * includeGitPull - if wish to git pulling function to be executed.
84 Returns:
85 Returns main.TRUE
86 """
Devin Lim58046fa2017-07-05 16:55:00 -070087 if includeGitPull :
88 self.gitPulling()
Jon Hallca319892017-06-15 15:25:22 -070089
Devin Lim142b5342017-07-20 15:22:39 -070090 try:
91 from tests.dependencies.Cluster import Cluster
92 except ImportError:
93 main.log.error( "Cluster not found. exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070094 main.cleanAndExit()
Devin Lim142b5342017-07-20 15:22:39 -070095 try:
96 main.Cluster
97 except ( NameError, AttributeError ):
98 main.Cluster = Cluster( main.ONOScell.nodes )
99
Devin Lim58046fa2017-07-05 16:55:00 -0700100 main.cellData = {} # For creating cell file
Devin Lim58046fa2017-07-05 16:55:00 -0700101
Jon Hallca319892017-06-15 15:25:22 -0700102 return main.TRUE
Devin Lim58046fa2017-07-05 16:55:00 -0700103
Jon Hallca319892017-06-15 15:25:22 -0700104 def envSetupException( self, e ):
Devin Lim142b5342017-07-20 15:22:39 -0700105 """
106 Description:
107 handles the exception that might occur from the environment setup.
108 Required:
109 * includeGitPull - exceeption code e.
110 """
Devin Lim58046fa2017-07-05 16:55:00 -0700111 main.log.exception( e )
Devin Lim44075962017-08-11 10:56:37 -0700112 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700113
Jon Hallca319892017-06-15 15:25:22 -0700114 def evnSetupConclusion( self, stepResult ):
Devin Lim142b5342017-07-20 15:22:39 -0700115 """
116 Description:
117 compare the result of the envSetup of the test.
118 Required:
119 * stepResult - Result of the envSetup.
120 """
Devin Lim58046fa2017-07-05 16:55:00 -0700121 utilities.assert_equals( expect=main.TRUE,
122 actual=stepResult,
123 onpass="Successfully construct " +
124 "test variables ",
125 onfail="Failed to construct test variables" )
126
127 main.commit = main.ONOSbench.getVersion( report=True )
128
Devin Lim142b5342017-07-20 15:22:39 -0700129 def setNumCtrls( self, hasMultiNodeRounds ):
130 """
131 Description:
132 Set new number of controls if it uses different number of nodes.
133 different number of nodes should be pre-defined in main.scale.
134 Required:
135 * hasMultiNodeRouds - if the test is testing different number of nodes.
136 """
Devin Lim58046fa2017-07-05 16:55:00 -0700137 if hasMultiNodeRounds:
138 try:
139 main.cycle
140 except Exception:
141 main.cycle = 0
142 main.cycle += 1
143 # main.scale[ 0 ] determines the current number of ONOS controller
Devin Lim142b5342017-07-20 15:22:39 -0700144 main.Cluster.setRunningNode( int( main.scale.pop( 0 ) ) )
Devin Lim58046fa2017-07-05 16:55:00 -0700145
Devin Lim142b5342017-07-20 15:22:39 -0700146 def killingAllOnos( self, cluster, killRemoveMax, stopOnos ):
147 """
148 Description:
149 killing the onos. It will either kill the current runningnodes or
150 max number of the nodes.
151 Required:
152 * cluster - the cluster driver that will be used.
153 * killRemoveMax - The boolean that will decide either to kill
154 only running nodes (False) or max number of nodes (True).
155 * stopOnos - If wish to stop onos before killing it. True for
156 enable stop , False for disable stop.
157 Returns:
158 Returns main.TRUE if successfully killing it.
159 """
160 main.log.info( "Safety check, killing all ONOS processes" )
Devin Lim58046fa2017-07-05 16:55:00 -0700161
Devin Lim142b5342017-07-20 15:22:39 -0700162 return cluster.kill( killRemoveMax, stopOnos )
Devin Lim58046fa2017-07-05 16:55:00 -0700163
Devin Lime9f0ccf2017-08-11 17:25:12 -0700164 def createApplyCell( self, cluster, newCell, cellName,
165 Mininet, useSSH, ips, installMax=False ):
Devin Lim142b5342017-07-20 15:22:39 -0700166 """
167 Description:
168 create new cell ( optional ) and apply it. It will also verify the
169 cell.
170 Required:
171 * cluster - the cluster driver that will be used.
172 * newCell - True for making a new cell and False for not making it.
173 * cellName - The name of the cell.
174 * Mininet - a mininet driver that will be used.
175 * useSSH - True for using ssh when creating a cell
176 * ips - ip(s) of the node(s).
177 Returns:
178 Returns main.TRUE if it successfully executed.
179 """
Devin Lim58046fa2017-07-05 16:55:00 -0700180 if newCell:
Devin Lim142b5342017-07-20 15:22:39 -0700181 cluster.createCell( cellName, Mininet, useSSH, ips )
Devin Lim58046fa2017-07-05 16:55:00 -0700182 main.step( "Apply cell to environment" )
Devin Lim142b5342017-07-20 15:22:39 -0700183 stepResult = cluster.applyCell( cellName )
Devin Lim58046fa2017-07-05 16:55:00 -0700184 utilities.assert_equals( expect=main.TRUE,
185 actual=stepResult,
186 onpass="Successfully applied cell to " +
187 "environment",
Devin Lim142b5342017-07-20 15:22:39 -0700188 onfail="Failed to apply cell to environment" )
Devin Lim58046fa2017-07-05 16:55:00 -0700189 return stepResult
190
Devin Lim142b5342017-07-20 15:22:39 -0700191 def uninstallOnos( self, cluster, uninstallMax ):
192 """
193 Description:
194 uninstalling onos and verify the result.
195 Required:
196 * cluster - a cluster driver that will be used.
197 * uninstallMax - True for uninstalling max number of nodes
198 False for uninstalling the current running nodes.
199 Returns:
200 Returns main.TRUE if it successfully uninstalled.
201 """
Devin Lim58046fa2017-07-05 16:55:00 -0700202 main.step( "Uninstalling ONOS package" )
Devin Lim142b5342017-07-20 15:22:39 -0700203 onosUninstallResult = cluster.uninstall( uninstallMax )
Devin Lim58046fa2017-07-05 16:55:00 -0700204 utilities.assert_equals( expect=main.TRUE,
205 actual=onosUninstallResult,
206 onpass="Successfully uninstalled ONOS package",
207 onfail="Failed to uninstall ONOS package" )
208 return onosUninstallResult
209
Devin Lim142b5342017-07-20 15:22:39 -0700210 def buildOnos( self, cluster ):
211 """
212 Description:
213 build the onos using buck build onos and verify the result
214 Required:
215 * cluster - the cluster driver that will be used.
216 Returns:
217 Returns main.TRUE if it successfully built.
218 """
Devin Lim58046fa2017-07-05 16:55:00 -0700219 main.step( "Creating ONOS package" )
220 packageResult = main.ONOSbench.buckBuild()
221 utilities.assert_equals( expect=main.TRUE,
222 actual=packageResult,
223 onpass="Successfully created ONOS package",
224 onfail="Failed to create ONOS package" )
225 return packageResult
226
Devin Lime9f0ccf2017-08-11 17:25:12 -0700227 def installOnos( self, cluster, installMax, parallel=True ):
Devin Lim142b5342017-07-20 15:22:39 -0700228 """
229 Description:
230 Installing onos and verify the result
231 Required:
232 * cluster - the cluster driver that will be used.
233 * installMax - True for installing max number of nodes
234 False for installing current running nodes only.
235 Returns:
236 Returns main.TRUE if it successfully installed
237 """
Devin Lim58046fa2017-07-05 16:55:00 -0700238 main.step( "Installing ONOS package" )
239 onosInstallResult = main.TRUE
240
Devin Lime9f0ccf2017-08-11 17:25:12 -0700241 cluster.install( installMax, parallel )
Devin Lim58046fa2017-07-05 16:55:00 -0700242 utilities.assert_equals( expect=main.TRUE,
243 actual=onosInstallResult,
244 onpass="Successfully installed ONOS package",
245 onfail="Failed to install ONOS package" )
246 if not onosInstallResult:
Devin Lim44075962017-08-11 10:56:37 -0700247 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700248 return onosInstallResult
249
Devin Lim142b5342017-07-20 15:22:39 -0700250 def setupSsh( self, cluster ):
251 """
252 Description:
253 set up ssh to the onos and verify the result
254 Required:
255 * cluster - the cluster driver that will be used.
256 Returns:
257 Returns main.TRUE if it successfully setup the ssh to
258 the onos.
259 """
Devin Lim58046fa2017-07-05 16:55:00 -0700260 main.step( "Set up ONOS secure SSH" )
Devin Lim142b5342017-07-20 15:22:39 -0700261 secureSshResult = cluster.ssh()
Devin Lim58046fa2017-07-05 16:55:00 -0700262 utilities.assert_equals( expect=main.TRUE,
263 actual=secureSshResult,
264 onpass="Test step PASS",
265 onfail="Test step FAIL" )
266 return secureSshResult
267
Devin Lim142b5342017-07-20 15:22:39 -0700268 def checkOnosService( self, cluster ):
269 """
270 Description:
271 Checking if the onos service is up and verify the result
272 Required:
273 * cluster - the cluster driver that will be used.
274 Returns:
275 Returns main.TRUE if it successfully checked
276 """
277 main.step( "Checking ONOS service" )
278 stepResult = cluster.checkService()
Devin Lim58046fa2017-07-05 16:55:00 -0700279 utilities.assert_equals( expect=main.TRUE,
280 actual=stepResult,
281 onpass="ONOS service is ready on all nodes",
282 onfail="ONOS service did not start properly on all nodes" )
283 return stepResult
284
Jon Hallca319892017-06-15 15:25:22 -0700285 def startOnosClis( self, cluster ):
Devin Lim142b5342017-07-20 15:22:39 -0700286 """
287 Description:
288 starting Onos using onosCli driver and verify the result
289 Required:
290 * cluster - the cluster driver that will be used.
291 Returns:
292 Returns main.TRUE if it successfully started. It will exit
293 the test if not started properly.
294 """
Devin Lim58046fa2017-07-05 16:55:00 -0700295 main.step( "Starting ONOS CLI sessions" )
Jon Hallca319892017-06-15 15:25:22 -0700296 startCliResult = cluster.startCLIs()
Devin Lim58046fa2017-07-05 16:55:00 -0700297 if not startCliResult:
298 main.log.info( "ONOS CLI did not start up properly" )
Devin Lim44075962017-08-11 10:56:37 -0700299 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700300 else:
301 main.log.info( "Successful CLI startup" )
302 utilities.assert_equals( expect=main.TRUE,
303 actual=startCliResult,
304 onpass="Successfully start ONOS cli",
305 onfail="Failed to start ONOS cli" )
306 return startCliResult
307
Jon Hall4f360bc2017-09-07 10:19:52 -0700308 def processList( self, functions, args ):
309 if functions is not None:
310 if isinstance( functions, list ):
311 i = 0
312 for f in functions:
313 f( *( args[ i ] ) ) if args is not None and args[ i ] is not None else f()
314 i += 1
315 else:
316 functions( *args ) if args is not None else functions()
317
Devin Lim142b5342017-07-20 15:22:39 -0700318 def ONOSSetUp( self, Mininet, cluster, hasMultiNodeRounds=False, startOnos=True, newCell=True,
Jon Hall4f360bc2017-09-07 10:19:52 -0700319 cellName="temp", removeLog=False, extraApply=None, applyArgs=None, extraClean=None,
320 cleanArgs=None, skipPack=False, installMax=False, useSSH=True, killRemoveMax=True,
Devin Lime9f0ccf2017-08-11 17:25:12 -0700321 stopOnos=False, installParallel=True ):
Devin Lim142b5342017-07-20 15:22:39 -0700322 """
323 Description:
324 Initial ONOS setting up of the tests. It will also verify the result of each steps.
325 The procedures will be:
326 killing onos
327 creating (optional) /applying cell
328 removing raft logs (optional)
329 uninstalling onos
330 extra procedure to be applied( optional )
331 building onos
332 installing onos
333 extra cleanup to be applied ( optional )
334 setting up ssh to the onos
335 checking the onos service
336 starting onos
337 Required:
338 * Mininet - the mininet driver that will be used
339 * cluster - the cluster driver that will be used.
340 * hasMultiNodeRouds - True if the test is testing different set of nodes
341 * startOnos - True if wish to start onos.
342 * newCell - True for making a new cell and False for not making it.
343 * cellName - Name of the cell that will be used.
344 * removeLog - True if wish to remove raft logs
Jon Hall4f360bc2017-09-07 10:19:52 -0700345 * extraApply - Function(s) that will be called before building ONOS. Default to None.
346 * applyArgs - argument of the functon(s) of the extraApply. Should be in list.
347 * extraClean - Function(s) that will be called after building ONOS. Defaults to None.
348 * cleanArgs - argument of the functon(s) of the extraClean. Should be in list.
Devin Lim142b5342017-07-20 15:22:39 -0700349 * skipPack - True if wish to skip some packing.
350 * installMax - True if wish to install onos max number of nodes
351 False if wish to install onos of running nodes only
352 * useSSH - True for using ssh when creating a cell
353 * killRemoveMax - True for removing/killing max number of nodes. False for
354 removing/killing running nodes only.
355 * stopOnos - True if wish to stop onos before killing it.
356 Returns:
357 Returns main.TRUE if it everything successfully proceeded.
358 """
359 self.setNumCtrls( hasMultiNodeRounds )
Devin Lim58046fa2017-07-05 16:55:00 -0700360
Devin Lim142b5342017-07-20 15:22:39 -0700361 main.case( "Starting up " + str( cluster.numCtrls ) +
Jon Hall4f360bc2017-09-07 10:19:52 -0700362 " node(s) ONOS cluster" )
Devin Lim142b5342017-07-20 15:22:39 -0700363 main.caseExplanation = "Set up ONOS with " + str( cluster.numCtrls ) + \
Devin Lim58046fa2017-07-05 16:55:00 -0700364 " node(s) ONOS cluster"
Devin Lim142b5342017-07-20 15:22:39 -0700365 killResult = self.killingAllOnos( cluster, killRemoveMax, stopOnos )
Devin Lim58046fa2017-07-05 16:55:00 -0700366
Devin Lim142b5342017-07-20 15:22:39 -0700367 main.log.info( "NODE COUNT = " + str( cluster.numCtrls ) )
368 cellResult = main.TRUE
369 packageResult = main.TRUE
370 onosUninstallResult = main.TRUE
371 onosCliResult = main.TRUE
Devin Lim58046fa2017-07-05 16:55:00 -0700372 if not skipPack:
Devin Lim142b5342017-07-20 15:22:39 -0700373 tempOnosIp = []
374 for ctrl in cluster.runningNodes:
375 tempOnosIp.append( ctrl.ipAddress )
376 cellResult = self.createApplyCell( cluster, newCell,
377 cellName, Mininet,
Devin Lime9f0ccf2017-08-11 17:25:12 -0700378 useSSH, tempOnosIp,
379 installMax )
Devin Lim58046fa2017-07-05 16:55:00 -0700380 if removeLog:
381 main.log.info("Removing raft logs")
382 main.ONOSbench.onosRemoveRaftLogs()
383
Devin Lim142b5342017-07-20 15:22:39 -0700384 onosUninstallResult = self.uninstallOnos( cluster, killRemoveMax )
Jon Hall4f360bc2017-09-07 10:19:52 -0700385 self.processList( extraApply, applyArgs )
Devin Lim142b5342017-07-20 15:22:39 -0700386 packageResult = self.buildOnos( cluster )
387
Devin Lime9f0ccf2017-08-11 17:25:12 -0700388 onosInstallResult = self.installOnos( cluster, installMax, installParallel )
Devin Lim58046fa2017-07-05 16:55:00 -0700389
Jon Hall4f360bc2017-09-07 10:19:52 -0700390 self.processList( extraClean, cleanArgs )
Devin Lim142b5342017-07-20 15:22:39 -0700391 secureSshResult = self.setupSsh( cluster )
Devin Lim58046fa2017-07-05 16:55:00 -0700392
Devin Lim142b5342017-07-20 15:22:39 -0700393 onosServiceResult = self.checkOnosService( cluster )
Devin Lim58046fa2017-07-05 16:55:00 -0700394
Devin Lim142b5342017-07-20 15:22:39 -0700395 if startOnos:
Jon Hallca319892017-06-15 15:25:22 -0700396 onosCliResult = self.startOnosClis( cluster )
Devin Lim58046fa2017-07-05 16:55:00 -0700397
Devin Lim142b5342017-07-20 15:22:39 -0700398 return killResult and cellResult and packageResult and onosUninstallResult and \
Jon Hall4f360bc2017-09-07 10:19:52 -0700399 onosInstallResult and secureSshResult and onosServiceResult and onosCliResult