blob: 9983ee91c4df3d0a703167b2c4d79bb29ab212fc [file] [log] [blame]
Joey Armstrong518f3572024-02-11 07:56:25 -05001// Copyright 2021-2024 Open Networking Foundation (ONF) and the ONF Contributors
Matteo Scandolo42f6e572021-01-25 15:11:34 -08002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Hardik Windlassec9341b2021-06-07 11:58:29 +000015// voltha-2.x e2e tests for openonu-go
Matteo Scandolo42f6e572021-01-25 15:11:34 -080016// uses bbsim to simulate OLT/ONUs
17
Joey Armstrongbccfa4b2023-09-27 17:34:22 -040018// [TODO] Update library() to the latest DSL syntax supported by jenkins
Matteo Scandoloa156b572021-02-04 11:52:18 -080019library identifier: 'cord-jenkins-libraries@master',
20 retriever: modernSCM([
Joey Armstrong9f66e3f2023-09-20 16:29:29 -040021 $class: 'GitSCMSource',
22 remote: 'https://gerrit.opencord.org/ci-management.git'
Matteo Scandoloa156b572021-02-04 11:52:18 -080023])
24
Joey Armstronge5aae1c2023-07-24 14:11:20 -040025//------------------//
26//---] GLOBAL [---//
27//------------------//
Joey Armstronge9725b12023-08-28 18:15:12 -040028String clusterName = 'kind-ci'
Joey Armstrongf076c312023-08-01 17:17:10 -040029
30// -----------------------------------------------------------------------
Joey Armstrong9f66e3f2023-09-20 16:29:29 -040031// Intent: Return branch name for the script. A hardcoded value is used
32// as a guarantee release jobs are running in an expected sandbox.
Joey Armstrongf076c312023-08-01 17:17:10 -040033// -----------------------------------------------------------------------
Joey Armstrongb65ada32023-08-03 12:50:20 -040034String branchName() {
Joey Armstrong9f66e3f2023-09-20 16:29:29 -040035 String br = 'master'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040036
Joey Armstrong9f66e3f2023-09-20 16:29:29 -040037 // "${branch}" is assigned by jenkins
38 if (br != branch) {
39 String err = [
40 'ERROR: Detected invalid branch',
Roger Luethi92354bf2023-10-05 09:22:19 +020041 "(expected=[${br}] != found=[${branch}])"
Joey Armstrong9f66e3f2023-09-20 16:29:29 -040042 ].join(' ')
43 throw new Exception(err) // groovylint-disable-line ThrowException
44 }
45
46 return (br)
Joey Armstrongf076c312023-08-01 17:17:10 -040047}
Hardik Windlassec9341b2021-06-07 11:58:29 +000048
Joey Armstronge5aae1c2023-07-24 14:11:20 -040049// -----------------------------------------------------------------------
Joey Armstrong06a68372023-07-24 16:37:16 -040050// Intent: Due to lack of a reliable stack trace, construct a literal.
Joey Armstrong0251e962023-08-25 20:51:31 -040051// Jenkins will re-write the call stack for serialization.S
52// -----------------------------------------------------------------------
53// Note: Hardcoded version string used to visualize changes in jenkins UI
Joey Armstrong06a68372023-07-24 16:37:16 -040054// -----------------------------------------------------------------------
Joey Armstrong97a8b882023-08-02 16:08:52 -040055String getIam(String func) {
Joey Armstrongb65ada32023-08-03 12:50:20 -040056 String branchName = branchName()
Joey Armstrong06a68372023-07-24 16:37:16 -040057 String src = [
58 'ci-management',
59 'jjb',
60 'pipeline',
61 'voltha',
Joey Armstrongb65ada32023-08-03 12:50:20 -040062 branchName,
Joey Armstrong06a68372023-07-24 16:37:16 -040063 'bbsim-tests.groovy'
64 ].join('/')
65
Joey Armstrongbccfa4b2023-09-27 17:34:22 -040066 String name = [src, func].join('::')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040067 return(name)
Joey Armstrong06a68372023-07-24 16:37:16 -040068}
69
70// -----------------------------------------------------------------------
Joey Armstrong0251e962023-08-25 20:51:31 -040071// Intent: Log progress message
72// -----------------------------------------------------------------------
73void enter(String name) {
74 // Announce ourselves for log usability
75 String iam = getIam(name)
76 println("${iam}: ENTER")
77 return
78}
79
80// -----------------------------------------------------------------------
81// Intent: Log progress message
82// -----------------------------------------------------------------------
83void leave(String name) {
84 // Announce ourselves for log usability
85 String iam = getIam(name)
86 println("${iam}: LEAVE")
87 return
88}
89
90// -----------------------------------------------------------------------
Joey Armstrongf0232762024-02-11 17:23:04 -050091// Intent: Display a message with visibility for logging
92// -----------------------------------------------------------------------
93String banner(String message) {
94 String iam = getIam('banner')
95
96 println("""
97
98** -----------------------------------------------------------------------
99** IAM: $iam
100** ${message}
101** -----------------------------------------------------------------------
102""")
103 return
104}
105
106// -----------------------------------------------------------------------
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400107// Intent: Determine if working on a release branch.
108// Note: Conditional is legacy, should also check for *-dev or *-pre
109// -----------------------------------------------------------------------
Joey Armstrong0251e962023-08-25 20:51:31 -0400110Boolean isReleaseBranch(String name) {
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400111 // List modifiers = ['-dev', '-pre', 'voltha-x.y.z-pre']
Joey Armstrongb65ada32023-08-03 12:50:20 -0400112 // if branchName in modifiers
113 return(name != 'master') // OR branchName.contains('-')
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400114}
115
116// -----------------------------------------------------------------------
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400117// Intent: Terminate orphaned port-forward from different namespaces
118// -----------------------------------------------------------------------
119void cleanupPortForward() {
120 enter('cleanupPortForward')
121
122 Map pkpfArgs =\
123 [
124 'banner' : true, // display banner for logging
125 'show_procs' : true, // display procs under consideration
126 'filler' : true // fix conditional trailing comma
127 ]
128
129 // 'kubectl.*port-forward'
130 pkill_port_forward('port-forward', pkpfArgs)
131 leave('cleanupPortForward')
132 return
133}
134
Joey Armstrongbccfa4b2023-09-27 17:34:22 -0400135// find . \( -name 'log*.html' -o -name 'output*.xml' -o -name 'report*.html' \) -p
136// -----------------------------------------------------------------------
137// Intent: Display contents of the logs directory
138// -----------------------------------------------------------------------
139// [TODO]
140// o where-4-art-thou logs directory ?
141// o Replace find {logfile} command with /bin/ls {logdir} when found.
142// Individual logs may be missing due to failure, show what is available.
143// -----------------------------------------------------------------------
144void findPublishedLogs() {
145 String iam = 'findPublishedLogs'
146
147 enter(iam)
148 sh(label : iam,
149 script : """
150find . -name 'output.xml' -print
151""")
152 leave(iam)
153 return
154}
155
156// -----------------------------------------------------------------------
157// Intent: Terminate kail-startup process launched earlier
158// -----------------------------------------------------------------------
159// :param caller: Name of parent calling function (debug context)
160// :type caller: String, optional
161// :returns: none
162// :rtype: void
163// -----------------------------------------------------------------------
164void killKailStartup(String caller='') {
165 String iam = "killKailStartup (caller=$caller)"
166
167 enter(iam)
168 sh(label : 'Terminate kail-startup',
169 script : """
170if [[ \$(pgrep --count '_TAG=kail-startup') -gt 0 ]]; then
171 pkill --uid \$(id -u) --echo --list-full --full '_TAG=kail-startup'
172fi
173""")
174 leave(iam)
175 return
176}
177
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400178// -----------------------------------------------------------------------
Joey Armstrong0251e962023-08-25 20:51:31 -0400179// Intent: Iterate over a list of test suites and invoke.
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400180// -----------------------------------------------------------------------
Joey Armstrong0251e962023-08-25 20:51:31 -0400181void execute_test\
182(
183 String testTarget, // functional-single-kind-dt
184 String workflow, // dt
185 String testLogging, // 'True'
186 Boolean teardown, // true
187 String testSpecificHelmFlags=''
188) {
Joey Armstrongb65ada32023-08-03 12:50:20 -0400189 String infraNamespace = 'default'
190 String volthaNamespace = 'voltha'
191 String logsDir = "$WORKSPACE/${testTarget}"
Joey Armstrong293e16b2022-11-26 20:16:33 -0500192
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400193 // -----------------------------------------------------------------------
Joey Armstrong268442d2023-08-22 17:16:10 -0400194 // Intent: Cleanup stale port-forwarding
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400195 // -----------------------------------------------------------------------
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400196 stage('Cleanup') {
197 if (teardown) {
Joey Armstrong84adc542023-04-11 14:47:34 -0400198 timeout(15) {
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400199 script {
Joey Armstrongb65ada32023-08-03 12:50:20 -0400200 helmTeardown(['default', infraNamespace, volthaNamespace])
Joey Armstrong84adc542023-04-11 14:47:34 -0400201 }
Joey Armstrong0251e962023-08-25 20:51:31 -0400202 } // timeout
203
204 timeout(5) {
205 script {
206 enter('Cleanup')
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400207 cleanupPortForward()
Joey Armstrong6146f7e2023-08-28 09:05:38 -0400208 leave('Cleanup')
Joey Armstrong0251e962023-08-25 20:51:31 -0400209 } // script
210 } // timeout
211 } // teardown
212 } // stage('Cleanup')
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500213
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400214 // -----------------------------------------------------------------------
215 // -----------------------------------------------------------------------
Joey Armstrong0251e962023-08-25 20:51:31 -0400216 stage('Deploy common infrastructure') {
217 script {
218 local dashargs = [
219 'kpi_exporter.enabled=false',
220 'dashboards.xos=false',
221 'dashboards.onos=false',
222 'dashboards.aaa=false',
223 'dashboards.voltha=false',
224 ].join(',')
225
226 local promargs = [
227 'prometheus.alertmanager.enabled=false',
228 'prometheus.pushgateway.enabled=false',
229 ].join(',')
230
Joey Armstrong6146f7e2023-08-28 09:05:38 -0400231 sh(label : 'Deploy common infrastructure',
232 script : """
Hardik Windlasse1660492022-03-14 15:12:46 +0000233 helm repo add onf https://charts.opencord.org
234 helm repo update
Joey Armstrong0251e962023-08-25 20:51:31 -0400235
236 echo -e "\nwithMonitoring=[$withMonitoring]"
Hardik Windlasse1660492022-03-14 15:12:46 +0000237 if [ ${withMonitoring} = true ] ; then
238 helm install nem-monitoring onf/nem-monitoring \
Joey Armstrong0251e962023-08-25 20:51:31 -0400239 --set ${promargs} \
240 --set ${dashargs}
Hardik Windlasse1660492022-03-14 15:12:46 +0000241 fi
Joey Armstrong0251e962023-08-25 20:51:31 -0400242 """)
243 } // script
244 } // stage('Deploy Common Infra')
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500245
Joey Armstrong0251e962023-08-25 20:51:31 -0400246 // -----------------------------------------------------------------------
247 // [TODO] Check onos_log output
248 // -----------------------------------------------------------------------
249 stage('Deploy Voltha') {
250 if (teardown) {
251 timeout(10) {
252 script {
253 String iam = getIam('Deploy Voltha')
254 String onosLog = "${logsDir}/onos-voltha-startup-combined.log"
Hardik Windlassec9341b2021-06-07 11:58:29 +0000255
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400256 sh(label : 'Launch kail-startup',
257 script : """
258mkdir -p "$logsDir"
259touch "$onosLog"
Joey Armstrongf404b642023-08-04 14:39:13 -0400260
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400261_TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} > "$onosLog" &
262""")
263
264 // if we're downloading a voltha-helm-charts patch,
265 // install from a local copy of the charts
Joey Armstrong0251e962023-08-25 20:51:31 -0400266 Boolean localCharts = false
Joey Armstrongf404b642023-08-04 14:39:13 -0400267
Joey Armstrong0251e962023-08-25 20:51:31 -0400268 if (volthaHelmChartsChange != ''
269 || gerritProject == 'voltha-helm-charts'
270 || isReleaseBranch(branch) // branch != 'master'
271 ) {
272 localCharts = true
273 }
Hardik Windlassec9341b2021-06-07 11:58:29 +0000274
Joey Armstrong0251e962023-08-25 20:51:31 -0400275 String branchName = branchName()
276 Boolean isRelease = isReleaseBranch(branch)
277 println([
278 " ** localCharts=${localCharts}",
279 "branchName=${branchName}",
280 "branch=${branch}",
281 "branch=isReleaseBranch=${isRelease}",
282 ].join(', '))
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800283
Joey Armstrong0251e962023-08-25 20:51:31 -0400284 // -----------------------------------------------------------------------
285 // Rewrite localHelmFlags using array join, moving code around and
286 // refactoring into standalone functions
287 // -----------------------------------------------------------------------
288 // NOTE temporary workaround expose ONOS node ports
289 // -----------------------------------------------------------------------
290 String localHelmFlags = [
291 extraHelmFlags.trim(),
292 "--set global.log_level=${logLevel.toUpperCase()}",
293 '--set onos-classic.onosSshPort=30115',
294 '--set onos-classic.onosApiPort=30120',
295 '--set onos-classic.onosOfPort=31653',
296 '--set onos-classic.individualOpenFlowNodePorts=true',
297 testSpecificHelmFlags
298 ].join(' ')
Joey Armstrong28e86ee2023-08-03 15:22:29 -0400299
Joey Armstrong0251e962023-08-25 20:51:31 -0400300 println("** ${iam} localHelmFlags = ${localHelmFlags}")
Hardik Windlassec9341b2021-06-07 11:58:29 +0000301
Joey Armstrong0251e962023-08-25 20:51:31 -0400302 if (gerritProject != '') {
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400303 localHelmFlags += getVolthaImageFlags(gerritProject)
Joey Armstrong0251e962023-08-25 20:51:31 -0400304 }
Matteo Scandolofcfc60d2021-02-24 09:06:48 -0800305
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400306 enter('volthaDeploy')
Joey Armstrong0251e962023-08-25 20:51:31 -0400307 volthaDeploy([
308 infraNamespace: infraNamespace,
309 volthaNamespace: volthaNamespace,
310 workflow: workflow.toLowerCase(),
311 withMacLearning: enableMacLearning.toBoolean(),
312 extraHelmFlags: localHelmFlags,
313 localCharts: localCharts,
314 bbsimReplica: olts.toInteger(),
315 dockerRegistry: registry,
316 ])
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400317 leave('volthaDeploy')
Joey Armstrong0251e962023-08-25 20:51:31 -0400318 } // script
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400319
Joey Armstrong1b7cc792023-09-26 14:19:21 -0400320 // Display spawned procs
321 script {
322 enter('bbsim-tests::pgrep_port_forward::0')
323 pgrep_port_forward('port-forw')
324 leave('bbsim-tests::pgrep_port_forward::0')
Joey Armstrongbccfa4b2023-09-27 17:34:22 -0400325
326 killKailStartup('Deploy Voltha')
Joey Armstrong1b7cc792023-09-26 14:19:21 -0400327 }
Joey Armstrong0251e962023-08-25 20:51:31 -0400328
Joey Armstrong0251e962023-08-25 20:51:31 -0400329 // -----------------------------------------------------------------------
330 // Bundle onos-voltha / kail logs
331 // -----------------------------------------------------------------------
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400332 sh(
333 label : 'Bundle logs: onos-voltha-startup-combined',
334 script : """
Joey Armstrong0251e962023-08-25 20:51:31 -0400335cat <<EOM
336
337** -----------------------------------------------------------------------
Joey Armstrong7ba23ac2023-08-29 15:21:53 -0400338** Combine and compress voltha startup log(s)
Joey Armstrong0251e962023-08-25 20:51:31 -0400339** -----------------------------------------------------------------------
340EOM
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400341
342pushd "${logsDir}" || { echo "ERROR: pushd $logsDir failed"; exit 1; }
343gzip -k onos-voltha-startup-combined.log
344rm onos-voltha-startup-combined.log
345popd || { echo "ERROR: popd $logsDir failed"; exit 1; }
Joey Armstrong0251e962023-08-25 20:51:31 -0400346 """)
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400347 } // timeout(10)
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400348
Joey Armstrong0251e962023-08-25 20:51:31 -0400349 // -----------------------------------------------------------------------
350 // -----------------------------------------------------------------------
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400351 sh(label : 'while-true-port-forward',
Roger Luethicebf79a2023-09-28 09:41:45 +0200352 script : """
Hardik Windlassec9341b2021-06-07 11:58:29 +0000353 JENKINS_NODE_COOKIE="dontKillMe" _TAG="voltha-infra-kafka" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n ${infraNamespace} svc/voltha-infra-kafka 9092:9092; done"&
354 bbsimDmiPortFwd=50075
355 for i in {0..${olts.toInteger() - 1}}; do
356 JENKINS_NODE_COOKIE="dontKillMe" _TAG="bbsim\${i}" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n ${volthaNamespace} svc/bbsim\${i} \${bbsimDmiPortFwd}:50075; done"&
357 ((bbsimDmiPortFwd++))
358 done
Hardik Windlass3bb089a2022-03-22 17:56:03 +0000359 if [ ${withMonitoring} = true ] ; then
360 JENKINS_NODE_COOKIE="dontKillMe" _TAG="nem-monitoring-prometheus-server" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n default svc/nem-monitoring-prometheus-server 31301:80; done"&
361 fi
Joey Armstrong7ba23ac2023-08-29 15:21:53 -0400362# ps aux | grep port-forward
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400363""")
Joey Armstrong0251e962023-08-25 20:51:31 -0400364 // ---------------------------------
365 // Sanity check port-forward spawned
366 // ---------------------------------
Joey Armstrong1b7cc792023-09-26 14:19:21 -0400367 script {
368 enter('bbsim-tests::pgrep_port_forward::1')
369 pgrep_port_forward('port-forw')
370 leave('bbsim-tests::pgrep_port_forward::1')
371 }
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500372
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400373 // setting ONOS log level
Joey Armstrong0251e962023-08-25 20:51:31 -0400374 script {
375 enter('setOnosLogLevels')
376 setOnosLogLevels([
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400377 onosNamespace: infraNamespace,
378 apps: [
379 'org.opencord.dhcpl2relay',
380 'org.opencord.olt',
381 'org.opencord.aaa',
382 'org.opencord.maclearner',
383 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
384 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
385 ],
386 logLevel: logLevel
387 ])
Joey Armstrong6146f7e2023-08-28 09:05:38 -0400388 leave('setOnosLogLevels')
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400389 } // script
390 } // if (teardown)
391 } // stage('Deploy Voltha')
392
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400393 // -----------------------------------------------------------------------
394 // -----------------------------------------------------------------------
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400395 stage("Run test ${testTarget} on workflow ${workflow}") {
Joey Armstrong6146f7e2023-08-28 09:05:38 -0400396 sh(
397 label : 'Monitor using mem_consumption.py',
398 script : """
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400399echo -e "\n** Monitor using mem_consumption.py ?"
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400400
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400401if [ ${withMonitoring} = true ] ; then
402 cat <<EOM
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400403
404** -----------------------------------------------------------------------
405** Monitoring memory usage with mem_consumption.py
406** -----------------------------------------------------------------------
407EOM
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400408 mkdir -p "$WORKSPACE/voltha-pods-mem-consumption-${workflow}"
409 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400410
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400411 echo '** Installing python virtualenv'
412 make venv-activate-patched
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400413
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400414 # Collect initial memory consumption
415 set +u && source .venv/bin/activate && set -u
416 python scripts/mem_consumption.py -o $WORKSPACE/voltha-pods-mem-consumption-${workflow} -a 0.0.0.0:31301 -n ${volthaNamespace}
417fi
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400418
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400419echo -e '** Monitor memory consumption: LEAVE\n'
420""")
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400421
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400422 sh(
423 label : "make testTarget=[${testTarget}]",
424 script : """
425echo -e "\n** make testTarget=[${testTarget}]"
426mkdir -p ${logsDir}
427export ROBOT_MISC_ARGS="-d ${logsDir} ${params.extraRobotArgs} "
428ROBOT_MISC_ARGS+="-v ONOS_SSH_PORT:30115 -v ONOS_REST_PORT:30120 -v NAMESPACE:${volthaNamespace} -v INFRA_NAMESPACE:${infraNamespace} -v container_log_dir:${logsDir} -v logging:${testLogging}"
429export KVSTOREPREFIX=voltha/voltha_voltha
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800430
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400431make -C "$WORKSPACE/voltha-system-tests" ${testTarget}
432""")
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400433
434 getPodsInfo("${logsDir}")
435
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400436 // [TODO] make conditional, bundle when logs are available
Joey Armstrong6146f7e2023-08-28 09:05:38 -0400437 sh(
438 label : 'Gather robot Framework logs',
439 script : """
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400440echo -e '\n** Gather robot Framework logs: ENTER'
Joey Armstrong7ba23ac2023-08-29 15:21:53 -0400441
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400442# set +e
443# collect logs collected in the Robot Framework StartLogging keyword
444cd "${logsDir}"
Joey Armstrong7ba23ac2023-08-29 15:21:53 -0400445
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400446echo "** Available logs:"
447/bin/ls -l "$logsDir"
448echo
Joey Armstrong7ba23ac2023-08-29 15:21:53 -0400449
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400450echo '** Bundle combined log'
451gzip *-combined.log || true
452rm -f *-combined.log || true
Joey Armstrong54dec092023-08-03 18:21:38 -0400453
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400454echo -e '** Gather robot Framework logs: LEAVE\n'
455""")
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400456
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400457 // -----------------------------------------------------------------------
458 // -----------------------------------------------------------------------
Joey Armstrong6146f7e2023-08-28 09:05:38 -0400459 sh(
460 label : 'Monitor pod-mem-consumption',
461 script : """
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400462echo -e '** Monitor pod-mem-consumption: ENTER'
463if [ ${withMonitoring} = true ] ; then
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400464 cat <<EOM
465
466** -----------------------------------------------------------------------
467** Monitoring pod-memory-consumption using mem_consumption.py
468** -----------------------------------------------------------------------
469EOM
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400470
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400471cd "$WORKSPACE/voltha-system-tests"
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400472
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400473echo '** Installing python virtualenv'
474make venv-activate-patched
475
476# Collect memory consumption of voltha pods once all the tests are complete
477set +u && source .venv/bin/activate && set -u
478python scripts/mem_consumption.py -o $WORKSPACE/voltha-pods-mem-consumption-${workflow} -a 0.0.0.0:31301 -n ${volthaNamespace}
479fi
480echo -e '** Monitor pod-mem-consumption: LEAVE\n'
481""")
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400482 } // stage
Joey Armstrongb65ada32023-08-03 12:50:20 -0400483
484 return
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400485} // execute_test()
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800486
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400487// -----------------------------------------------------------------------
488// -----------------------------------------------------------------------
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400489void collectArtifacts(exitStatus) {
Joey Armstrong0251e962023-08-25 20:51:31 -0400490 script {
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400491 enter("exitStatus=${exitStatus}")
Joey Armstrongf0232762024-02-11 17:23:04 -0500492 banner('collectArtifacts')
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400493 }
Joey Armstrongf0232762024-02-11 17:23:04 -0500494
Joey Armstrong5353d312024-02-09 19:03:03 -0500495 dotkube(['debug':false])
Joey Armstrongcd419122023-08-07 14:56:39 -0400496 getPodsInfo("$WORKSPACE/${exitStatus}")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400497
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400498 sh(label : 'kubectl logs > voltha.log',
499 script : """
500kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha \
501 > $WORKSPACE/${exitStatus}/voltha.log
502""")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400503
Joey Armstrongcd419122023-08-07 14:56:39 -0400504 archiveArtifacts artifacts: '**/*.log,**/*.gz,**/*.txt,**/*.html,**/voltha-pods-mem-consumption-att/*,**/voltha-pods-mem-consumption-dt/*,**/voltha-pods-mem-consumption-tt/*'
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400505
Joey Armstrongbccfa4b2023-09-27 17:34:22 -0400506 script { killKailStartup('collectArtifacts') }
507 script { findPublishedLogs() }
Joey Armstrong97a8b882023-08-02 16:08:52 -0400508
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400509 enter('RobotPublisher')
Joey Armstrongcd419122023-08-07 14:56:39 -0400510 step([$class: 'RobotPublisher',
Joey Armstrong0251e962023-08-25 20:51:31 -0400511 disableArchiveOutput: false,
512 logFileName: '**/*/log*.html',
513 otherFiles: '',
514 outputFileName: '**/*/output*.xml',
515 outputPath: '.',
516 passThreshold: 100,
517 reportFileName: '**/*/report*.html',
518 unstableThreshold: 0,
519 onlyCritical: true])
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400520 leave('RobotPublisher')
Joey Armstrongcd419122023-08-07 14:56:39 -0400521
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400522 leave("exitStatus=${exitStatus}")
Joey Armstrongcd419122023-08-07 14:56:39 -0400523 return
Hardik Windlassec9341b2021-06-07 11:58:29 +0000524}
525
Joey Armstrongb65ada32023-08-03 12:50:20 -0400526// -----------------------------------------------------------------------
527// Intent: main
528// -----------------------------------------------------------------------
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800529pipeline {
Joey Armstrong0251e962023-08-25 20:51:31 -0400530 /* no label, executor is determined by JJB */
531 agent {
532 label "${params.buildNode}"
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800533 }
Joey Armstrong84adc542023-04-11 14:47:34 -0400534
Joey Armstrong0251e962023-08-25 20:51:31 -0400535 options {
536 timeout(time: "${timeout}", unit: 'MINUTES')
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800537 }
Joey Armstronged161f72023-04-11 13:16:59 -0400538
Joey Armstrong0251e962023-08-25 20:51:31 -0400539 environment {
540 KUBECONFIG = "$HOME/.kube/kind-${clusterName}"
541 VOLTCONFIG = "$HOME/.volt/config"
542 PATH = "$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
543 DIAGS_PROFILE = 'VOLTHA_PROFILE'
544 SSHPASS = 'karaf'
545 }
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400546
Joey Armstrong0251e962023-08-25 20:51:31 -0400547 stages {
548 stage('Download Code') {
Joey Armstrongf404b642023-08-04 14:39:13 -0400549 steps {
Joey Armstrongdef9c402024-01-30 18:05:29 -0500550 enter('getVolthaCode')
Joey Armstrong0251e962023-08-25 20:51:31 -0400551 getVolthaCode([
552 branch: "${branch}",
553 gerritProject: "${gerritProject}",
554 gerritRefspec: "${gerritRefspec}",
555 volthaSystemTestsChange: "${volthaSystemTestsChange}",
556 volthaHelmChartsChange: "${volthaHelmChartsChange}",
557 ])
Joey Armstrongdef9c402024-01-30 18:05:29 -0500558 leave('getVolthaCode')
Joey Armstrong0251e962023-08-25 20:51:31 -0400559 }
560 }
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400561
Joey Armstrong0251e962023-08-25 20:51:31 -0400562 stage('Build patch v1.1') {
563 // build the patch only if gerritProject is specified
564 when {
565 expression { return !gerritProject.isEmpty() }
566 }
567
568 steps {
Joey Armstrongdef9c402024-01-30 18:05:29 -0500569 enter('buildVolthaComponent')
Joey Armstrong0251e962023-08-25 20:51:31 -0400570 // NOTE that the correct patch has already been checked out
571 // during the getVolthaCode step
572 buildVolthaComponent("${gerritProject}")
Joey Armstrongdef9c402024-01-30 18:05:29 -0500573 leave('buildVolthaComponent')
Joey Armstrong0251e962023-08-25 20:51:31 -0400574 }
575 }
576
577 // -----------------------------------------------------------------------
578 // -----------------------------------------------------------------------
579 stage('Install Kail')
580 {
581 steps
582 {
583 script
584 {
585 String cmd = [
586 'make',
587 '--no-print-directory',
588 '-C', "$WORKSPACE/voltha-system-tests",
589 "KAIL_PATH=\"$WORKSPACE/bin\"",
590 'kail',
591 ].join(' ')
592
593 println(" ** Running: ${cmd}")
594 sh("${cmd}")
595 } // script
596 } // steps
597 } // stage
598
599 // -----------------------------------------------------------------------
600 // -----------------------------------------------------------------------
601 stage('Install Tools') {
602 steps {
603 script {
604 String branchName = branchName()
605 String iam = getIam('Install Tools')
606
607 println("${iam}: ENTER (branch=$branch)")
608 installKind(branch) // needed early by stage(Cleanup)
609 println("${iam}: LEAVE (branch=$branch)")
610 } // script
611 } // steps
612 } // stage
613
614 // -----------------------------------------------------------------------
615 // -----------------------------------------------------------------------
616 stage('Create K8s Cluster') {
617 steps {
618 script {
619 def clusterExists = sh(
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400620 label : 'Create K8s Cluster',
Joey Armstrong0251e962023-08-25 20:51:31 -0400621 returnStdout: true,
622 script: """kind get clusters | grep "${clusterName}" | wc -l""")
623
624 if (clusterExists.trim() == '0') {
625 createKubernetesCluster([nodes: 3, name: clusterName])
626 }
627 } // script
628 } // steps
629 } // stage('Create K8s Cluster')
630
631 // -----------------------------------------------------------------------
632 // -----------------------------------------------------------------------
633 stage('Replace voltctl') {
634 // if the project is voltctl, override the downloaded one with the built one
635 when {
636 expression { return gerritProject == 'voltctl' }
637 }
638
639 // Hmmmm(?) where did the voltctl download happen ?
640 // Likely Makefile but would be helpful to document here.
641 steps {
642 script {
643 String iam = getIam('Replace voltctl')
644
645 println("${iam} Running: installVoltctl($branch)")
646 println("${iam}: ENTER")
647 installVoltctl("$branch")
648 println("${iam}: LEAVE")
649 } // script
650 } // step
651 } // stage
652
653 // -----------------------------------------------------------------------
654 // -----------------------------------------------------------------------
655 stage('Load image in kind nodes')
656 {
657 when {
658 expression { return !gerritProject.isEmpty() }
659 }
660 steps {
661 loadToKind()
662 } // steps
663 } // stage
664
665 // -----------------------------------------------------------------------
666 // [TODO] verify testing output
667 // -----------------------------------------------------------------------
668 stage('Parse and execute tests')
669 {
670 steps {
671 script {
672 // Announce ourselves for log usability
673 enter('Parse and execute tests')
674
Joey Armstrong6146f7e2023-08-28 09:05:38 -0400675 def tests = readYaml text: testTargets // typeof == Map (?)
Joey Armstrong0251e962023-08-25 20:51:31 -0400676 println("** [DEBUG]: tests=$tests")
677
678 // Display expected tests for times when output goes dark
679 tests.eachWithIndex { test, idx ->
680 String target = test['target']
681 println("** test[${idx}]: ${target}\n")
682 }
683
684 println('''
685** -----------------------------------------------------------------------
686** NOTE: For odd/silent job failures verify a few details
687** - All tests mentioned in the tests-to-run index were logged.
688** - Test suites display ENTER/LEAVE mesasge pairs.
689** - Processing terminated prematurely when LEAVE strings are missing.
690** -----------------------------------------------------------------------
691''')
692 tests.eachWithIndex { test, idx ->
693 println "** readYaml test suite[$idx]) test=[${test}]"
694
Joey Armstrongf404b642023-08-04 14:39:13 -0400695 String target = test['target']
696 String workflow = test['workflow']
697 String flags = test['flags']
698 Boolean teardown = test['teardown'].toBoolean()
699 Boolean logging = test['logging'].toBoolean()
700 String testLogging = (logging) ? 'True' : 'False'
701
Joey Armstrong0251e962023-08-25 20:51:31 -0400702 print("""
Joey Armstrong268442d2023-08-22 17:16:10 -0400703** -----------------------------------------------------------------------
Joey Armstrong0251e962023-08-25 20:51:31 -0400704** Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}
Joey Armstrong268442d2023-08-22 17:16:10 -0400705** -----------------------------------------------------------------------
Joey Armstrong268442d2023-08-22 17:16:10 -0400706""")
707
Joey Armstrong0251e962023-08-25 20:51:31 -0400708 try {
Joey Armstrong6146f7e2023-08-28 09:05:38 -0400709 enter("execute_test (target=$target)")
Joey Armstrong0251e962023-08-25 20:51:31 -0400710 execute_test(target, workflow, testLogging, teardown, flags)
711 }
Joey Armstrong9341c9a2023-08-28 12:09:19 -0400712 // groovylint-disable-next-line CatchException
Joey Armstrong0251e962023-08-25 20:51:31 -0400713 catch (Exception err) {
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400714 String iamexc = getIam(test)
Joey Armstrong9341c9a2023-08-28 12:09:19 -0400715 println("** ${iamexc}: EXCEPTION ${err}")
Joey Armstrong0251e962023-08-25 20:51:31 -0400716 }
717 finally {
718 leave("execute_test (target=$target)")
719 }
Joey Armstrongb65ada32023-08-03 12:50:20 -0400720 } // for
Joey Armstrong0251e962023-08-25 20:51:31 -0400721 // Premature exit if this message is not logged
722 leave('Parse and execute tests')
Joey Armstrongb65ada32023-08-03 12:50:20 -0400723 } // script
724 } // steps
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400725 } // stage
726 } // stages
Joey Armstrong84adc542023-04-11 14:47:34 -0400727
728 post
Joey Armstrongbccfa4b2023-09-27 17:34:22 -0400729 { // https://www.jenkins.io/doc/book/pipeline/syntax/#post
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400730 aborted {
731 collectArtifacts('aborted')
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400732 }
733 failure {
734 collectArtifacts('failed')
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400735 }
736 always {
737 collectArtifacts('always')
Joey Armstrongbccfa4b2023-09-27 17:34:22 -0400738 }
739 cleanup {
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400740 script { cleanupPortForward() }
741 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800742 }
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400743} // pipeline
Joey Armstronged161f72023-04-11 13:16:59 -0400744
Joey Armstrong664c55a2023-08-28 14:22:33 -0400745// [EOF]