blob: 750dde64b6472ae0fbfb6c781ad21fcd297e5bc8 [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
128 main.commit = main.ONOSbench.getVersion( report=True )
129
Devin Lim142b5342017-07-20 15:22:39 -0700130 def setNumCtrls( self, hasMultiNodeRounds ):
131 """
132 Description:
133 Set new number of controls if it uses different number of nodes.
134 different number of nodes should be pre-defined in main.scale.
135 Required:
136 * hasMultiNodeRouds - if the test is testing different number of nodes.
137 """
Devin Lim58046fa2017-07-05 16:55:00 -0700138 if hasMultiNodeRounds:
139 try:
140 main.cycle
141 except Exception:
142 main.cycle = 0
143 main.cycle += 1
144 # main.scale[ 0 ] determines the current number of ONOS controller
Devin Lim142b5342017-07-20 15:22:39 -0700145 main.Cluster.setRunningNode( int( main.scale.pop( 0 ) ) )
Devin Lim58046fa2017-07-05 16:55:00 -0700146
Devin Lim142b5342017-07-20 15:22:39 -0700147 def killingAllOnos( self, cluster, killRemoveMax, stopOnos ):
148 """
149 Description:
150 killing the onos. It will either kill the current runningnodes or
151 max number of the nodes.
152 Required:
153 * cluster - the cluster driver that will be used.
154 * killRemoveMax - The boolean that will decide either to kill
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700155 only running nodes ( False ) or max number of nodes ( True ).
Devin Lim142b5342017-07-20 15:22:39 -0700156 * stopOnos - If wish to stop onos before killing it. True for
157 enable stop , False for disable stop.
158 Returns:
159 Returns main.TRUE if successfully killing it.
160 """
161 main.log.info( "Safety check, killing all ONOS processes" )
Devin Lim58046fa2017-07-05 16:55:00 -0700162
Devin Lim142b5342017-07-20 15:22:39 -0700163 return cluster.kill( killRemoveMax, stopOnos )
Devin Lim58046fa2017-07-05 16:55:00 -0700164
Devin Lime9f0ccf2017-08-11 17:25:12 -0700165 def createApplyCell( self, cluster, newCell, cellName,
166 Mininet, useSSH, ips, installMax=False ):
Devin Lim142b5342017-07-20 15:22:39 -0700167 """
168 Description:
169 create new cell ( optional ) and apply it. It will also verify the
170 cell.
171 Required:
172 * cluster - the cluster driver that will be used.
173 * newCell - True for making a new cell and False for not making it.
174 * cellName - The name of the cell.
175 * Mininet - a mininet driver that will be used.
176 * useSSH - True for using ssh when creating a cell
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700177 * ips - ip( s ) of the node( s ).
Devin Lim142b5342017-07-20 15:22:39 -0700178 Returns:
179 Returns main.TRUE if it successfully executed.
180 """
Devin Lim58046fa2017-07-05 16:55:00 -0700181 if newCell:
Devin Lim142b5342017-07-20 15:22:39 -0700182 cluster.createCell( cellName, Mininet, useSSH, ips )
Devin Lim58046fa2017-07-05 16:55:00 -0700183 main.step( "Apply cell to environment" )
Devin Lim142b5342017-07-20 15:22:39 -0700184 stepResult = cluster.applyCell( cellName )
Devin Lim58046fa2017-07-05 16:55:00 -0700185 utilities.assert_equals( expect=main.TRUE,
186 actual=stepResult,
187 onpass="Successfully applied cell to " +
188 "environment",
Devin Lim142b5342017-07-20 15:22:39 -0700189 onfail="Failed to apply cell to environment" )
Devin Lim58046fa2017-07-05 16:55:00 -0700190 return stepResult
191
Devin Lim142b5342017-07-20 15:22:39 -0700192 def uninstallOnos( self, cluster, uninstallMax ):
193 """
194 Description:
195 uninstalling onos and verify the result.
196 Required:
197 * cluster - a cluster driver that will be used.
198 * uninstallMax - True for uninstalling max number of nodes
199 False for uninstalling the current running nodes.
200 Returns:
201 Returns main.TRUE if it successfully uninstalled.
202 """
Devin Lim58046fa2017-07-05 16:55:00 -0700203 main.step( "Uninstalling ONOS package" )
Devin Lim142b5342017-07-20 15:22:39 -0700204 onosUninstallResult = cluster.uninstall( uninstallMax )
Devin Lim58046fa2017-07-05 16:55:00 -0700205 utilities.assert_equals( expect=main.TRUE,
206 actual=onosUninstallResult,
207 onpass="Successfully uninstalled ONOS package",
208 onfail="Failed to uninstall ONOS package" )
209 return onosUninstallResult
210
Devin Lim142b5342017-07-20 15:22:39 -0700211 def buildOnos( self, cluster ):
212 """
213 Description:
214 build the onos using buck build onos and verify the result
215 Required:
216 * cluster - the cluster driver that will be used.
217 Returns:
218 Returns main.TRUE if it successfully built.
219 """
Devin Lim58046fa2017-07-05 16:55:00 -0700220 main.step( "Creating ONOS package" )
221 packageResult = main.ONOSbench.buckBuild()
222 utilities.assert_equals( expect=main.TRUE,
223 actual=packageResult,
224 onpass="Successfully created ONOS package",
225 onfail="Failed to create ONOS package" )
226 return packageResult
227
Devin Lime9f0ccf2017-08-11 17:25:12 -0700228 def installOnos( self, cluster, installMax, parallel=True ):
Devin Lim142b5342017-07-20 15:22:39 -0700229 """
230 Description:
231 Installing onos and verify the result
232 Required:
233 * cluster - the cluster driver that will be used.
234 * installMax - True for installing max number of nodes
235 False for installing current running nodes only.
236 Returns:
237 Returns main.TRUE if it successfully installed
238 """
Devin Lim58046fa2017-07-05 16:55:00 -0700239 main.step( "Installing ONOS package" )
240 onosInstallResult = main.TRUE
241
Devin Lime9f0ccf2017-08-11 17:25:12 -0700242 cluster.install( installMax, parallel )
Devin Lim58046fa2017-07-05 16:55:00 -0700243 utilities.assert_equals( expect=main.TRUE,
244 actual=onosInstallResult,
245 onpass="Successfully installed ONOS package",
246 onfail="Failed to install ONOS package" )
247 if not onosInstallResult:
Devin Lim44075962017-08-11 10:56:37 -0700248 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700249 return onosInstallResult
250
Devin Lim142b5342017-07-20 15:22:39 -0700251 def setupSsh( self, cluster ):
252 """
253 Description:
254 set up ssh to the onos and verify the result
255 Required:
256 * cluster - the cluster driver that will be used.
257 Returns:
258 Returns main.TRUE if it successfully setup the ssh to
259 the onos.
260 """
Devin Lim58046fa2017-07-05 16:55:00 -0700261 main.step( "Set up ONOS secure SSH" )
Devin Lim142b5342017-07-20 15:22:39 -0700262 secureSshResult = cluster.ssh()
Devin Lim58046fa2017-07-05 16:55:00 -0700263 utilities.assert_equals( expect=main.TRUE,
264 actual=secureSshResult,
265 onpass="Test step PASS",
266 onfail="Test step FAIL" )
267 return secureSshResult
268
Devin Lim142b5342017-07-20 15:22:39 -0700269 def checkOnosService( self, cluster ):
270 """
271 Description:
272 Checking if the onos service is up and verify the result
273 Required:
274 * cluster - the cluster driver that will be used.
275 Returns:
276 Returns main.TRUE if it successfully checked
277 """
278 main.step( "Checking ONOS service" )
279 stepResult = cluster.checkService()
Devin Lim58046fa2017-07-05 16:55:00 -0700280 utilities.assert_equals( expect=main.TRUE,
281 actual=stepResult,
282 onpass="ONOS service is ready on all nodes",
283 onfail="ONOS service did not start properly on all nodes" )
284 return stepResult
285
Jon Hallca319892017-06-15 15:25:22 -0700286 def startOnosClis( self, cluster ):
Devin Lim142b5342017-07-20 15:22:39 -0700287 """
288 Description:
289 starting Onos using onosCli driver and verify the result
290 Required:
291 * cluster - the cluster driver that will be used.
292 Returns:
293 Returns main.TRUE if it successfully started. It will exit
294 the test if not started properly.
295 """
Devin Lim58046fa2017-07-05 16:55:00 -0700296 main.step( "Starting ONOS CLI sessions" )
Jon Hallca319892017-06-15 15:25:22 -0700297 startCliResult = cluster.startCLIs()
Devin Lim58046fa2017-07-05 16:55:00 -0700298 if not startCliResult:
299 main.log.info( "ONOS CLI did not start up properly" )
Devin Lim44075962017-08-11 10:56:37 -0700300 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700301 else:
302 main.log.info( "Successful CLI startup" )
303 utilities.assert_equals( expect=main.TRUE,
304 actual=startCliResult,
305 onpass="Successfully start ONOS cli",
306 onfail="Failed to start ONOS cli" )
307 return startCliResult
308
Jon Hall4f360bc2017-09-07 10:19:52 -0700309 def processList( self, functions, args ):
310 if functions is not None:
311 if isinstance( functions, list ):
312 i = 0
313 for f in functions:
314 f( *( args[ i ] ) ) if args is not None and args[ i ] is not None else f()
315 i += 1
316 else:
317 functions( *args ) if args is not None else functions()
318
Devin Lim142b5342017-07-20 15:22:39 -0700319 def ONOSSetUp( self, Mininet, cluster, hasMultiNodeRounds=False, startOnos=True, newCell=True,
Jon Hall4f360bc2017-09-07 10:19:52 -0700320 cellName="temp", removeLog=False, extraApply=None, applyArgs=None, extraClean=None,
321 cleanArgs=None, skipPack=False, installMax=False, useSSH=True, killRemoveMax=True,
Devin Lime9f0ccf2017-08-11 17:25:12 -0700322 stopOnos=False, installParallel=True ):
Devin Lim142b5342017-07-20 15:22:39 -0700323 """
324 Description:
325 Initial ONOS setting up of the tests. It will also verify the result of each steps.
326 The procedures will be:
327 killing onos
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700328 creating ( optional ) /applying cell
329 removing raft logs ( optional )
Devin Lim142b5342017-07-20 15:22:39 -0700330 uninstalling onos
331 extra procedure to be applied( optional )
332 building onos
333 installing onos
334 extra cleanup to be applied ( optional )
335 setting up ssh to the onos
336 checking the onos service
337 starting onos
338 Required:
339 * Mininet - the mininet driver that will be used
340 * cluster - the cluster driver that will be used.
341 * hasMultiNodeRouds - True if the test is testing different set of nodes
342 * startOnos - True if wish to start onos.
343 * newCell - True for making a new cell and False for not making it.
344 * cellName - Name of the cell that will be used.
345 * removeLog - True if wish to remove raft logs
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700346 * extraApply - Function( s ) that will be called before building ONOS. Default to None.
347 * applyArgs - argument of the functon( s ) of the extraApply. Should be in list.
348 * extraClean - Function( s ) that will be called after building ONOS. Defaults to None.
349 * cleanArgs - argument of the functon( s ) of the extraClean. Should be in list.
Devin Lim142b5342017-07-20 15:22:39 -0700350 * skipPack - True if wish to skip some packing.
351 * installMax - True if wish to install onos max number of nodes
352 False if wish to install onos of running nodes only
353 * useSSH - True for using ssh when creating a cell
354 * killRemoveMax - True for removing/killing max number of nodes. False for
355 removing/killing running nodes only.
356 * stopOnos - True if wish to stop onos before killing it.
357 Returns:
358 Returns main.TRUE if it everything successfully proceeded.
359 """
360 self.setNumCtrls( hasMultiNodeRounds )
Devin Lim58046fa2017-07-05 16:55:00 -0700361
Devin Lim142b5342017-07-20 15:22:39 -0700362 main.case( "Starting up " + str( cluster.numCtrls ) +
Jon Hall4f360bc2017-09-07 10:19:52 -0700363 " node(s) ONOS cluster" )
Devin Lim142b5342017-07-20 15:22:39 -0700364 main.caseExplanation = "Set up ONOS with " + str( cluster.numCtrls ) + \
Devin Lim58046fa2017-07-05 16:55:00 -0700365 " node(s) ONOS cluster"
Devin Lim142b5342017-07-20 15:22:39 -0700366 killResult = self.killingAllOnos( cluster, killRemoveMax, stopOnos )
Devin Lim58046fa2017-07-05 16:55:00 -0700367
Devin Lim142b5342017-07-20 15:22:39 -0700368 main.log.info( "NODE COUNT = " + str( cluster.numCtrls ) )
369 cellResult = main.TRUE
370 packageResult = main.TRUE
371 onosUninstallResult = main.TRUE
372 onosCliResult = main.TRUE
Devin Lim58046fa2017-07-05 16:55:00 -0700373 if not skipPack:
Devin Lim142b5342017-07-20 15:22:39 -0700374 tempOnosIp = []
375 for ctrl in cluster.runningNodes:
376 tempOnosIp.append( ctrl.ipAddress )
377 cellResult = self.createApplyCell( cluster, newCell,
378 cellName, Mininet,
Devin Lime9f0ccf2017-08-11 17:25:12 -0700379 useSSH, tempOnosIp,
380 installMax )
Devin Lim58046fa2017-07-05 16:55:00 -0700381 if removeLog:
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700382 main.log.info( "Removing raft logs" )
Devin Lim58046fa2017-07-05 16:55:00 -0700383 main.ONOSbench.onosRemoveRaftLogs()
384
Devin Lim142b5342017-07-20 15:22:39 -0700385 onosUninstallResult = self.uninstallOnos( cluster, killRemoveMax )
Jon Hall4f360bc2017-09-07 10:19:52 -0700386 self.processList( extraApply, applyArgs )
Devin Lim142b5342017-07-20 15:22:39 -0700387 packageResult = self.buildOnos( cluster )
388
Devin Lime9f0ccf2017-08-11 17:25:12 -0700389 onosInstallResult = self.installOnos( cluster, installMax, installParallel )
Devin Lim58046fa2017-07-05 16:55:00 -0700390
Jon Hall4f360bc2017-09-07 10:19:52 -0700391 self.processList( extraClean, cleanArgs )
Devin Lim142b5342017-07-20 15:22:39 -0700392 secureSshResult = self.setupSsh( cluster )
Devin Lim58046fa2017-07-05 16:55:00 -0700393
Devin Lim142b5342017-07-20 15:22:39 -0700394 onosServiceResult = self.checkOnosService( cluster )
Devin Lim58046fa2017-07-05 16:55:00 -0700395
Devin Lim142b5342017-07-20 15:22:39 -0700396 if startOnos:
Jon Hallca319892017-06-15 15:25:22 -0700397 onosCliResult = self.startOnosClis( cluster )
Devin Lim58046fa2017-07-05 16:55:00 -0700398
Devin Lim142b5342017-07-20 15:22:39 -0700399 return killResult and cellResult and packageResult and onosUninstallResult and \
Jon Hall4f360bc2017-09-07 10:19:52 -0700400 onosInstallResult and secureSshResult and onosServiceResult and onosCliResult