blob: 6ea536170a10f9dec3afae606dcc9658bca25531 [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
Devin Lim0c972b72018-02-08 14:53:59 -080030 def envSetupDescription( self, includeCaseDesc=True ):
Devin Lim142b5342017-07-20 15:22:39 -070031 """
32 Introduction part of the test. It will initialize some basic vairables.
33 """
Devin Lim0c972b72018-02-08 14:53:59 -080034 if includeCaseDesc:
35 main.case( "Constructing test variables and building ONOS package" )
36 main.caseExplanation = "For loading from params file, and pull" + \
37 " and build the latest ONOS package"
Jon Halla604fd42018-05-04 14:27:27 -070038 main.step( "Constructing test variables" )
Devin Lim142b5342017-07-20 15:22:39 -070039 try:
40 from tests.dependencies.Cluster import Cluster
41 except ImportError:
42 main.log.error( "Cluster not found. exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070043 main.cleanAndExit()
Devin Lim142b5342017-07-20 15:22:39 -070044 try:
45 main.Cluster
46 except ( NameError, AttributeError ):
47 main.Cluster = Cluster( main.ONOScell.nodes )
48 main.ONOSbench = main.Cluster.controllers[ 0 ].Bench
Jon Halld74d2952018-03-01 13:26:39 -080049 main.testOnDirectory = re.sub( "(/tests)$", "", main.testsRoot )
Devin Lim58046fa2017-07-05 16:55:00 -070050
Devin Lim0c972b72018-02-08 14:53:59 -080051 def gitPulling( self, includeCaseDesc=True ):
Devin Lim142b5342017-07-20 15:22:39 -070052 """
53 it will do git checkout or pull if they are enabled from the params file.
54 """
Devin Lim0c972b72018-02-08 14:53:59 -080055
56 if includeCaseDesc:
57 main.case( "Pull onos branch and build onos on Teststation." )
58
Devin Lim58046fa2017-07-05 16:55:00 -070059 gitPull = main.params[ 'GIT' ][ 'pull' ]
60 gitBranch = main.params[ 'GIT' ][ 'branch' ]
61 if gitPull == 'True':
62 main.step( "Git Checkout ONOS branch: " + gitBranch )
63 stepResult = main.ONOSbench.gitCheckout( branch=gitBranch )
64 utilities.assert_equals( expect=main.TRUE,
65 actual=stepResult,
66 onpass="Successfully checkout onos branch.",
67 onfail="Failed to checkout onos branch. Exiting test..." )
Jon Hall4f360bc2017-09-07 10:19:52 -070068 if not stepResult:
69 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070070
71 main.step( "Git Pull on ONOS branch:" + gitBranch )
72 stepResult = main.ONOSbench.gitPull()
73 utilities.assert_equals( expect=main.TRUE,
74 actual=stepResult,
75 onpass="Successfully pull onos. ",
76 onfail="Failed to pull onos. Exiting test ..." )
Jon Hall4f360bc2017-09-07 10:19:52 -070077 if not stepResult:
78 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070079
80 else:
81 main.log.info( "Skipped git checkout and pull as they are disabled in params file" )
82
Devin Lim0c972b72018-02-08 14:53:59 -080083 def envSetup( self, includeGitPull=True, includeCaseDesc=True ):
Devin Lim142b5342017-07-20 15:22:39 -070084 """
85 Description:
86 some environment setup for the test.
87 Required:
88 * includeGitPull - if wish to git pulling function to be executed.
89 Returns:
90 Returns main.TRUE
91 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070092 if includeGitPull:
Devin Lim0c972b72018-02-08 14:53:59 -080093 self.gitPulling( includeCaseDesc )
Jon Hallca319892017-06-15 15:25:22 -070094
Devin Lim142b5342017-07-20 15:22:39 -070095 try:
96 from tests.dependencies.Cluster import Cluster
97 except ImportError:
98 main.log.error( "Cluster not found. exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070099 main.cleanAndExit()
Devin Lim142b5342017-07-20 15:22:39 -0700100 try:
101 main.Cluster
102 except ( NameError, AttributeError ):
103 main.Cluster = Cluster( main.ONOScell.nodes )
104
Devin Lim58046fa2017-07-05 16:55:00 -0700105 main.cellData = {} # For creating cell file
Devin Lim58046fa2017-07-05 16:55:00 -0700106
Jon Hallca319892017-06-15 15:25:22 -0700107 return main.TRUE
Devin Lim58046fa2017-07-05 16:55:00 -0700108
Jon Hallca319892017-06-15 15:25:22 -0700109 def envSetupException( self, e ):
Devin Lim142b5342017-07-20 15:22:39 -0700110 """
111 Description:
112 handles the exception that might occur from the environment setup.
113 Required:
114 * includeGitPull - exceeption code e.
115 """
Devin Lim58046fa2017-07-05 16:55:00 -0700116 main.log.exception( e )
Devin Lim44075962017-08-11 10:56:37 -0700117 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700118
Jon Hallca319892017-06-15 15:25:22 -0700119 def evnSetupConclusion( self, stepResult ):
Devin Lim142b5342017-07-20 15:22:39 -0700120 """
121 Description:
122 compare the result of the envSetup of the test.
123 Required:
124 * stepResult - Result of the envSetup.
125 """
Devin Lim58046fa2017-07-05 16:55:00 -0700126 utilities.assert_equals( expect=main.TRUE,
127 actual=stepResult,
128 onpass="Successfully construct " +
129 "test variables ",
130 onfail="Failed to construct test variables" )
131
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800132 url = self.generateGraphURL()
133 main.log.wiki( url )
134
Devin Lim58046fa2017-07-05 16:55:00 -0700135 main.commit = main.ONOSbench.getVersion( report=True )
136
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800137 def generateGraphURL( self, width=525, height=350 ):
138 """
139 Description:
140 Obtain the URL for the graph that corresponds to the test being run.
141 """
142
143 nodeCluster = main.params[ 'GRAPH' ][ 'nodeCluster' ]
144 testname = main.TEST
145 branch = main.ONOSbench.getBranchName()
146 maxBuildsToShow = main.params[ 'GRAPH' ][ 'builds' ]
147
148 return '<ac:structured-macro ac:name="html">\n' + \
149 '<ac:plain-text-body><![CDATA[\n' + \
Devin Limd1fb8e92018-02-28 16:29:33 -0800150 '<img src="https://jenkins.onosproject.org/view/QA/job/postjob-' + \
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800151 nodeCluster + \
152 '/lastSuccessfulBuild/artifact/' + \
153 testname + \
154 '_' + \
155 branch + \
156 '_' + \
157 maxBuildsToShow + \
158 '-builds_graph.jpg", alt="' + \
159 testname + \
160 '", style="width:' + \
161 str( width ) + \
162 'px;height:' + \
163 str( height ) + \
164 'px;border:0"' + \
165 '>' + \
166 ']]></ac:plain-text-body>\n' + \
167 '</ac:structured-macro>\n'
168
Devin Lim142b5342017-07-20 15:22:39 -0700169 def setNumCtrls( self, hasMultiNodeRounds ):
170 """
171 Description:
Jon Hall3e6edb32018-08-21 16:20:30 -0700172 Set new number of controllers if it uses different number of nodes.
Devin Lim142b5342017-07-20 15:22:39 -0700173 different number of nodes should be pre-defined in main.scale.
174 Required:
175 * hasMultiNodeRouds - if the test is testing different number of nodes.
176 """
Devin Lim58046fa2017-07-05 16:55:00 -0700177 if hasMultiNodeRounds:
178 try:
179 main.cycle
180 except Exception:
181 main.cycle = 0
182 main.cycle += 1
Jon Hall3e6edb32018-08-21 16:20:30 -0700183 # main.scale[ 0 ] determines the current number of ONOS controllers
Devin Lim142b5342017-07-20 15:22:39 -0700184 main.Cluster.setRunningNode( int( main.scale.pop( 0 ) ) )
Devin Lim58046fa2017-07-05 16:55:00 -0700185
You Wangf9d95be2018-08-01 14:35:37 -0700186 def killingAllAtomix( self, cluster, killRemoveMax, stopAtomix ):
187 """
188 Description:
189 killing atomix. It will either kill the current runningnodes or
190 max number of the nodes.
191 Required:
192 * cluster - the cluster driver that will be used.
193 * killRemoveMax - The boolean that will decide either to kill
194 only running nodes ( False ) or max number of nodes ( True ).
195 * stopAtomix - If wish to stop atomix before killing it. True for
196 enable stop, False for disable stop.
197 Returns:
198 Returns main.TRUE if successfully killing it.
199 """
200 main.log.info( "Safety check, killing all Atomix processes" )
201 return cluster.killAtomix( killRemoveMax, stopAtomix )
202
Devin Lim142b5342017-07-20 15:22:39 -0700203 def killingAllOnos( self, cluster, killRemoveMax, stopOnos ):
204 """
205 Description:
206 killing the onos. It will either kill the current runningnodes or
207 max number of the nodes.
208 Required:
209 * cluster - the cluster driver that will be used.
210 * killRemoveMax - The boolean that will decide either to kill
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700211 only running nodes ( False ) or max number of nodes ( True ).
Devin Lim142b5342017-07-20 15:22:39 -0700212 * stopOnos - If wish to stop onos before killing it. True for
You Wangf9d95be2018-08-01 14:35:37 -0700213 enable stop, False for disable stop.
Devin Lim142b5342017-07-20 15:22:39 -0700214 Returns:
215 Returns main.TRUE if successfully killing it.
216 """
217 main.log.info( "Safety check, killing all ONOS processes" )
You Wangf9d95be2018-08-01 14:35:37 -0700218 return cluster.killOnos( killRemoveMax, stopOnos )
Devin Lim58046fa2017-07-05 16:55:00 -0700219
You Wang09b596b2018-01-10 10:42:38 -0800220 def createApplyCell( self, cluster, newCell, cellName, cellApps,
Jon Hall3e6edb32018-08-21 16:20:30 -0700221 mininetIp, useSSH, onosIps, installMax=False,
222 atomixClusterSize=None ):
Devin Lim142b5342017-07-20 15:22:39 -0700223 """
224 Description:
225 create new cell ( optional ) and apply it. It will also verify the
226 cell.
Jon Hall3e6edb32018-08-21 16:20:30 -0700227 Required Arguments:
Devin Lim142b5342017-07-20 15:22:39 -0700228 * cluster - the cluster driver that will be used.
229 * newCell - True for making a new cell and False for not making it.
230 * cellName - The name of the cell.
You Wang09b596b2018-01-10 10:42:38 -0800231 * cellApps - The onos apps string.
You Wanga0f6ff62018-01-11 15:46:30 -0800232 * mininetIp - Mininet IP address.
Devin Lim142b5342017-07-20 15:22:39 -0700233 * useSSH - True for using ssh when creating a cell
Jon Hall3e6edb32018-08-21 16:20:30 -0700234 * onosIps - ip( s ) of the ONOS node( s ).
235 Optional Arguments:
236 * installMax
237 * atomixClusterSize - The size of the atomix cluster. Defaults to same
238 as ONOS Cluster size
Devin Lim142b5342017-07-20 15:22:39 -0700239 Returns:
240 Returns main.TRUE if it successfully executed.
241 """
Jon Hall3e6edb32018-08-21 16:20:30 -0700242 if atomixClusterSize is None:
243 atomixClusterSize = len( cluster.runningNodes )
244 atomixClusterSize = int( atomixClusterSize )
245 cluster.setAtomixNodes( atomixClusterSize )
246 atomixIps = [ node.ipAddress for node in cluster.atomixNodes ]
247 main.log.info( "Atomix Cluster Size = {} ".format( atomixClusterSize ) )
Devin Lim58046fa2017-07-05 16:55:00 -0700248 if newCell:
Jon Hall3e6edb32018-08-21 16:20:30 -0700249 cluster.createCell( cellName, cellApps, mininetIp, useSSH, onosIps,
250 atomixIps, installMax )
Devin Lim58046fa2017-07-05 16:55:00 -0700251 main.step( "Apply cell to environment" )
Devin Lim142b5342017-07-20 15:22:39 -0700252 stepResult = cluster.applyCell( cellName )
Devin Lim58046fa2017-07-05 16:55:00 -0700253 utilities.assert_equals( expect=main.TRUE,
254 actual=stepResult,
255 onpass="Successfully applied cell to " +
256 "environment",
Devin Lim142b5342017-07-20 15:22:39 -0700257 onfail="Failed to apply cell to environment" )
Devin Lim58046fa2017-07-05 16:55:00 -0700258 return stepResult
259
You Wangf9d95be2018-08-01 14:35:37 -0700260 def uninstallAtomix( self, cluster, uninstallMax ):
261 """
262 Description:
263 uninstalling atomix and verify the result.
264 Required:
265 * cluster - a cluster driver that will be used.
266 * uninstallMax - True for uninstalling max number of nodes
Jon Hall3e6edb32018-08-21 16:20:30 -0700267 False for uninstalling the current running nodes.
You Wangf9d95be2018-08-01 14:35:37 -0700268 Returns:
269 Returns main.TRUE if it successfully uninstalled.
270 """
271 main.step( "Uninstalling Atomix" )
272 atomixUninstallResult = cluster.uninstallAtomix( uninstallMax )
273 utilities.assert_equals( expect=main.TRUE,
274 actual=atomixUninstallResult,
275 onpass="Successfully uninstalled Atomix",
276 onfail="Failed to uninstall Atomix" )
277 return atomixUninstallResult
278
Devin Lim142b5342017-07-20 15:22:39 -0700279 def uninstallOnos( self, cluster, uninstallMax ):
280 """
281 Description:
282 uninstalling onos and verify the result.
283 Required:
284 * cluster - a cluster driver that will be used.
285 * uninstallMax - True for uninstalling max number of nodes
286 False for uninstalling the current running nodes.
287 Returns:
288 Returns main.TRUE if it successfully uninstalled.
289 """
Devin Lim58046fa2017-07-05 16:55:00 -0700290 main.step( "Uninstalling ONOS package" )
You Wangf9d95be2018-08-01 14:35:37 -0700291 onosUninstallResult = cluster.uninstallOnos( uninstallMax )
Devin Lim58046fa2017-07-05 16:55:00 -0700292 utilities.assert_equals( expect=main.TRUE,
293 actual=onosUninstallResult,
294 onpass="Successfully uninstalled ONOS package",
295 onfail="Failed to uninstall ONOS package" )
296 return onosUninstallResult
297
Devin Lim142b5342017-07-20 15:22:39 -0700298 def buildOnos( self, cluster ):
299 """
300 Description:
You Wangd54c7052018-08-07 16:06:27 -0700301 build the onos using bazel build onos and verify the result
Devin Lim142b5342017-07-20 15:22:39 -0700302 Required:
303 * cluster - the cluster driver that will be used.
304 Returns:
305 Returns main.TRUE if it successfully built.
306 """
Devin Lim58046fa2017-07-05 16:55:00 -0700307 main.step( "Creating ONOS package" )
You Wangd54c7052018-08-07 16:06:27 -0700308 packageResult = main.ONOSbench.bazelBuild()
Devin Lim58046fa2017-07-05 16:55:00 -0700309 utilities.assert_equals( expect=main.TRUE,
310 actual=packageResult,
311 onpass="Successfully created ONOS package",
312 onfail="Failed to create ONOS package" )
313 return packageResult
314
Jon Hall3e6edb32018-08-21 16:20:30 -0700315 def installAtomix( self, cluster, parallel=True ):
You Wangf9d95be2018-08-01 14:35:37 -0700316 """
317 Description:
318 Installing atomix and verify the result
319 Required:
320 * cluster - the cluster driver that will be used.
You Wangf9d95be2018-08-01 14:35:37 -0700321 False for installing current running nodes only.
322 Returns:
323 Returns main.TRUE if it successfully installed
324 """
325 main.step( "Installing Atomix" )
326 atomixInstallResult = main.TRUE
327
Jon Hallb685a1c2018-10-30 15:17:01 -0700328 atomixInstallResult = cluster.installAtomix( parallel )
You Wangf9d95be2018-08-01 14:35:37 -0700329 utilities.assert_equals( expect=main.TRUE,
330 actual=atomixInstallResult,
331 onpass="Successfully installed Atomix",
332 onfail="Failed to install Atomix" )
333 if not atomixInstallResult:
334 main.cleanAndExit()
335 return atomixInstallResult
336
Devin Lime9f0ccf2017-08-11 17:25:12 -0700337 def installOnos( self, cluster, installMax, parallel=True ):
Devin Lim142b5342017-07-20 15:22:39 -0700338 """
339 Description:
340 Installing onos and verify the result
341 Required:
342 * cluster - the cluster driver that will be used.
343 * installMax - True for installing max number of nodes
344 False for installing current running nodes only.
345 Returns:
346 Returns main.TRUE if it successfully installed
347 """
Devin Lim58046fa2017-07-05 16:55:00 -0700348 main.step( "Installing ONOS package" )
349 onosInstallResult = main.TRUE
350
You Wangf9d95be2018-08-01 14:35:37 -0700351 cluster.installOnos( installMax, parallel )
Devin Lim58046fa2017-07-05 16:55:00 -0700352 utilities.assert_equals( expect=main.TRUE,
353 actual=onosInstallResult,
354 onpass="Successfully installed ONOS package",
355 onfail="Failed to install ONOS package" )
356 if not onosInstallResult:
Devin Lim44075962017-08-11 10:56:37 -0700357 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700358 return onosInstallResult
359
Devin Lim142b5342017-07-20 15:22:39 -0700360 def setupSsh( self, cluster ):
361 """
362 Description:
363 set up ssh to the onos and verify the result
364 Required:
365 * cluster - the cluster driver that will be used.
366 Returns:
367 Returns main.TRUE if it successfully setup the ssh to
368 the onos.
369 """
Devin Lim58046fa2017-07-05 16:55:00 -0700370 main.step( "Set up ONOS secure SSH" )
Devin Lim142b5342017-07-20 15:22:39 -0700371 secureSshResult = cluster.ssh()
Devin Lim58046fa2017-07-05 16:55:00 -0700372 utilities.assert_equals( expect=main.TRUE,
373 actual=secureSshResult,
Jon Hall3e6edb32018-08-21 16:20:30 -0700374 onpass="Secured ONOS ssh",
375 onfail="Failed to secure ssh" )
Devin Lim58046fa2017-07-05 16:55:00 -0700376 return secureSshResult
377
Devin Lim142b5342017-07-20 15:22:39 -0700378 def checkOnosService( self, cluster ):
379 """
380 Description:
381 Checking if the onos service is up and verify the result
382 Required:
383 * cluster - the cluster driver that will be used.
384 Returns:
385 Returns main.TRUE if it successfully checked
386 """
387 main.step( "Checking ONOS service" )
388 stepResult = cluster.checkService()
Devin Lim58046fa2017-07-05 16:55:00 -0700389 utilities.assert_equals( expect=main.TRUE,
390 actual=stepResult,
391 onpass="ONOS service is ready on all nodes",
392 onfail="ONOS service did not start properly on all nodes" )
393 return stepResult
394
Jon Hallca319892017-06-15 15:25:22 -0700395 def startOnosClis( self, cluster ):
Devin Lim142b5342017-07-20 15:22:39 -0700396 """
397 Description:
398 starting Onos using onosCli driver and verify the result
399 Required:
400 * cluster - the cluster driver that will be used.
401 Returns:
402 Returns main.TRUE if it successfully started. It will exit
403 the test if not started properly.
404 """
Devin Lim58046fa2017-07-05 16:55:00 -0700405 main.step( "Starting ONOS CLI sessions" )
Jon Hallca319892017-06-15 15:25:22 -0700406 startCliResult = cluster.startCLIs()
Devin Lim58046fa2017-07-05 16:55:00 -0700407 if not startCliResult:
408 main.log.info( "ONOS CLI did not start up properly" )
Devin Lim44075962017-08-11 10:56:37 -0700409 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700410 else:
411 main.log.info( "Successful CLI startup" )
412 utilities.assert_equals( expect=main.TRUE,
413 actual=startCliResult,
414 onpass="Successfully start ONOS cli",
415 onfail="Failed to start ONOS cli" )
416 return startCliResult
417
You Wang0d9f2c02018-08-10 14:56:32 -0700418 def checkOnosNodes( self, cluster ):
419 """
420 Description:
421 Checking if the onos nodes are in READY state
422 Required:
423 * cluster - the cluster driver that will be used.
424 Returns:
425 Returns main.TRUE if it successfully checked
426 """
427 main.step( "Checking ONOS nodes" )
428 stepResult = utilities.retry( main.Cluster.nodesCheck,
429 False,
You Wang07831cb2018-09-04 12:18:04 -0700430 attempts=90 )
You Wang0d9f2c02018-08-10 14:56:32 -0700431
432 utilities.assert_equals( expect=True,
433 actual=stepResult,
434 onpass="All ONOS nodes are in READY state",
435 onfail="Not all ONOS nodes are in READY state" )
436
437 if not stepResult:
438 for ctrl in main.Cluster.active():
439 main.log.debug( "{} components not ACTIVE: \n{}".format(
440 ctrl.name,
Jon Hall6c9e2da2018-11-06 12:01:23 -0800441 ctrl.CLI.sendline( "onos:scr-list | grep -v ACTIVE" ) ) ) #FIXME: This output has changed a lot
You Wang0d9f2c02018-08-10 14:56:32 -0700442 main.log.error( "Failed to start ONOS, stopping test" )
You Wangba973f02018-08-30 12:33:41 -0700443 main.cleanAndExit()
444 return main.TRUE
You Wang0d9f2c02018-08-10 14:56:32 -0700445
446 def checkOnosApps( self, cluster, apps ):
447 """
448 Description:
449 Checking if the onos applications are activated
450 Required:
451 * cluster - the cluster driver that will be used.
452 * apps: list of applications that are expected to be activated
453 Returns:
454 Returns main.TRUE if it successfully checked
455 """
456 main.step( "Checking ONOS applications" )
457 stepResult = utilities.retry( main.Cluster.appsCheck,
458 False,
459 args = [ apps ],
460 sleep=5,
Jon Hall3e6edb32018-08-21 16:20:30 -0700461 attempts=90 )
You Wang0d9f2c02018-08-10 14:56:32 -0700462
463 utilities.assert_equals( expect=True,
464 actual=stepResult,
465 onpass="All ONOS apps are activated",
466 onfail="Not all ONOS apps are activated" )
467
468 return main.TRUE if stepResult else main.FALSE
469
Jon Hall4f360bc2017-09-07 10:19:52 -0700470 def processList( self, functions, args ):
471 if functions is not None:
472 if isinstance( functions, list ):
473 i = 0
474 for f in functions:
475 f( *( args[ i ] ) ) if args is not None and args[ i ] is not None else f()
476 i += 1
477 else:
478 functions( *args ) if args is not None else functions()
479
You Wanga0f6ff62018-01-11 15:46:30 -0800480 def ONOSSetUp( self, cluster, hasMultiNodeRounds=False, startOnos=True, newCell=True,
You Wangcdc51fe2018-08-12 17:14:56 -0700481 cellName="temp", cellApps="drivers", appPrefix="org.onosproject.",
Jon Hall3e6edb32018-08-21 16:20:30 -0700482 mininetIp="", extraApply=None, applyArgs=None,
483 extraClean=None, cleanArgs=None, skipPack=False, installMax=False,
484 atomixClusterSize=None, useSSH=True, killRemoveMax=True, stopAtomix=False,
485 stopOnos=False, installParallel=True, cellApply=True,
You Wangdbb95d62018-09-05 15:58:08 -0700486 includeCaseDesc=True, restartCluster=True ):
Devin Lim142b5342017-07-20 15:22:39 -0700487 """
488 Description:
489 Initial ONOS setting up of the tests. It will also verify the result of each steps.
490 The procedures will be:
491 killing onos
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700492 creating ( optional ) /applying cell
493 removing raft logs ( optional )
Devin Lim142b5342017-07-20 15:22:39 -0700494 uninstalling onos
495 extra procedure to be applied( optional )
496 building onos
497 installing onos
498 extra cleanup to be applied ( optional )
499 setting up ssh to the onos
500 checking the onos service
501 starting onos
Jon Hall3e6edb32018-08-21 16:20:30 -0700502 Required Arguments:
Devin Lim142b5342017-07-20 15:22:39 -0700503 * cluster - the cluster driver that will be used.
Jon Hall3e6edb32018-08-21 16:20:30 -0700504 Optional Arguments:
505 * hasMultiNodeRounds - True if the test is testing different set of nodes
Devin Lim142b5342017-07-20 15:22:39 -0700506 * startOnos - True if wish to start onos.
507 * newCell - True for making a new cell and False for not making it.
508 * cellName - Name of the cell that will be used.
You Wang0d9f2c02018-08-10 14:56:32 -0700509 * cellApps - The cell apps string. Will be overwritten by main.apps if it exists
You Wangcdc51fe2018-08-12 17:14:56 -0700510 * appPrefix - Prefix of app names. Will use "org.onosproject." by default
You Wanga0f6ff62018-01-11 15:46:30 -0800511 * mininetIp - Mininet IP address.
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700512 * extraApply - Function( s ) that will be called before building ONOS. Default to None.
513 * applyArgs - argument of the functon( s ) of the extraApply. Should be in list.
514 * extraClean - Function( s ) that will be called after building ONOS. Defaults to None.
515 * cleanArgs - argument of the functon( s ) of the extraClean. Should be in list.
Devin Lim142b5342017-07-20 15:22:39 -0700516 * skipPack - True if wish to skip some packing.
517 * installMax - True if wish to install onos max number of nodes
Jon Hall3e6edb32018-08-21 16:20:30 -0700518 False if wish to install onos of running nodes only
519 * atomixClusterSize - The number of Atomix nodes in the cluster.
520 Defaults to None which will be the number of OC# nodes in the cell
Devin Lim142b5342017-07-20 15:22:39 -0700521 * useSSH - True for using ssh when creating a cell
522 * killRemoveMax - True for removing/killing max number of nodes. False for
Jon Hall3e6edb32018-08-21 16:20:30 -0700523 removing/killing running nodes only.
You Wangf9d95be2018-08-01 14:35:37 -0700524 * stopAtomix - True if wish to stop atomix before killing it.
Devin Lim142b5342017-07-20 15:22:39 -0700525 * stopOnos - True if wish to stop onos before killing it.
You Wangdbb95d62018-09-05 15:58:08 -0700526 * restartCluster - True if wish to kill and restart atomix and onos clusters
Devin Lim142b5342017-07-20 15:22:39 -0700527 Returns:
528 Returns main.TRUE if it everything successfully proceeded.
529 """
530 self.setNumCtrls( hasMultiNodeRounds )
Devin Lim0c972b72018-02-08 14:53:59 -0800531 if includeCaseDesc:
532 main.case( "Starting up " + str( cluster.numCtrls ) +
533 " node(s) ONOS cluster" )
534 main.caseExplanation = "Set up ONOS with " + str( cluster.numCtrls ) + \
535 " node(s) ONOS cluster"
Devin Lim58046fa2017-07-05 16:55:00 -0700536
Jon Hall3e6edb32018-08-21 16:20:30 -0700537 main.log.info( "ONOS cluster size = " + str( cluster.numCtrls ) )
Devin Lim142b5342017-07-20 15:22:39 -0700538 cellResult = main.TRUE
Devin Lim6437c9c2018-01-29 17:24:16 -0800539 if cellApply:
You Wang0d9f2c02018-08-10 14:56:32 -0700540 try:
541 apps = main.apps
542 except ( NameError, AttributeError ):
543 apps = cellApps
544 main.log.debug( "Apps: " + str( apps ) )
Devin Lim142b5342017-07-20 15:22:39 -0700545 tempOnosIp = []
546 for ctrl in cluster.runningNodes:
547 tempOnosIp.append( ctrl.ipAddress )
You Wanga0f6ff62018-01-11 15:46:30 -0800548 if mininetIp == "":
549 mininetIp = "localhost"
550 for key, value in main.componentDictionary.items():
551 if value['type'] in ['MininetCliDriver', 'RemoteMininetDriver'] and hasattr( main, key ):
552 mininetIp = getattr( main, key ).ip_address
553 break
Devin Lim142b5342017-07-20 15:22:39 -0700554 cellResult = self.createApplyCell( cluster, newCell,
You Wang0d9f2c02018-08-10 14:56:32 -0700555 cellName, apps,
You Wanga0f6ff62018-01-11 15:46:30 -0800556 mininetIp, useSSH,
Jon Hall3e6edb32018-08-21 16:20:30 -0700557 tempOnosIp, installMax,
558 atomixClusterSize )
Devin Lim58046fa2017-07-05 16:55:00 -0700559
You Wangdbb95d62018-09-05 15:58:08 -0700560 if restartCluster:
561 atomixKillResult = self.killingAllAtomix( cluster, killRemoveMax, stopAtomix )
562 onosKillResult = self.killingAllOnos( cluster, killRemoveMax, stopOnos )
563 killResult = atomixKillResult and onosKillResult
564 else:
565 killResult = main.TRUE
You Wang4cc61912018-08-28 10:10:58 -0700566
You Wangdbb95d62018-09-05 15:58:08 -0700567 if restartCluster:
568 atomixUninstallResult = self.uninstallAtomix( cluster, killRemoveMax )
569 onosUninstallResult = self.uninstallOnos( cluster, killRemoveMax )
570 uninstallResult = atomixUninstallResult and onosUninstallResult
571 self.processList( extraApply, applyArgs )
Devin Lim6437c9c2018-01-29 17:24:16 -0800572
You Wangdbb95d62018-09-05 15:58:08 -0700573 packageResult = main.TRUE
574 if not skipPack:
575 packageResult = self.buildOnos(cluster)
Devin Lim142b5342017-07-20 15:22:39 -0700576
You Wangdbb95d62018-09-05 15:58:08 -0700577 atomixInstallResult = self.installAtomix( cluster, installParallel )
578 onosInstallResult = self.installOnos( cluster, installMax, installParallel )
579 installResult = atomixInstallResult and onosInstallResult
Devin Lim58046fa2017-07-05 16:55:00 -0700580
You Wangdbb95d62018-09-05 15:58:08 -0700581 self.processList( extraClean, cleanArgs )
582 secureSshResult = self.setupSsh( cluster )
583 else:
584 packageResult = main.TRUE
585 uninstallResult = main.TRUE
586 installResult = main.TRUE
587 secureSshResult = main.TRUE
Devin Lim58046fa2017-07-05 16:55:00 -0700588
Devin Lim142b5342017-07-20 15:22:39 -0700589 onosServiceResult = self.checkOnosService( cluster )
Devin Lim58046fa2017-07-05 16:55:00 -0700590
You Wang4cc61912018-08-28 10:10:58 -0700591 onosCliResult = main.TRUE
Devin Lim142b5342017-07-20 15:22:39 -0700592 if startOnos:
Jon Hallca319892017-06-15 15:25:22 -0700593 onosCliResult = self.startOnosClis( cluster )
Devin Lim58046fa2017-07-05 16:55:00 -0700594
You Wang0d9f2c02018-08-10 14:56:32 -0700595 onosNodesResult = self.checkOnosNodes( cluster )
596
597 onosAppsResult = main.TRUE
598 if cellApply:
599 if apps:
600 apps = apps.split( ',' )
You Wangcdc51fe2018-08-12 17:14:56 -0700601 apps = [ appPrefix + app for app in apps ]
You Wang0d9f2c02018-08-10 14:56:32 -0700602 onosAppsResult = self.checkOnosApps( cluster, apps )
603 else:
604 main.log.warn( "No apps were specified to be checked after startup" )
605
You Wangf9d95be2018-08-01 14:35:37 -0700606 return killResult and cellResult and packageResult and uninstallResult and \
You Wang0d9f2c02018-08-10 14:56:32 -0700607 installResult and secureSshResult and onosServiceResult and onosCliResult and \
608 onosNodesResult and onosAppsResult