blob: ad2de22c58e2d88928aa177b3c7cf0b9d52d3501 [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
Jon Hallf2527902020-07-30 12:56:08 -0700133 if main.params[ 'GRAPH' ].get('jobName'):
134 url = self.generateGraphURL( testname=main.params[ 'GRAPH' ][ 'jobName' ] )
135 else:
136 url = self.generateGraphURL()
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800137 main.log.wiki( url )
138
Devin Lim58046fa2017-07-05 16:55:00 -0700139 main.commit = main.ONOSbench.getVersion( report=True )
140
Jon Hallf2527902020-07-30 12:56:08 -0700141 def generateGraphURL( self, testname=main.TEST, width=525, height=350 ):
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800142 """
143 Description:
144 Obtain the URL for the graph that corresponds to the test being run.
145 """
146
147 nodeCluster = main.params[ 'GRAPH' ][ 'nodeCluster' ]
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800148 branch = main.ONOSbench.getBranchName()
149 maxBuildsToShow = main.params[ 'GRAPH' ][ 'builds' ]
150
151 return '<ac:structured-macro ac:name="html">\n' + \
152 '<ac:plain-text-body><![CDATA[\n' + \
Devin Limd1fb8e92018-02-28 16:29:33 -0800153 '<img src="https://jenkins.onosproject.org/view/QA/job/postjob-' + \
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800154 nodeCluster + \
155 '/lastSuccessfulBuild/artifact/' + \
156 testname + \
157 '_' + \
158 branch + \
159 '_' + \
160 maxBuildsToShow + \
161 '-builds_graph.jpg", alt="' + \
162 testname + \
163 '", style="width:' + \
164 str( width ) + \
165 'px;height:' + \
166 str( height ) + \
167 'px;border:0"' + \
168 '>' + \
169 ']]></ac:plain-text-body>\n' + \
170 '</ac:structured-macro>\n'
171
Devin Lim142b5342017-07-20 15:22:39 -0700172 def setNumCtrls( self, hasMultiNodeRounds ):
173 """
174 Description:
Jon Hall3e6edb32018-08-21 16:20:30 -0700175 Set new number of controllers if it uses different number of nodes.
Devin Lim142b5342017-07-20 15:22:39 -0700176 different number of nodes should be pre-defined in main.scale.
177 Required:
178 * hasMultiNodeRouds - if the test is testing different number of nodes.
179 """
Devin Lim58046fa2017-07-05 16:55:00 -0700180 if hasMultiNodeRounds:
181 try:
182 main.cycle
183 except Exception:
184 main.cycle = 0
185 main.cycle += 1
Jon Hall3e6edb32018-08-21 16:20:30 -0700186 # main.scale[ 0 ] determines the current number of ONOS controllers
Devin Lim142b5342017-07-20 15:22:39 -0700187 main.Cluster.setRunningNode( int( main.scale.pop( 0 ) ) )
Devin Lim58046fa2017-07-05 16:55:00 -0700188
You Wangf9d95be2018-08-01 14:35:37 -0700189 def killingAllAtomix( self, cluster, killRemoveMax, stopAtomix ):
190 """
191 Description:
192 killing atomix. It will either kill the current runningnodes or
193 max number of the nodes.
194 Required:
195 * cluster - the cluster driver that will be used.
196 * killRemoveMax - The boolean that will decide either to kill
197 only running nodes ( False ) or max number of nodes ( True ).
198 * stopAtomix - If wish to stop atomix before killing it. True for
199 enable stop, False for disable stop.
200 Returns:
201 Returns main.TRUE if successfully killing it.
202 """
203 main.log.info( "Safety check, killing all Atomix processes" )
204 return cluster.killAtomix( killRemoveMax, stopAtomix )
205
Devin Lim142b5342017-07-20 15:22:39 -0700206 def killingAllOnos( self, cluster, killRemoveMax, stopOnos ):
207 """
208 Description:
209 killing the onos. It will either kill the current runningnodes or
210 max number of the nodes.
211 Required:
212 * cluster - the cluster driver that will be used.
213 * killRemoveMax - The boolean that will decide either to kill
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700214 only running nodes ( False ) or max number of nodes ( True ).
Devin Lim142b5342017-07-20 15:22:39 -0700215 * stopOnos - If wish to stop onos before killing it. True for
You Wangf9d95be2018-08-01 14:35:37 -0700216 enable stop, False for disable stop.
Devin Lim142b5342017-07-20 15:22:39 -0700217 Returns:
218 Returns main.TRUE if successfully killing it.
219 """
220 main.log.info( "Safety check, killing all ONOS processes" )
You Wangf9d95be2018-08-01 14:35:37 -0700221 return cluster.killOnos( killRemoveMax, stopOnos )
Devin Lim58046fa2017-07-05 16:55:00 -0700222
You Wang09b596b2018-01-10 10:42:38 -0800223 def createApplyCell( self, cluster, newCell, cellName, cellApps,
Jon Hall3e6edb32018-08-21 16:20:30 -0700224 mininetIp, useSSH, onosIps, installMax=False,
225 atomixClusterSize=None ):
Devin Lim142b5342017-07-20 15:22:39 -0700226 """
227 Description:
228 create new cell ( optional ) and apply it. It will also verify the
229 cell.
Jon Hall3e6edb32018-08-21 16:20:30 -0700230 Required Arguments:
Devin Lim142b5342017-07-20 15:22:39 -0700231 * cluster - the cluster driver that will be used.
232 * newCell - True for making a new cell and False for not making it.
233 * cellName - The name of the cell.
You Wang09b596b2018-01-10 10:42:38 -0800234 * cellApps - The onos apps string.
You Wanga0f6ff62018-01-11 15:46:30 -0800235 * mininetIp - Mininet IP address.
Devin Lim142b5342017-07-20 15:22:39 -0700236 * useSSH - True for using ssh when creating a cell
Jon Hall3e6edb32018-08-21 16:20:30 -0700237 * onosIps - ip( s ) of the ONOS node( s ).
238 Optional Arguments:
239 * installMax
240 * atomixClusterSize - The size of the atomix cluster. Defaults to same
241 as ONOS Cluster size
Devin Lim142b5342017-07-20 15:22:39 -0700242 Returns:
243 Returns main.TRUE if it successfully executed.
244 """
Jon Hall3e6edb32018-08-21 16:20:30 -0700245 if atomixClusterSize is None:
246 atomixClusterSize = len( cluster.runningNodes )
247 atomixClusterSize = int( atomixClusterSize )
248 cluster.setAtomixNodes( atomixClusterSize )
249 atomixIps = [ node.ipAddress for node in cluster.atomixNodes ]
250 main.log.info( "Atomix Cluster Size = {} ".format( atomixClusterSize ) )
Devin Lim58046fa2017-07-05 16:55:00 -0700251 if newCell:
Jon Hall3e6edb32018-08-21 16:20:30 -0700252 cluster.createCell( cellName, cellApps, mininetIp, useSSH, onosIps,
253 atomixIps, installMax )
Devin Lim58046fa2017-07-05 16:55:00 -0700254 main.step( "Apply cell to environment" )
Devin Lim142b5342017-07-20 15:22:39 -0700255 stepResult = cluster.applyCell( cellName )
Devin Lim58046fa2017-07-05 16:55:00 -0700256 utilities.assert_equals( expect=main.TRUE,
257 actual=stepResult,
258 onpass="Successfully applied cell to " +
259 "environment",
Devin Lim142b5342017-07-20 15:22:39 -0700260 onfail="Failed to apply cell to environment" )
Devin Lim58046fa2017-07-05 16:55:00 -0700261 return stepResult
262
You Wangf9d95be2018-08-01 14:35:37 -0700263 def uninstallAtomix( self, cluster, uninstallMax ):
264 """
265 Description:
266 uninstalling atomix and verify the result.
267 Required:
268 * cluster - a cluster driver that will be used.
269 * uninstallMax - True for uninstalling max number of nodes
Jon Hall3e6edb32018-08-21 16:20:30 -0700270 False for uninstalling the current running nodes.
You Wangf9d95be2018-08-01 14:35:37 -0700271 Returns:
272 Returns main.TRUE if it successfully uninstalled.
273 """
274 main.step( "Uninstalling Atomix" )
275 atomixUninstallResult = cluster.uninstallAtomix( uninstallMax )
276 utilities.assert_equals( expect=main.TRUE,
277 actual=atomixUninstallResult,
278 onpass="Successfully uninstalled Atomix",
279 onfail="Failed to uninstall Atomix" )
280 return atomixUninstallResult
281
Devin Lim142b5342017-07-20 15:22:39 -0700282 def uninstallOnos( self, cluster, uninstallMax ):
283 """
284 Description:
285 uninstalling onos and verify the result.
286 Required:
287 * cluster - a cluster driver that will be used.
288 * uninstallMax - True for uninstalling max number of nodes
289 False for uninstalling the current running nodes.
290 Returns:
291 Returns main.TRUE if it successfully uninstalled.
292 """
Devin Lim58046fa2017-07-05 16:55:00 -0700293 main.step( "Uninstalling ONOS package" )
You Wangf9d95be2018-08-01 14:35:37 -0700294 onosUninstallResult = cluster.uninstallOnos( uninstallMax )
Devin Lim58046fa2017-07-05 16:55:00 -0700295 utilities.assert_equals( expect=main.TRUE,
296 actual=onosUninstallResult,
297 onpass="Successfully uninstalled ONOS package",
298 onfail="Failed to uninstall ONOS package" )
299 return onosUninstallResult
300
Devin Lim142b5342017-07-20 15:22:39 -0700301 def buildOnos( self, cluster ):
302 """
303 Description:
You Wangd54c7052018-08-07 16:06:27 -0700304 build the onos using bazel build onos and verify the result
Devin Lim142b5342017-07-20 15:22:39 -0700305 Required:
306 * cluster - the cluster driver that will be used.
307 Returns:
308 Returns main.TRUE if it successfully built.
309 """
Devin Lim58046fa2017-07-05 16:55:00 -0700310 main.step( "Creating ONOS package" )
You Wangd54c7052018-08-07 16:06:27 -0700311 packageResult = main.ONOSbench.bazelBuild()
Devin Lim58046fa2017-07-05 16:55:00 -0700312 utilities.assert_equals( expect=main.TRUE,
313 actual=packageResult,
314 onpass="Successfully created ONOS package",
315 onfail="Failed to create ONOS package" )
You Wang8f5ff152019-02-28 11:35:25 -0800316 if not packageResult:
317 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700318 return packageResult
319
Jon Hall3e6edb32018-08-21 16:20:30 -0700320 def installAtomix( self, cluster, parallel=True ):
You Wangf9d95be2018-08-01 14:35:37 -0700321 """
322 Description:
323 Installing atomix and verify the result
324 Required:
325 * cluster - the cluster driver that will be used.
You Wangf9d95be2018-08-01 14:35:37 -0700326 False for installing current running nodes only.
327 Returns:
328 Returns main.TRUE if it successfully installed
329 """
330 main.step( "Installing Atomix" )
331 atomixInstallResult = main.TRUE
332
Jon Hallb685a1c2018-10-30 15:17:01 -0700333 atomixInstallResult = cluster.installAtomix( parallel )
You Wangf9d95be2018-08-01 14:35:37 -0700334 utilities.assert_equals( expect=main.TRUE,
335 actual=atomixInstallResult,
336 onpass="Successfully installed Atomix",
337 onfail="Failed to install Atomix" )
338 if not atomixInstallResult:
339 main.cleanAndExit()
340 return atomixInstallResult
341
Devin Lime9f0ccf2017-08-11 17:25:12 -0700342 def installOnos( self, cluster, installMax, parallel=True ):
Devin Lim142b5342017-07-20 15:22:39 -0700343 """
344 Description:
345 Installing onos and verify the result
346 Required:
347 * cluster - the cluster driver that will be used.
348 * installMax - True for installing max number of nodes
349 False for installing current running nodes only.
350 Returns:
351 Returns main.TRUE if it successfully installed
352 """
Devin Lim58046fa2017-07-05 16:55:00 -0700353 main.step( "Installing ONOS package" )
354 onosInstallResult = main.TRUE
355
You Wangf9d95be2018-08-01 14:35:37 -0700356 cluster.installOnos( installMax, parallel )
Devin Lim58046fa2017-07-05 16:55:00 -0700357 utilities.assert_equals( expect=main.TRUE,
358 actual=onosInstallResult,
359 onpass="Successfully installed ONOS package",
360 onfail="Failed to install ONOS package" )
361 if not onosInstallResult:
Devin Lim44075962017-08-11 10:56:37 -0700362 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700363 return onosInstallResult
364
Devin Lim142b5342017-07-20 15:22:39 -0700365 def setupSsh( self, cluster ):
366 """
367 Description:
368 set up ssh to the onos and verify the result
369 Required:
370 * cluster - the cluster driver that will be used.
371 Returns:
372 Returns main.TRUE if it successfully setup the ssh to
373 the onos.
374 """
Devin Lim58046fa2017-07-05 16:55:00 -0700375 main.step( "Set up ONOS secure SSH" )
Devin Lim142b5342017-07-20 15:22:39 -0700376 secureSshResult = cluster.ssh()
Devin Lim58046fa2017-07-05 16:55:00 -0700377 utilities.assert_equals( expect=main.TRUE,
378 actual=secureSshResult,
Jon Hall3e6edb32018-08-21 16:20:30 -0700379 onpass="Secured ONOS ssh",
380 onfail="Failed to secure ssh" )
Devin Lim58046fa2017-07-05 16:55:00 -0700381 return secureSshResult
382
Devin Lim142b5342017-07-20 15:22:39 -0700383 def checkOnosService( self, cluster ):
384 """
385 Description:
386 Checking if the onos service is up and verify the result
387 Required:
388 * cluster - the cluster driver that will be used.
389 Returns:
390 Returns main.TRUE if it successfully checked
391 """
392 main.step( "Checking ONOS service" )
393 stepResult = cluster.checkService()
Devin Lim58046fa2017-07-05 16:55:00 -0700394 utilities.assert_equals( expect=main.TRUE,
395 actual=stepResult,
396 onpass="ONOS service is ready on all nodes",
397 onfail="ONOS service did not start properly on all nodes" )
398 return stepResult
399
Jon Hallca319892017-06-15 15:25:22 -0700400 def startOnosClis( self, cluster ):
Devin Lim142b5342017-07-20 15:22:39 -0700401 """
402 Description:
403 starting Onos using onosCli driver and verify the result
404 Required:
405 * cluster - the cluster driver that will be used.
406 Returns:
407 Returns main.TRUE if it successfully started. It will exit
408 the test if not started properly.
409 """
Devin Lim58046fa2017-07-05 16:55:00 -0700410 main.step( "Starting ONOS CLI sessions" )
Jon Hallca319892017-06-15 15:25:22 -0700411 startCliResult = cluster.startCLIs()
Devin Lim58046fa2017-07-05 16:55:00 -0700412 if not startCliResult:
413 main.log.info( "ONOS CLI did not start up properly" )
Devin Lim44075962017-08-11 10:56:37 -0700414 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700415 else:
416 main.log.info( "Successful CLI startup" )
417 utilities.assert_equals( expect=main.TRUE,
418 actual=startCliResult,
419 onpass="Successfully start ONOS cli",
420 onfail="Failed to start ONOS cli" )
421 return startCliResult
422
You Wang0d9f2c02018-08-10 14:56:32 -0700423 def checkOnosNodes( self, cluster ):
424 """
425 Description:
426 Checking if the onos nodes are in READY state
427 Required:
428 * cluster - the cluster driver that will be used.
429 Returns:
430 Returns main.TRUE if it successfully checked
431 """
432 main.step( "Checking ONOS nodes" )
433 stepResult = utilities.retry( main.Cluster.nodesCheck,
434 False,
You Wang07831cb2018-09-04 12:18:04 -0700435 attempts=90 )
You Wang0d9f2c02018-08-10 14:56:32 -0700436
437 utilities.assert_equals( expect=True,
438 actual=stepResult,
439 onpass="All ONOS nodes are in READY state",
440 onfail="Not all ONOS nodes are in READY state" )
441
442 if not stepResult:
443 for ctrl in main.Cluster.active():
444 main.log.debug( "{} components not ACTIVE: \n{}".format(
445 ctrl.name,
Jon Hall6c9e2da2018-11-06 12:01:23 -0800446 ctrl.CLI.sendline( "onos:scr-list | grep -v ACTIVE" ) ) ) #FIXME: This output has changed a lot
You Wang0d9f2c02018-08-10 14:56:32 -0700447 main.log.error( "Failed to start ONOS, stopping test" )
You Wang7880b372019-02-27 16:50:47 -0800448 main.cleanAndExit( msg="Failed to start ONOS: not all nodes are in READY state" )
You Wangba973f02018-08-30 12:33:41 -0700449 return main.TRUE
You Wang0d9f2c02018-08-10 14:56:32 -0700450
451 def checkOnosApps( self, cluster, apps ):
452 """
453 Description:
454 Checking if the onos applications are activated
455 Required:
456 * cluster - the cluster driver that will be used.
457 * apps: list of applications that are expected to be activated
458 Returns:
459 Returns main.TRUE if it successfully checked
460 """
461 main.step( "Checking ONOS applications" )
462 stepResult = utilities.retry( main.Cluster.appsCheck,
463 False,
464 args = [ apps ],
465 sleep=5,
Jon Hall3e6edb32018-08-21 16:20:30 -0700466 attempts=90 )
You Wang0d9f2c02018-08-10 14:56:32 -0700467
468 utilities.assert_equals( expect=True,
469 actual=stepResult,
470 onpass="All ONOS apps are activated",
471 onfail="Not all ONOS apps are activated" )
472
473 return main.TRUE if stepResult else main.FALSE
474
Jon Hall4f360bc2017-09-07 10:19:52 -0700475 def processList( self, functions, args ):
476 if functions is not None:
477 if isinstance( functions, list ):
478 i = 0
479 for f in functions:
480 f( *( args[ i ] ) ) if args is not None and args[ i ] is not None else f()
481 i += 1
482 else:
483 functions( *args ) if args is not None else functions()
484
You Wangb1665b52019-02-01 15:49:48 -0800485 def ONOSSetUp( self, cluster, hasMultiNodeRounds=False, startOnosCli=True, newCell=True,
You Wangcdc51fe2018-08-12 17:14:56 -0700486 cellName="temp", cellApps="drivers", appPrefix="org.onosproject.",
Jon Hall3e6edb32018-08-21 16:20:30 -0700487 mininetIp="", extraApply=None, applyArgs=None,
488 extraClean=None, cleanArgs=None, skipPack=False, installMax=False,
489 atomixClusterSize=None, useSSH=True, killRemoveMax=True, stopAtomix=False,
490 stopOnos=False, installParallel=True, cellApply=True,
You Wangdbb95d62018-09-05 15:58:08 -0700491 includeCaseDesc=True, restartCluster=True ):
Devin Lim142b5342017-07-20 15:22:39 -0700492 """
493 Description:
494 Initial ONOS setting up of the tests. It will also verify the result of each steps.
495 The procedures will be:
496 killing onos
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700497 creating ( optional ) /applying cell
498 removing raft logs ( optional )
Devin Lim142b5342017-07-20 15:22:39 -0700499 uninstalling onos
500 extra procedure to be applied( optional )
501 building onos
502 installing onos
503 extra cleanup to be applied ( optional )
504 setting up ssh to the onos
505 checking the onos service
506 starting onos
Jon Hall3e6edb32018-08-21 16:20:30 -0700507 Required Arguments:
Devin Lim142b5342017-07-20 15:22:39 -0700508 * cluster - the cluster driver that will be used.
Jon Hall3e6edb32018-08-21 16:20:30 -0700509 Optional Arguments:
510 * hasMultiNodeRounds - True if the test is testing different set of nodes
You Wangb1665b52019-02-01 15:49:48 -0800511 * startOnosCli - True if wish to start onos CLI.
Devin Lim142b5342017-07-20 15:22:39 -0700512 * newCell - True for making a new cell and False for not making it.
513 * cellName - Name of the cell that will be used.
You Wang0d9f2c02018-08-10 14:56:32 -0700514 * cellApps - The cell apps string. Will be overwritten by main.apps if it exists
You Wangcdc51fe2018-08-12 17:14:56 -0700515 * appPrefix - Prefix of app names. Will use "org.onosproject." by default
You Wanga0f6ff62018-01-11 15:46:30 -0800516 * mininetIp - Mininet IP address.
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700517 * extraApply - Function( s ) that will be called before building ONOS. Default to None.
518 * applyArgs - argument of the functon( s ) of the extraApply. Should be in list.
519 * extraClean - Function( s ) that will be called after building ONOS. Defaults to None.
520 * cleanArgs - argument of the functon( s ) of the extraClean. Should be in list.
Devin Lim142b5342017-07-20 15:22:39 -0700521 * skipPack - True if wish to skip some packing.
522 * installMax - True if wish to install onos max number of nodes
Jon Hall3e6edb32018-08-21 16:20:30 -0700523 False if wish to install onos of running nodes only
524 * atomixClusterSize - The number of Atomix nodes in the cluster.
525 Defaults to None which will be the number of OC# nodes in the cell
Devin Lim142b5342017-07-20 15:22:39 -0700526 * useSSH - True for using ssh when creating a cell
527 * killRemoveMax - True for removing/killing max number of nodes. False for
Jon Hall3e6edb32018-08-21 16:20:30 -0700528 removing/killing running nodes only.
You Wangf9d95be2018-08-01 14:35:37 -0700529 * stopAtomix - True if wish to stop atomix before killing it.
Devin Lim142b5342017-07-20 15:22:39 -0700530 * stopOnos - True if wish to stop onos before killing it.
You Wangdbb95d62018-09-05 15:58:08 -0700531 * restartCluster - True if wish to kill and restart atomix and onos clusters
Devin Lim142b5342017-07-20 15:22:39 -0700532 Returns:
533 Returns main.TRUE if it everything successfully proceeded.
534 """
535 self.setNumCtrls( hasMultiNodeRounds )
Devin Lim0c972b72018-02-08 14:53:59 -0800536 if includeCaseDesc:
537 main.case( "Starting up " + str( cluster.numCtrls ) +
538 " node(s) ONOS cluster" )
539 main.caseExplanation = "Set up ONOS with " + str( cluster.numCtrls ) + \
540 " node(s) ONOS cluster"
Devin Lim58046fa2017-07-05 16:55:00 -0700541
Jon Hall3e6edb32018-08-21 16:20:30 -0700542 main.log.info( "ONOS cluster size = " + str( cluster.numCtrls ) )
Devin Lim142b5342017-07-20 15:22:39 -0700543 cellResult = main.TRUE
Devin Lim6437c9c2018-01-29 17:24:16 -0800544 if cellApply:
You Wang0d9f2c02018-08-10 14:56:32 -0700545 try:
546 apps = main.apps
547 except ( NameError, AttributeError ):
548 apps = cellApps
549 main.log.debug( "Apps: " + str( apps ) )
Devin Lim142b5342017-07-20 15:22:39 -0700550 tempOnosIp = []
551 for ctrl in cluster.runningNodes:
552 tempOnosIp.append( ctrl.ipAddress )
You Wanga0f6ff62018-01-11 15:46:30 -0800553 if mininetIp == "":
554 mininetIp = "localhost"
555 for key, value in main.componentDictionary.items():
556 if value['type'] in ['MininetCliDriver', 'RemoteMininetDriver'] and hasattr( main, key ):
557 mininetIp = getattr( main, key ).ip_address
558 break
Devin Lim142b5342017-07-20 15:22:39 -0700559 cellResult = self.createApplyCell( cluster, newCell,
You Wang0d9f2c02018-08-10 14:56:32 -0700560 cellName, apps,
You Wanga0f6ff62018-01-11 15:46:30 -0800561 mininetIp, useSSH,
Jon Hall3e6edb32018-08-21 16:20:30 -0700562 tempOnosIp, installMax,
563 atomixClusterSize )
Devin Lim58046fa2017-07-05 16:55:00 -0700564
You Wangdbb95d62018-09-05 15:58:08 -0700565 if restartCluster:
566 atomixKillResult = self.killingAllAtomix( cluster, killRemoveMax, stopAtomix )
567 onosKillResult = self.killingAllOnos( cluster, killRemoveMax, stopOnos )
568 killResult = atomixKillResult and onosKillResult
569 else:
570 killResult = main.TRUE
You Wang4cc61912018-08-28 10:10:58 -0700571
You Wangdbb95d62018-09-05 15:58:08 -0700572 if restartCluster:
573 atomixUninstallResult = self.uninstallAtomix( cluster, killRemoveMax )
574 onosUninstallResult = self.uninstallOnos( cluster, killRemoveMax )
575 uninstallResult = atomixUninstallResult and onosUninstallResult
576 self.processList( extraApply, applyArgs )
Devin Lim6437c9c2018-01-29 17:24:16 -0800577
You Wangdbb95d62018-09-05 15:58:08 -0700578 packageResult = main.TRUE
579 if not skipPack:
580 packageResult = self.buildOnos(cluster)
Devin Lim142b5342017-07-20 15:22:39 -0700581
You Wangdbb95d62018-09-05 15:58:08 -0700582 atomixInstallResult = self.installAtomix( cluster, installParallel )
583 onosInstallResult = self.installOnos( cluster, installMax, installParallel )
584 installResult = atomixInstallResult and onosInstallResult
Devin Lim58046fa2017-07-05 16:55:00 -0700585
You Wangdbb95d62018-09-05 15:58:08 -0700586 self.processList( extraClean, cleanArgs )
587 secureSshResult = self.setupSsh( cluster )
588 else:
589 packageResult = main.TRUE
590 uninstallResult = main.TRUE
591 installResult = main.TRUE
592 secureSshResult = main.TRUE
Devin Lim58046fa2017-07-05 16:55:00 -0700593
Devin Lim142b5342017-07-20 15:22:39 -0700594 onosServiceResult = self.checkOnosService( cluster )
Devin Lim58046fa2017-07-05 16:55:00 -0700595
You Wang4cc61912018-08-28 10:10:58 -0700596 onosCliResult = main.TRUE
You Wangb1665b52019-02-01 15:49:48 -0800597 if startOnosCli:
Jon Hallca319892017-06-15 15:25:22 -0700598 onosCliResult = self.startOnosClis( cluster )
Devin Lim58046fa2017-07-05 16:55:00 -0700599
You Wang0d9f2c02018-08-10 14:56:32 -0700600 onosNodesResult = self.checkOnosNodes( cluster )
601
602 onosAppsResult = main.TRUE
603 if cellApply:
604 if apps:
605 apps = apps.split( ',' )
You Wangcdc51fe2018-08-12 17:14:56 -0700606 apps = [ appPrefix + app for app in apps ]
You Wang0d9f2c02018-08-10 14:56:32 -0700607 onosAppsResult = self.checkOnosApps( cluster, apps )
608 else:
609 main.log.warn( "No apps were specified to be checked after startup" )
610
Jon Hall43060f62020-06-23 13:13:33 -0700611 externalAppsResult = main.TRUE
612 if main.params.get( 'EXTERNAL_APPS' ):
613 for app, url in main.params[ 'EXTERNAL_APPS' ].iteritems():
614 path, fileName = os.path.split( url )
615 main.ONOSbench.onosApp( main.Cluster.controllers[0].ipAddress, "install!", fileName )
616
You Wangf9d95be2018-08-01 14:35:37 -0700617 return killResult and cellResult and packageResult and uninstallResult and \
You Wang0d9f2c02018-08-10 14:56:32 -0700618 installResult and secureSshResult and onosServiceResult and onosCliResult and \
619 onosNodesResult and onosAppsResult