blob: 1afbfa96c5621d88a33a555be6ee6d3889290260 [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 Hall627b1572020-12-01 12:01:15 -080029 try:
30 main.persistentSetup
31 except ( NameError, AttributeError ):
32 main.persistentSetup = False
Jon Hall4f360bc2017-09-07 10:19:52 -070033
Devin Lim0c972b72018-02-08 14:53:59 -080034 def envSetupDescription( self, includeCaseDesc=True ):
Devin Lim142b5342017-07-20 15:22:39 -070035 """
36 Introduction part of the test. It will initialize some basic vairables.
37 """
Devin Lim0c972b72018-02-08 14:53:59 -080038 if includeCaseDesc:
39 main.case( "Constructing test variables and building ONOS package" )
40 main.caseExplanation = "For loading from params file, and pull" + \
41 " and build the latest ONOS package"
Jon Halla604fd42018-05-04 14:27:27 -070042 main.step( "Constructing test variables" )
Devin Lim142b5342017-07-20 15:22:39 -070043 try:
44 from tests.dependencies.Cluster import Cluster
45 except ImportError:
46 main.log.error( "Cluster not found. exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -070047 main.cleanAndExit()
Devin Lim142b5342017-07-20 15:22:39 -070048 try:
49 main.Cluster
50 except ( NameError, AttributeError ):
Jon Hall3c0114c2020-08-11 15:07:42 -070051 main.Cluster = Cluster( main.ONOScell.nodes, useDocker=main.ONOScell.useDocker )
Devin Lim142b5342017-07-20 15:22:39 -070052 main.ONOSbench = main.Cluster.controllers[ 0 ].Bench
Jon Halld74d2952018-03-01 13:26:39 -080053 main.testOnDirectory = re.sub( "(/tests)$", "", main.testsRoot )
Devin Lim58046fa2017-07-05 16:55:00 -070054
Devin Lim0c972b72018-02-08 14:53:59 -080055 def gitPulling( self, includeCaseDesc=True ):
Devin Lim142b5342017-07-20 15:22:39 -070056 """
57 it will do git checkout or pull if they are enabled from the params file.
58 """
Devin Lim0c972b72018-02-08 14:53:59 -080059
60 if includeCaseDesc:
61 main.case( "Pull onos branch and build onos on Teststation." )
62
Devin Lim58046fa2017-07-05 16:55:00 -070063 gitPull = main.params[ 'GIT' ][ 'pull' ]
64 gitBranch = main.params[ 'GIT' ][ 'branch' ]
65 if gitPull == 'True':
66 main.step( "Git Checkout ONOS branch: " + gitBranch )
67 stepResult = main.ONOSbench.gitCheckout( branch=gitBranch )
68 utilities.assert_equals( expect=main.TRUE,
69 actual=stepResult,
70 onpass="Successfully checkout onos branch.",
71 onfail="Failed to checkout onos branch. Exiting test..." )
Jon Hall4f360bc2017-09-07 10:19:52 -070072 if not stepResult:
73 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070074
75 main.step( "Git Pull on ONOS branch:" + gitBranch )
76 stepResult = main.ONOSbench.gitPull()
77 utilities.assert_equals( expect=main.TRUE,
78 actual=stepResult,
79 onpass="Successfully pull onos. ",
80 onfail="Failed to pull onos. Exiting test ..." )
Jon Hall4f360bc2017-09-07 10:19:52 -070081 if not stepResult:
82 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -070083
84 else:
85 main.log.info( "Skipped git checkout and pull as they are disabled in params file" )
86
Devin Lim0c972b72018-02-08 14:53:59 -080087 def envSetup( self, includeGitPull=True, includeCaseDesc=True ):
Devin Lim142b5342017-07-20 15:22:39 -070088 """
89 Description:
90 some environment setup for the test.
91 Required:
92 * includeGitPull - if wish to git pulling function to be executed.
93 Returns:
94 Returns main.TRUE
95 """
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070096 if includeGitPull:
Devin Lim0c972b72018-02-08 14:53:59 -080097 self.gitPulling( includeCaseDesc )
Jon Hallca319892017-06-15 15:25:22 -070098
Devin Lim142b5342017-07-20 15:22:39 -070099 try:
100 from tests.dependencies.Cluster import Cluster
101 except ImportError:
102 main.log.error( "Cluster not found. exiting the test" )
Devin Lim44075962017-08-11 10:56:37 -0700103 main.cleanAndExit()
Devin Lim142b5342017-07-20 15:22:39 -0700104 try:
105 main.Cluster
106 except ( NameError, AttributeError ):
Jon Hall3c0114c2020-08-11 15:07:42 -0700107 main.Cluster = Cluster( main.ONOScell.nodes, useDocker=main.ONOScell.useDocker )
Devin Lim142b5342017-07-20 15:22:39 -0700108
Devin Lim58046fa2017-07-05 16:55:00 -0700109 main.cellData = {} # For creating cell file
Devin Lim58046fa2017-07-05 16:55:00 -0700110
Jon Hallca319892017-06-15 15:25:22 -0700111 return main.TRUE
Devin Lim58046fa2017-07-05 16:55:00 -0700112
Jon Hall3c0114c2020-08-11 15:07:42 -0700113 def envSetupException( self, error ):
Devin Lim142b5342017-07-20 15:22:39 -0700114 """
115 Description:
116 handles the exception that might occur from the environment setup.
117 Required:
Jon Hall3c0114c2020-08-11 15:07:42 -0700118 * error - exception returned from except.
Devin Lim142b5342017-07-20 15:22:39 -0700119 """
Jon Hall3c0114c2020-08-11 15:07:42 -0700120 main.log.exception( error )
Devin Lim44075962017-08-11 10:56:37 -0700121 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700122
Jon Hallaa1d9b82020-07-30 13:49:42 -0700123 def envSetupConclusion( self, stepResult ):
Devin Lim142b5342017-07-20 15:22:39 -0700124 """
125 Description:
126 compare the result of the envSetup of the test.
127 Required:
128 * stepResult - Result of the envSetup.
129 """
Devin Lim58046fa2017-07-05 16:55:00 -0700130 utilities.assert_equals( expect=main.TRUE,
131 actual=stepResult,
132 onpass="Successfully construct " +
133 "test variables ",
134 onfail="Failed to construct test variables" )
135
Jon Hallf2527902020-07-30 12:56:08 -0700136 if main.params[ 'GRAPH' ].get('jobName'):
137 url = self.generateGraphURL( testname=main.params[ 'GRAPH' ][ 'jobName' ] )
138 else:
139 url = self.generateGraphURL()
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800140 main.log.wiki( url )
141
Jon Hallc5b4c1c2020-12-15 16:50:54 -0800142 if not main.persistentSetup:
143 # ONOS is not deployed by the test
144 # TODO: Try to get commit another way, maybe container labels?
145 # Or try to link to deployment job?
146 main.commit = main.ONOSbench.getVersion( report=True )
Devin Lim58046fa2017-07-05 16:55:00 -0700147
Jon Hallf2527902020-07-30 12:56:08 -0700148 def generateGraphURL( self, testname=main.TEST, width=525, height=350 ):
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800149 """
150 Description:
151 Obtain the URL for the graph that corresponds to the test being run.
152 """
153
154 nodeCluster = main.params[ 'GRAPH' ][ 'nodeCluster' ]
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800155 branch = main.ONOSbench.getBranchName()
156 maxBuildsToShow = main.params[ 'GRAPH' ][ 'builds' ]
157
158 return '<ac:structured-macro ac:name="html">\n' + \
159 '<ac:plain-text-body><![CDATA[\n' + \
Devin Limd1fb8e92018-02-28 16:29:33 -0800160 '<img src="https://jenkins.onosproject.org/view/QA/job/postjob-' + \
Jeremy Ronquillo7f8fb572017-11-14 08:28:41 -0800161 nodeCluster + \
162 '/lastSuccessfulBuild/artifact/' + \
163 testname + \
164 '_' + \
165 branch + \
166 '_' + \
167 maxBuildsToShow + \
168 '-builds_graph.jpg", alt="' + \
169 testname + \
170 '", style="width:' + \
171 str( width ) + \
172 'px;height:' + \
173 str( height ) + \
174 'px;border:0"' + \
175 '>' + \
176 ']]></ac:plain-text-body>\n' + \
177 '</ac:structured-macro>\n'
178
Devin Lim142b5342017-07-20 15:22:39 -0700179 def setNumCtrls( self, hasMultiNodeRounds ):
180 """
181 Description:
Jon Hall3e6edb32018-08-21 16:20:30 -0700182 Set new number of controllers if it uses different number of nodes.
Devin Lim142b5342017-07-20 15:22:39 -0700183 different number of nodes should be pre-defined in main.scale.
184 Required:
185 * hasMultiNodeRouds - if the test is testing different number of nodes.
186 """
Devin Lim58046fa2017-07-05 16:55:00 -0700187 if hasMultiNodeRounds:
188 try:
189 main.cycle
190 except Exception:
191 main.cycle = 0
192 main.cycle += 1
Jon Hall3e6edb32018-08-21 16:20:30 -0700193 # main.scale[ 0 ] determines the current number of ONOS controllers
Devin Lim142b5342017-07-20 15:22:39 -0700194 main.Cluster.setRunningNode( int( main.scale.pop( 0 ) ) )
Devin Lim58046fa2017-07-05 16:55:00 -0700195
You Wangf9d95be2018-08-01 14:35:37 -0700196 def killingAllAtomix( self, cluster, killRemoveMax, stopAtomix ):
197 """
198 Description:
199 killing atomix. It will either kill the current runningnodes or
200 max number of the nodes.
201 Required:
202 * cluster - the cluster driver that will be used.
203 * killRemoveMax - The boolean that will decide either to kill
204 only running nodes ( False ) or max number of nodes ( True ).
205 * stopAtomix - If wish to stop atomix before killing it. True for
206 enable stop, False for disable stop.
207 Returns:
208 Returns main.TRUE if successfully killing it.
209 """
210 main.log.info( "Safety check, killing all Atomix processes" )
211 return cluster.killAtomix( killRemoveMax, stopAtomix )
212
Devin Lim142b5342017-07-20 15:22:39 -0700213 def killingAllOnos( self, cluster, killRemoveMax, stopOnos ):
214 """
215 Description:
216 killing the onos. It will either kill the current runningnodes or
217 max number of the nodes.
218 Required:
219 * cluster - the cluster driver that will be used.
220 * killRemoveMax - The boolean that will decide either to kill
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700221 only running nodes ( False ) or max number of nodes ( True ).
Devin Lim142b5342017-07-20 15:22:39 -0700222 * stopOnos - If wish to stop onos before killing it. True for
You Wangf9d95be2018-08-01 14:35:37 -0700223 enable stop, False for disable stop.
Devin Lim142b5342017-07-20 15:22:39 -0700224 Returns:
225 Returns main.TRUE if successfully killing it.
226 """
227 main.log.info( "Safety check, killing all ONOS processes" )
You Wangf9d95be2018-08-01 14:35:37 -0700228 return cluster.killOnos( killRemoveMax, stopOnos )
Devin Lim58046fa2017-07-05 16:55:00 -0700229
Jon Hall3c0114c2020-08-11 15:07:42 -0700230 def killingAllOnosDocker( self, cluster, killRemoveMax ):
231 """
232 Description:
233 killing the onos docker images . It will either kill the
234 current runningnodes or max number of the nodes.
235 Required:
236 * cluster - the cluster driver that will be used.
237 * killRemoveMax - The boolean that will decide either to kill
238 only running nodes ( False ) or max number of nodes ( True ).
239 Returns:
240 Returns main.TRUE if successfully killing it.
241 """
242 main.log.info( "Safety check, stopping all ONOS docker containers" )
243 return cluster.dockerStop( killRemoveMax )
244
You Wang09b596b2018-01-10 10:42:38 -0800245 def createApplyCell( self, cluster, newCell, cellName, cellApps,
Jon Hall3e6edb32018-08-21 16:20:30 -0700246 mininetIp, useSSH, onosIps, installMax=False,
247 atomixClusterSize=None ):
Devin Lim142b5342017-07-20 15:22:39 -0700248 """
249 Description:
250 create new cell ( optional ) and apply it. It will also verify the
251 cell.
Jon Hall3e6edb32018-08-21 16:20:30 -0700252 Required Arguments:
Devin Lim142b5342017-07-20 15:22:39 -0700253 * cluster - the cluster driver that will be used.
254 * newCell - True for making a new cell and False for not making it.
255 * cellName - The name of the cell.
You Wang09b596b2018-01-10 10:42:38 -0800256 * cellApps - The onos apps string.
You Wanga0f6ff62018-01-11 15:46:30 -0800257 * mininetIp - Mininet IP address.
Devin Lim142b5342017-07-20 15:22:39 -0700258 * useSSH - True for using ssh when creating a cell
Jon Hall3e6edb32018-08-21 16:20:30 -0700259 * onosIps - ip( s ) of the ONOS node( s ).
260 Optional Arguments:
261 * installMax
262 * atomixClusterSize - The size of the atomix cluster. Defaults to same
263 as ONOS Cluster size
Devin Lim142b5342017-07-20 15:22:39 -0700264 Returns:
265 Returns main.TRUE if it successfully executed.
266 """
Jon Hall3e6edb32018-08-21 16:20:30 -0700267 if atomixClusterSize is None:
268 atomixClusterSize = len( cluster.runningNodes )
Jon Hall3c0114c2020-08-11 15:07:42 -0700269 if atomixClusterSize is 1:
270 atomixClusterSize = len( cluster.controllers )
Jon Hall3e6edb32018-08-21 16:20:30 -0700271 atomixClusterSize = int( atomixClusterSize )
272 cluster.setAtomixNodes( atomixClusterSize )
273 atomixIps = [ node.ipAddress for node in cluster.atomixNodes ]
274 main.log.info( "Atomix Cluster Size = {} ".format( atomixClusterSize ) )
Devin Lim58046fa2017-07-05 16:55:00 -0700275 if newCell:
Jon Hall3e6edb32018-08-21 16:20:30 -0700276 cluster.createCell( cellName, cellApps, mininetIp, useSSH, onosIps,
277 atomixIps, installMax )
Devin Lim58046fa2017-07-05 16:55:00 -0700278 main.step( "Apply cell to environment" )
Devin Lim142b5342017-07-20 15:22:39 -0700279 stepResult = cluster.applyCell( cellName )
Devin Lim58046fa2017-07-05 16:55:00 -0700280 utilities.assert_equals( expect=main.TRUE,
281 actual=stepResult,
282 onpass="Successfully applied cell to " +
283 "environment",
Devin Lim142b5342017-07-20 15:22:39 -0700284 onfail="Failed to apply cell to environment" )
Devin Lim58046fa2017-07-05 16:55:00 -0700285 return stepResult
286
You Wangf9d95be2018-08-01 14:35:37 -0700287 def uninstallAtomix( self, cluster, uninstallMax ):
288 """
289 Description:
290 uninstalling atomix and verify the result.
291 Required:
292 * cluster - a cluster driver that will be used.
293 * uninstallMax - True for uninstalling max number of nodes
Jon Hall3e6edb32018-08-21 16:20:30 -0700294 False for uninstalling the current running nodes.
You Wangf9d95be2018-08-01 14:35:37 -0700295 Returns:
296 Returns main.TRUE if it successfully uninstalled.
297 """
298 main.step( "Uninstalling Atomix" )
299 atomixUninstallResult = cluster.uninstallAtomix( uninstallMax )
300 utilities.assert_equals( expect=main.TRUE,
301 actual=atomixUninstallResult,
302 onpass="Successfully uninstalled Atomix",
303 onfail="Failed to uninstall Atomix" )
304 return atomixUninstallResult
305
Devin Lim142b5342017-07-20 15:22:39 -0700306 def uninstallOnos( self, cluster, uninstallMax ):
307 """
308 Description:
309 uninstalling onos and verify the result.
310 Required:
311 * cluster - a cluster driver that will be used.
312 * uninstallMax - True for uninstalling max number of nodes
313 False for uninstalling the current running nodes.
314 Returns:
315 Returns main.TRUE if it successfully uninstalled.
316 """
Devin Lim58046fa2017-07-05 16:55:00 -0700317 main.step( "Uninstalling ONOS package" )
You Wangf9d95be2018-08-01 14:35:37 -0700318 onosUninstallResult = cluster.uninstallOnos( uninstallMax )
Devin Lim58046fa2017-07-05 16:55:00 -0700319 utilities.assert_equals( expect=main.TRUE,
320 actual=onosUninstallResult,
321 onpass="Successfully uninstalled ONOS package",
322 onfail="Failed to uninstall ONOS package" )
323 return onosUninstallResult
324
Devin Lim142b5342017-07-20 15:22:39 -0700325 def buildOnos( self, cluster ):
326 """
327 Description:
You Wangd54c7052018-08-07 16:06:27 -0700328 build the onos using bazel build onos and verify the result
Devin Lim142b5342017-07-20 15:22:39 -0700329 Required:
330 * cluster - the cluster driver that will be used.
331 Returns:
332 Returns main.TRUE if it successfully built.
333 """
Devin Lim58046fa2017-07-05 16:55:00 -0700334 main.step( "Creating ONOS package" )
You Wangd54c7052018-08-07 16:06:27 -0700335 packageResult = main.ONOSbench.bazelBuild()
Devin Lim58046fa2017-07-05 16:55:00 -0700336 utilities.assert_equals( expect=main.TRUE,
337 actual=packageResult,
338 onpass="Successfully created ONOS package",
339 onfail="Failed to create ONOS package" )
You Wang8f5ff152019-02-28 11:35:25 -0800340 if not packageResult:
341 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700342 return packageResult
343
Jon Hall3c0114c2020-08-11 15:07:42 -0700344 def buildDocker( self, cluster ):
345 """
346 Description:
347 Build the latest docker
348 Required:
349 * cluster - the cluster driver that will be used.
350 Returns:
351 Returns main.TRUE if it successfully built.
352 """
353 main.step( "Building ONOS Docker image" )
354 buildResult = cluster.dockerBuild()
355 utilities.assert_equals( expect=main.TRUE,
356 actual=buildResult,
357 onpass="Successfully created ONOS docker",
358 onfail="Failed to create ONOS docker" )
359 if not buildResult:
360 main.cleanAndExit()
361 return buildResult
362
Jon Hall3e6edb32018-08-21 16:20:30 -0700363 def installAtomix( self, cluster, parallel=True ):
You Wangf9d95be2018-08-01 14:35:37 -0700364 """
365 Description:
366 Installing atomix and verify the result
367 Required:
368 * cluster - the cluster driver that will be used.
You Wangf9d95be2018-08-01 14:35:37 -0700369 False for installing current running nodes only.
370 Returns:
371 Returns main.TRUE if it successfully installed
372 """
373 main.step( "Installing Atomix" )
374 atomixInstallResult = main.TRUE
375
Jon Hallb685a1c2018-10-30 15:17:01 -0700376 atomixInstallResult = cluster.installAtomix( parallel )
You Wangf9d95be2018-08-01 14:35:37 -0700377 utilities.assert_equals( expect=main.TRUE,
378 actual=atomixInstallResult,
379 onpass="Successfully installed Atomix",
380 onfail="Failed to install Atomix" )
381 if not atomixInstallResult:
382 main.cleanAndExit()
383 return atomixInstallResult
384
Devin Lime9f0ccf2017-08-11 17:25:12 -0700385 def installOnos( self, cluster, installMax, parallel=True ):
Devin Lim142b5342017-07-20 15:22:39 -0700386 """
387 Description:
388 Installing onos and verify the result
389 Required:
390 * cluster - the cluster driver that will be used.
391 * installMax - True for installing max number of nodes
392 False for installing current running nodes only.
393 Returns:
394 Returns main.TRUE if it successfully installed
395 """
Devin Lim58046fa2017-07-05 16:55:00 -0700396 main.step( "Installing ONOS package" )
397 onosInstallResult = main.TRUE
398
You Wangf9d95be2018-08-01 14:35:37 -0700399 cluster.installOnos( installMax, parallel )
Devin Lim58046fa2017-07-05 16:55:00 -0700400 utilities.assert_equals( expect=main.TRUE,
401 actual=onosInstallResult,
402 onpass="Successfully installed ONOS package",
403 onfail="Failed to install ONOS package" )
404 if not onosInstallResult:
Devin Lim44075962017-08-11 10:56:37 -0700405 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700406 return onosInstallResult
407
Jon Hall3c0114c2020-08-11 15:07:42 -0700408 def startDocker( self, cluster, installMax, parallel=True ):
409 """
410 Description:
411 Start onos docker containers and verify the result
412 Required:
413 * cluster - the cluster driver that will be used.
414 * installMax - True for installing max number of nodes
415 False for installing current running nodes only.
416 Returns:
417 Returns main.TRUE if it successfully installed
418 """
419 main.step( "Create Cluster Config" )
420 configResult = cluster.genPartitions()
421 utilities.assert_equals( expect=main.TRUE,
422 actual=configResult,
423 onpass="Successfully create cluster config",
424 onfail="Failed to create cluster config" )
425
426 # install atomix docker containers
427 main.step( "Installing Atomix via docker containers" )
428 atomixInstallResult = cluster.startAtomixDocker( parallel )
429 utilities.assert_equals( expect=main.TRUE,
430 actual=atomixInstallResult,
431 onpass="Successfully start atomix containers",
432 onfail="Failed to start atomix containers" )
433
434 main.step( "Installing ONOS via docker containers" )
435 onosInstallResult = cluster.startONOSDocker( installMax, parallel )
436 utilities.assert_equals( expect=main.TRUE,
437 actual=onosInstallResult,
438 onpass="Successfully start ONOS containers",
439 onfail="Failed to start ONOS containers" )
440 if not onosInstallResult and atomixInstallResult:
441 main.cleanAndExit()
442 return onosInstallResult and atomixInstallResult
443
Devin Lim142b5342017-07-20 15:22:39 -0700444 def setupSsh( self, cluster ):
445 """
446 Description:
447 set up ssh to the onos and verify the result
448 Required:
449 * cluster - the cluster driver that will be used.
450 Returns:
451 Returns main.TRUE if it successfully setup the ssh to
452 the onos.
453 """
Devin Lim58046fa2017-07-05 16:55:00 -0700454 main.step( "Set up ONOS secure SSH" )
Devin Lim142b5342017-07-20 15:22:39 -0700455 secureSshResult = cluster.ssh()
Devin Lim58046fa2017-07-05 16:55:00 -0700456 utilities.assert_equals( expect=main.TRUE,
457 actual=secureSshResult,
Jon Hall3e6edb32018-08-21 16:20:30 -0700458 onpass="Secured ONOS ssh",
459 onfail="Failed to secure ssh" )
Devin Lim58046fa2017-07-05 16:55:00 -0700460 return secureSshResult
461
Devin Lim142b5342017-07-20 15:22:39 -0700462 def checkOnosService( self, cluster ):
463 """
464 Description:
465 Checking if the onos service is up and verify the result
466 Required:
467 * cluster - the cluster driver that will be used.
468 Returns:
469 Returns main.TRUE if it successfully checked
470 """
471 main.step( "Checking ONOS service" )
472 stepResult = cluster.checkService()
Devin Lim58046fa2017-07-05 16:55:00 -0700473 utilities.assert_equals( expect=main.TRUE,
474 actual=stepResult,
475 onpass="ONOS service is ready on all nodes",
476 onfail="ONOS service did not start properly on all nodes" )
477 return stepResult
478
Jon Hallca319892017-06-15 15:25:22 -0700479 def startOnosClis( self, cluster ):
Devin Lim142b5342017-07-20 15:22:39 -0700480 """
481 Description:
482 starting Onos using onosCli driver and verify the result
483 Required:
484 * cluster - the cluster driver that will be used.
485 Returns:
486 Returns main.TRUE if it successfully started. It will exit
487 the test if not started properly.
488 """
Devin Lim58046fa2017-07-05 16:55:00 -0700489 main.step( "Starting ONOS CLI sessions" )
Jon Hallca319892017-06-15 15:25:22 -0700490 startCliResult = cluster.startCLIs()
Devin Lim58046fa2017-07-05 16:55:00 -0700491 if not startCliResult:
492 main.log.info( "ONOS CLI did not start up properly" )
Devin Lim44075962017-08-11 10:56:37 -0700493 main.cleanAndExit()
Devin Lim58046fa2017-07-05 16:55:00 -0700494 else:
495 main.log.info( "Successful CLI startup" )
496 utilities.assert_equals( expect=main.TRUE,
497 actual=startCliResult,
498 onpass="Successfully start ONOS cli",
499 onfail="Failed to start ONOS cli" )
500 return startCliResult
501
You Wang0d9f2c02018-08-10 14:56:32 -0700502 def checkOnosNodes( self, cluster ):
503 """
504 Description:
505 Checking if the onos nodes are in READY state
506 Required:
507 * cluster - the cluster driver that will be used.
508 Returns:
509 Returns main.TRUE if it successfully checked
510 """
511 main.step( "Checking ONOS nodes" )
512 stepResult = utilities.retry( main.Cluster.nodesCheck,
513 False,
You Wang07831cb2018-09-04 12:18:04 -0700514 attempts=90 )
You Wang0d9f2c02018-08-10 14:56:32 -0700515
516 utilities.assert_equals( expect=True,
517 actual=stepResult,
518 onpass="All ONOS nodes are in READY state",
519 onfail="Not all ONOS nodes are in READY state" )
520
521 if not stepResult:
522 for ctrl in main.Cluster.active():
523 main.log.debug( "{} components not ACTIVE: \n{}".format(
524 ctrl.name,
Jon Hallf29368d2020-07-31 12:23:56 -0700525 # FIXME: This output has changed a lot
526 ctrl.CLI.sendline( "onos:scr-list | grep -v ACTIVE" ) ) )
You Wang0d9f2c02018-08-10 14:56:32 -0700527 main.log.error( "Failed to start ONOS, stopping test" )
You Wang7880b372019-02-27 16:50:47 -0800528 main.cleanAndExit( msg="Failed to start ONOS: not all nodes are in READY state" )
You Wangba973f02018-08-30 12:33:41 -0700529 return main.TRUE
You Wang0d9f2c02018-08-10 14:56:32 -0700530
531 def checkOnosApps( self, cluster, apps ):
532 """
533 Description:
534 Checking if the onos applications are activated
535 Required:
536 * cluster - the cluster driver that will be used.
537 * apps: list of applications that are expected to be activated
538 Returns:
539 Returns main.TRUE if it successfully checked
540 """
541 main.step( "Checking ONOS applications" )
542 stepResult = utilities.retry( main.Cluster.appsCheck,
543 False,
544 args = [ apps ],
545 sleep=5,
Jon Hall3e6edb32018-08-21 16:20:30 -0700546 attempts=90 )
You Wang0d9f2c02018-08-10 14:56:32 -0700547
548 utilities.assert_equals( expect=True,
549 actual=stepResult,
550 onpass="All ONOS apps are activated",
551 onfail="Not all ONOS apps are activated" )
552
553 return main.TRUE if stepResult else main.FALSE
554
Jon Hall4f360bc2017-09-07 10:19:52 -0700555 def processList( self, functions, args ):
556 if functions is not None:
557 if isinstance( functions, list ):
558 i = 0
559 for f in functions:
560 f( *( args[ i ] ) ) if args is not None and args[ i ] is not None else f()
561 i += 1
562 else:
563 functions( *args ) if args is not None else functions()
564
You Wangb1665b52019-02-01 15:49:48 -0800565 def ONOSSetUp( self, cluster, hasMultiNodeRounds=False, startOnosCli=True, newCell=True,
You Wangcdc51fe2018-08-12 17:14:56 -0700566 cellName="temp", cellApps="drivers", appPrefix="org.onosproject.",
Jon Hall3e6edb32018-08-21 16:20:30 -0700567 mininetIp="", extraApply=None, applyArgs=None,
568 extraClean=None, cleanArgs=None, skipPack=False, installMax=False,
569 atomixClusterSize=None, useSSH=True, killRemoveMax=True, stopAtomix=False,
570 stopOnos=False, installParallel=True, cellApply=True,
You Wangdbb95d62018-09-05 15:58:08 -0700571 includeCaseDesc=True, restartCluster=True ):
Devin Lim142b5342017-07-20 15:22:39 -0700572 """
573 Description:
574 Initial ONOS setting up of the tests. It will also verify the result of each steps.
575 The procedures will be:
576 killing onos
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700577 creating ( optional ) /applying cell
578 removing raft logs ( optional )
Devin Lim142b5342017-07-20 15:22:39 -0700579 uninstalling onos
580 extra procedure to be applied( optional )
581 building onos
582 installing onos
583 extra cleanup to be applied ( optional )
584 setting up ssh to the onos
585 checking the onos service
586 starting onos
Jon Hall3e6edb32018-08-21 16:20:30 -0700587 Required Arguments:
Devin Lim142b5342017-07-20 15:22:39 -0700588 * cluster - the cluster driver that will be used.
Jon Hall3e6edb32018-08-21 16:20:30 -0700589 Optional Arguments:
590 * hasMultiNodeRounds - True if the test is testing different set of nodes
You Wangb1665b52019-02-01 15:49:48 -0800591 * startOnosCli - True if wish to start onos CLI.
Devin Lim142b5342017-07-20 15:22:39 -0700592 * newCell - True for making a new cell and False for not making it.
593 * cellName - Name of the cell that will be used.
You Wang0d9f2c02018-08-10 14:56:32 -0700594 * cellApps - The cell apps string. Will be overwritten by main.apps if it exists
You Wangcdc51fe2018-08-12 17:14:56 -0700595 * appPrefix - Prefix of app names. Will use "org.onosproject." by default
You Wanga0f6ff62018-01-11 15:46:30 -0800596 * mininetIp - Mininet IP address.
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -0700597 * extraApply - Function( s ) that will be called before building ONOS. Default to None.
598 * applyArgs - argument of the functon( s ) of the extraApply. Should be in list.
599 * extraClean - Function( s ) that will be called after building ONOS. Defaults to None.
600 * cleanArgs - argument of the functon( s ) of the extraClean. Should be in list.
Devin Lim142b5342017-07-20 15:22:39 -0700601 * skipPack - True if wish to skip some packing.
602 * installMax - True if wish to install onos max number of nodes
Jon Hall3e6edb32018-08-21 16:20:30 -0700603 False if wish to install onos of running nodes only
604 * atomixClusterSize - The number of Atomix nodes in the cluster.
605 Defaults to None which will be the number of OC# nodes in the cell
Devin Lim142b5342017-07-20 15:22:39 -0700606 * useSSH - True for using ssh when creating a cell
607 * killRemoveMax - True for removing/killing max number of nodes. False for
Jon Hall3e6edb32018-08-21 16:20:30 -0700608 removing/killing running nodes only.
You Wangf9d95be2018-08-01 14:35:37 -0700609 * stopAtomix - True if wish to stop atomix before killing it.
Devin Lim142b5342017-07-20 15:22:39 -0700610 * stopOnos - True if wish to stop onos before killing it.
You Wangdbb95d62018-09-05 15:58:08 -0700611 * restartCluster - True if wish to kill and restart atomix and onos clusters
Devin Lim142b5342017-07-20 15:22:39 -0700612 Returns:
613 Returns main.TRUE if it everything successfully proceeded.
614 """
615 self.setNumCtrls( hasMultiNodeRounds )
Jon Hall627b1572020-12-01 12:01:15 -0800616 if not main.persistentSetup:
617 if includeCaseDesc:
618 main.case( "Starting up " + str( cluster.numCtrls ) +
619 " node(s) ONOS cluster" )
620 main.caseExplanation = "Set up ONOS with " + str( cluster.numCtrls ) + \
621 " node(s) ONOS cluster"
Devin Lim58046fa2017-07-05 16:55:00 -0700622
Jon Hall3e6edb32018-08-21 16:20:30 -0700623 main.log.info( "ONOS cluster size = " + str( cluster.numCtrls ) )
Devin Lim142b5342017-07-20 15:22:39 -0700624 cellResult = main.TRUE
Devin Lim6437c9c2018-01-29 17:24:16 -0800625 if cellApply:
You Wang0d9f2c02018-08-10 14:56:32 -0700626 try:
627 apps = main.apps
628 except ( NameError, AttributeError ):
629 apps = cellApps
630 main.log.debug( "Apps: " + str( apps ) )
Devin Lim142b5342017-07-20 15:22:39 -0700631 tempOnosIp = []
632 for ctrl in cluster.runningNodes:
633 tempOnosIp.append( ctrl.ipAddress )
You Wanga0f6ff62018-01-11 15:46:30 -0800634 if mininetIp == "":
635 mininetIp = "localhost"
636 for key, value in main.componentDictionary.items():
637 if value['type'] in ['MininetCliDriver', 'RemoteMininetDriver'] and hasattr( main, key ):
638 mininetIp = getattr( main, key ).ip_address
639 break
Devin Lim142b5342017-07-20 15:22:39 -0700640 cellResult = self.createApplyCell( cluster, newCell,
You Wang0d9f2c02018-08-10 14:56:32 -0700641 cellName, apps,
You Wanga0f6ff62018-01-11 15:46:30 -0800642 mininetIp, useSSH,
Jon Hall3e6edb32018-08-21 16:20:30 -0700643 tempOnosIp, installMax,
644 atomixClusterSize )
Devin Lim58046fa2017-07-05 16:55:00 -0700645
Jon Hall627b1572020-12-01 12:01:15 -0800646 if not main.persistentSetup and restartCluster:
You Wangdbb95d62018-09-05 15:58:08 -0700647 atomixKillResult = self.killingAllAtomix( cluster, killRemoveMax, stopAtomix )
648 onosKillResult = self.killingAllOnos( cluster, killRemoveMax, stopOnos )
Jon Hall3c0114c2020-08-11 15:07:42 -0700649 dockerKillResult = self.killingAllOnosDocker( cluster, killRemoveMax )
You Wangdbb95d62018-09-05 15:58:08 -0700650 killResult = atomixKillResult and onosKillResult
651 else:
652 killResult = main.TRUE
You Wang4cc61912018-08-28 10:10:58 -0700653
Jon Hall627b1572020-12-01 12:01:15 -0800654 if not main.persistentSetup and restartCluster:
You Wangdbb95d62018-09-05 15:58:08 -0700655 atomixUninstallResult = self.uninstallAtomix( cluster, killRemoveMax )
656 onosUninstallResult = self.uninstallOnos( cluster, killRemoveMax )
657 uninstallResult = atomixUninstallResult and onosUninstallResult
658 self.processList( extraApply, applyArgs )
Devin Lim6437c9c2018-01-29 17:24:16 -0800659
You Wangdbb95d62018-09-05 15:58:08 -0700660 packageResult = main.TRUE
661 if not skipPack:
Jon Hall3c0114c2020-08-11 15:07:42 -0700662 if cluster.useDocker:
663 packageResult = self.buildDocker( cluster )
664 else:
665 packageResult = self.buildOnos( cluster )
Devin Lim142b5342017-07-20 15:22:39 -0700666
Jon Hall3c0114c2020-08-11 15:07:42 -0700667 if cluster.useDocker:
668 installResult = self.startDocker( cluster, installMax, installParallel )
669 else:
670 atomixInstallResult = self.installAtomix( cluster, installParallel )
671 onosInstallResult = self.installOnos( cluster, installMax, installParallel )
672 installResult = atomixInstallResult and onosInstallResult
673
674 preCLIResult = main.TRUE
675 if cluster.useDocker:
676 attachResult = cluster.attachToONOSDocker()
677 prepareResult = cluster.prepareForCLI()
678
679 preCLIResult = preCLIResult and attachResult and prepareResult
Devin Lim58046fa2017-07-05 16:55:00 -0700680
You Wangdbb95d62018-09-05 15:58:08 -0700681 self.processList( extraClean, cleanArgs )
682 secureSshResult = self.setupSsh( cluster )
683 else:
684 packageResult = main.TRUE
685 uninstallResult = main.TRUE
686 installResult = main.TRUE
687 secureSshResult = main.TRUE
Jon Hall3c0114c2020-08-11 15:07:42 -0700688 preCLIResult = main.TRUE
Devin Lim58046fa2017-07-05 16:55:00 -0700689
Jon Hall3c0114c2020-08-11 15:07:42 -0700690 onosServiceResult = main.TRUE
691 if not cluster.useDocker:
692 onosServiceResult = self.checkOnosService( cluster )
Jon Hall627b1572020-12-01 12:01:15 -0800693 elif main.persistentSetup:
694 for ctrl in cluster.getRunningNodes():
695 ctrl.inDocker = True
Devin Lim58046fa2017-07-05 16:55:00 -0700696
You Wang4cc61912018-08-28 10:10:58 -0700697 onosCliResult = main.TRUE
You Wangb1665b52019-02-01 15:49:48 -0800698 if startOnosCli:
Jon Hallca319892017-06-15 15:25:22 -0700699 onosCliResult = self.startOnosClis( cluster )
Devin Lim58046fa2017-07-05 16:55:00 -0700700
You Wang0d9f2c02018-08-10 14:56:32 -0700701 onosNodesResult = self.checkOnosNodes( cluster )
702
Jon Hall39570262020-11-17 12:18:19 -0800703 externalAppsResult = main.TRUE
Jon Hall627b1572020-12-01 12:01:15 -0800704 if not main.persistentSetup and main.params.get( 'EXTERNAL_APPS' ):
Jon Hall39570262020-11-17 12:18:19 -0800705 node = main.Cluster.controllers[0]
706 for app, url in main.params[ 'EXTERNAL_APPS' ].iteritems():
707 path, fileName = os.path.split( url )
708 main.ONOSbench.onosApp( node.ipAddress, "reinstall!", fileName, appName=app, user=node.karafUser, password=node.karafPass )
709
710
You Wang0d9f2c02018-08-10 14:56:32 -0700711 onosAppsResult = main.TRUE
Jon Hall627b1572020-12-01 12:01:15 -0800712 if not main.persistentSetup and cellApply:
You Wang0d9f2c02018-08-10 14:56:32 -0700713 if apps:
Jon Hall39570262020-11-17 12:18:19 -0800714 newApps = []
715 appNames = apps.split( ',' )
Jon Hall3c0114c2020-08-11 15:07:42 -0700716 if cluster.useDocker:
717 node = main.Cluster.active( 0 )
Jon Hall39570262020-11-17 12:18:19 -0800718 for app in appNames:
719 appName = app if "org." in app else appPrefix + app
720 node.activateApp( appName )
721 newApps.append( appName )
Jon Hall3c0114c2020-08-11 15:07:42 -0700722
Jon Hall39570262020-11-17 12:18:19 -0800723 onosAppsResult = self.checkOnosApps( cluster, newApps )
You Wang0d9f2c02018-08-10 14:56:32 -0700724 else:
725 main.log.warn( "No apps were specified to be checked after startup" )
726
You Wangf9d95be2018-08-01 14:35:37 -0700727 return killResult and cellResult and packageResult and uninstallResult and \
You Wang0d9f2c02018-08-10 14:56:32 -0700728 installResult and secureSshResult and onosServiceResult and onosCliResult and \
Jon Hall3c0114c2020-08-11 15:07:42 -0700729 onosNodesResult and onosAppsResult and preCLIResult