blob: e8c2181c574b07f07f3d0102d34e7a5aef645736 [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// -----------------------------------------------------------------------
42// Intent: Due to lack of a reliable stack trace, construct a literal.
43// Jenkins will re-write the call stack for serialization.
44// -----------------------------------------------------------------------
45String getIam(String func) {
Joey Armstrong54dec092023-08-03 18:21:38 -040046 String branchName = branchName()
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040047 String src = [
48 'ci-management',
49 'jjb',
50 'pipeline',
51 'voltha',
Joey Armstrong54dec092023-08-03 18:21:38 -040052 branchName,
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040053 'bbsim-tests.groovy'
54 ].join('/')
55
56 String name = [src, func].join('::')
57 return(name)
58}
59
60// -----------------------------------------------------------------------
61// Intent: Determine if working on a release branch.
62// Note: Conditional is legacy, should also check for *-dev or *-pre
63// -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -040064Boolean isReleaseBranch(String name) {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040065 // List modifiers = ['-dev', '-pre', 'voltha-x.y.z-pre']
Joey Armstrong54dec092023-08-03 18:21:38 -040066 // if branchName in modifiers
67 return(name != 'master') // OR branchName.contains('-')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040068}
69
70// -----------------------------------------------------------------------
Joey Armstrong38a87832023-08-23 17:02:50 -040071// Intent:
Joey Armstrongf060aee2023-08-22 21:55:26 -040072// -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -040073void pgrep_proc(String proc) {
74 String cmd = [
75 'pgrep',
76 '--older', 5, // delay to exclude pgrep
77 '--list-full',
78 proc,
79 ].join(' ')
80
81 println("** Running: ${cmd}")
82 sh("set +euo pipefail && ${cmd}")
Joey Armstrongf060aee2023-08-22 21:55:26 -040083 return
84}
85
86// -----------------------------------------------------------------------
87// -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -040088void pkill_proc(String proc) {
89 String cmd = [
90 'pkill',
91 '--older', 5, // delay to exclude pkill
92 '--echo',
93 proc,
94 ].join(' ')
95
96 println("** Running: ${cmd}")
97 sh(""" [[ \$(pgrep --count "${proc}") -gt 0 ]] && "${cmd}" """)
Joey Armstrongf060aee2023-08-22 21:55:26 -040098 return
99}
100
101// -----------------------------------------------------------------------
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400102// Intent:
103// -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400104void execute_test(testTarget, workflow, testLogging, teardown, testSpecificHelmFlags='') {
Joey Armstrong54dec092023-08-03 18:21:38 -0400105 String infraNamespace = 'default'
106 String volthaNamespace = 'voltha'
107 String logsDir = "$WORKSPACE/${testTarget}"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400108
109 stage('IAM')
110 {
111 script
112 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400113 // Announce ourselves for log usability
Joey Armstrong642540a2023-08-10 10:26:36 -0400114 String iam = getIam('execute_test')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400115 println("${iam}: ENTER")
116 println("${iam}: LEAVE")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400117 }
118 }
Joey Armstrong54dec092023-08-03 18:21:38 -0400119
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400120 // -----------------------------------------------------------------------
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400121 // Intent: Cleanup stale port-forwarding
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400122 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400123 stage('Cleanup') {
Joey Armstrong38a87832023-08-23 17:02:50 -0400124 if (teardown) {
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400125 timeout(15) {
Joey Armstrong38a87832023-08-23 17:02:50 -0400126 script {
Joey Armstrong54dec092023-08-03 18:21:38 -0400127 helmTeardown(['default', infraNamespace, volthaNamespace])
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400128 }
Joey Armstrongf060aee2023-08-22 21:55:26 -0400129 } // timeout
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400130
Joey Armstrongf060aee2023-08-22 21:55:26 -0400131 timeout(5) {
132 script {
133 String iam = getIam('Cleanup')
134 println("${iam}: ENTER")
Joey Armstrong268442d2023-08-22 17:16:10 -0400135
Joey Armstrongf060aee2023-08-22 21:55:26 -0400136 // remove orphaned port-forward from different namespaces
137 String proc = 'port-forw'
138 pgrep_proc(proc)
139 pkill_proc(proc)
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400140 pgrep_proc(proc) // proc count == 0
Joey Armstrongf060aee2023-08-22 21:55:26 -0400141 println("${iam}: LEAVE")
Joey Armstrong38a87832023-08-23 17:02:50 -0400142 } // script
Joey Armstrongf060aee2023-08-22 21:55:26 -0400143 } // timeout
144 } // teardown
Joey Armstrong38a87832023-08-23 17:02:50 -0400145 } // stage('Cleanup')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400146
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400147 // -----------------------------------------------------------------------
148 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400149 stage('Deploy common infrastructure') {
150 script {
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400151 local dashargs = [
152 'kpi_exporter.enabled=false',
153 'dashboards.xos=false',
154 'dashboards.onos=false',
155 'dashboards.aaa=false',
156 'dashboards.voltha=false',
157 ].join(',')
158
159 local promargs = [
160 'prometheus.alertmanager.enabled=false',
161 'prometheus.pushgateway.enabled=false',
162 ].join(',')
163
Joey Armstrong38a87832023-08-23 17:02:50 -0400164 sh("""
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400165 helm repo add onf https://charts.opencord.org
166 helm repo update
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400167
168 echo -e "\nwithMonitoring=[$withMonitoring]"
169 if [ ${withMonitoring} = true ] ; then
170 helm install nem-monitoring onf/nem-monitoring \
Joey Armstrong38a87832023-08-23 17:02:50 -0400171 --set ${promargs} \
172 --set ${dashargs}
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400173 fi
Joey Armstrong38a87832023-08-23 17:02:50 -0400174 """)
175 } // script
176 } // stage('Deploy Common Infra')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400177
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400178 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400179 // [TODO] Check onos_log output
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400180 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400181 stage('Deploy Voltha') {
182 if (teardown) {
183 timeout(10) {
184 script {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400185 String iam = getIam('Deploy Voltha')
Joey Armstrong38a87832023-08-23 17:02:50 -0400186 String onosLog = "${logsDir}/onos-voltha-startup-combined.log"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400187sh("""
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400188 mkdir -p ${logsDir}
Joey Armstrong38a87832023-08-23 17:02:50 -0400189 touch "$onosLog"
190 echo "** kail-startup ENTER: \$(date)" > "$onosLog"
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400191
192 # Intermixed output (tee -a &) may get conflusing but let(s) see
193 # what messages are logged during startup.
Joey Armstrong38a87832023-08-23 17:02:50 -0400194 # _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} >> "$onosLog" &
195 _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} | tee -a "$onosLog" &
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400196 """)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400197
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400198 // if we're downloading a voltha-helm-charts patch, then install from a local copy of the charts
199 Boolean localCharts = false
Joey Armstrong642540a2023-08-10 10:26:36 -0400200
Joey Armstrong54dec092023-08-03 18:21:38 -0400201 if (volthaHelmChartsChange != ''
202 || gerritProject == 'voltha-helm-charts'
203 || isReleaseBranch(branch) // branch != 'master'
204 ) {
205 localCharts = true
206 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400207
Joey Armstrong54dec092023-08-03 18:21:38 -0400208 String branchName = branchName()
Joey Armstrong38a87832023-08-23 17:02:50 -0400209 Boolean isRelease = isReleaseBranch(branch)
Joey Armstrong54dec092023-08-03 18:21:38 -0400210 println([
211 " ** localCharts=${localCharts}",
212 "branchName=${branchName}",
213 "branch=${branch}",
Joey Armstrong38a87832023-08-23 17:02:50 -0400214 "branch=isReleaseBranch=${isRelease}",
Joey Armstrong54dec092023-08-03 18:21:38 -0400215 ].join(', '))
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400216
Joey Armstrong54dec092023-08-03 18:21:38 -0400217 // -----------------------------------------------------------------------
218 // Rewrite localHelmFlags using array join, moving code around and
Joey Armstrong642540a2023-08-10 10:26:36 -0400219 // refactoring into standalone functions
Joey Armstrong54dec092023-08-03 18:21:38 -0400220 // -----------------------------------------------------------------------
221 // hudson.remoting.ProxyException: groovy.lang.MissingMethodException:
222 // No signature of method: java.lang.String.positive() is applicable for argument types: () values: []
223 // -----------------------------------------------------------------------
224 // NOTE temporary workaround expose ONOS node ports
225 // -----------------------------------------------------------------------
226 String localHelmFlags = [
227 extraHelmFlags.trim(),
228 "--set global.log_level=${logLevel.toUpperCase()}",
229 '--set onos-classic.onosSshPort=30115',
230 '--set onos-classic.onosApiPort=30120',
231 '--set onos-classic.onosOfPort=31653',
232 '--set onos-classic.individualOpenFlowNodePorts=true',
233 testSpecificHelmFlags
234 ].join(' ')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400235
Joey Armstrongf060aee2023-08-22 21:55:26 -0400236 println("** ${iam} localHelmFlags = ${localHelmFlags}")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400237
Joey Armstrong54dec092023-08-03 18:21:38 -0400238 if (gerritProject != '') {
239 localHelmFlags = "${localHelmFlags} " + getVolthaImageFlags("${gerritProject}")
240 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400241
Joey Armstrong38a87832023-08-23 17:02:50 -0400242 println("** ${iam}: ENTER")
Joey Armstrong54dec092023-08-03 18:21:38 -0400243 volthaDeploy([
244 infraNamespace: infraNamespace,
245 volthaNamespace: volthaNamespace,
246 workflow: workflow.toLowerCase(),
247 withMacLearning: enableMacLearning.toBoolean(),
248 extraHelmFlags: localHelmFlags,
249 localCharts: localCharts,
250 bbsimReplica: olts.toInteger(),
251 dockerRegistry: registry,
252 ])
Joey Armstrong38a87832023-08-23 17:02:50 -0400253 println("** ${iam}: LEAVE")
Joey Armstrong54dec092023-08-03 18:21:38 -0400254 } // script
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400255
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400256 // -----------------------------------------------------------------------
257 // Intent: Replacing P_IDS with pgrep/pkill is a step forward.
258 // Why not simply use a pid file, capture _TAG=kail-startup above
259 // Grep runs the risk of terminating stray commands (??-good <=> bad-??)
Joey Armstrong54dec092023-08-03 18:21:38 -0400260 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400261 script {
262 String proc = '_TAG=kail-startup'
Joey Armstrongdddbbf92023-08-22 16:00:41 -0400263
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400264 println("${iam}: ENTER")
265 println("${iam}: Shutdown process $proc")
266 pgrep_proc(proc)
267 pkill_proc(proc)
268 println("${iam}: LEAVE")
269 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400270
Joey Armstronged345862023-08-23 12:24:20 -0400271 // -----------------------------------------------------------------------
272 // Bundle onos-voltha / kail logs
273 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400274 sh("""
275cat <<EOM
276
277** -----------------------------------------------------------------------
278** Combine an compress voltha startup log(s)
279** -----------------------------------------------------------------------
280EOM
281 pushd "${logsDir}" || { echo "ERROR: pushd $logsDir failed"; exit 1; }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400282 gzip -k onos-voltha-startup-combined.log
283 rm onos-voltha-startup-combined.log
Joey Armstrongf060aee2023-08-22 21:55:26 -0400284 popd
285 """)
Joey Armstrong38a87832023-08-23 17:02:50 -0400286 } // timeout(10)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400287
Joey Armstrongf060aee2023-08-22 21:55:26 -0400288
289 // -----------------------------------------------------------------------
290 // -----------------------------------------------------------------------
291 sh """
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400292 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"&
293 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"&
294 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"&
295 bbsimDmiPortFwd=50075
296 for i in {0..${olts.toInteger() - 1}}; do
297 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"&
298 ((bbsimDmiPortFwd++))
299 done
300 if [ ${withMonitoring} = true ] ; then
301 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"&
302 fi
303 ps aux | grep port-forward
304 """
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400305 script {
306 String proc = 'port-forward'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400307
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400308 println("${iam}: ENTER")
309 println("Display spawned ${proc}")
310 pgrep_proc(proc)
311 println("${iam}: LEAVE")
312 }
Joey Armstrongf060aee2023-08-22 21:55:26 -0400313
314 // setting ONOS log level
315 script {
316 println('** setOnosLogLevels: ENTER')
Joey Armstrong54dec092023-08-03 18:21:38 -0400317 setOnosLogLevels([
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400318 onosNamespace: infraNamespace,
319 apps: [
320 'org.opencord.dhcpl2relay',
321 'org.opencord.olt',
322 'org.opencord.aaa',
323 'org.opencord.maclearner',
324 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
325 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
326 ],
327 logLevel: logLevel
328 ])
Joey Armstrongf060aee2023-08-22 21:55:26 -0400329 println('** setOnosLogLevels: LEAVE')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400330 } // script
331 } // if (teardown)
332 } // stage('Deploy Voltha')
333
Joey Armstrongf060aee2023-08-22 21:55:26 -0400334 // -----------------------------------------------------------------------
335 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400336 stage("Run test ${testTarget} on workflow ${workflow}")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400337 {
338 sh """
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 Armstrong7bcb5782023-06-07 12:25:57 -0400360 """
361
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
374 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400375 echo -e '\n** Gather robot Framework logs: ENTER'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400376 # set +e
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400377 # collect logs collected in the Robot Framework StartLogging keyword
378 cd ${logsDir}
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400379 gzip *-combined.log
380 rm -f *-combined.log
Joey Armstrong54dec092023-08-03 18:21:38 -0400381
382 echo -e '** Gather robot Framework logs: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400383 """
384
Joey Armstrongf060aee2023-08-22 21:55:26 -0400385 // -----------------------------------------------------------------------
386 // -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400387 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400388 echo -e '** Monitor pod-mem-consumption: ENTER'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400389 if [ ${withMonitoring} = true ] ; then
Joey Armstrongf060aee2023-08-22 21:55:26 -0400390 cat <<EOM
391
392** -----------------------------------------------------------------------
393** Monitoring pod-memory-consumption using mem_consumption.py
394** -----------------------------------------------------------------------
395EOM
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400396 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400397
398 echo '** Installing python virtualenv'
399 make venv-activate-patched
Joey Armstrong38a87832023-08-23 17:02:50 -0400400
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400401 set +u && source .venv/bin/activate && set -u
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400402 # Collect memory consumption of voltha pods once all the tests are complete
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400403 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 -0400404 fi
Joey Armstrong54dec092023-08-03 18:21:38 -0400405 echo -e '** Monitor pod-mem-consumption: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400406 """
407 } // stage
Joey Armstrong54dec092023-08-03 18:21:38 -0400408
409 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400410} // execute_test()
411
412// -----------------------------------------------------------------------
413// -----------------------------------------------------------------------
Joey Armstrong54dec092023-08-03 18:21:38 -0400414def collectArtifacts(exitStatus) {
Joey Armstrong6115fd62023-08-24 08:19:28 -0400415 script {
416 String iam = getIam('collectArtifacts')
417 println("${iam}: ENTER (exitStatus=${exitStatus})")
418 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400419
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400420 echo '''
421
422** -----------------------------------------------------------------------
423** collectArtifacts
424** -----------------------------------------------------------------------
425'''
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400426
Joey Armstrong642540a2023-08-10 10:26:36 -0400427 getPodsInfo("$WORKSPACE/${exitStatus}")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400428
Joey Armstrong642540a2023-08-10 10:26:36 -0400429 sh """
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400430 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400431 """
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400432
Joey Armstrong642540a2023-08-10 10:26:36 -0400433 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 -0400434
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400435 script {
436 println("${iam}: ENTER")
437 pgrep_proc('kail-startup')
438 pkill_proc('kail')
439 println("${iam}: LEAVE")
440 }
441
Joey Armstrong642540a2023-08-10 10:26:36 -0400442 println("${iam}: ENTER RobotPublisher")
443 step([$class: 'RobotPublisher',
444 disableArchiveOutput: false,
445 logFileName: '**/*/log*.html',
446 otherFiles: '',
447 outputFileName: '**/*/output*.xml',
448 outputPath: '.',
449 passThreshold: 100,
450 reportFileName: '**/*/report*.html',
451 unstableThreshold: 0,
452 onlyCritical: true]);
453 println("${iam}: LEAVE RobotPublisher")
454
455 println("${iam}: LEAVE (exitStatus=${exitStatus})")
456 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400457}
458
Joey Armstrong54dec092023-08-03 18:21:38 -0400459// -----------------------------------------------------------------------
460// Intent: main
461// -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400462pipeline {
463
464 /* no label, executor is determined by JJB */
465 agent {
466 label "${params.buildNode}"
467 }
468 options {
469 timeout(time: "${timeout}", unit: 'MINUTES')
470 }
471 environment {
Joey Armstrong642540a2023-08-10 10:26:36 -0400472 KUBECONFIG = "$HOME/.kube/kind-${clusterName}"
473 VOLTCONFIG = "$HOME/.volt/config"
474 PATH = "$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
475 DIAGS_PROFILE = 'VOLTHA_PROFILE'
476 SSHPASS = 'karaf'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400477 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400478
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400479 stages {
480 stage('Download Code') {
481 steps {
482 getVolthaCode([
483 branch: "${branch}",
484 gerritProject: "${gerritProject}",
485 gerritRefspec: "${gerritRefspec}",
486 volthaSystemTestsChange: "${volthaSystemTestsChange}",
487 volthaHelmChartsChange: "${volthaHelmChartsChange}",
488 ])
489 }
490 }
491
492 stage('Build patch v1.1')
493 {
494 // build the patch only if gerritProject is specified
495 when
496 {
497 expression
498 {
499 return !gerritProject.isEmpty()
500 }
501 }
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400502
503 steps
504 {
505 // NOTE that the correct patch has already been checked out
506 // during the getVolthaCode step
507 buildVolthaComponent("${gerritProject}")
508 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400509 }
510
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400511 // -----------------------------------------------------------------------
512 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400513 stage('Install Kail')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400514 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400515 steps
516 {
517 script
518 {
519 String cmd = [
520 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400521 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400522 '-C', "$WORKSPACE/voltha-system-tests",
523 "KAIL_PATH=\"$WORKSPACE/bin\"",
524 'kail',
525 ].join(' ')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400526
Joey Armstrongf060aee2023-08-22 21:55:26 -0400527 println(" ** Running: ${cmd}")
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400528 sh("${cmd}")
529 } // script
530 } // steps
531 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400532
533 // -----------------------------------------------------------------------
534 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400535 stage('Install Kind')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400536 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400537 steps
538 {
539 script
540 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400541
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400542 String cmd = [
543 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400544 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400545 '-C', "$WORKSPACE/voltha-system-tests",
546 "KIND_PATH=\"$WORKSPACE/bin\"",
547 'install-command-kind',
548 ].join(' ')
Joey Armstrong642540a2023-08-10 10:26:36 -0400549
Joey Armstrongf060aee2023-08-22 21:55:26 -0400550 println(" ** Running: ${cmd}")
551 sh("${cmd}")
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400552 } // script
553 } // steps
554 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400555
556 // -----------------------------------------------------------------------
557 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400558 stage('Create K8s Cluster') {
559 steps {
560 script {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400561 def clusterExists = sh(
Joey Armstrongf060aee2023-08-22 21:55:26 -0400562 returnStdout: true,
563 script: """kind get clusters | grep "${clusterName}" | wc -l""")
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400564
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400565 if (clusterExists.trim() == '0') {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400566 createKubernetesCluster([nodes: 3, name: clusterName])
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400567 }
Joey Armstrongf060aee2023-08-22 21:55:26 -0400568 } // script
569 } // steps
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400570 } // stage('Create K8s Cluster')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400571
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400572 // -----------------------------------------------------------------------
573 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400574 stage('Replace voltctl') {
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400575 // if the project is voltctl, override the downloaded one with the built one
576 when {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400577 expression { return gerritProject == 'voltctl' }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400578 }
579
580 // Hmmmm(?) where did the voltctl download happen ?
581 // Likely Makefile but would be helpful to document here.
Joey Armstrongf060aee2023-08-22 21:55:26 -0400582 steps {
Joey Armstrong6115fd62023-08-24 08:19:28 -0400583 script {
584 String iam = getIam('Replace voltctl')
585
586 println("${iam} Running: installVoltctl($branch)")
587 println("${iam}: ENTER")
588 installVoltctl("$branch")
589 println("${iam}: LEAVE")
590 } // script
591 } // steps
Joey Armstrong268442d2023-08-22 17:16:10 -0400592 } // stage
593
594 // -----------------------------------------------------------------------
595 // -----------------------------------------------------------------------
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400596 stage('Load image in kind nodes')
597 {
598 when {
599 expression { return !gerritProject.isEmpty() }
600 }
601 steps {
602 loadToKind()
603 } // steps
604 } // stage
605
606 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400607 // [TODO] verify testing output
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400608 // -----------------------------------------------------------------------
609 stage('Parse and execute tests')
610 {
611 steps {
612 script {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400613 // Announce ourselves for log usability
614 String iam = getIam('execute_test')
615 println("${iam}: ENTER")
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400616
617 def tests = readYaml text: testTargets
618
619 println("** $iam: Testing index: tests-to-run")
620 tests.eachWithIndex { test, idx ->
621 String target = test['target']
622 println("** $idx: $target")
Joey Armstrong38a87832023-08-23 17:02:50 -0400623 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400624 println("** NOTE: For odd failures compare tests-to-run with teste output")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400625
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400626 tests.eachWithIndex { test, idx ->
627 println "** readYaml test suite[$idx]) test=[${test}]"
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400628
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400629 String target = test['target']
630 String workflow = test['workflow']
631 String flags = test['flags']
632 Boolean teardown = test['teardown'].toBoolean()
633 Boolean logging = test['logging'].toBoolean()
634 String testLogging = (logging) ? 'True' : 'False'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400635
Joey Armstrong268442d2023-08-22 17:16:10 -0400636 print("""
Joey Armstrong268442d2023-08-22 17:16:10 -0400637** -----------------------------------------------------------------------
Joey Armstrong38a87832023-08-23 17:02:50 -0400638** Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}
Joey Armstrong268442d2023-08-22 17:16:10 -0400639** -----------------------------------------------------------------------
Joey Armstrong38a87832023-08-23 17:02:50 -0400640""")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400641
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400642 try {
643 println "Executing test ${target}: ENTER"
644 execute_test(target, workflow, testLogging, teardown, flags)
645 }
646 catch (Exception err) {
647 println("** ${iam}: EXCEPTION ${err}")
648 }
649 finally {
650 println "Executing test ${target}: LEAVE"
651 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400652
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400653 } // for
Joey Armstrong642540a2023-08-10 10:26:36 -0400654
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400655 // Premature exit if this message is not logged
656 println("${iam}: LEAVE (testing ran to completion)")
Joey Armstrong54dec092023-08-03 18:21:38 -0400657 } // script
658 } // steps
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400659 } // stage
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400660 } // stages
661
662 post
663 {
664 aborted { collectArtifacts('aborted') }
665 failure { collectArtifacts('failed') }
666 always { collectArtifacts('always') }
667 }
668} // pipeline
669
670// EOF