blob: a6ce2f226e566f7da4df94908e21878161bd7e6b [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([
21 $class: 'GitSCMSource',
22 remote: 'https://gerrit.opencord.org/ci-management.git'
23])
24
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040025//------------------//
26//---] GLOBAL [---//
27//------------------//
Joey Armstrong54dec092023-08-03 18:21:38 -040028String clusterName = 'kind-ci' // was def
Joey Armstrong7bcb5782023-06-07 12:25:57 -040029
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040030// -----------------------------------------------------------------------
31// Intent:
32// -----------------------------------------------------------------------
Joey Armstrong54dec092023-08-03 18:21:38 -040033String branchName() {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040034 String name = 'voltha-2.12'
35
36 // [TODO] Sanity check the target branch
37 // if (name != jenkins.branch) { fatal }
38 return(name)
39}
40
41// -----------------------------------------------------------------------
Joey Armstrongaf4eef22023-08-25 16:14:45 -040042// Intent: Difficult at times to determine when pipeline jobs have
43// regenerated. Hardcode a version string that can be assigned
44// per-script to be sure latest repository changes are being used.
45// -----------------------------------------------------------------------
46String pipelineVer() {
Joey Armstrongdd0cd6b2023-08-25 17:27:56 -040047 String version = '757ba9ea12d8d815c10301b7f265f3fcd7c41d26'
Joey Armstrongaf4eef22023-08-25 16:14:45 -040048 return(version)
49}
50
51// -----------------------------------------------------------------------
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040052// Intent: Due to lack of a reliable stack trace, construct a literal.
Joey Armstrongd0b5af02023-08-25 15:12:54 -040053// Jenkins will re-write the call stack for serialization.S
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040054// -----------------------------------------------------------------------
Joey Armstrongd0b5af02023-08-25 15:12:54 -040055// Note: Hardcoded version string used to visualize changes in jenkins UI
56// -----------------------------------------------------------------------
Joey Armstrongaf4eef22023-08-25 16:14:45 -040057String getIam(String func) {
Joey Armstrong54dec092023-08-03 18:21:38 -040058 String branchName = branchName()
Joey Armstrongaf4eef22023-08-25 16:14:45 -040059 String version = pipelineVer()
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040060 String src = [
61 'ci-management',
62 'jjb',
63 'pipeline',
64 'voltha',
Joey Armstrong54dec092023-08-03 18:21:38 -040065 branchName,
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040066 'bbsim-tests.groovy'
67 ].join('/')
68
Joey Armstrongd0b5af02023-08-25 15:12:54 -040069 String name = [src, version, func].join('::')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040070 return(name)
71}
72
73// -----------------------------------------------------------------------
Joey Armstrongaf4eef22023-08-25 16:14:45 -040074// Intent: Log progress message
75// -----------------------------------------------------------------------
Joey Armstrong7229d9b2023-08-25 18:03:13 -040076void enter(String name) {
Joey Armstrongaf4eef22023-08-25 16:14:45 -040077 // Announce ourselves for log usability
78 String iam = getIam(name)
79 println("${iam}: ENTER")
80 return
81}
82
83// -----------------------------------------------------------------------
84// Intent: Log progress message
85// -----------------------------------------------------------------------
Joey Armstrong7229d9b2023-08-25 18:03:13 -040086void leave(String name) {
Joey Armstrongaf4eef22023-08-25 16:14:45 -040087 // Announce ourselves for log usability
88 String iam = getIam(name)
89 println("${iam}: LEAVE")
90 return
91}
92
93// -----------------------------------------------------------------------
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040094// Intent: Determine if working on a release branch.
95// Note: Conditional is legacy, should also check for *-dev or *-pre
96// -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -040097Boolean isReleaseBranch(String name) {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040098 // List modifiers = ['-dev', '-pre', 'voltha-x.y.z-pre']
Joey Armstrong54dec092023-08-03 18:21:38 -040099 // if branchName in modifiers
100 return(name != 'master') // OR branchName.contains('-')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400101}
102
103// -----------------------------------------------------------------------
Joey Armstrongaf4eef22023-08-25 16:14:45 -0400104// Intent: Iterate over a list of test suites and invoke.
Joey Armstrongf060aee2023-08-22 21:55:26 -0400105// -----------------------------------------------------------------------
Joey Armstrongaf4eef22023-08-25 16:14:45 -0400106void execute_test\
107(
108 String testTarget, // functional-single-kind-dt
109 String workflow, // dt
110 String testLogging, // 'True'
111 Boolean teardown, // true
112 String testSpecificHelmFlags=''
113) {
Joey Armstrong54dec092023-08-03 18:21:38 -0400114 String infraNamespace = 'default'
115 String volthaNamespace = 'voltha'
116 String logsDir = "$WORKSPACE/${testTarget}"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400117
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400118 // -----------------------------------------------------------------------
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400119 // Intent: Cleanup stale port-forwarding
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400120 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400121 stage('Cleanup') {
Joey Armstrong38a87832023-08-23 17:02:50 -0400122 if (teardown) {
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400123 timeout(15) {
Joey Armstrong38a87832023-08-23 17:02:50 -0400124 script {
Joey Armstrong54dec092023-08-03 18:21:38 -0400125 helmTeardown(['default', infraNamespace, volthaNamespace])
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400126 }
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400127 } // timeout
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400128
Joey Armstrongf060aee2023-08-22 21:55:26 -0400129 timeout(5) {
130 script {
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400131 enter('Cleanup')
132 // remove orphaned port-forward from different namespaces
Joey Armstrongebc18022023-08-26 13:20:49 -0400133 String proc = 'kubectl .*port-forward' // was 'port-forw'
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400134 pgrep_proc(proc)
135 pkill_proc(proc)
Joey Armstrongebc18022023-08-26 13:20:49 -0400136
137 // todo: fatal unless (proc count==0)
138 pgrep_proc(proc)
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400139 enter('Cleanup')
140 } // script
141 } // timeout
Joey Armstrongf060aee2023-08-22 21:55:26 -0400142 } // teardown
Joey Armstrong38a87832023-08-23 17:02:50 -0400143 } // stage('Cleanup')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400144
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400145 // -----------------------------------------------------------------------
146 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400147 stage('Deploy common infrastructure') {
148 script {
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400149 local dashargs = [
150 'kpi_exporter.enabled=false',
151 'dashboards.xos=false',
152 'dashboards.onos=false',
153 'dashboards.aaa=false',
154 'dashboards.voltha=false',
155 ].join(',')
156
157 local promargs = [
158 'prometheus.alertmanager.enabled=false',
159 'prometheus.pushgateway.enabled=false',
160 ].join(',')
161
Joey Armstrong38a87832023-08-23 17:02:50 -0400162 sh("""
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400163 helm repo add onf https://charts.opencord.org
164 helm repo update
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400165
166 echo -e "\nwithMonitoring=[$withMonitoring]"
167 if [ ${withMonitoring} = true ] ; then
168 helm install nem-monitoring onf/nem-monitoring \
Joey Armstrong38a87832023-08-23 17:02:50 -0400169 --set ${promargs} \
170 --set ${dashargs}
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400171 fi
Joey Armstrong38a87832023-08-23 17:02:50 -0400172 """)
173 } // script
174 } // stage('Deploy Common Infra')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400175
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400176 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400177 // [TODO] Check onos_log output
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400178 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400179 stage('Deploy Voltha') {
180 if (teardown) {
181 timeout(10) {
182 script {
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400183 String iam = getIam('Deploy Voltha')
184 String onosLog = "${logsDir}/onos-voltha-startup-combined.log"
185 sh("""
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400186 mkdir -p ${logsDir}
Joey Armstrong38a87832023-08-23 17:02:50 -0400187 touch "$onosLog"
188 echo "** kail-startup ENTER: \$(date)" > "$onosLog"
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400189
190 # Intermixed output (tee -a &) may get conflusing but let(s) see
191 # what messages are logged during startup.
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400192 # _TAG=ka7il-startup kail -n ${infraNamespace} -n ${volthaNamespace} >> "$onosLog" &
Joey Armstrong38a87832023-08-23 17:02:50 -0400193 _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} | tee -a "$onosLog" &
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400194 """)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400195
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400196 // if we're downloading a voltha-helm-charts patch, then install from a local copy of the charts
197 Boolean localCharts = false
Joey Armstrong642540a2023-08-10 10:26:36 -0400198
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400199 if (volthaHelmChartsChange != ''
200 || gerritProject == 'voltha-helm-charts'
201 || isReleaseBranch(branch) // branch != 'master'
202 ) {
203 localCharts = true
204 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400205
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400206 String branchName = branchName()
207 Boolean isRelease = isReleaseBranch(branch)
208 println([
209 " ** localCharts=${localCharts}",
210 "branchName=${branchName}",
211 "branch=${branch}",
212 "branch=isReleaseBranch=${isRelease}",
213 ].join(', '))
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400214
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400215 // -----------------------------------------------------------------------
216 // Rewrite localHelmFlags using array join, moving code around and
217 // refactoring into standalone functions
218 // -----------------------------------------------------------------------
219 // NOTE temporary workaround expose ONOS node ports
220 // -----------------------------------------------------------------------
221 String localHelmFlags = [
222 extraHelmFlags.trim(),
223 "--set global.log_level=${logLevel.toUpperCase()}",
224 '--set onos-classic.onosSshPort=30115',
225 '--set onos-classic.onosApiPort=30120',
226 '--set onos-classic.onosOfPort=31653',
227 '--set onos-classic.individualOpenFlowNodePorts=true',
228 testSpecificHelmFlags
229 ].join(' ')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400230
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400231 println("** ${iam} localHelmFlags = ${localHelmFlags}")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400232
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400233 if (gerritProject != '') {
234 localHelmFlags = "${localHelmFlags} " + getVolthaImageFlags("${gerritProject}")
235 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400236
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400237 println("** ${iam}: ENTER")
238 volthaDeploy([
239 infraNamespace: infraNamespace,
240 volthaNamespace: volthaNamespace,
241 workflow: workflow.toLowerCase(),
242 withMacLearning: enableMacLearning.toBoolean(),
243 extraHelmFlags: localHelmFlags,
244 localCharts: localCharts,
245 bbsimReplica: olts.toInteger(),
246 dockerRegistry: registry,
247 ])
248 println("** ${iam}: LEAVE")
249 } // script
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400250
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400251 // -----------------------------------------------------------------------
252 // Intent: Replacing P_IDS with pgrep/pkill is a step forward.
253 // Why not simply use a pid file, capture _TAG=kail-startup above
254 // Grep runs the risk of terminating stray commands (??-good <=> bad-??)
255 // -----------------------------------------------------------------------
256 script {
257 String proc = '_TAG=kail-startup'
Joey Armstrongdddbbf92023-08-22 16:00:41 -0400258
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400259 println("${iam}: ENTER")
260 println("${iam}: Shutdown process $proc")
261 pgrep_proc(proc)
262 pkill_proc(proc)
263 pgrep_proc(proc)
264 println("${iam}: LEAVE")
265 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400266
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400267 // -----------------------------------------------------------------------
268 // Bundle onos-voltha / kail logs
269 // -----------------------------------------------------------------------
270 sh("""
Joey Armstrongf060aee2023-08-22 21:55:26 -0400271cat <<EOM
272
273** -----------------------------------------------------------------------
274** Combine an compress voltha startup log(s)
275** -----------------------------------------------------------------------
276EOM
277 pushd "${logsDir}" || { echo "ERROR: pushd $logsDir failed"; exit 1; }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400278 gzip -k onos-voltha-startup-combined.log
279 rm onos-voltha-startup-combined.log
Joey Armstrongf060aee2023-08-22 21:55:26 -0400280 popd
281 """)
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400282 } // timeout(10)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400283
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400284 // -----------------------------------------------------------------------
285 // -----------------------------------------------------------------------
286 sh """
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400287 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"&
288 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"&
289 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"&
290 bbsimDmiPortFwd=50075
291 for i in {0..${olts.toInteger() - 1}}; do
292 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"&
293 ((bbsimDmiPortFwd++))
294 done
295 if [ ${withMonitoring} = true ] ; then
296 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"&
297 fi
298 ps aux | grep port-forward
299 """
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400300 // ---------------------------------
301 // Sanity check port-forward spawned
302 // ---------------------------------
303 script {
304 enter('port-forward check')
Joey Armstrongebc18022023-08-26 13:20:49 -0400305 // String proc = 'kubectl.*port-forward' // was 'port-forward'
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400306 String proc = 'port-forward'
307 println("Display spawned ${proc}")
308 pgrep_proc(proc)
309 leave('port-forward check')
310 }
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400311
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400312 // setting ONOS log level
313 script {
314 enter('setOnosLogLevels')
315 setOnosLogLevels([
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400316 onosNamespace: infraNamespace,
317 apps: [
318 'org.opencord.dhcpl2relay',
319 'org.opencord.olt',
320 'org.opencord.aaa',
321 'org.opencord.maclearner',
322 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
323 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
324 ],
325 logLevel: logLevel
326 ])
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400327 enter('setOnosLogLevels')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400328 } // script
329 } // if (teardown)
330 } // stage('Deploy Voltha')
331
Joey Armstrongf060aee2023-08-22 21:55:26 -0400332 // -----------------------------------------------------------------------
333 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400334 stage("Run test ${testTarget} on workflow ${workflow}")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400335 {
Joey Armstrongebc18022023-08-26 13:20:49 -0400336 sh(
337 label : 'Monitor using mem_consumption.py',
338 script : """
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400339 echo -e "\n** Monitor using mem_consumption.py ?"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400340
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400341 if [ ${withMonitoring} = true ] ; then
Joey Armstrongf060aee2023-08-22 21:55:26 -0400342 cat <<EOM
343
344** -----------------------------------------------------------------------
345** Monitoring memory usage with mem_consumption.py
346** -----------------------------------------------------------------------
347EOM
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400348 mkdir -p "$WORKSPACE/voltha-pods-mem-consumption-${workflow}"
349 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400350
351 echo '** Installing python virtualenv'
352 make venv-activate-patched
353
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400354 set +u && source .venv/bin/activate && set -u
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400355 # Collect initial memory consumption
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400356 python scripts/mem_consumption.py -o $WORKSPACE/voltha-pods-mem-consumption-${workflow} -a 0.0.0.0:31301 -n ${volthaNamespace}
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400357 fi
Joey Armstrongf060aee2023-08-22 21:55:26 -0400358
359 echo -e '** Monitor memory consumption: LEAVE\n'
Joey Armstrongebc18022023-08-26 13:20:49 -0400360 """)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400361
362 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400363 echo -e "\n** make testTarget=[${testTarget}]"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400364 mkdir -p ${logsDir}
365 export ROBOT_MISC_ARGS="-d ${logsDir} ${params.extraRobotArgs} "
366 ROBOT_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}"
367 export KVSTOREPREFIX=voltha/voltha_voltha
368
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400369 make -C "$WORKSPACE/voltha-system-tests" ${testTarget}
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400370 """
371
372 getPodsInfo("${logsDir}")
373
Joey Armstrongebc18022023-08-26 13:20:49 -0400374 sh(
375 label : 'Gather robot Framework logs',
376 script : """
Joey Armstrong54dec092023-08-03 18:21:38 -0400377 echo -e '\n** Gather robot Framework logs: ENTER'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400378 # set +e
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400379 # collect logs collected in the Robot Framework StartLogging keyword
380 cd ${logsDir}
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400381 gzip *-combined.log
382 rm -f *-combined.log
Joey Armstrong54dec092023-08-03 18:21:38 -0400383
384 echo -e '** Gather robot Framework logs: LEAVE\n'
Joey Armstrongebc18022023-08-26 13:20:49 -0400385 """)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400386
Joey Armstrongf060aee2023-08-22 21:55:26 -0400387 // -----------------------------------------------------------------------
388 // -----------------------------------------------------------------------
Joey Armstrongebc18022023-08-26 13:20:49 -0400389 sh(
390 label : 'Monitor pod-mem-consumption',
391 script : """
Joey Armstrong54dec092023-08-03 18:21:38 -0400392 echo -e '** Monitor pod-mem-consumption: ENTER'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400393 if [ ${withMonitoring} = true ] ; then
Joey Armstrongf060aee2023-08-22 21:55:26 -0400394 cat <<EOM
395
396** -----------------------------------------------------------------------
397** Monitoring pod-memory-consumption using mem_consumption.py
398** -----------------------------------------------------------------------
399EOM
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400400 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400401
402 echo '** Installing python virtualenv'
403 make venv-activate-patched
Joey Armstrong38a87832023-08-23 17:02:50 -0400404
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400405 set +u && source .venv/bin/activate && set -u
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400406 # Collect memory consumption of voltha pods once all the tests are complete
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400407 python scripts/mem_consumption.py -o $WORKSPACE/voltha-pods-mem-consumption-${workflow} -a 0.0.0.0:31301 -n ${volthaNamespace}
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400408 fi
Joey Armstrong54dec092023-08-03 18:21:38 -0400409 echo -e '** Monitor pod-mem-consumption: LEAVE\n'
Joey Armstrongebc18022023-08-26 13:20:49 -0400410 """)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400411 } // stage
Joey Armstrong54dec092023-08-03 18:21:38 -0400412
413 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400414} // execute_test()
415
416// -----------------------------------------------------------------------
417// -----------------------------------------------------------------------
Joey Armstrong54dec092023-08-03 18:21:38 -0400418def collectArtifacts(exitStatus) {
Joey Armstrong6115fd62023-08-24 08:19:28 -0400419 script {
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400420 String iam = getIam('collectArtifacts')
421 println("${iam}: ENTER (exitStatus=${exitStatus})")
Joey Armstrong6115fd62023-08-24 08:19:28 -0400422 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400423
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400424 echo '''
425
426** -----------------------------------------------------------------------
427** collectArtifacts
428** -----------------------------------------------------------------------
429'''
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400430
Joey Armstrong642540a2023-08-10 10:26:36 -0400431 getPodsInfo("$WORKSPACE/${exitStatus}")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400432
Joey Armstrong642540a2023-08-10 10:26:36 -0400433 sh """
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400434 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400435 """
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400436
Joey Armstrong642540a2023-08-10 10:26:36 -0400437 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 -0400438
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400439 script {
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400440 println("${iam}: ENTER")
441 pgrep_proc('kail-startup')
442 pkill_proc('kail')
443 println("${iam}: LEAVE")
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400444 }
Joey Armstrongdd0cd6b2023-08-25 17:27:56 -0400445
Joey Armstrong642540a2023-08-10 10:26:36 -0400446 println("${iam}: ENTER RobotPublisher")
447 step([$class: 'RobotPublisher',
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400448 disableArchiveOutput: false,
449 logFileName: '**/*/log*.html',
450 otherFiles: '',
451 outputFileName: '**/*/output*.xml',
452 outputPath: '.',
453 passThreshold: 100,
454 reportFileName: '**/*/report*.html',
455 unstableThreshold: 0,
456 onlyCritical: true])
Joey Armstrong642540a2023-08-10 10:26:36 -0400457 println("${iam}: LEAVE RobotPublisher")
458
459 println("${iam}: LEAVE (exitStatus=${exitStatus})")
460 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400461}
462
Joey Armstrong54dec092023-08-03 18:21:38 -0400463// -----------------------------------------------------------------------
464// Intent: main
465// -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400466pipeline {
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400467 /* no label, executor is determined by JJB */
468 agent {
469 label "${params.buildNode}"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400470 }
471
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400472 options {
473 timeout(time: "${timeout}", unit: 'MINUTES')
474 }
475
476 environment {
477 KUBECONFIG = "$HOME/.kube/kind-${clusterName}"
478 VOLTCONFIG = "$HOME/.volt/config"
479 PATH = "$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
480 DIAGS_PROFILE = 'VOLTHA_PROFILE'
481 SSHPASS = 'karaf'
482 }
483
484 stages {
485 stage('Download Code') {
486 steps {
487 getVolthaCode([
488 branch: "${branch}",
489 gerritProject: "${gerritProject}",
490 gerritRefspec: "${gerritRefspec}",
491 volthaSystemTestsChange: "${volthaSystemTestsChange}",
492 volthaHelmChartsChange: "${volthaHelmChartsChange}",
493 ])
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400494 }
495 }
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400496
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400497 stage('Build patch v1.1') {
498 // build the patch only if gerritProject is specified
499 when {
500 expression { return !gerritProject.isEmpty() }
501 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400502
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400503 steps {
504 // NOTE that the correct patch has already been checked out
505 // during the getVolthaCode step
506 buildVolthaComponent("${gerritProject}")
507 }
508 }
509
510 // -----------------------------------------------------------------------
511 // -----------------------------------------------------------------------
512 stage('Install Kail')
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400513 {
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400514 steps
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400515 {
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400516 script
517 {
518 String cmd = [
519 'make',
520 '--no-print-directory',
521 '-C', "$WORKSPACE/voltha-system-tests",
522 "KAIL_PATH=\"$WORKSPACE/bin\"",
523 'kail',
524 ].join(' ')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400525
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400526 println(" ** Running: ${cmd}")
527 sh("${cmd}")
528 } // script
529 } // steps
530 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400531
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400532 // -----------------------------------------------------------------------
533 // -----------------------------------------------------------------------
534 stage('Install Tools') {
535 steps {
536 script {
537 String branchName = branchName()
538 String iam = getIam('Install Tools')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400539
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400540 println("${iam}: ENTER (branch=$branch)")
541 installKind(branch) // needed early by stage(Cleanup)
542 println("${iam}: LEAVE (branch=$branch)")
543 } // script
544 } // steps
545 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400546
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400547 // -----------------------------------------------------------------------
548 // -----------------------------------------------------------------------
549 stage('Create K8s Cluster') {
550 steps {
551 script {
552 def clusterExists = sh(
553 returnStdout: true,
554 script: """kind get clusters | grep "${clusterName}" | wc -l""")
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400555
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400556 if (clusterExists.trim() == '0') {
557 createKubernetesCluster([nodes: 3, name: clusterName])
558 }
559 } // script
560 } // steps
561 } // stage('Create K8s Cluster')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400562
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400563 // -----------------------------------------------------------------------
564 // -----------------------------------------------------------------------
565 stage('Replace voltctl') {
566 // if the project is voltctl, override the downloaded one with the built one
567 when {
568 expression { return gerritProject == 'voltctl' }
569 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400570
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400571 // Hmmmm(?) where did the voltctl download happen ?
572 // Likely Makefile but would be helpful to document here.
573 steps {
574 script {
575 String iam = getIam('Replace voltctl')
Joey Armstrong6115fd62023-08-24 08:19:28 -0400576
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400577 println("${iam} Running: installVoltctl($branch)")
578 println("${iam}: ENTER")
579 installVoltctl("$branch")
580 println("${iam}: LEAVE")
581 } // script
582 } // step
583 } // stage
Joey Armstrong268442d2023-08-22 17:16:10 -0400584
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400585 // -----------------------------------------------------------------------
586 // -----------------------------------------------------------------------
587 stage('Load image in kind nodes')
588 {
589 when {
590 expression { return !gerritProject.isEmpty() }
591 }
592 steps {
593 loadToKind()
594 } // steps
595 } // stage
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400596
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400597 // -----------------------------------------------------------------------
598 // [TODO] verify testing output
599 // -----------------------------------------------------------------------
600 stage('Parse and execute tests')
601 {
602 steps {
603 script {
604 // Announce ourselves for log usability
605 enter('Parse and execute tests')
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400606
Joey Armstrongebc18022023-08-26 13:20:49 -0400607 def tests = readYaml text: testTargets // typeof == Map (?)
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400608 println("** [DEBUG]: tests=$tests")
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400609
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400610 // Display expected tests for times when output goes dark
611 tests.eachWithIndex { test, idx ->
612 String target = test['target']
613 println("** test[${idx}]: ${target}\n")
614 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400615
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400616 println('''
Joey Armstrongb29d5612023-08-24 12:53:46 -0400617** -----------------------------------------------------------------------
618** NOTE: For odd/silent job failures verify a few details
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400619** - All tests mentioned in the tests-to-run index were logged.
Joey Armstrongb29d5612023-08-24 12:53:46 -0400620** - Test suites display ENTER/LEAVE mesasge pairs.
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400621** - Processing terminated prematurely when LEAVE strings are missing.
Joey Armstrongb29d5612023-08-24 12:53:46 -0400622** -----------------------------------------------------------------------
Joey Armstrongbe7c9242023-08-24 16:20:31 -0400623''')
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400624 tests.eachWithIndex { test, idx ->
625 println "** readYaml test suite[$idx]) test=[${test}]"
Joey Armstrongf46b3ae2023-08-25 11:07:20 -0400626
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400627 String target = test['target']
628 String workflow = test['workflow']
629 String flags = test['flags']
630 Boolean teardown = test['teardown'].toBoolean()
631 Boolean logging = test['logging'].toBoolean()
632 String testLogging = (logging) ? 'True' : 'False'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400633
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400634 print("""
Joey Armstrong268442d2023-08-22 17:16:10 -0400635** -----------------------------------------------------------------------
Joey Armstrong38a87832023-08-23 17:02:50 -0400636** Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}
Joey Armstrong268442d2023-08-22 17:16:10 -0400637** -----------------------------------------------------------------------
Joey Armstrong38a87832023-08-23 17:02:50 -0400638""")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400639
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400640 try {
641 leave("execute_test (target=$target)")
642 execute_test(target, workflow, testLogging, teardown, flags)
643 }
644 catch (Exception err) {
645 println("** ${iam}: EXCEPTION ${err}")
646 }
647 finally {
648 leave("execute_test (target=$target)")
649 }
650 } // for
651 // Premature exit if this message is not logged
652 leave('Parse and execute tests')
Joey Armstrong54dec092023-08-03 18:21:38 -0400653 } // script
654 } // steps
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400655 } // stage
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400656 } // stages
657
658 post
659 {
660 aborted { collectArtifacts('aborted') }
661 failure { collectArtifacts('failed') }
662 always { collectArtifacts('always') }
663 }
664} // pipeline
665
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400666// [EOF] - 2