blob: bc082a04342fb6b551c7f1e8555b975ee1ae6d35 [file] [log] [blame]
Joey Armstrong7bcb5782023-06-07 12:25:57 -04001// Copyright 2021-2023 Open Networking Foundation (ONF) and the ONF Contributors
2//
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
15// voltha-2.x e2e tests for openonu-go
16// uses bbsim to simulate OLT/ONUs
17
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040018// [TODO] Update syntax below to the latest supported
Joey Armstrong7bcb5782023-06-07 12:25:57 -040019library identifier: 'cord-jenkins-libraries@master',
20 retriever: modernSCM([
Joey Armstrong43cb15a2023-09-01 14:32:27 -040021 $class: 'GitSCMSource',
22 remote: 'https://gerrit.opencord.org/ci-management.git'
Joey Armstrong7bcb5782023-06-07 12:25:57 -040023])
24
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040025//------------------//
26//---] GLOBAL [---//
27//------------------//
Joey Armstronge9725b12023-08-28 18:15:12 -040028String clusterName = 'kind-ci'
Joey Armstrong7bcb5782023-06-07 12:25:57 -040029
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040030// -----------------------------------------------------------------------
Joey Armstrong43cb15a2023-09-01 14:32:27 -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 Armstrong0e0a42b2023-08-02 21:04:21 -040033// -----------------------------------------------------------------------
Joey Armstrong54dec092023-08-03 18:21:38 -040034String branchName() {
Joey Armstrong43cb15a2023-09-01 14:32:27 -040035 String br = 'voltha-2.12'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040036
Joey Armstrong43cb15a2023-09-01 14:32:27 -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 CatchException
44 }
45
46 return (br)
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040047}
48
49// -----------------------------------------------------------------------
Joey Armstrongaf4eef22023-08-25 16:14:45 -040050// Intent: Difficult at times to determine when pipeline jobs have
51// regenerated. Hardcode a version string that can be assigned
52// per-script to be sure latest repository changes are being used.
53// -----------------------------------------------------------------------
Joey Armstrong43cb15a2023-09-01 14:32:27 -040054String pipelineVer() {
55 String version = '2563719757ee52af49cf9da3fe76ed4bb6877588'
Joey Armstrongaf4eef22023-08-25 16:14:45 -040056 return(version)
57}
58
59// -----------------------------------------------------------------------
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040060// Intent: Due to lack of a reliable stack trace, construct a literal.
Joey Armstrongd0b5af02023-08-25 15:12:54 -040061// Jenkins will re-write the call stack for serialization.S
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040062// -----------------------------------------------------------------------
Joey Armstrongd0b5af02023-08-25 15:12:54 -040063// Note: Hardcoded version string used to visualize changes in jenkins UI
64// -----------------------------------------------------------------------
Joey Armstrongaf4eef22023-08-25 16:14:45 -040065String getIam(String func) {
Joey Armstrong54dec092023-08-03 18:21:38 -040066 String branchName = branchName()
Joey Armstrongaf4eef22023-08-25 16:14:45 -040067 String version = pipelineVer()
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040068 String src = [
69 'ci-management',
70 'jjb',
71 'pipeline',
72 'voltha',
Joey Armstrong54dec092023-08-03 18:21:38 -040073 branchName,
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040074 'bbsim-tests.groovy'
75 ].join('/')
76
Joey Armstrongd0b5af02023-08-25 15:12:54 -040077 String name = [src, version, func].join('::')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040078 return(name)
79}
80
81// -----------------------------------------------------------------------
Joey Armstrongaf4eef22023-08-25 16:14:45 -040082// Intent: Log progress message
83// -----------------------------------------------------------------------
Joey Armstrong7229d9b2023-08-25 18:03:13 -040084void enter(String name) {
Joey Armstrongaf4eef22023-08-25 16:14:45 -040085 // Announce ourselves for log usability
86 String iam = getIam(name)
87 println("${iam}: ENTER")
88 return
89}
90
91// -----------------------------------------------------------------------
92// Intent: Log progress message
93// -----------------------------------------------------------------------
Joey Armstrong7229d9b2023-08-25 18:03:13 -040094void leave(String name) {
Joey Armstrongaf4eef22023-08-25 16:14:45 -040095 // Announce ourselves for log usability
96 String iam = getIam(name)
97 println("${iam}: LEAVE")
98 return
99}
100
101// -----------------------------------------------------------------------
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400102// Intent: Determine if working on a release branch.
103// Note: Conditional is legacy, should also check for *-dev or *-pre
104// -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400105Boolean isReleaseBranch(String name) {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400106 // List modifiers = ['-dev', '-pre', 'voltha-x.y.z-pre']
Joey Armstrong54dec092023-08-03 18:21:38 -0400107 // if branchName in modifiers
108 return(name != 'master') // OR branchName.contains('-')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400109}
110
111// -----------------------------------------------------------------------
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400112// Intent: Terminate orphaned port-forward from different namespaces
113// -----------------------------------------------------------------------
114void cleanupPortForward() {
115 enter('cleanupPortForward')
116
117 Map pkpfArgs =\
118 [
119 'banner' : true, // display banner for logging
120 'show_procs' : true, // display procs under consideration
121 'filler' : true // fix conditional trailing comma
122 ]
123
124 // 'kubectl.*port-forward'
125 pkill_port_forward('port-forward', pkpfArgs)
126 leave('cleanupPortForward')
127 return
128}
129
130// -----------------------------------------------------------------------
Joey Armstrongaf4eef22023-08-25 16:14:45 -0400131// Intent: Iterate over a list of test suites and invoke.
Joey Armstrongf060aee2023-08-22 21:55:26 -0400132// -----------------------------------------------------------------------
Joey Armstrongaf4eef22023-08-25 16:14:45 -0400133void execute_test\
134(
135 String testTarget, // functional-single-kind-dt
136 String workflow, // dt
137 String testLogging, // 'True'
138 Boolean teardown, // true
139 String testSpecificHelmFlags=''
140) {
Joey Armstrong54dec092023-08-03 18:21:38 -0400141 String infraNamespace = 'default'
142 String volthaNamespace = 'voltha'
143 String logsDir = "$WORKSPACE/${testTarget}"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400144
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400145 // -----------------------------------------------------------------------
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400146 // Intent: Cleanup stale port-forwarding
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400147 // -----------------------------------------------------------------------
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400148 stage('Cleanup') {
149 if (teardown) {
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400150 timeout(15) {
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400151 script {
Joey Armstrong54dec092023-08-03 18:21:38 -0400152 helmTeardown(['default', infraNamespace, volthaNamespace])
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400153 }
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400154 } // timeout
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400155
Joey Armstrongf060aee2023-08-22 21:55:26 -0400156 timeout(5) {
157 script {
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400158 enter('Cleanup')
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400159 cleanupPortForward()
Joey Armstrong6146f7e2023-08-28 09:05:38 -0400160 leave('Cleanup')
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400161 } // script
162 } // timeout
Joey Armstrongf060aee2023-08-22 21:55:26 -0400163 } // teardown
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400164 }// stage('Cleanup')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400165
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400166 // -----------------------------------------------------------------------
167 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400168 stage('Deploy common infrastructure') {
169 script {
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400170 local dashargs = [
171 'kpi_exporter.enabled=false',
172 'dashboards.xos=false',
173 'dashboards.onos=false',
174 'dashboards.aaa=false',
175 'dashboards.voltha=false',
176 ].join(',')
177
178 local promargs = [
179 'prometheus.alertmanager.enabled=false',
180 'prometheus.pushgateway.enabled=false',
181 ].join(',')
182
Joey Armstrong6146f7e2023-08-28 09:05:38 -0400183 sh(label : 'Deploy common infrastructure',
184 script : """
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400185 helm repo add onf https://charts.opencord.org
186 helm repo update
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400187
188 echo -e "\nwithMonitoring=[$withMonitoring]"
189 if [ ${withMonitoring} = true ] ; then
190 helm install nem-monitoring onf/nem-monitoring \
Joey Armstrong38a87832023-08-23 17:02:50 -0400191 --set ${promargs} \
192 --set ${dashargs}
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400193 fi
Joey Armstrong38a87832023-08-23 17:02:50 -0400194 """)
195 } // script
196 } // stage('Deploy Common Infra')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400197
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400198 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400199 // [TODO] Check onos_log output
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400200 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400201 stage('Deploy Voltha') {
202 if (teardown) {
203 timeout(10) {
204 script {
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400205 String iam = getIam('Deploy Voltha')
206 String onosLog = "${logsDir}/onos-voltha-startup-combined.log"
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400207
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400208 sh(label : 'Launch kail-startup',
209 script : """
210mkdir -p "$logsDir"
211touch "$onosLog"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400212
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400213_TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} > "$onosLog" &
214""")
215
216 // if we're downloading a voltha-helm-charts patch,
217 // install from a local copy of the charts
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400218 Boolean localCharts = false
Joey Armstrong642540a2023-08-10 10:26:36 -0400219
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400220 if (volthaHelmChartsChange != ''
221 || gerritProject == 'voltha-helm-charts'
222 || isReleaseBranch(branch) // branch != 'master'
223 ) {
224 localCharts = true
225 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400226
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400227 String branchName = branchName()
228 Boolean isRelease = isReleaseBranch(branch)
229 println([
230 " ** localCharts=${localCharts}",
231 "branchName=${branchName}",
232 "branch=${branch}",
233 "branch=isReleaseBranch=${isRelease}",
234 ].join(', '))
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400235
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400236 // -----------------------------------------------------------------------
237 // Rewrite localHelmFlags using array join, moving code around and
238 // refactoring into standalone functions
239 // -----------------------------------------------------------------------
240 // NOTE temporary workaround expose ONOS node ports
241 // -----------------------------------------------------------------------
242 String localHelmFlags = [
243 extraHelmFlags.trim(),
244 "--set global.log_level=${logLevel.toUpperCase()}",
245 '--set onos-classic.onosSshPort=30115',
246 '--set onos-classic.onosApiPort=30120',
247 '--set onos-classic.onosOfPort=31653',
248 '--set onos-classic.individualOpenFlowNodePorts=true',
249 testSpecificHelmFlags
250 ].join(' ')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400251
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400252 println("** ${iam} localHelmFlags = ${localHelmFlags}")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400253
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400254 if (gerritProject != '') {
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400255 localHelmFlags += getVolthaImageFlags(gerritProject)
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400256 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400257
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400258 enter('volthaDeploy')
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400259 volthaDeploy([
260 infraNamespace: infraNamespace,
261 volthaNamespace: volthaNamespace,
262 workflow: workflow.toLowerCase(),
263 withMacLearning: enableMacLearning.toBoolean(),
264 extraHelmFlags: localHelmFlags,
265 localCharts: localCharts,
266 bbsimReplica: olts.toInteger(),
267 dockerRegistry: registry,
268 ])
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400269 leave('volthaDeploy')
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400270 } // script
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400271
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400272 script { pgrep_port_forward() }
Joey Armstrongdddbbf92023-08-22 16:00:41 -0400273
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400274 sh(label : 'Terminate kail-startup',
275 script : """
Joey Armstrong12a8c832023-08-28 16:50:24 -0400276if [[ \$(pgrep --count '_TAG=kail-startup') -gt 0 ]]; then
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400277 pkill --uid \$(uid -u) --echo --list-full --full '_TAG=kail-startup'
Joey Armstrong12a8c832023-08-28 16:50:24 -0400278fi
Joey Armstrong664c55a2023-08-28 14:22:33 -0400279""")
280
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400281 sh(label : 'Lingering kail-startup check',
282 script : """
283pgrep --uid \$(uid -u) --list-full --full 'kail-startup' || true
Joey Armstrong664c55a2023-08-28 14:22:33 -0400284""")
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400285
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400286 // -----------------------------------------------------------------------
287 // Bundle onos-voltha / kail logs
288 // -----------------------------------------------------------------------
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400289 sh(
290 label : 'Bundle logs: onos-voltha-startup-combined',
291 script : """
Joey Armstrongf060aee2023-08-22 21:55:26 -0400292cat <<EOM
293
294** -----------------------------------------------------------------------
Joey Armstrong7ba23ac2023-08-29 15:21:53 -0400295** Combine and compress voltha startup log(s)
Joey Armstrongf060aee2023-08-22 21:55:26 -0400296** -----------------------------------------------------------------------
297EOM
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400298
299pushd "${logsDir}" || { echo "ERROR: pushd $logsDir failed"; exit 1; }
300gzip -k onos-voltha-startup-combined.log
301rm onos-voltha-startup-combined.log
302popd || { echo "ERROR: popd $logsDir failed"; exit 1; }
Joey Armstrongf060aee2023-08-22 21:55:26 -0400303 """)
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400304 } // timeout(10)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400305
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400306 // -----------------------------------------------------------------------
307 // -----------------------------------------------------------------------
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400308 sh(label : 'while-true-port-forward',
309 """
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400310 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"&
311 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"&
312 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"&
313 bbsimDmiPortFwd=50075
314 for i in {0..${olts.toInteger() - 1}}; do
315 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"&
316 ((bbsimDmiPortFwd++))
317 done
318 if [ ${withMonitoring} = true ] ; then
319 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"&
320 fi
Joey Armstrong7ba23ac2023-08-29 15:21:53 -0400321# ps aux | grep port-forward
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400322""")
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400323 // ---------------------------------
324 // Sanity check port-forward spawned
325 // ---------------------------------
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400326 // [TODO] - Wait until forwarding successful else fatal
327 script { pgrep_port_forward() }
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400328
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400329 // setting ONOS log level
330 script {
331 enter('setOnosLogLevels')
332 setOnosLogLevels([
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400333 onosNamespace: infraNamespace,
334 apps: [
335 'org.opencord.dhcpl2relay',
336 'org.opencord.olt',
337 'org.opencord.aaa',
338 'org.opencord.maclearner',
339 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
340 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
341 ],
342 logLevel: logLevel
343 ])
Joey Armstrong6146f7e2023-08-28 09:05:38 -0400344 leave('setOnosLogLevels')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400345 } // script
346 } // if (teardown)
347 } // stage('Deploy Voltha')
348
Joey Armstrongf060aee2023-08-22 21:55:26 -0400349 // -----------------------------------------------------------------------
350 // -----------------------------------------------------------------------
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400351 stage("Run test ${testTarget} on workflow ${workflow}") {
Joey Armstrongebc18022023-08-26 13:20:49 -0400352 sh(
353 label : 'Monitor using mem_consumption.py',
354 script : """
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400355echo -e "\n** Monitor using mem_consumption.py ?"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400356
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400357if [ ${withMonitoring} = true ] ; then
358 cat <<EOM
Joey Armstrongf060aee2023-08-22 21:55:26 -0400359
360** -----------------------------------------------------------------------
361** Monitoring memory usage with mem_consumption.py
362** -----------------------------------------------------------------------
363EOM
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400364 mkdir -p "$WORKSPACE/voltha-pods-mem-consumption-${workflow}"
365 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400366
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400367 echo '** Installing python virtualenv'
368 make venv-activate-patched
Joey Armstrongf060aee2023-08-22 21:55:26 -0400369
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400370 # Collect initial memory consumption
371 set +u && source .venv/bin/activate && set -u
372 python scripts/mem_consumption.py -o $WORKSPACE/voltha-pods-mem-consumption-${workflow} -a 0.0.0.0:31301 -n ${volthaNamespace}
373fi
Joey Armstrongf060aee2023-08-22 21:55:26 -0400374
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400375echo -e '** Monitor memory consumption: LEAVE\n'
376""")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400377
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400378 sh(
379 label : "make testTarget=[${testTarget}]",
380 script : """
381echo -e "\n** make testTarget=[${testTarget}]"
382mkdir -p ${logsDir}
383export ROBOT_MISC_ARGS="-d ${logsDir} ${params.extraRobotArgs} "
384ROBOT_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}"
385export KVSTOREPREFIX=voltha/voltha_voltha
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400386
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400387make -C "$WORKSPACE/voltha-system-tests" ${testTarget}
388""")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400389
390 getPodsInfo("${logsDir}")
391
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400392 // [TODO] make conditional, bundle when logs are available
Joey Armstrongebc18022023-08-26 13:20:49 -0400393 sh(
394 label : 'Gather robot Framework logs',
395 script : """
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400396echo -e '\n** Gather robot Framework logs: ENTER'
Joey Armstrong7ba23ac2023-08-29 15:21:53 -0400397
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400398# set +e
399# collect logs collected in the Robot Framework StartLogging keyword
400cd "${logsDir}"
Joey Armstrong7ba23ac2023-08-29 15:21:53 -0400401
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400402echo "** Available logs:"
403/bin/ls -l "$logsDir"
404echo
Joey Armstrong7ba23ac2023-08-29 15:21:53 -0400405
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400406echo '** Bundle combined log'
407gzip *-combined.log || true
408rm -f *-combined.log || true
Joey Armstrong54dec092023-08-03 18:21:38 -0400409
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400410echo -e '** Gather robot Framework logs: LEAVE\n'
411""")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400412
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400413 // -----------------------------------------------------------------------
414 // -----------------------------------------------------------------------
Joey Armstrongebc18022023-08-26 13:20:49 -0400415 sh(
416 label : 'Monitor pod-mem-consumption',
417 script : """
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400418echo -e '** Monitor pod-mem-consumption: ENTER'
419if [ ${withMonitoring} = true ] ; then
Joey Armstrongf060aee2023-08-22 21:55:26 -0400420 cat <<EOM
421
422** -----------------------------------------------------------------------
423** Monitoring pod-memory-consumption using mem_consumption.py
424** -----------------------------------------------------------------------
425EOM
Joey Armstrongf060aee2023-08-22 21:55:26 -0400426
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400427cd "$WORKSPACE/voltha-system-tests"
Joey Armstrong38a87832023-08-23 17:02:50 -0400428
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400429echo '** Installing python virtualenv'
430make venv-activate-patched
431
432# Collect memory consumption of voltha pods once all the tests are complete
433set +u && source .venv/bin/activate && set -u
434python scripts/mem_consumption.py -o $WORKSPACE/voltha-pods-mem-consumption-${workflow} -a 0.0.0.0:31301 -n ${volthaNamespace}
435fi
436echo -e '** Monitor pod-mem-consumption: LEAVE\n'
437""")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400438 } // stage
Joey Armstrong54dec092023-08-03 18:21:38 -0400439
440 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400441} // execute_test()
442
443// -----------------------------------------------------------------------
444// -----------------------------------------------------------------------
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400445void collectArtifacts(exitStatus) {
Joey Armstrong6115fd62023-08-24 08:19:28 -0400446 script {
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400447 String iam = getIam('collectArtifacts')
448 println("${iam}: ENTER (exitStatus=${exitStatus})")
Joey Armstrong6115fd62023-08-24 08:19:28 -0400449 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400450
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400451 echo '''
452
453** -----------------------------------------------------------------------
454** collectArtifacts
455** -----------------------------------------------------------------------
456'''
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400457
Joey Armstrong642540a2023-08-10 10:26:36 -0400458 getPodsInfo("$WORKSPACE/${exitStatus}")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400459
Joey Armstrong642540a2023-08-10 10:26:36 -0400460 sh """
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400461 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400462 """
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400463
Joey Armstrong642540a2023-08-10 10:26:36 -0400464 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 -0400465
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400466 script {
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400467 println("${iam}: ENTER")
Joey Armstrong664c55a2023-08-28 14:22:33 -0400468 /*
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400469 pgrep_proc('kail-startup')
470 pkill_proc('kail')
Joey Armstrong664c55a2023-08-28 14:22:33 -0400471 */
472 sh(label : 'pgrep_proc - kill-pre',
473 script : """
Joey Armstronge9725b12023-08-28 18:15:12 -0400474pgrep --uid "\$(id -u)" --list-full --full 'kail-startup' || true
Joey Armstrong664c55a2023-08-28 14:22:33 -0400475""")
476 sh(label : 'pkill_proc - kail',
477 script : """
Joey Armstrong12a8c832023-08-28 16:50:24 -0400478if [[ \$(pgrep --count '_TAG=kail') -gt 0 ]]; then
479 pkill --uid "\$(id -u)" --echo --full 'kail'
480fi
Joey Armstrong664c55a2023-08-28 14:22:33 -0400481""")
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400482 println("${iam}: LEAVE")
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400483 }
Joey Armstrongdd0cd6b2023-08-25 17:27:56 -0400484
Joey Armstrong642540a2023-08-10 10:26:36 -0400485 println("${iam}: ENTER RobotPublisher")
486 step([$class: 'RobotPublisher',
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400487 disableArchiveOutput: false,
488 logFileName: '**/*/log*.html',
489 otherFiles: '',
490 outputFileName: '**/*/output*.xml',
491 outputPath: '.',
492 passThreshold: 100,
493 reportFileName: '**/*/report*.html',
494 unstableThreshold: 0,
495 onlyCritical: true])
Joey Armstrong642540a2023-08-10 10:26:36 -0400496 println("${iam}: LEAVE RobotPublisher")
497
498 println("${iam}: LEAVE (exitStatus=${exitStatus})")
499 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400500}
501
Joey Armstrong54dec092023-08-03 18:21:38 -0400502// -----------------------------------------------------------------------
503// Intent: main
504// -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400505pipeline {
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400506 /* no label, executor is determined by JJB */
507 agent {
508 label "${params.buildNode}"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400509 }
510
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400511 options {
512 timeout(time: "${timeout}", unit: 'MINUTES')
513 }
514
515 environment {
516 KUBECONFIG = "$HOME/.kube/kind-${clusterName}"
517 VOLTCONFIG = "$HOME/.volt/config"
518 PATH = "$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
519 DIAGS_PROFILE = 'VOLTHA_PROFILE'
520 SSHPASS = 'karaf'
521 }
522
523 stages {
524 stage('Download Code') {
525 steps {
526 getVolthaCode([
527 branch: "${branch}",
528 gerritProject: "${gerritProject}",
529 gerritRefspec: "${gerritRefspec}",
530 volthaSystemTestsChange: "${volthaSystemTestsChange}",
531 volthaHelmChartsChange: "${volthaHelmChartsChange}",
532 ])
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400533 }
534 }
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400535
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400536 stage('Build patch v1.1') {
537 // build the patch only if gerritProject is specified
538 when {
539 expression { return !gerritProject.isEmpty() }
540 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400541
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400542 steps {
543 // NOTE that the correct patch has already been checked out
544 // during the getVolthaCode step
545 buildVolthaComponent("${gerritProject}")
546 }
547 }
548
549 // -----------------------------------------------------------------------
550 // -----------------------------------------------------------------------
551 stage('Install Kail')
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400552 {
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400553 steps
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400554 {
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400555 script
556 {
557 String cmd = [
558 'make',
559 '--no-print-directory',
560 '-C', "$WORKSPACE/voltha-system-tests",
561 "KAIL_PATH=\"$WORKSPACE/bin\"",
562 'kail',
563 ].join(' ')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400564
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400565 println(" ** Running: ${cmd}")
566 sh("${cmd}")
567 } // script
568 } // steps
569 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400570
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400571 // -----------------------------------------------------------------------
572 // -----------------------------------------------------------------------
573 stage('Install Tools') {
574 steps {
575 script {
576 String branchName = branchName()
577 String iam = getIam('Install Tools')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400578
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400579 println("${iam}: ENTER (branch=$branch)")
580 installKind(branch) // needed early by stage(Cleanup)
581 println("${iam}: LEAVE (branch=$branch)")
582 } // script
583 } // steps
584 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400585
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400586 // -----------------------------------------------------------------------
587 // -----------------------------------------------------------------------
588 stage('Create K8s Cluster') {
589 steps {
590 script {
591 def clusterExists = sh(
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400592 label : 'Create K8s Cluster',
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400593 returnStdout: true,
594 script: """kind get clusters | grep "${clusterName}" | wc -l""")
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400595
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400596 if (clusterExists.trim() == '0') {
597 createKubernetesCluster([nodes: 3, name: clusterName])
598 }
599 } // script
600 } // steps
601 } // stage('Create K8s Cluster')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400602
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400603 // -----------------------------------------------------------------------
604 // -----------------------------------------------------------------------
605 stage('Replace voltctl') {
606 // if the project is voltctl, override the downloaded one with the built one
607 when {
608 expression { return gerritProject == 'voltctl' }
609 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400610
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400611 // Hmmmm(?) where did the voltctl download happen ?
612 // Likely Makefile but would be helpful to document here.
613 steps {
614 script {
615 String iam = getIam('Replace voltctl')
Joey Armstrong6115fd62023-08-24 08:19:28 -0400616
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400617 println("${iam} Running: installVoltctl($branch)")
618 println("${iam}: ENTER")
619 installVoltctl("$branch")
620 println("${iam}: LEAVE")
621 } // script
622 } // step
623 } // stage
Joey Armstrong268442d2023-08-22 17:16:10 -0400624
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400625 // -----------------------------------------------------------------------
626 // -----------------------------------------------------------------------
627 stage('Load image in kind nodes')
628 {
629 when {
630 expression { return !gerritProject.isEmpty() }
631 }
632 steps {
633 loadToKind()
634 } // steps
635 } // stage
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400636
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400637 // -----------------------------------------------------------------------
638 // [TODO] verify testing output
639 // -----------------------------------------------------------------------
640 stage('Parse and execute tests')
641 {
642 steps {
643 script {
644 // Announce ourselves for log usability
645 enter('Parse and execute tests')
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400646
Joey Armstrongebc18022023-08-26 13:20:49 -0400647 def tests = readYaml text: testTargets // typeof == Map (?)
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400648 println("** [DEBUG]: tests=$tests")
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400649
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400650 // Display expected tests for times when output goes dark
651 tests.eachWithIndex { test, idx ->
652 String target = test['target']
653 println("** test[${idx}]: ${target}\n")
654 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400655
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400656 println('''
Joey Armstrongb29d5612023-08-24 12:53:46 -0400657** -----------------------------------------------------------------------
658** NOTE: For odd/silent job failures verify a few details
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400659** - All tests mentioned in the tests-to-run index were logged.
Joey Armstrongb29d5612023-08-24 12:53:46 -0400660** - Test suites display ENTER/LEAVE mesasge pairs.
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400661** - Processing terminated prematurely when LEAVE strings are missing.
Joey Armstrongb29d5612023-08-24 12:53:46 -0400662** -----------------------------------------------------------------------
Joey Armstrongbe7c9242023-08-24 16:20:31 -0400663''')
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400664 tests.eachWithIndex { test, idx ->
665 println "** readYaml test suite[$idx]) test=[${test}]"
Joey Armstrongf46b3ae2023-08-25 11:07:20 -0400666
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400667 String target = test['target']
668 String workflow = test['workflow']
669 String flags = test['flags']
670 Boolean teardown = test['teardown'].toBoolean()
671 Boolean logging = test['logging'].toBoolean()
672 String testLogging = (logging) ? 'True' : 'False'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400673
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400674 print("""
Joey Armstrong268442d2023-08-22 17:16:10 -0400675** -----------------------------------------------------------------------
Joey Armstrong38a87832023-08-23 17:02:50 -0400676** Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}
Joey Armstrong268442d2023-08-22 17:16:10 -0400677** -----------------------------------------------------------------------
Joey Armstrong38a87832023-08-23 17:02:50 -0400678""")
Joey Armstrong664c55a2023-08-28 14:22:33 -0400679
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400680 try {
Joey Armstrong6146f7e2023-08-28 09:05:38 -0400681 enter("execute_test (target=$target)")
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400682 execute_test(target, workflow, testLogging, teardown, flags)
683 }
Joey Armstrong9341c9a2023-08-28 12:09:19 -0400684 // groovylint-disable-next-line CatchException
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400685 catch (Exception err) {
Joey Armstrong9341c9a2023-08-28 12:09:19 -0400686 String iamexc = getIam(name)
687 println("** ${iamexc}: EXCEPTION ${err}")
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400688 }
689 finally {
690 leave("execute_test (target=$target)")
691 }
692 } // for
693 // Premature exit if this message is not logged
694 leave('Parse and execute tests')
Joey Armstrong54dec092023-08-03 18:21:38 -0400695 } // script
696 } // steps
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400697 } // stage
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400698 } // stages
699
700 post
701 {
Joey Armstrong43cb15a2023-09-01 14:32:27 -0400702 aborted {
703 collectArtifacts('aborted')
704 script{ cleanupPortForward() }
705 }
706 failure {
707 collectArtifacts('failed')
708 script{ cleanupPortForward() }
709 }
710 always {
711 collectArtifacts('always')
712 script{ cleanupPortForward() }
713 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400714 }
715} // pipeline
716
Joey Armstrong664c55a2023-08-28 14:22:33 -0400717// [EOF]