blob: fabfe9a0df038587de6a4f03f0d57ea07bf9fafd [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:
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 Hallaa1d9b82020-07-30 13:49:42 -0700119 def envSetupConclusion( 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
Jon Hallf2527902020-07-30 12:56:08 -0700132 if main.params[ 'GRAPH' ].get('jobName'):
133 url = self.generateGraphURL( testname=main.params[ 'GRAPH' ][ 'jobName' ] )
134 else:
135 url = self.generateGraphURL()
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800136 main.log.wiki( url )
137
Devin Lim58046fa2017-07-05 16:55:00 -0700138 main.commit = main.ONOSbench.getVersion( report=True )
139
Jon Hallf2527902020-07-30 12:56:08 -0700140 def generateGraphURL( self, testname=main.TEST, width=525, height=350 ):
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800141 """
142 Description:
143 Obtain the URL for the graph that corresponds to the test being run.
144 """
145
146 nodeCluster = main.params[ 'GRAPH' ][ 'nodeCluster' ]
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800147 branch = main.ONOSbench.getBranchName()
148 maxBuildsToShow = main.params[ 'GRAPH' ][ 'builds' ]
149
150 return '<ac:structured-macro ac:name="html">\n' + \
151 '<ac:plain-text-body><![CDATA[\n' + \
Devin Limd1fb8e92018-02-28 16:29:33 -0800152 '<img src="https://jenkins.onosproject.org/view/QA/job/postjob-' + \
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800153 nodeCluster + \
154 '/lastSuccessfulBuild/artifact/' + \
155 testname + \
156 '_' + \
157 branch + \
158 '_' + \
159 maxBuildsToShow + \
160 '-builds_graph.jpg", alt="' + \
161 testname + \
162 '", style="width:' + \
163 str( width ) + \
164 'px;height:' + \
165 str( height ) + \
166 'px;border:0"' + \
167 '>' + \
168 ']]></ac:plain-text-body>\n' + \
169 '</ac:structured-macro>\n'
170
Devin Lim142b5342017-07-20 15:22:39 -0700171 def setNumCtrls( self, hasMultiNodeRounds ):
172 """
173 Description:
Jon Hall3e6edb32018-08-21 16:20:30 -0700174 Set new number of controllers if it uses different number of nodes.
Devin Lim142b5342017-07-20 15:22:39 -0700175 different number of nodes should be pre-defined in main.scale.
176 Required:
177 * hasMultiNodeRouds - if the test is testing different number of nodes.
178 """
Devin Lim58046fa2017-07-05 16:55:00 -0700179 if hasMultiNodeRounds:
180 try:
181 main.cycle
182 except Exception:
183 main.cycle = 0
184 main.cycle += 1
Jon Hall3e6edb32018-08-21 16:20:30 -0700185 # main.scale[ 0 ] determines the current number of ONOS controllers
Devin Lim142b5342017-07-20 15:22:39 -0700186 main.Cluster.setRunningNode( int( main.scale.pop( 0 ) ) )
Devin Lim58046fa2017-07-05 16:55:00 -0700187
You Wangf9d95be2018-08-01 14:35:37 -0700188 def killingAllAtomix( self, cluster, killRemoveMax, stopAtomix ):
189 """
190 Description:
191 killing atomix. It will either kill the current runningnodes or
192 max number of the nodes.
193 Required:
194 * cluster - the cluster driver that will be used.
195 * killRemoveMax - The boolean that will decide either to kill
196 only running nodes ( False ) or max number of nodes ( True ).
197 * stopAtomix - If wish to stop atomix before killing it. True for
198 enable stop, False for disable stop.
199 Returns:
200 Returns main.TRUE if successfully killing it.
201 """
202 main.log.info( "Safety check, killing all Atomix processes" )
203 return cluster.killAtomix( killRemoveMax, stopAtomix )
204
Devin Lim142b5342017-07-20 15:22:39 -0700205 def killingAllOnos( self, cluster, killRemoveMax, stopOnos ):
206 """
207 Description:
208 killing the onos. It will either kill the current runningnodes or
209 max number of the nodes.
210 Required:
211 * cluster - the cluster driver that will be used.
212 * killRemoveMax - The boolean that will decide either to kill
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700213 only running nodes ( False ) or max number of nodes ( True ).
Devin Lim142b5342017-07-20 15:22:39 -0700214 * stopOnos - If wish to stop onos before killing it. True for
You Wangf9d95be2018-08-01 14:35:37 -0700215 enable stop, False for disable stop.
Devin Lim142b5342017-07-20 15:22:39 -0700216 Returns:
217 Returns main.TRUE if successfully killing it.
218 """
219 main.log.info( "Safety check, killing all ONOS processes" )
You Wangf9d95be2018-08-01 14:35:37 -0700220 return cluster.killOnos( killRemoveMax, stopOnos )
Devin Lim58046fa2017-07-05 16:55:00 -0700221
You Wang09b596b2018-01-10 10:42:38 -0800222 def createApplyCell( self, cluster, newCell, cellName, cellApps,
Jon Hall3e6edb32018-08-21 16:20:30 -0700223 mininetIp, useSSH, onosIps, installMax=False,
224 atomixClusterSize=None ):
Devin Lim142b5342017-07-20 15:22:39 -0700225 """
226 Description:
227 create new cell ( optional ) and apply it. It will also verify the
228 cell.
Jon Hall3e6edb32018-08-21 16:20:30 -0700229 Required Arguments:
Devin Lim142b5342017-07-20 15:22:39 -0700230 * cluster - the cluster driver that will be used.
231 * newCell - True for making a new cell and False for not making it.
232 * cellName - The name of the cell.
You Wang09b596b2018-01-10 10:42:38 -0800233 * cellApps - The onos apps string.
You Wanga0f6ff62018-01-11 15:46:30 -0800234 * mininetIp - Mininet IP address.
Devin Lim142b5342017-07-20 15:22:39 -0700235 * useSSH - True for using ssh when creating a cell
Jon Hall3e6edb32018-08-21 16:20:30 -0700236 * onosIps - ip( s ) of the ONOS node( s ).
237 Optional Arguments:
238 * installMax
239 * atomixClusterSize - The size of the atomix cluster. Defaults to same
240 as ONOS Cluster size
Devin Lim142b5342017-07-20 15:22:39 -0700241 Returns:
242 Returns main.TRUE if it successfully executed.
243 """
Jon Hall3e6edb32018-08-21 16:20:30 -0700244 if atomixClusterSize is None:
245 atomixClusterSize = len( cluster.runningNodes )
246 atomixClusterSize = int( atomixClusterSize )
247 cluster.setAtomixNodes( atomixClusterSize )
248 atomixIps = [ node.ipAddress for node in cluster.atomixNodes ]
249 main.log.info( "Atomix Cluster Size = {} ".format( atomixClusterSize ) )
Devin Lim58046fa2017-07-05 16:55:00 -0700250 if newCell:
Jon Hall3e6edb32018-08-21 16:20:30 -0700251 cluster.createCell( cellName, cellApps, mininetIp, useSSH, onosIps,
252 atomixIps, installMax )
Devin Lim58046fa2017-07-05 16:55:00 -0700253 main.step( "Apply cell to environment" )
Devin Lim142b5342017-07-20 15:22:39 -0700254 stepResult = cluster.applyCell( cellName )
Devin Lim58046fa2017-07-05 16:55:00 -0700255 utilities.assert_equals( expect=main.TRUE,
256 actual=stepResult,
257 onpass="Successfully applied cell to " +
258 "environment",
Devin Lim142b5342017-07-20 15:22:39 -0700259 onfail="Failed to apply cell to environment" )
Devin Lim58046fa2017-07-05 16:55:00 -0700260 return stepResult
261
You Wangf9d95be2018-08-01 14:35:37 -0700262 def uninstallAtomix( self, cluster, uninstallMax ):
263 """
264 Description:
265 uninstalling atomix and verify the result.
266 Required:
267 * cluster - a cluster driver that will be used.
268 * uninstallMax - True for uninstalling max number of nodes
Jon Hall3e6edb32018-08-21 16:20:30 -0700269 False for uninstalling the current running nodes.
You Wangf9d95be2018-08-01 14:35:37 -0700270 Returns:
271 Returns main.TRUE if it successfully uninstalled.
272 """
273 main.step( "Uninstalling Atomix" )
274 atomixUninstallResult = cluster.uninstallAtomix( uninstallMax )
275 utilities.assert_equals( expect=main.TRUE,
276 actual=atomixUninstallResult,
277 onpass="Successfully uninstalled Atomix",
278 onfail="Failed to uninstall Atomix" )
279 return atomixUninstallResult
280
Devin Lim142b5342017-07-20 15:22:39 -0700281 def uninstallOnos( self, cluster, uninstallMax ):
282 """
283 Description:
284 uninstalling onos and verify the result.
285 Required:
286 * cluster - a cluster driver that will be used.
287 * uninstallMax - True for uninstalling max number of nodes
288 False for uninstalling the current running nodes.
289 Returns:
290 Returns main.TRUE if it successfully uninstalled.
291 """
Devin Lim58046fa2017-07-05 16:55:00 -0700292 main.step( "Uninstalling ONOS package" )
You Wangf9d95be2018-08-01 14:35:37 -0700293 onosUninstallResult = cluster.uninstallOnos( uninstallMax )
Devin Lim58046fa2017-07-05 16:55:00 -0700294 utilities.assert_equals( expect=main.TRUE,
295 actual=onosUninstallResult,
296 onpass="Successfully uninstalled ONOS package",
297 onfail="Failed to uninstall ONOS package" )
298 return onosUninstallResult
299
Devin Lim142b5342017-07-20 15:22:39 -0700300 def buildOnos( self, cluster ):
301 """
302 Description:
You Wangd54c7052018-08-07 16:06:27 -0700303 build the onos using bazel build onos and verify the result
Devin Lim142b5342017-07-20 15:22:39 -0700304 Required:
305 * cluster - the cluster driver that will be used.
306 Returns:
307 Returns main.TRUE if it successfully built.
308 """
Devin Lim58046fa2017-07-05 16:55:00 -0700309 main.step( "Creating ONOS package" )
You Wangd54c7052018-08-07 16:06:27 -0700310 packageResult = main.ONOSbench.bazelBuild()
Devin Lim58046fa2017-07-05 16:55:00 -0700311 utilities.assert_equals( expect=main.TRUE,
312 actual=packageResult,
313 onpass="Successfully created ONOS package",
314 onfail="Failed to create ONOS package" )
You Wang8f5ff152019-02-28 11:35:25 -0800315 if not packageResult:
316 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700317 return packageResult
318
Jon Hall3e6edb32018-08-21 16:20:30 -0700319 def installAtomix( self, cluster, parallel=True ):
You Wangf9d95be2018-08-01 14:35:37 -0700320 """
321 Description:
322 Installing atomix and verify the result
323 Required:
324 * cluster - the cluster driver that will be used.
You Wangf9d95be2018-08-01 14:35:37 -0700325 False for installing current running nodes only.
326 Returns:
327 Returns main.TRUE if it successfully installed
328 """
329 main.step( "Installing Atomix" )
330 atomixInstallResult = main.TRUE
331
Jon Hallb685a1c2018-10-30 15:17:01 -0700332 atomixInstallResult = cluster.installAtomix( parallel )
You Wangf9d95be2018-08-01 14:35:37 -0700333 utilities.assert_equals( expect=main.TRUE,
334 actual=atomixInstallResult,
335 onpass="Successfully installed Atomix",
336 onfail="Failed to install Atomix" )
337 if not atomixInstallResult:
338 main.cleanAndExit()
339 return atomixInstallResult
340
Devin Lime9f0ccf2017-08-11 17:25:12 -0700341 def installOnos( self, cluster, installMax, parallel=True ):
Devin Lim142b5342017-07-20 15:22:39 -0700342 """
343 Description:
344 Installing onos and verify the result
345 Required:
346 * cluster - the cluster driver that will be used.
347 * installMax - True for installing max number of nodes
348 False for installing current running nodes only.
349 Returns:
350 Returns main.TRUE if it successfully installed
351 """
Devin Lim58046fa2017-07-05 16:55:00 -0700352 main.step( "Installing ONOS package" )
353 onosInstallResult = main.TRUE
354
You Wangf9d95be2018-08-01 14:35:37 -0700355 cluster.installOnos( installMax, parallel )
Devin Lim58046fa2017-07-05 16:55:00 -0700356 utilities.assert_equals( expect=main.TRUE,
357 actual=onosInstallResult,
358 onpass="Successfully installed ONOS package",
359 onfail="Failed to install ONOS package" )
360 if not onosInstallResult:
Devin Lim44075962017-08-11 10:56:37 -0700361 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700362 return onosInstallResult
363
Devin Lim142b5342017-07-20 15:22:39 -0700364 def setupSsh( self, cluster ):
365 """
366 Description:
367 set up ssh to the onos and verify the result
368 Required:
369 * cluster - the cluster driver that will be used.
370 Returns:
371 Returns main.TRUE if it successfully setup the ssh to
372 the onos.
373 """
Devin Lim58046fa2017-07-05 16:55:00 -0700374 main.step( "Set up ONOS secure SSH" )
Devin Lim142b5342017-07-20 15:22:39 -0700375 secureSshResult = cluster.ssh()
Devin Lim58046fa2017-07-05 16:55:00 -0700376 utilities.assert_equals( expect=main.TRUE,
377 actual=secureSshResult,
Jon Hall3e6edb32018-08-21 16:20:30 -0700378 onpass="Secured ONOS ssh",
379 onfail="Failed to secure ssh" )
Devin Lim58046fa2017-07-05 16:55:00 -0700380 return secureSshResult
381
Devin Lim142b5342017-07-20 15:22:39 -0700382 def checkOnosService( self, cluster ):
383 """
384 Description:
385 Checking if the onos service is up and verify the result
386 Required:
387 * cluster - the cluster driver that will be used.
388 Returns:
389 Returns main.TRUE if it successfully checked
390 """
391 main.step( "Checking ONOS service" )
392 stepResult = cluster.checkService()
Devin Lim58046fa2017-07-05 16:55:00 -0700393 utilities.assert_equals( expect=main.TRUE,
394 actual=stepResult,
395 onpass="ONOS service is ready on all nodes",
396 onfail="ONOS service did not start properly on all nodes" )
397 return stepResult
398
Jon Hallca319892017-06-15 15:25:22 -0700399 def startOnosClis( self, cluster ):
Devin Lim142b5342017-07-20 15:22:39 -0700400 """
401 Description:
402 starting Onos using onosCli driver and verify the result
403 Required:
404 * cluster - the cluster driver that will be used.
405 Returns:
406 Returns main.TRUE if it successfully started. It will exit
407 the test if not started properly.
408 """
Devin Lim58046fa2017-07-05 16:55:00 -0700409 main.step( "Starting ONOS CLI sessions" )
Jon Hallca319892017-06-15 15:25:22 -0700410 startCliResult = cluster.startCLIs()
Devin Lim58046fa2017-07-05 16:55:00 -0700411 if not startCliResult:
412 main.log.info( "ONOS CLI did not start up properly" )
Devin Lim44075962017-08-11 10:56:37 -0700413 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700414 else:
415 main.log.info( "Successful CLI startup" )
416 utilities.assert_equals( expect=main.TRUE,
417 actual=startCliResult,
418 onpass="Successfully start ONOS cli",
419 onfail="Failed to start ONOS cli" )
420 return startCliResult
421
You Wang0d9f2c02018-08-10 14:56:32 -0700422 def checkOnosNodes( self, cluster ):
423 """
424 Description:
425 Checking if the onos nodes are in READY state
426 Required:
427 * cluster - the cluster driver that will be used.
428 Returns:
429 Returns main.TRUE if it successfully checked
430 """
431 main.step( "Checking ONOS nodes" )
432 stepResult = utilities.retry( main.Cluster.nodesCheck,
433 False,
You Wang07831cb2018-09-04 12:18:04 -0700434 attempts=90 )
You Wang0d9f2c02018-08-10 14:56:32 -0700435
436 utilities.assert_equals( expect=True,
437 actual=stepResult,
438 onpass="All ONOS nodes are in READY state",
439 onfail="Not all ONOS nodes are in READY state" )
440
441 if not stepResult:
442 for ctrl in main.Cluster.active():
443 main.log.debug( "{} components not ACTIVE: \n{}".format(
444 ctrl.name,
Jon Hallf29368d2020-07-31 12:23:56 -0700445 # FIXME: This output has changed a lot
446 ctrl.CLI.sendline( "onos:scr-list | grep -v ACTIVE" ) ) )
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