blob: 128a20d290c12c32827f165855b0784603772fe0 [file] [log] [blame]
Joey Armstrong8c6f6482023-01-12 12:31:44 -05001// Copyright 2021-2023 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',
41 '(expected=[$br] != found=[$branch])'
42 ].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 Armstronge5aae1c2023-07-24 14:11:20 -040091// Intent: Determine if working on a release branch.
92// Note: Conditional is legacy, should also check for *-dev or *-pre
93// -----------------------------------------------------------------------
Joey Armstrong0251e962023-08-25 20:51:31 -040094Boolean isReleaseBranch(String name) {
Joey Armstronge5aae1c2023-07-24 14:11:20 -040095 // List modifiers = ['-dev', '-pre', 'voltha-x.y.z-pre']
Joey Armstrongb65ada32023-08-03 12:50:20 -040096 // if branchName in modifiers
97 return(name != 'master') // OR branchName.contains('-')
Joey Armstronge5aae1c2023-07-24 14:11:20 -040098}
99
100// -----------------------------------------------------------------------
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400101// Intent: Terminate orphaned port-forward from different namespaces
102// -----------------------------------------------------------------------
103void cleanupPortForward() {
104 enter('cleanupPortForward')
105
106 Map pkpfArgs =\
107 [
108 'banner' : true, // display banner for logging
109 'show_procs' : true, // display procs under consideration
110 'filler' : true // fix conditional trailing comma
111 ]
112
113 // 'kubectl.*port-forward'
114 pkill_port_forward('port-forward', pkpfArgs)
115 leave('cleanupPortForward')
116 return
117}
118
Joey Armstrongbccfa4b2023-09-27 17:34:22 -0400119// find . \( -name 'log*.html' -o -name 'output*.xml' -o -name 'report*.html' \) -p
120// -----------------------------------------------------------------------
121// Intent: Display contents of the logs directory
122// -----------------------------------------------------------------------
123// [TODO]
124// o where-4-art-thou logs directory ?
125// o Replace find {logfile} command with /bin/ls {logdir} when found.
126// Individual logs may be missing due to failure, show what is available.
127// -----------------------------------------------------------------------
128void findPublishedLogs() {
129 String iam = 'findPublishedLogs'
130
131 enter(iam)
132 sh(label : iam,
133 script : """
134find . -name 'output.xml' -print
135""")
136 leave(iam)
137 return
138}
139
140// -----------------------------------------------------------------------
141// Intent: Terminate kail-startup process launched earlier
142// -----------------------------------------------------------------------
143// :param caller: Name of parent calling function (debug context)
144// :type caller: String, optional
145// :returns: none
146// :rtype: void
147// -----------------------------------------------------------------------
148void killKailStartup(String caller='') {
149 String iam = "killKailStartup (caller=$caller)"
150
151 enter(iam)
152 sh(label : 'Terminate kail-startup',
153 script : """
154if [[ \$(pgrep --count '_TAG=kail-startup') -gt 0 ]]; then
155 pkill --uid \$(id -u) --echo --list-full --full '_TAG=kail-startup'
156fi
157""")
158 leave(iam)
159 return
160}
161
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400162// -----------------------------------------------------------------------
Joey Armstrong0251e962023-08-25 20:51:31 -0400163// Intent: Iterate over a list of test suites and invoke.
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400164// -----------------------------------------------------------------------
Joey Armstrong0251e962023-08-25 20:51:31 -0400165void execute_test\
166(
167 String testTarget, // functional-single-kind-dt
168 String workflow, // dt
169 String testLogging, // 'True'
170 Boolean teardown, // true
171 String testSpecificHelmFlags=''
172) {
Joey Armstrongb65ada32023-08-03 12:50:20 -0400173 String infraNamespace = 'default'
174 String volthaNamespace = 'voltha'
175 String logsDir = "$WORKSPACE/${testTarget}"
Joey Armstrong293e16b2022-11-26 20:16:33 -0500176
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400177 // -----------------------------------------------------------------------
Joey Armstrong268442d2023-08-22 17:16:10 -0400178 // Intent: Cleanup stale port-forwarding
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400179 // -----------------------------------------------------------------------
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400180 stage('Cleanup') {
181 if (teardown) {
Joey Armstrong84adc542023-04-11 14:47:34 -0400182 timeout(15) {
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400183 script {
Joey Armstrongb65ada32023-08-03 12:50:20 -0400184 helmTeardown(['default', infraNamespace, volthaNamespace])
Joey Armstrong84adc542023-04-11 14:47:34 -0400185 }
Joey Armstrong0251e962023-08-25 20:51:31 -0400186 } // timeout
187
188 timeout(5) {
189 script {
190 enter('Cleanup')
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400191 cleanupPortForward()
Joey Armstrong6146f7e2023-08-28 09:05:38 -0400192 leave('Cleanup')
Joey Armstrong0251e962023-08-25 20:51:31 -0400193 } // script
194 } // timeout
195 } // teardown
196 } // stage('Cleanup')
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500197
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400198 // -----------------------------------------------------------------------
199 // -----------------------------------------------------------------------
Joey Armstrong0251e962023-08-25 20:51:31 -0400200 stage('Deploy common infrastructure') {
201 script {
202 local dashargs = [
203 'kpi_exporter.enabled=false',
204 'dashboards.xos=false',
205 'dashboards.onos=false',
206 'dashboards.aaa=false',
207 'dashboards.voltha=false',
208 ].join(',')
209
210 local promargs = [
211 'prometheus.alertmanager.enabled=false',
212 'prometheus.pushgateway.enabled=false',
213 ].join(',')
214
Joey Armstrong6146f7e2023-08-28 09:05:38 -0400215 sh(label : 'Deploy common infrastructure',
216 script : """
Hardik Windlasse1660492022-03-14 15:12:46 +0000217 helm repo add onf https://charts.opencord.org
218 helm repo update
Joey Armstrong0251e962023-08-25 20:51:31 -0400219
220 echo -e "\nwithMonitoring=[$withMonitoring]"
Hardik Windlasse1660492022-03-14 15:12:46 +0000221 if [ ${withMonitoring} = true ] ; then
222 helm install nem-monitoring onf/nem-monitoring \
Joey Armstrong0251e962023-08-25 20:51:31 -0400223 --set ${promargs} \
224 --set ${dashargs}
Hardik Windlasse1660492022-03-14 15:12:46 +0000225 fi
Joey Armstrong0251e962023-08-25 20:51:31 -0400226 """)
227 } // script
228 } // stage('Deploy Common Infra')
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500229
Joey Armstrong0251e962023-08-25 20:51:31 -0400230 // -----------------------------------------------------------------------
231 // [TODO] Check onos_log output
232 // -----------------------------------------------------------------------
233 stage('Deploy Voltha') {
234 if (teardown) {
235 timeout(10) {
236 script {
237 String iam = getIam('Deploy Voltha')
238 String onosLog = "${logsDir}/onos-voltha-startup-combined.log"
Hardik Windlassec9341b2021-06-07 11:58:29 +0000239
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400240 sh(label : 'Launch kail-startup',
241 script : """
242mkdir -p "$logsDir"
243touch "$onosLog"
Joey Armstrongf404b642023-08-04 14:39:13 -0400244
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400245_TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} > "$onosLog" &
246""")
247
248 // if we're downloading a voltha-helm-charts patch,
249 // install from a local copy of the charts
Joey Armstrong0251e962023-08-25 20:51:31 -0400250 Boolean localCharts = false
Joey Armstrongf404b642023-08-04 14:39:13 -0400251
Joey Armstrong0251e962023-08-25 20:51:31 -0400252 if (volthaHelmChartsChange != ''
253 || gerritProject == 'voltha-helm-charts'
254 || isReleaseBranch(branch) // branch != 'master'
255 ) {
256 localCharts = true
257 }
Hardik Windlassec9341b2021-06-07 11:58:29 +0000258
Joey Armstrong0251e962023-08-25 20:51:31 -0400259 String branchName = branchName()
260 Boolean isRelease = isReleaseBranch(branch)
261 println([
262 " ** localCharts=${localCharts}",
263 "branchName=${branchName}",
264 "branch=${branch}",
265 "branch=isReleaseBranch=${isRelease}",
266 ].join(', '))
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800267
Joey Armstrong0251e962023-08-25 20:51:31 -0400268 // -----------------------------------------------------------------------
269 // Rewrite localHelmFlags using array join, moving code around and
270 // refactoring into standalone functions
271 // -----------------------------------------------------------------------
272 // NOTE temporary workaround expose ONOS node ports
273 // -----------------------------------------------------------------------
274 String localHelmFlags = [
275 extraHelmFlags.trim(),
276 "--set global.log_level=${logLevel.toUpperCase()}",
277 '--set onos-classic.onosSshPort=30115',
278 '--set onos-classic.onosApiPort=30120',
279 '--set onos-classic.onosOfPort=31653',
280 '--set onos-classic.individualOpenFlowNodePorts=true',
281 testSpecificHelmFlags
282 ].join(' ')
Joey Armstrong28e86ee2023-08-03 15:22:29 -0400283
Joey Armstrong0251e962023-08-25 20:51:31 -0400284 println("** ${iam} localHelmFlags = ${localHelmFlags}")
Hardik Windlassec9341b2021-06-07 11:58:29 +0000285
Joey Armstrong0251e962023-08-25 20:51:31 -0400286 if (gerritProject != '') {
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400287 localHelmFlags += getVolthaImageFlags(gerritProject)
Joey Armstrong0251e962023-08-25 20:51:31 -0400288 }
Matteo Scandolofcfc60d2021-02-24 09:06:48 -0800289
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400290 enter('volthaDeploy')
Joey Armstrong0251e962023-08-25 20:51:31 -0400291 volthaDeploy([
292 infraNamespace: infraNamespace,
293 volthaNamespace: volthaNamespace,
294 workflow: workflow.toLowerCase(),
295 withMacLearning: enableMacLearning.toBoolean(),
296 extraHelmFlags: localHelmFlags,
297 localCharts: localCharts,
298 bbsimReplica: olts.toInteger(),
299 dockerRegistry: registry,
300 ])
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400301 leave('volthaDeploy')
Joey Armstrong0251e962023-08-25 20:51:31 -0400302 } // script
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400303
Joey Armstrong1b7cc792023-09-26 14:19:21 -0400304 // Display spawned procs
305 script {
306 enter('bbsim-tests::pgrep_port_forward::0')
307 pgrep_port_forward('port-forw')
308 leave('bbsim-tests::pgrep_port_forward::0')
Joey Armstrongbccfa4b2023-09-27 17:34:22 -0400309
310 killKailStartup('Deploy Voltha')
Joey Armstrong1b7cc792023-09-26 14:19:21 -0400311 }
Joey Armstrong0251e962023-08-25 20:51:31 -0400312
Joey Armstrong0251e962023-08-25 20:51:31 -0400313 // -----------------------------------------------------------------------
314 // Bundle onos-voltha / kail logs
315 // -----------------------------------------------------------------------
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400316 sh(
317 label : 'Bundle logs: onos-voltha-startup-combined',
318 script : """
Joey Armstrong0251e962023-08-25 20:51:31 -0400319cat <<EOM
320
321** -----------------------------------------------------------------------
Joey Armstrong7ba23ac2023-08-29 15:21:53 -0400322** Combine and compress voltha startup log(s)
Joey Armstrong0251e962023-08-25 20:51:31 -0400323** -----------------------------------------------------------------------
324EOM
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400325
326pushd "${logsDir}" || { echo "ERROR: pushd $logsDir failed"; exit 1; }
327gzip -k onos-voltha-startup-combined.log
328rm onos-voltha-startup-combined.log
329popd || { echo "ERROR: popd $logsDir failed"; exit 1; }
Joey Armstrong0251e962023-08-25 20:51:31 -0400330 """)
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400331 } // timeout(10)
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400332
Joey Armstrong0251e962023-08-25 20:51:31 -0400333 // -----------------------------------------------------------------------
334 // -----------------------------------------------------------------------
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400335 sh(label : 'while-true-port-forward',
336 """
Hardik Windlassec9341b2021-06-07 11:58:29 +0000337 JENKINS_NODE_COOKIE="dontKillMe" _TAG="voltha-voltha-api" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n ${volthaNamespace} svc/voltha-voltha-api 55555:55555; done"&
338 JENKINS_NODE_COOKIE="dontKillMe" _TAG="voltha-infra-etcd" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n ${infraNamespace} svc/voltha-infra-etcd 2379:2379; done"&
339 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"&
340 bbsimDmiPortFwd=50075
341 for i in {0..${olts.toInteger() - 1}}; do
342 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"&
343 ((bbsimDmiPortFwd++))
344 done
Hardik Windlass3bb089a2022-03-22 17:56:03 +0000345 if [ ${withMonitoring} = true ] ; then
346 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"&
347 fi
Joey Armstrong7ba23ac2023-08-29 15:21:53 -0400348# ps aux | grep port-forward
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400349""")
Joey Armstrong0251e962023-08-25 20:51:31 -0400350 // ---------------------------------
351 // Sanity check port-forward spawned
352 // ---------------------------------
Joey Armstrong1b7cc792023-09-26 14:19:21 -0400353 script {
354 enter('bbsim-tests::pgrep_port_forward::1')
355 pgrep_port_forward('port-forw')
356 leave('bbsim-tests::pgrep_port_forward::1')
357 }
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500358
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400359 // setting ONOS log level
Joey Armstrong0251e962023-08-25 20:51:31 -0400360 script {
361 enter('setOnosLogLevels')
362 setOnosLogLevels([
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400363 onosNamespace: infraNamespace,
364 apps: [
365 'org.opencord.dhcpl2relay',
366 'org.opencord.olt',
367 'org.opencord.aaa',
368 'org.opencord.maclearner',
369 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
370 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
371 ],
372 logLevel: logLevel
373 ])
Joey Armstrong6146f7e2023-08-28 09:05:38 -0400374 leave('setOnosLogLevels')
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400375 } // script
376 } // if (teardown)
377 } // stage('Deploy Voltha')
378
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400379 // -----------------------------------------------------------------------
380 // -----------------------------------------------------------------------
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400381 stage("Run test ${testTarget} on workflow ${workflow}") {
Joey Armstrong6146f7e2023-08-28 09:05:38 -0400382 sh(
383 label : 'Monitor using mem_consumption.py',
384 script : """
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400385echo -e "\n** Monitor using mem_consumption.py ?"
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400386
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400387if [ ${withMonitoring} = true ] ; then
388 cat <<EOM
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400389
390** -----------------------------------------------------------------------
391** Monitoring memory usage with mem_consumption.py
392** -----------------------------------------------------------------------
393EOM
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400394 mkdir -p "$WORKSPACE/voltha-pods-mem-consumption-${workflow}"
395 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400396
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400397 echo '** Installing python virtualenv'
398 make venv-activate-patched
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400399
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400400 # Collect initial memory consumption
401 set +u && source .venv/bin/activate && set -u
402 python scripts/mem_consumption.py -o $WORKSPACE/voltha-pods-mem-consumption-${workflow} -a 0.0.0.0:31301 -n ${volthaNamespace}
403fi
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400404
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400405echo -e '** Monitor memory consumption: LEAVE\n'
406""")
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400407
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400408 sh(
409 label : "make testTarget=[${testTarget}]",
410 script : """
411echo -e "\n** make testTarget=[${testTarget}]"
412mkdir -p ${logsDir}
413export ROBOT_MISC_ARGS="-d ${logsDir} ${params.extraRobotArgs} "
414ROBOT_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}"
415export KVSTOREPREFIX=voltha/voltha_voltha
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800416
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400417make -C "$WORKSPACE/voltha-system-tests" ${testTarget}
418""")
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400419
420 getPodsInfo("${logsDir}")
421
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400422 // [TODO] make conditional, bundle when logs are available
Joey Armstrong6146f7e2023-08-28 09:05:38 -0400423 sh(
424 label : 'Gather robot Framework logs',
425 script : """
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400426echo -e '\n** Gather robot Framework logs: ENTER'
Joey Armstrong7ba23ac2023-08-29 15:21:53 -0400427
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400428# set +e
429# collect logs collected in the Robot Framework StartLogging keyword
430cd "${logsDir}"
Joey Armstrong7ba23ac2023-08-29 15:21:53 -0400431
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400432echo "** Available logs:"
433/bin/ls -l "$logsDir"
434echo
Joey Armstrong7ba23ac2023-08-29 15:21:53 -0400435
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400436echo '** Bundle combined log'
437gzip *-combined.log || true
438rm -f *-combined.log || true
Joey Armstrong54dec092023-08-03 18:21:38 -0400439
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400440echo -e '** Gather robot Framework logs: LEAVE\n'
441""")
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400442
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400443 // -----------------------------------------------------------------------
444 // -----------------------------------------------------------------------
Joey Armstrong6146f7e2023-08-28 09:05:38 -0400445 sh(
446 label : 'Monitor pod-mem-consumption',
447 script : """
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400448echo -e '** Monitor pod-mem-consumption: ENTER'
449if [ ${withMonitoring} = true ] ; then
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400450 cat <<EOM
451
452** -----------------------------------------------------------------------
453** Monitoring pod-memory-consumption using mem_consumption.py
454** -----------------------------------------------------------------------
455EOM
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400456
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400457cd "$WORKSPACE/voltha-system-tests"
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400458
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400459echo '** Installing python virtualenv'
460make venv-activate-patched
461
462# Collect memory consumption of voltha pods once all the tests are complete
463set +u && source .venv/bin/activate && set -u
464python scripts/mem_consumption.py -o $WORKSPACE/voltha-pods-mem-consumption-${workflow} -a 0.0.0.0:31301 -n ${volthaNamespace}
465fi
466echo -e '** Monitor pod-mem-consumption: LEAVE\n'
467""")
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400468 } // stage
Joey Armstrongb65ada32023-08-03 12:50:20 -0400469
470 return
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400471} // execute_test()
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800472
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400473// -----------------------------------------------------------------------
474// -----------------------------------------------------------------------
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400475void collectArtifacts(exitStatus) {
Joey Armstrong0251e962023-08-25 20:51:31 -0400476 script {
477 String iam = getIam('collectArtifacts')
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400478 enter("exitStatus=${exitStatus}")
Joey Armstrongcd419122023-08-07 14:56:39 -0400479
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400480 println("""
Joey Armstrong97a8b882023-08-02 16:08:52 -0400481
482** -----------------------------------------------------------------------
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400483** IAM: $iam
Joey Armstrong97a8b882023-08-02 16:08:52 -0400484** collectArtifacts
485** -----------------------------------------------------------------------
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400486""")
487 }
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400488
Joey Armstrongcd419122023-08-07 14:56:39 -0400489 getPodsInfo("$WORKSPACE/${exitStatus}")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400490
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400491 sh(label : 'kubectl logs > voltha.log',
492 script : """
493kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha \
494 > $WORKSPACE/${exitStatus}/voltha.log
495""")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400496
Joey Armstrongcd419122023-08-07 14:56:39 -0400497 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 -0400498
Joey Armstrongbccfa4b2023-09-27 17:34:22 -0400499 script { killKailStartup('collectArtifacts') }
500 script { findPublishedLogs() }
Joey Armstrong97a8b882023-08-02 16:08:52 -0400501
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400502 enter('RobotPublisher')
Joey Armstrongcd419122023-08-07 14:56:39 -0400503 step([$class: 'RobotPublisher',
Joey Armstrong0251e962023-08-25 20:51:31 -0400504 disableArchiveOutput: false,
505 logFileName: '**/*/log*.html',
506 otherFiles: '',
507 outputFileName: '**/*/output*.xml',
508 outputPath: '.',
509 passThreshold: 100,
510 reportFileName: '**/*/report*.html',
511 unstableThreshold: 0,
512 onlyCritical: true])
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400513 leave('RobotPublisher')
Joey Armstrongcd419122023-08-07 14:56:39 -0400514
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400515 leave("exitStatus=${exitStatus}")
Joey Armstrongcd419122023-08-07 14:56:39 -0400516 return
Hardik Windlassec9341b2021-06-07 11:58:29 +0000517}
518
Joey Armstrongb65ada32023-08-03 12:50:20 -0400519// -----------------------------------------------------------------------
520// Intent: main
521// -----------------------------------------------------------------------
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800522pipeline {
Joey Armstrong0251e962023-08-25 20:51:31 -0400523 /* no label, executor is determined by JJB */
524 agent {
525 label "${params.buildNode}"
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800526 }
Joey Armstrong84adc542023-04-11 14:47:34 -0400527
Joey Armstrong0251e962023-08-25 20:51:31 -0400528 options {
529 timeout(time: "${timeout}", unit: 'MINUTES')
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800530 }
Joey Armstronged161f72023-04-11 13:16:59 -0400531
Joey Armstrong0251e962023-08-25 20:51:31 -0400532 environment {
533 KUBECONFIG = "$HOME/.kube/kind-${clusterName}"
534 VOLTCONFIG = "$HOME/.volt/config"
535 PATH = "$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
536 DIAGS_PROFILE = 'VOLTHA_PROFILE'
537 SSHPASS = 'karaf'
538 }
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400539
Joey Armstrong0251e962023-08-25 20:51:31 -0400540 stages {
541 stage('Download Code') {
Joey Armstrongf404b642023-08-04 14:39:13 -0400542 steps {
Joey Armstrong0251e962023-08-25 20:51:31 -0400543 getVolthaCode([
544 branch: "${branch}",
545 gerritProject: "${gerritProject}",
546 gerritRefspec: "${gerritRefspec}",
547 volthaSystemTestsChange: "${volthaSystemTestsChange}",
548 volthaHelmChartsChange: "${volthaHelmChartsChange}",
549 ])
550 }
551 }
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400552
Joey Armstrong0251e962023-08-25 20:51:31 -0400553 stage('Build patch v1.1') {
554 // build the patch only if gerritProject is specified
555 when {
556 expression { return !gerritProject.isEmpty() }
557 }
558
559 steps {
560 // NOTE that the correct patch has already been checked out
561 // during the getVolthaCode step
562 buildVolthaComponent("${gerritProject}")
563 }
564 }
565
566 // -----------------------------------------------------------------------
567 // -----------------------------------------------------------------------
568 stage('Install Kail')
569 {
570 steps
571 {
572 script
573 {
574 String cmd = [
575 'make',
576 '--no-print-directory',
577 '-C', "$WORKSPACE/voltha-system-tests",
578 "KAIL_PATH=\"$WORKSPACE/bin\"",
579 'kail',
580 ].join(' ')
581
582 println(" ** Running: ${cmd}")
583 sh("${cmd}")
584 } // script
585 } // steps
586 } // stage
587
588 // -----------------------------------------------------------------------
589 // -----------------------------------------------------------------------
590 stage('Install Tools') {
591 steps {
592 script {
593 String branchName = branchName()
594 String iam = getIam('Install Tools')
595
596 println("${iam}: ENTER (branch=$branch)")
597 installKind(branch) // needed early by stage(Cleanup)
598 println("${iam}: LEAVE (branch=$branch)")
599 } // script
600 } // steps
601 } // stage
602
603 // -----------------------------------------------------------------------
604 // -----------------------------------------------------------------------
605 stage('Create K8s Cluster') {
606 steps {
607 script {
608 def clusterExists = sh(
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400609 label : 'Create K8s Cluster',
Joey Armstrong0251e962023-08-25 20:51:31 -0400610 returnStdout: true,
611 script: """kind get clusters | grep "${clusterName}" | wc -l""")
612
613 if (clusterExists.trim() == '0') {
614 createKubernetesCluster([nodes: 3, name: clusterName])
615 }
616 } // script
617 } // steps
618 } // stage('Create K8s Cluster')
619
620 // -----------------------------------------------------------------------
621 // -----------------------------------------------------------------------
622 stage('Replace voltctl') {
623 // if the project is voltctl, override the downloaded one with the built one
624 when {
625 expression { return gerritProject == 'voltctl' }
626 }
627
628 // Hmmmm(?) where did the voltctl download happen ?
629 // Likely Makefile but would be helpful to document here.
630 steps {
631 script {
632 String iam = getIam('Replace voltctl')
633
634 println("${iam} Running: installVoltctl($branch)")
635 println("${iam}: ENTER")
636 installVoltctl("$branch")
637 println("${iam}: LEAVE")
638 } // script
639 } // step
640 } // stage
641
642 // -----------------------------------------------------------------------
643 // -----------------------------------------------------------------------
644 stage('Load image in kind nodes')
645 {
646 when {
647 expression { return !gerritProject.isEmpty() }
648 }
649 steps {
650 loadToKind()
651 } // steps
652 } // stage
653
654 // -----------------------------------------------------------------------
655 // [TODO] verify testing output
656 // -----------------------------------------------------------------------
657 stage('Parse and execute tests')
658 {
659 steps {
660 script {
661 // Announce ourselves for log usability
662 enter('Parse and execute tests')
663
Joey Armstrong6146f7e2023-08-28 09:05:38 -0400664 def tests = readYaml text: testTargets // typeof == Map (?)
Joey Armstrong0251e962023-08-25 20:51:31 -0400665 println("** [DEBUG]: tests=$tests")
666
667 // Display expected tests for times when output goes dark
668 tests.eachWithIndex { test, idx ->
669 String target = test['target']
670 println("** test[${idx}]: ${target}\n")
671 }
672
673 println('''
674** -----------------------------------------------------------------------
675** NOTE: For odd/silent job failures verify a few details
676** - All tests mentioned in the tests-to-run index were logged.
677** - Test suites display ENTER/LEAVE mesasge pairs.
678** - Processing terminated prematurely when LEAVE strings are missing.
679** -----------------------------------------------------------------------
680''')
681 tests.eachWithIndex { test, idx ->
682 println "** readYaml test suite[$idx]) test=[${test}]"
683
Joey Armstrongf404b642023-08-04 14:39:13 -0400684 String target = test['target']
685 String workflow = test['workflow']
686 String flags = test['flags']
687 Boolean teardown = test['teardown'].toBoolean()
688 Boolean logging = test['logging'].toBoolean()
689 String testLogging = (logging) ? 'True' : 'False'
690
Joey Armstrong0251e962023-08-25 20:51:31 -0400691 print("""
Joey Armstrong268442d2023-08-22 17:16:10 -0400692** -----------------------------------------------------------------------
Joey Armstrong0251e962023-08-25 20:51:31 -0400693** Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}
Joey Armstrong268442d2023-08-22 17:16:10 -0400694** -----------------------------------------------------------------------
Joey Armstrong268442d2023-08-22 17:16:10 -0400695""")
696
Joey Armstrong0251e962023-08-25 20:51:31 -0400697 try {
Joey Armstrong6146f7e2023-08-28 09:05:38 -0400698 enter("execute_test (target=$target)")
Joey Armstrong0251e962023-08-25 20:51:31 -0400699 execute_test(target, workflow, testLogging, teardown, flags)
700 }
Joey Armstrong9341c9a2023-08-28 12:09:19 -0400701 // groovylint-disable-next-line CatchException
Joey Armstrong0251e962023-08-25 20:51:31 -0400702 catch (Exception err) {
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400703 String iamexc = getIam(test)
Joey Armstrong9341c9a2023-08-28 12:09:19 -0400704 println("** ${iamexc}: EXCEPTION ${err}")
Joey Armstrong0251e962023-08-25 20:51:31 -0400705 }
706 finally {
707 leave("execute_test (target=$target)")
708 }
Joey Armstrongb65ada32023-08-03 12:50:20 -0400709 } // for
Joey Armstrong0251e962023-08-25 20:51:31 -0400710 // Premature exit if this message is not logged
711 leave('Parse and execute tests')
Joey Armstrongb65ada32023-08-03 12:50:20 -0400712 } // script
713 } // steps
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400714 } // stage
715 } // stages
Joey Armstrong84adc542023-04-11 14:47:34 -0400716
717 post
Joey Armstrongbccfa4b2023-09-27 17:34:22 -0400718 { // https://www.jenkins.io/doc/book/pipeline/syntax/#post
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400719 aborted {
720 collectArtifacts('aborted')
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400721 }
722 failure {
723 collectArtifacts('failed')
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400724 }
725 always {
726 collectArtifacts('always')
Joey Armstrongbccfa4b2023-09-27 17:34:22 -0400727 }
728 cleanup {
Joey Armstrong9f66e3f2023-09-20 16:29:29 -0400729 script { cleanupPortForward() }
730 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800731 }
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400732} // pipeline
Joey Armstronged161f72023-04-11 13:16:59 -0400733
Joey Armstrong664c55a2023-08-28 14:22:33 -0400734// [EOF]