blob: f273eb55023413bbef72b5b9afedb92e7163b1dd [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 Armstrongec1ae0a2023-08-23 21:51:45 -0400415 String iam = getIam('collectArtifacts')
Joey Armstrong642540a2023-08-10 10:26:36 -0400416
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400417 echo '''
418
419** -----------------------------------------------------------------------
420** collectArtifacts
421** -----------------------------------------------------------------------
422'''
Joey Armstrong642540a2023-08-10 10:26:36 -0400423 println("${iam}: ENTER (exitStatus=${exitStatus})")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400424
Joey Armstrong642540a2023-08-10 10:26:36 -0400425 getPodsInfo("$WORKSPACE/${exitStatus}")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400426
Joey Armstrong642540a2023-08-10 10:26:36 -0400427 sh """
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400428 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400429 """
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400430
Joey Armstrong642540a2023-08-10 10:26:36 -0400431 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 -0400432
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400433 script {
434 println("${iam}: ENTER")
435 pgrep_proc('kail-startup')
436 pkill_proc('kail')
437 println("${iam}: LEAVE")
438 }
439
Joey Armstrong642540a2023-08-10 10:26:36 -0400440 println("${iam}: ENTER RobotPublisher")
441 step([$class: 'RobotPublisher',
442 disableArchiveOutput: false,
443 logFileName: '**/*/log*.html',
444 otherFiles: '',
445 outputFileName: '**/*/output*.xml',
446 outputPath: '.',
447 passThreshold: 100,
448 reportFileName: '**/*/report*.html',
449 unstableThreshold: 0,
450 onlyCritical: true]);
451 println("${iam}: LEAVE RobotPublisher")
452
453 println("${iam}: LEAVE (exitStatus=${exitStatus})")
454 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400455}
456
Joey Armstrong54dec092023-08-03 18:21:38 -0400457// -----------------------------------------------------------------------
458// Intent: main
459// -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400460pipeline {
461
462 /* no label, executor is determined by JJB */
463 agent {
464 label "${params.buildNode}"
465 }
466 options {
467 timeout(time: "${timeout}", unit: 'MINUTES')
468 }
469 environment {
Joey Armstrong642540a2023-08-10 10:26:36 -0400470 KUBECONFIG = "$HOME/.kube/kind-${clusterName}"
471 VOLTCONFIG = "$HOME/.volt/config"
472 PATH = "$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
473 DIAGS_PROFILE = 'VOLTHA_PROFILE'
474 SSHPASS = 'karaf'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400475 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400476
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400477 stages {
478 stage('Download Code') {
479 steps {
480 getVolthaCode([
481 branch: "${branch}",
482 gerritProject: "${gerritProject}",
483 gerritRefspec: "${gerritRefspec}",
484 volthaSystemTestsChange: "${volthaSystemTestsChange}",
485 volthaHelmChartsChange: "${volthaHelmChartsChange}",
486 ])
487 }
488 }
489
490 stage('Build patch v1.1')
491 {
492 // build the patch only if gerritProject is specified
493 when
494 {
495 expression
496 {
497 return !gerritProject.isEmpty()
498 }
499 }
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400500
501 steps
502 {
503 // NOTE that the correct patch has already been checked out
504 // during the getVolthaCode step
505 buildVolthaComponent("${gerritProject}")
506 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400507 }
508
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400509 // -----------------------------------------------------------------------
510 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400511 stage('Install Kail')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400512 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400513 steps
514 {
515 script
516 {
517 String cmd = [
518 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400519 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400520 '-C', "$WORKSPACE/voltha-system-tests",
521 "KAIL_PATH=\"$WORKSPACE/bin\"",
522 'kail',
523 ].join(' ')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400524
Joey Armstrongf060aee2023-08-22 21:55:26 -0400525 println(" ** Running: ${cmd}")
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400526 sh("${cmd}")
527 } // script
528 } // steps
529 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400530
531 // -----------------------------------------------------------------------
532 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400533 stage('Install Kind')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400534 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400535 steps
536 {
537 script
538 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400539
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400540 String cmd = [
541 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400542 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400543 '-C', "$WORKSPACE/voltha-system-tests",
544 "KIND_PATH=\"$WORKSPACE/bin\"",
545 'install-command-kind',
546 ].join(' ')
Joey Armstrong642540a2023-08-10 10:26:36 -0400547
Joey Armstrongf060aee2023-08-22 21:55:26 -0400548 println(" ** Running: ${cmd}")
549 sh("${cmd}")
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400550 } // script
551 } // steps
552 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400553
554 // -----------------------------------------------------------------------
555 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400556 stage('Create K8s Cluster') {
557 steps {
558 script {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400559 def clusterExists = sh(
Joey Armstrongf060aee2023-08-22 21:55:26 -0400560 returnStdout: true,
561 script: """kind get clusters | grep "${clusterName}" | wc -l""")
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400562
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400563 if (clusterExists.trim() == '0') {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400564 createKubernetesCluster([nodes: 3, name: clusterName])
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400565 }
Joey Armstrongf060aee2023-08-22 21:55:26 -0400566 } // script
567 } // steps
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400568 } // stage('Create K8s Cluster')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400569
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400570 // -----------------------------------------------------------------------
571 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400572 stage('Replace voltctl') {
573 String iam = getIam('Replace voltctl')
574
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 Armstrongec1ae0a2023-08-23 21:51:45 -0400583 println("${iam} Running: installVoltctl($branch)")
584 println("${iam}: ENTER")
585 installVoltctl("$branch")
586 println("${iam}: LEAVE")
Joey Armstrong268442d2023-08-22 17:16:10 -0400587 } // steps
588 } // stage
589
590 // -----------------------------------------------------------------------
591 // -----------------------------------------------------------------------
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400592 stage('Load image in kind nodes')
593 {
594 when {
595 expression { return !gerritProject.isEmpty() }
596 }
597 steps {
598 loadToKind()
599 } // steps
600 } // stage
601
602 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400603 // [TODO] verify testing output
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400604 // -----------------------------------------------------------------------
605 stage('Parse and execute tests')
606 {
607 steps {
608 script {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400609 // Announce ourselves for log usability
610 String iam = getIam('execute_test')
611 println("${iam}: ENTER")
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400612
613 def tests = readYaml text: testTargets
614
615 println("** $iam: Testing index: tests-to-run")
616 tests.eachWithIndex { test, idx ->
617 String target = test['target']
618 println("** $idx: $target")
Joey Armstrong38a87832023-08-23 17:02:50 -0400619 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400620 println("** NOTE: For odd failures compare tests-to-run with teste output")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400621
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400622 tests.eachWithIndex { test, idx ->
623 println "** readYaml test suite[$idx]) test=[${test}]"
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400624
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400625 String target = test['target']
626 String workflow = test['workflow']
627 String flags = test['flags']
628 Boolean teardown = test['teardown'].toBoolean()
629 Boolean logging = test['logging'].toBoolean()
630 String testLogging = (logging) ? 'True' : 'False'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400631
Joey Armstrong268442d2023-08-22 17:16:10 -0400632 print("""
Joey Armstrong268442d2023-08-22 17:16:10 -0400633** -----------------------------------------------------------------------
Joey Armstrong38a87832023-08-23 17:02:50 -0400634** Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}
Joey Armstrong268442d2023-08-22 17:16:10 -0400635** -----------------------------------------------------------------------
Joey Armstrong38a87832023-08-23 17:02:50 -0400636""")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400637
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400638 try {
639 println "Executing test ${target}: ENTER"
640 execute_test(target, workflow, testLogging, teardown, flags)
641 }
642 catch (Exception err) {
643 println("** ${iam}: EXCEPTION ${err}")
644 }
645 finally {
646 println "Executing test ${target}: LEAVE"
647 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400648
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400649 } // for
Joey Armstrong642540a2023-08-10 10:26:36 -0400650
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400651 // Premature exit if this message is not logged
652 println("${iam}: LEAVE (testing ran to completion)")
Joey Armstrong54dec092023-08-03 18:21:38 -0400653 } // script
654 } // steps
Joey Armstrong008cfaf2023-08-18 14:49:06 -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
666// EOF