blob: 0a00fd7da1e083d3ea915a8188a7bca3969fb27c [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
Jon Hall43060f62020-06-23 13:13:33 -070022import os
Devin Lim58046fa2017-07-05 16:55:00 -070023
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070024
Devin Lim58046fa2017-07-05 16:55:00 -070025class ONOSSetup:
26 main = None
Jon Hall4f360bc2017-09-07 10:19:52 -070027
Devin Lim58046fa2017-07-05 16:55:00 -070028 def __init__( self ):
29 self.default = ''
Jon Hall4f360bc2017-09-07 10:19:52 -070030
Devin Lim0c972b72018-02-08 14:53:59 -080031 def envSetupDescription( self, includeCaseDesc=True ):
Devin Lim142b5342017-07-20 15:22:39 -070032 """
33 Introduction part of the test. It will initialize some basic vairables.
34 """
Devin Lim0c972b72018-02-08 14:53:59 -080035 if includeCaseDesc:
36 main.case( "Constructing test variables and building ONOS package" )
37 main.caseExplanation = "For loading from params file, and pull" + \
38 " and build the latest ONOS package"
Jon Halla604fd42018-05-04 14:27:27 -070039 main.step( "Constructing test variables" )
Devin Lim142b5342017-07-20 15:22:39 -070040 try:
41 from tests.dependencies.Cluster import Cluster
42 except ImportError:
43 main.log.error( "Cluster not found. exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070044 main.cleanAndExit()
Devin Lim142b5342017-07-20 15:22:39 -070045 try:
46 main.Cluster
47 except ( NameError, AttributeError ):
48 main.Cluster = Cluster( main.ONOScell.nodes )
49 main.ONOSbench = main.Cluster.controllers[ 0 ].Bench
Jon Halld74d2952018-03-01 13:26:39 -080050 main.testOnDirectory = re.sub( "(/tests)$", "", main.testsRoot )
Devin Lim58046fa2017-07-05 16:55:00 -070051
Devin Lim0c972b72018-02-08 14:53:59 -080052 def gitPulling( self, includeCaseDesc=True ):
Devin Lim142b5342017-07-20 15:22:39 -070053 """
54 it will do git checkout or pull if they are enabled from the params file.
55 """
Devin Lim0c972b72018-02-08 14:53:59 -080056
57 if includeCaseDesc:
58 main.case( "Pull onos branch and build onos on Teststation." )
59
Devin Lim58046fa2017-07-05 16:55:00 -070060 gitPull = main.params[ 'GIT' ][ 'pull' ]
61 gitBranch = main.params[ 'GIT' ][ 'branch' ]
62 if gitPull == 'True':
63 main.step( "Git Checkout ONOS branch: " + gitBranch )
64 stepResult = main.ONOSbench.gitCheckout( branch=gitBranch )
65 utilities.assert_equals( expect=main.TRUE,
66 actual=stepResult,
67 onpass="Successfully checkout onos branch.",
68 onfail="Failed to checkout onos branch. Exiting test..." )
Jon Hall4f360bc2017-09-07 10:19:52 -070069 if not stepResult:
70 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070071
72 main.step( "Git Pull on ONOS branch:" + gitBranch )
73 stepResult = main.ONOSbench.gitPull()
74 utilities.assert_equals( expect=main.TRUE,
75 actual=stepResult,
76 onpass="Successfully pull onos. ",
77 onfail="Failed to pull onos. Exiting test ..." )
Jon Hall4f360bc2017-09-07 10:19:52 -070078 if not stepResult:
79 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070080
81 else:
82 main.log.info( "Skipped git checkout and pull as they are disabled in params file" )
83
Devin Lim0c972b72018-02-08 14:53:59 -080084 def envSetup( self, includeGitPull=True, includeCaseDesc=True ):
Devin Lim142b5342017-07-20 15:22:39 -070085 """
86 Description:
87 some environment setup for the test.
88 Required:
89 * includeGitPull - if wish to git pulling function to be executed.
90 Returns:
91 Returns main.TRUE
92 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070093 if includeGitPull:
Devin Lim0c972b72018-02-08 14:53:59 -080094 self.gitPulling( includeCaseDesc )
Jon Hallca319892017-06-15 15:25:22 -070095
Devin Lim142b5342017-07-20 15:22:39 -070096 try:
97 from tests.dependencies.Cluster import Cluster
98 except ImportError:
99 main.log.error( "Cluster not found. exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700100 main.cleanAndExit()
Devin Lim142b5342017-07-20 15:22:39 -0700101 try:
102 main.Cluster
103 except ( NameError, AttributeError ):
104 main.Cluster = Cluster( main.ONOScell.nodes )
105
Devin Lim58046fa2017-07-05 16:55:00 -0700106 main.cellData = {} # For creating cell file
Devin Lim58046fa2017-07-05 16:55:00 -0700107
Jon Hallca319892017-06-15 15:25:22 -0700108 return main.TRUE
Devin Lim58046fa2017-07-05 16:55:00 -0700109
Jon Hallca319892017-06-15 15:25:22 -0700110 def envSetupException( self, e ):
Devin Lim142b5342017-07-20 15:22:39 -0700111 """
112 Description:
113 handles the exception that might occur from the environment setup.
114 Required:
115 * includeGitPull - exceeption code e.
116 """
Devin Lim58046fa2017-07-05 16:55:00 -0700117 main.log.exception( e )
Devin Lim44075962017-08-11 10:56:37 -0700118 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700119
Jon Hallca319892017-06-15 15:25:22 -0700120 def evnSetupConclusion( self, stepResult ):
Devin Lim142b5342017-07-20 15:22:39 -0700121 """
122 Description:
123 compare the result of the envSetup of the test.
124 Required:
125 * stepResult - Result of the envSetup.
126 """
Devin Lim58046fa2017-07-05 16:55:00 -0700127 utilities.assert_equals( expect=main.TRUE,
128 actual=stepResult,
129 onpass="Successfully construct " +
130 "test variables ",
131 onfail="Failed to construct test variables" )
132
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800133 url = self.generateGraphURL()
134 main.log.wiki( url )
135
Devin Lim58046fa2017-07-05 16:55:00 -0700136 main.commit = main.ONOSbench.getVersion( report=True )
137
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800138 def generateGraphURL( self, width=525, height=350 ):
139 """
140 Description:
141 Obtain the URL for the graph that corresponds to the test being run.
142 """
143
144 nodeCluster = main.params[ 'GRAPH' ][ 'nodeCluster' ]
145 testname = main.TEST
146 branch = main.ONOSbench.getBranchName()
147 maxBuildsToShow = main.params[ 'GRAPH' ][ 'builds' ]
148
149 return '<ac:structured-macro ac:name="html">\n' + \
150 '<ac:plain-text-body><![CDATA[\n' + \
Devin Limd1fb8e92018-02-28 16:29:33 -0800151 '<img src="https://jenkins.onosproject.org/view/QA/job/postjob-' + \
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800152 nodeCluster + \
153 '/lastSuccessfulBuild/artifact/' + \
154 testname + \
155 '_' + \
156 branch + \
157 '_' + \
158 maxBuildsToShow + \
159 '-builds_graph.jpg", alt="' + \
160 testname + \
161 '", style="width:' + \
162 str( width ) + \
163 'px;height:' + \
164 str( height ) + \
165 'px;border:0"' + \
166 '>' + \
167 ']]></ac:plain-text-body>\n' + \
168 '</ac:structured-macro>\n'
169
Devin Lim142b5342017-07-20 15:22:39 -0700170 def setNumCtrls( self, hasMultiNodeRounds ):
171 """
172 Description:
Jon Hall3e6edb32018-08-21 16:20:30 -0700173 Set new number of controllers if it uses different number of nodes.
Devin Lim142b5342017-07-20 15:22:39 -0700174 different number of nodes should be pre-defined in main.scale.
175 Required:
176 * hasMultiNodeRouds - if the test is testing different number of nodes.
177 """
Devin Lim58046fa2017-07-05 16:55:00 -0700178 if hasMultiNodeRounds:
179 try:
180 main.cycle
181 except Exception:
182 main.cycle = 0
183 main.cycle += 1
Jon Hall3e6edb32018-08-21 16:20:30 -0700184 # main.scale[ 0 ] determines the current number of ONOS controllers
Devin Lim142b5342017-07-20 15:22:39 -0700185 main.Cluster.setRunningNode( int( main.scale.pop( 0 ) ) )
Devin Lim58046fa2017-07-05 16:55:00 -0700186
You Wangf9d95be2018-08-01 14:35:37 -0700187 def killingAllAtomix( self, cluster, killRemoveMax, stopAtomix ):
188 """
189 Description:
190 killing atomix. It will either kill the current runningnodes or
191 max number of the nodes.
192 Required:
193 * cluster - the cluster driver that will be used.
194 * killRemoveMax - The boolean that will decide either to kill
195 only running nodes ( False ) or max number of nodes ( True ).
196 * stopAtomix - If wish to stop atomix before killing it. True for
197 enable stop, False for disable stop.
198 Returns:
199 Returns main.TRUE if successfully killing it.
200 """
201 main.log.info( "Safety check, killing all Atomix processes" )
202 return cluster.killAtomix( killRemoveMax, stopAtomix )
203
Devin Lim142b5342017-07-20 15:22:39 -0700204 def killingAllOnos( self, cluster, killRemoveMax, stopOnos ):
205 """
206 Description:
207 killing the onos. It will either kill the current runningnodes or
208 max number of the nodes.
209 Required:
210 * cluster - the cluster driver that will be used.
211 * killRemoveMax - The boolean that will decide either to kill
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700212 only running nodes ( False ) or max number of nodes ( True ).
Devin Lim142b5342017-07-20 15:22:39 -0700213 * stopOnos - If wish to stop onos before killing it. True for
You Wangf9d95be2018-08-01 14:35:37 -0700214 enable stop, False for disable stop.
Devin Lim142b5342017-07-20 15:22:39 -0700215 Returns:
216 Returns main.TRUE if successfully killing it.
217 """
218 main.log.info( "Safety check, killing all ONOS processes" )
You Wangf9d95be2018-08-01 14:35:37 -0700219 return cluster.killOnos( killRemoveMax, stopOnos )
Devin Lim58046fa2017-07-05 16:55:00 -0700220
You Wang09b596b2018-01-10 10:42:38 -0800221 def createApplyCell( self, cluster, newCell, cellName, cellApps,
Jon Hall3e6edb32018-08-21 16:20:30 -0700222 mininetIp, useSSH, onosIps, installMax=False,
223 atomixClusterSize=None ):
Devin Lim142b5342017-07-20 15:22:39 -0700224 """
225 Description:
226 create new cell ( optional ) and apply it. It will also verify the
227 cell.
Jon Hall3e6edb32018-08-21 16:20:30 -0700228 Required Arguments:
Devin Lim142b5342017-07-20 15:22:39 -0700229 * cluster - the cluster driver that will be used.
230 * newCell - True for making a new cell and False for not making it.
231 * cellName - The name of the cell.
You Wang09b596b2018-01-10 10:42:38 -0800232 * cellApps - The onos apps string.
You Wanga0f6ff62018-01-11 15:46:30 -0800233 * mininetIp - Mininet IP address.
Devin Lim142b5342017-07-20 15:22:39 -0700234 * useSSH - True for using ssh when creating a cell
Jon Hall3e6edb32018-08-21 16:20:30 -0700235 * onosIps - ip( s ) of the ONOS node( s ).
236 Optional Arguments:
237 * installMax
238 * atomixClusterSize - The size of the atomix cluster. Defaults to same
239 as ONOS Cluster size
Devin Lim142b5342017-07-20 15:22:39 -0700240 Returns:
241 Returns main.TRUE if it successfully executed.
242 """
Jon Hall3e6edb32018-08-21 16:20:30 -0700243 if atomixClusterSize is None:
244 atomixClusterSize = len( cluster.runningNodes )
245 atomixClusterSize = int( atomixClusterSize )
246 cluster.setAtomixNodes( atomixClusterSize )
247 atomixIps = [ node.ipAddress for node in cluster.atomixNodes ]
248 main.log.info( "Atomix Cluster Size = {} ".format( atomixClusterSize ) )
Devin Lim58046fa2017-07-05 16:55:00 -0700249 if newCell:
Jon Hall3e6edb32018-08-21 16:20:30 -0700250 cluster.createCell( cellName, cellApps, mininetIp, useSSH, onosIps,
251 atomixIps, installMax )
Devin Lim58046fa2017-07-05 16:55:00 -0700252 main.step( "Apply cell to environment" )
Devin Lim142b5342017-07-20 15:22:39 -0700253 stepResult = cluster.applyCell( cellName )
Devin Lim58046fa2017-07-05 16:55:00 -0700254 utilities.assert_equals( expect=main.TRUE,
255 actual=stepResult,
256 onpass="Successfully applied cell to " +
257 "environment",
Devin Lim142b5342017-07-20 15:22:39 -0700258 onfail="Failed to apply cell to environment" )
Devin Lim58046fa2017-07-05 16:55:00 -0700259 return stepResult
260
You Wangf9d95be2018-08-01 14:35:37 -0700261 def uninstallAtomix( self, cluster, uninstallMax ):
262 """
263 Description:
264 uninstalling atomix and verify the result.
265 Required:
266 * cluster - a cluster driver that will be used.
267 * uninstallMax - True for uninstalling max number of nodes
Jon Hall3e6edb32018-08-21 16:20:30 -0700268 False for uninstalling the current running nodes.
You Wangf9d95be2018-08-01 14:35:37 -0700269 Returns:
270 Returns main.TRUE if it successfully uninstalled.
271 """
272 main.step( "Uninstalling Atomix" )
273 atomixUninstallResult = cluster.uninstallAtomix( uninstallMax )
274 utilities.assert_equals( expect=main.TRUE,
275 actual=atomixUninstallResult,
276 onpass="Successfully uninstalled Atomix",
277 onfail="Failed to uninstall Atomix" )
278 return atomixUninstallResult
279
Devin Lim142b5342017-07-20 15:22:39 -0700280 def uninstallOnos( self, cluster, uninstallMax ):
281 """
282 Description:
283 uninstalling onos and verify the result.
284 Required:
285 * cluster - a cluster driver that will be used.
286 * uninstallMax - True for uninstalling max number of nodes
287 False for uninstalling the current running nodes.
288 Returns:
289 Returns main.TRUE if it successfully uninstalled.
290 """
Devin Lim58046fa2017-07-05 16:55:00 -0700291 main.step( "Uninstalling ONOS package" )
You Wangf9d95be2018-08-01 14:35:37 -0700292 onosUninstallResult = cluster.uninstallOnos( uninstallMax )
Devin Lim58046fa2017-07-05 16:55:00 -0700293 utilities.assert_equals( expect=main.TRUE,
294 actual=onosUninstallResult,
295 onpass="Successfully uninstalled ONOS package",
296 onfail="Failed to uninstall ONOS package" )
297 return onosUninstallResult
298
Devin Lim142b5342017-07-20 15:22:39 -0700299 def buildOnos( self, cluster ):
300 """
301 Description:
You Wangd54c7052018-08-07 16:06:27 -0700302 build the onos using bazel build onos and verify the result
Devin Lim142b5342017-07-20 15:22:39 -0700303 Required:
304 * cluster - the cluster driver that will be used.
305 Returns:
306 Returns main.TRUE if it successfully built.
307 """
Devin Lim58046fa2017-07-05 16:55:00 -0700308 main.step( "Creating ONOS package" )
You Wangd54c7052018-08-07 16:06:27 -0700309 packageResult = main.ONOSbench.bazelBuild()
Devin Lim58046fa2017-07-05 16:55:00 -0700310 utilities.assert_equals( expect=main.TRUE,
311 actual=packageResult,
312 onpass="Successfully created ONOS package",
313 onfail="Failed to create ONOS package" )
You Wang8f5ff152019-02-28 11:35:25 -0800314 if not packageResult:
315 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700316 return packageResult
317
Jon Hall3e6edb32018-08-21 16:20:30 -0700318 def installAtomix( self, cluster, parallel=True ):
You Wangf9d95be2018-08-01 14:35:37 -0700319 """
320 Description:
321 Installing atomix and verify the result
322 Required:
323 * cluster - the cluster driver that will be used.
You Wangf9d95be2018-08-01 14:35:37 -0700324 False for installing current running nodes only.
325 Returns:
326 Returns main.TRUE if it successfully installed
327 """
328 main.step( "Installing Atomix" )
329 atomixInstallResult = main.TRUE
330
Jon Hallb685a1c2018-10-30 15:17:01 -0700331 atomixInstallResult = cluster.installAtomix( parallel )
You Wangf9d95be2018-08-01 14:35:37 -0700332 utilities.assert_equals( expect=main.TRUE,
333 actual=atomixInstallResult,
334 onpass="Successfully installed Atomix",
335 onfail="Failed to install Atomix" )
336 if not atomixInstallResult:
337 main.cleanAndExit()
338 return atomixInstallResult
339
Devin Lime9f0ccf2017-08-11 17:25:12 -0700340 def installOnos( self, cluster, installMax, parallel=True ):
Devin Lim142b5342017-07-20 15:22:39 -0700341 """
342 Description:
343 Installing onos and verify the result
344 Required:
345 * cluster - the cluster driver that will be used.
346 * installMax - True for installing max number of nodes
347 False for installing current running nodes only.
348 Returns:
349 Returns main.TRUE if it successfully installed
350 """
Devin Lim58046fa2017-07-05 16:55:00 -0700351 main.step( "Installing ONOS package" )
352 onosInstallResult = main.TRUE
353
You Wangf9d95be2018-08-01 14:35:37 -0700354 cluster.installOnos( installMax, parallel )
Devin Lim58046fa2017-07-05 16:55:00 -0700355 utilities.assert_equals( expect=main.TRUE,
356 actual=onosInstallResult,
357 onpass="Successfully installed ONOS package",
358 onfail="Failed to install ONOS package" )
359 if not onosInstallResult:
Devin Lim44075962017-08-11 10:56:37 -0700360 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700361 return onosInstallResult
362
Devin Lim142b5342017-07-20 15:22:39 -0700363 def setupSsh( self, cluster ):
364 """
365 Description:
366 set up ssh to the onos and verify the result
367 Required:
368 * cluster - the cluster driver that will be used.
369 Returns:
370 Returns main.TRUE if it successfully setup the ssh to
371 the onos.
372 """
Devin Lim58046fa2017-07-05 16:55:00 -0700373 main.step( "Set up ONOS secure SSH" )
Devin Lim142b5342017-07-20 15:22:39 -0700374 secureSshResult = cluster.ssh()
Devin Lim58046fa2017-07-05 16:55:00 -0700375 utilities.assert_equals( expect=main.TRUE,
376 actual=secureSshResult,
Jon Hall3e6edb32018-08-21 16:20:30 -0700377 onpass="Secured ONOS ssh",
378 onfail="Failed to secure ssh" )
Devin Lim58046fa2017-07-05 16:55:00 -0700379 return secureSshResult
380
Devin Lim142b5342017-07-20 15:22:39 -0700381 def checkOnosService( self, cluster ):
382 """
383 Description:
384 Checking if the onos service is up and verify the result
385 Required:
386 * cluster - the cluster driver that will be used.
387 Returns:
388 Returns main.TRUE if it successfully checked
389 """
390 main.step( "Checking ONOS service" )
391 stepResult = cluster.checkService()
Devin Lim58046fa2017-07-05 16:55:00 -0700392 utilities.assert_equals( expect=main.TRUE,
393 actual=stepResult,
394 onpass="ONOS service is ready on all nodes",
395 onfail="ONOS service did not start properly on all nodes" )
396 return stepResult
397
Jon Hallca319892017-06-15 15:25:22 -0700398 def startOnosClis( self, cluster ):
Devin Lim142b5342017-07-20 15:22:39 -0700399 """
400 Description:
401 starting Onos using onosCli driver and verify the result
402 Required:
403 * cluster - the cluster driver that will be used.
404 Returns:
405 Returns main.TRUE if it successfully started. It will exit
406 the test if not started properly.
407 """
Devin Lim58046fa2017-07-05 16:55:00 -0700408 main.step( "Starting ONOS CLI sessions" )
Jon Hallca319892017-06-15 15:25:22 -0700409 startCliResult = cluster.startCLIs()
Devin Lim58046fa2017-07-05 16:55:00 -0700410 if not startCliResult:
411 main.log.info( "ONOS CLI did not start up properly" )
Devin Lim44075962017-08-11 10:56:37 -0700412 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700413 else:
414 main.log.info( "Successful CLI startup" )
415 utilities.assert_equals( expect=main.TRUE,
416 actual=startCliResult,
417 onpass="Successfully start ONOS cli",
418 onfail="Failed to start ONOS cli" )
419 return startCliResult
420
You Wang0d9f2c02018-08-10 14:56:32 -0700421 def checkOnosNodes( self, cluster ):
422 """
423 Description:
424 Checking if the onos nodes are in READY state
425 Required:
426 * cluster - the cluster driver that will be used.
427 Returns:
428 Returns main.TRUE if it successfully checked
429 """
430 main.step( "Checking ONOS nodes" )
431 stepResult = utilities.retry( main.Cluster.nodesCheck,
432 False,
You Wang07831cb2018-09-04 12:18:04 -0700433 attempts=90 )
You Wang0d9f2c02018-08-10 14:56:32 -0700434
435 utilities.assert_equals( expect=True,
436 actual=stepResult,
437 onpass="All ONOS nodes are in READY state",
438 onfail="Not all ONOS nodes are in READY state" )
439
440 if not stepResult:
441 for ctrl in main.Cluster.active():
442 main.log.debug( "{} components not ACTIVE: \n{}".format(
443 ctrl.name,
Jon Hall6c9e2da2018-11-06 12:01:23 -0800444 ctrl.CLI.sendline( "onos:scr-list | grep -v ACTIVE" ) ) ) #FIXME: This output has changed a lot
You Wang0d9f2c02018-08-10 14:56:32 -0700445 main.log.error( "Failed to start ONOS, stopping test" )
You Wang7880b372019-02-27 16:50:47 -0800446 main.cleanAndExit( msg="Failed to start ONOS: not all nodes are in READY state" )
You Wangba973f02018-08-30 12:33:41 -0700447 return main.TRUE
You Wang0d9f2c02018-08-10 14:56:32 -0700448
449 def checkOnosApps( self, cluster, apps ):
450 """
451 Description:
452 Checking if the onos applications are activated
453 Required:
454 * cluster - the cluster driver that will be used.
455 * apps: list of applications that are expected to be activated
456 Returns:
457 Returns main.TRUE if it successfully checked
458 """
459 main.step( "Checking ONOS applications" )
460 stepResult = utilities.retry( main.Cluster.appsCheck,
461 False,
462 args = [ apps ],
463 sleep=5,
Jon Hall3e6edb32018-08-21 16:20:30 -0700464 attempts=90 )
You Wang0d9f2c02018-08-10 14:56:32 -0700465
466 utilities.assert_equals( expect=True,
467 actual=stepResult,
468 onpass="All ONOS apps are activated",
469 onfail="Not all ONOS apps are activated" )
470
471 return main.TRUE if stepResult else main.FALSE
472
Jon Hall4f360bc2017-09-07 10:19:52 -0700473 def processList( self, functions, args ):
474 if functions is not None:
475 if isinstance( functions, list ):
476 i = 0
477 for f in functions:
478 f( *( args[ i ] ) ) if args is not None and args[ i ] is not None else f()
479 i += 1
480 else:
481 functions( *args ) if args is not None else functions()
482
You Wangb1665b52019-02-01 15:49:48 -0800483 def ONOSSetUp( self, cluster, hasMultiNodeRounds=False, startOnosCli=True, newCell=True,
You Wangcdc51fe2018-08-12 17:14:56 -0700484 cellName="temp", cellApps="drivers", appPrefix="org.onosproject.",
Jon Hall3e6edb32018-08-21 16:20:30 -0700485 mininetIp="", extraApply=None, applyArgs=None,
486 extraClean=None, cleanArgs=None, skipPack=False, installMax=False,
487 atomixClusterSize=None, useSSH=True, killRemoveMax=True, stopAtomix=False,
488 stopOnos=False, installParallel=True, cellApply=True,
You Wangdbb95d62018-09-05 15:58:08 -0700489 includeCaseDesc=True, restartCluster=True ):
Devin Lim142b5342017-07-20 15:22:39 -0700490 """
491 Description:
492 Initial ONOS setting up of the tests. It will also verify the result of each steps.
493 The procedures will be:
494 killing onos
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700495 creating ( optional ) /applying cell
496 removing raft logs ( optional )
Devin Lim142b5342017-07-20 15:22:39 -0700497 uninstalling onos
498 extra procedure to be applied( optional )
499 building onos
500 installing onos
501 extra cleanup to be applied ( optional )
502 setting up ssh to the onos
503 checking the onos service
504 starting onos
Jon Hall3e6edb32018-08-21 16:20:30 -0700505 Required Arguments:
Devin Lim142b5342017-07-20 15:22:39 -0700506 * cluster - the cluster driver that will be used.
Jon Hall3e6edb32018-08-21 16:20:30 -0700507 Optional Arguments:
508 * hasMultiNodeRounds - True if the test is testing different set of nodes
You Wangb1665b52019-02-01 15:49:48 -0800509 * startOnosCli - True if wish to start onos CLI.
Devin Lim142b5342017-07-20 15:22:39 -0700510 * newCell - True for making a new cell and False for not making it.
511 * cellName - Name of the cell that will be used.
You Wang0d9f2c02018-08-10 14:56:32 -0700512 * cellApps - The cell apps string. Will be overwritten by main.apps if it exists
You Wangcdc51fe2018-08-12 17:14:56 -0700513 * appPrefix - Prefix of app names. Will use "org.onosproject." by default
You Wanga0f6ff62018-01-11 15:46:30 -0800514 * mininetIp - Mininet IP address.
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700515 * extraApply - Function( s ) that will be called before building ONOS. Default to None.
516 * applyArgs - argument of the functon( s ) of the extraApply. Should be in list.
517 * extraClean - Function( s ) that will be called after building ONOS. Defaults to None.
518 * cleanArgs - argument of the functon( s ) of the extraClean. Should be in list.
Devin Lim142b5342017-07-20 15:22:39 -0700519 * skipPack - True if wish to skip some packing.
520 * installMax - True if wish to install onos max number of nodes
Jon Hall3e6edb32018-08-21 16:20:30 -0700521 False if wish to install onos of running nodes only
522 * atomixClusterSize - The number of Atomix nodes in the cluster.
523 Defaults to None which will be the number of OC# nodes in the cell
Devin Lim142b5342017-07-20 15:22:39 -0700524 * useSSH - True for using ssh when creating a cell
525 * killRemoveMax - True for removing/killing max number of nodes. False for
Jon Hall3e6edb32018-08-21 16:20:30 -0700526 removing/killing running nodes only.
You Wangf9d95be2018-08-01 14:35:37 -0700527 * stopAtomix - True if wish to stop atomix before killing it.
Devin Lim142b5342017-07-20 15:22:39 -0700528 * stopOnos - True if wish to stop onos before killing it.
You Wangdbb95d62018-09-05 15:58:08 -0700529 * restartCluster - True if wish to kill and restart atomix and onos clusters
Devin Lim142b5342017-07-20 15:22:39 -0700530 Returns:
531 Returns main.TRUE if it everything successfully proceeded.
532 """
533 self.setNumCtrls( hasMultiNodeRounds )
Devin Lim0c972b72018-02-08 14:53:59 -0800534 if includeCaseDesc:
535 main.case( "Starting up " + str( cluster.numCtrls ) +
536 " node(s) ONOS cluster" )
537 main.caseExplanation = "Set up ONOS with " + str( cluster.numCtrls ) + \
538 " node(s) ONOS cluster"
Devin Lim58046fa2017-07-05 16:55:00 -0700539
Jon Hall3e6edb32018-08-21 16:20:30 -0700540 main.log.info( "ONOS cluster size = " + str( cluster.numCtrls ) )
Devin Lim142b5342017-07-20 15:22:39 -0700541 cellResult = main.TRUE
Devin Lim6437c9c2018-01-29 17:24:16 -0800542 if cellApply:
You Wang0d9f2c02018-08-10 14:56:32 -0700543 try:
544 apps = main.apps
545 except ( NameError, AttributeError ):
546 apps = cellApps
547 main.log.debug( "Apps: " + str( apps ) )
Devin Lim142b5342017-07-20 15:22:39 -0700548 tempOnosIp = []
549 for ctrl in cluster.runningNodes:
550 tempOnosIp.append( ctrl.ipAddress )
You Wanga0f6ff62018-01-11 15:46:30 -0800551 if mininetIp == "":
552 mininetIp = "localhost"
553 for key, value in main.componentDictionary.items():
554 if value['type'] in ['MininetCliDriver', 'RemoteMininetDriver'] and hasattr( main, key ):
555 mininetIp = getattr( main, key ).ip_address
556 break
Devin Lim142b5342017-07-20 15:22:39 -0700557 cellResult = self.createApplyCell( cluster, newCell,
You Wang0d9f2c02018-08-10 14:56:32 -0700558 cellName, apps,
You Wanga0f6ff62018-01-11 15:46:30 -0800559 mininetIp, useSSH,
Jon Hall3e6edb32018-08-21 16:20:30 -0700560 tempOnosIp, installMax,
561 atomixClusterSize )
Devin Lim58046fa2017-07-05 16:55:00 -0700562
You Wangdbb95d62018-09-05 15:58:08 -0700563 if restartCluster:
564 atomixKillResult = self.killingAllAtomix( cluster, killRemoveMax, stopAtomix )
565 onosKillResult = self.killingAllOnos( cluster, killRemoveMax, stopOnos )
566 killResult = atomixKillResult and onosKillResult
567 else:
568 killResult = main.TRUE
You Wang4cc61912018-08-28 10:10:58 -0700569
You Wangdbb95d62018-09-05 15:58:08 -0700570 if restartCluster:
571 atomixUninstallResult = self.uninstallAtomix( cluster, killRemoveMax )
572 onosUninstallResult = self.uninstallOnos( cluster, killRemoveMax )
573 uninstallResult = atomixUninstallResult and onosUninstallResult
574 self.processList( extraApply, applyArgs )
Devin Lim6437c9c2018-01-29 17:24:16 -0800575
You Wangdbb95d62018-09-05 15:58:08 -0700576 packageResult = main.TRUE
577 if not skipPack:
578 packageResult = self.buildOnos(cluster)
Devin Lim142b5342017-07-20 15:22:39 -0700579
You Wangdbb95d62018-09-05 15:58:08 -0700580 atomixInstallResult = self.installAtomix( cluster, installParallel )
581 onosInstallResult = self.installOnos( cluster, installMax, installParallel )
582 installResult = atomixInstallResult and onosInstallResult
Devin Lim58046fa2017-07-05 16:55:00 -0700583
You Wangdbb95d62018-09-05 15:58:08 -0700584 self.processList( extraClean, cleanArgs )
585 secureSshResult = self.setupSsh( cluster )
586 else:
587 packageResult = main.TRUE
588 uninstallResult = main.TRUE
589 installResult = main.TRUE
590 secureSshResult = main.TRUE
Devin Lim58046fa2017-07-05 16:55:00 -0700591
Devin Lim142b5342017-07-20 15:22:39 -0700592 onosServiceResult = self.checkOnosService( cluster )
Devin Lim58046fa2017-07-05 16:55:00 -0700593
You Wang4cc61912018-08-28 10:10:58 -0700594 onosCliResult = main.TRUE
You Wangb1665b52019-02-01 15:49:48 -0800595 if startOnosCli:
Jon Hallca319892017-06-15 15:25:22 -0700596 onosCliResult = self.startOnosClis( cluster )
Devin Lim58046fa2017-07-05 16:55:00 -0700597
You Wang0d9f2c02018-08-10 14:56:32 -0700598 onosNodesResult = self.checkOnosNodes( cluster )
599
600 onosAppsResult = main.TRUE
601 if cellApply:
602 if apps:
603 apps = apps.split( ',' )
You Wangcdc51fe2018-08-12 17:14:56 -0700604 apps = [ appPrefix + app for app in apps ]
You Wang0d9f2c02018-08-10 14:56:32 -0700605 onosAppsResult = self.checkOnosApps( cluster, apps )
606 else:
607 main.log.warn( "No apps were specified to be checked after startup" )
608
Jon Hall43060f62020-06-23 13:13:33 -0700609 externalAppsResult = main.TRUE
610 if main.params.get( 'EXTERNAL_APPS' ):
611 for app, url in main.params[ 'EXTERNAL_APPS' ].iteritems():
612 path, fileName = os.path.split( url )
613 main.ONOSbench.onosApp( main.Cluster.controllers[0].ipAddress, "install!", fileName )
614
You Wangf9d95be2018-08-01 14:35:37 -0700615 return killResult and cellResult and packageResult and uninstallResult and \
You Wang0d9f2c02018-08-10 14:56:32 -0700616 installResult and secureSshResult and onosServiceResult and onosCliResult and \
617 onosNodesResult and onosAppsResult