blob: b3105c37240c2ce7304edddf3b4875769ec3306a [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 Armstronge9725b12023-08-28 18:15:12 -040028String clusterName = 'kind-ci'
Joey Armstrong7bcb5782023-06-07 12:25:57 -040029
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040030// -----------------------------------------------------------------------
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// -----------------------------------------------------------------------
Joey Armstrong25637192023-08-30 09:53:05 -040046String pipelineVer() {
47 String version = '45c11f80698d3be1416a86d2872d6e25aa24baa8'
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')
Joey Armstrong664c55a2023-08-28 14:22:33 -0400132
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400133 // remove orphaned port-forward from different namespaces
Joey Armstrong25637192023-08-30 09:53:05 -0400134 // String proc = 'kubectl.*port-forward' // was 'port-forw'
135
136 /* Pass Gstring args to sh() having problems
137 implicit cast from GString to java.lang.String unsupported
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400138 pgrep_proc(proc)
139 pkill_proc(proc)
Joey Armstrong664c55a2023-08-28 14:22:33 -0400140 pgrep_proc(proc) // todo: fatal unless (proc count==0)
141 */
Joey Armstrongebc18022023-08-26 13:20:49 -0400142
Joey Armstrong664c55a2023-08-28 14:22:33 -0400143 sh(label : 'pgrep_proc - kill-pre',
144 script : """
Joey Armstrong12a8c832023-08-28 16:50:24 -0400145pgrep --uid "\$(id -u)" --list-full --full 'kubectl.*port-forward' || true
Joey Armstrong664c55a2023-08-28 14:22:33 -0400146""")
147
148 sh(label : 'pkill_proc - kubectl.*port-forward',
149 script : """
Joey Armstrong12a8c832023-08-28 16:50:24 -0400150if [[ \$(pgrep --count 'kubectl.*port-forward') -gt 0 ]]; then
151 pkill --uid "\$(id -u)" --echo --full 'kubectl.*port-forward'
152fi
Joey Armstrong664c55a2023-08-28 14:22:33 -0400153""")
154
155 sh(label : 'pgrep_proc - kill-post',
156 script : """
Joey Armstrong12a8c832023-08-28 16:50:24 -0400157pgrep --uid "\$(id -u)" --list-full --full 'kubectl.*port-forward' || true
Joey Armstrong664c55a2023-08-28 14:22:33 -0400158""")
159
Joey Armstrong6146f7e2023-08-28 09:05:38 -0400160 leave('Cleanup')
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400161 } // script
162 } // timeout
Joey Armstrongf060aee2023-08-22 21:55:26 -0400163 } // teardown
Joey Armstrong38a87832023-08-23 17:02:50 -0400164 } // stage('Cleanup')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400165
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400166 // -----------------------------------------------------------------------
167 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400168 stage('Deploy common infrastructure') {
169 script {
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400170 local dashargs = [
171 'kpi_exporter.enabled=false',
172 'dashboards.xos=false',
173 'dashboards.onos=false',
174 'dashboards.aaa=false',
175 'dashboards.voltha=false',
176 ].join(',')
177
178 local promargs = [
179 'prometheus.alertmanager.enabled=false',
180 'prometheus.pushgateway.enabled=false',
181 ].join(',')
182
Joey Armstrong6146f7e2023-08-28 09:05:38 -0400183 sh(label : 'Deploy common infrastructure',
184 script : """
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400185 helm repo add onf https://charts.opencord.org
186 helm repo update
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400187
188 echo -e "\nwithMonitoring=[$withMonitoring]"
189 if [ ${withMonitoring} = true ] ; then
190 helm install nem-monitoring onf/nem-monitoring \
Joey Armstrong38a87832023-08-23 17:02:50 -0400191 --set ${promargs} \
192 --set ${dashargs}
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400193 fi
Joey Armstrong38a87832023-08-23 17:02:50 -0400194 """)
195 } // script
196 } // stage('Deploy Common Infra')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400197
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400198 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400199 // [TODO] Check onos_log output
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400200 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400201 stage('Deploy Voltha') {
202 if (teardown) {
203 timeout(10) {
204 script {
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400205 String iam = getIam('Deploy Voltha')
206 String onosLog = "${logsDir}/onos-voltha-startup-combined.log"
207 sh("""
Joey Armstrongd1c45752023-08-29 16:56:05 -0400208 mkdir -p "$logsDir"
Joey Armstrong38a87832023-08-23 17:02:50 -0400209 touch "$onosLog"
210 echo "** kail-startup ENTER: \$(date)" > "$onosLog"
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400211
212 # Intermixed output (tee -a &) may get conflusing but let(s) see
213 # what messages are logged during startup.
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400214 # _TAG=ka7il-startup kail -n ${infraNamespace} -n ${volthaNamespace} >> "$onosLog" &
Joey Armstrong38a87832023-08-23 17:02:50 -0400215 _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} | tee -a "$onosLog" &
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400216 """)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400217
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400218 // if we're downloading a voltha-helm-charts patch, then install from a local copy of the charts
219 Boolean localCharts = false
Joey Armstrong642540a2023-08-10 10:26:36 -0400220
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400221 if (volthaHelmChartsChange != ''
222 || gerritProject == 'voltha-helm-charts'
223 || isReleaseBranch(branch) // branch != 'master'
224 ) {
225 localCharts = true
226 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400227
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400228 String branchName = branchName()
229 Boolean isRelease = isReleaseBranch(branch)
230 println([
231 " ** localCharts=${localCharts}",
232 "branchName=${branchName}",
233 "branch=${branch}",
234 "branch=isReleaseBranch=${isRelease}",
235 ].join(', '))
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400236
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400237 // -----------------------------------------------------------------------
238 // Rewrite localHelmFlags using array join, moving code around and
239 // refactoring into standalone functions
240 // -----------------------------------------------------------------------
241 // NOTE temporary workaround expose ONOS node ports
242 // -----------------------------------------------------------------------
243 String localHelmFlags = [
244 extraHelmFlags.trim(),
245 "--set global.log_level=${logLevel.toUpperCase()}",
246 '--set onos-classic.onosSshPort=30115',
247 '--set onos-classic.onosApiPort=30120',
248 '--set onos-classic.onosOfPort=31653',
249 '--set onos-classic.individualOpenFlowNodePorts=true',
250 testSpecificHelmFlags
251 ].join(' ')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400252
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400253 println("** ${iam} localHelmFlags = ${localHelmFlags}")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400254
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400255 if (gerritProject != '') {
256 localHelmFlags = "${localHelmFlags} " + getVolthaImageFlags("${gerritProject}")
257 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400258
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400259 println("** ${iam}: ENTER")
260 volthaDeploy([
261 infraNamespace: infraNamespace,
262 volthaNamespace: volthaNamespace,
263 workflow: workflow.toLowerCase(),
264 withMacLearning: enableMacLearning.toBoolean(),
265 extraHelmFlags: localHelmFlags,
266 localCharts: localCharts,
267 bbsimReplica: olts.toInteger(),
268 dockerRegistry: registry,
269 ])
270 println("** ${iam}: LEAVE")
271 } // script
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400272
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400273 // -----------------------------------------------------------------------
274 // Intent: Replacing P_IDS with pgrep/pkill is a step forward.
275 // Why not simply use a pid file, capture _TAG=kail-startup above
276 // Grep runs the risk of terminating stray commands (??-good <=> bad-??)
277 // -----------------------------------------------------------------------
278 script {
279 String proc = '_TAG=kail-startup'
Joey Armstrongdddbbf92023-08-22 16:00:41 -0400280
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400281 println("${iam}: ENTER")
282 println("${iam}: Shutdown process $proc")
Joey Armstrong664c55a2023-08-28 14:22:33 -0400283 /*
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400284 pgrep_proc(proc)
285 pkill_proc(proc)
286 pgrep_proc(proc)
Joey Armstrong664c55a2023-08-28 14:22:33 -0400287 */
288
289 sh(label : 'pgrep_proc - kill-pre',
290 script : """
Joey Armstrong12a8c832023-08-28 16:50:24 -0400291pgrep --uid "\$(id -u)" --list-full --full '_TAG=kail-startup' || true
Joey Armstrong664c55a2023-08-28 14:22:33 -0400292""")
293
294 sh(label : 'pkill_proc - _TAG=kail-startup',
295 script : """
Joey Armstrong12a8c832023-08-28 16:50:24 -0400296if [[ \$(pgrep --count '_TAG=kail-startup') -gt 0 ]]; then
297 pkill --uid "\$(id -u)" --echo --full '_TAG=kail-startup'
298fi
Joey Armstrong664c55a2023-08-28 14:22:33 -0400299""")
300
301 sh(label : 'pgrep_proc - kill-post',
302 script : """
Joey Armstrong12a8c832023-08-28 16:50:24 -0400303pgrep --uid "\$(id -u)" --list-full --full '_TAG=kail-startup' || true
Joey Armstrong664c55a2023-08-28 14:22:33 -0400304""")
305
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400306 println("${iam}: LEAVE")
307 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400308
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400309 // -----------------------------------------------------------------------
310 // Bundle onos-voltha / kail logs
311 // -----------------------------------------------------------------------
312 sh("""
Joey Armstrongf060aee2023-08-22 21:55:26 -0400313cat <<EOM
314
315** -----------------------------------------------------------------------
Joey Armstrong7ba23ac2023-08-29 15:21:53 -0400316** Combine and compress voltha startup log(s)
Joey Armstrongf060aee2023-08-22 21:55:26 -0400317** -----------------------------------------------------------------------
318EOM
319 pushd "${logsDir}" || { echo "ERROR: pushd $logsDir failed"; exit 1; }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400320 gzip -k onos-voltha-startup-combined.log
321 rm onos-voltha-startup-combined.log
Joey Armstrongf060aee2023-08-22 21:55:26 -0400322 popd
323 """)
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400324 } // timeout(10)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400325
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400326 // -----------------------------------------------------------------------
327 // -----------------------------------------------------------------------
328 sh """
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400329 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"&
330 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"&
331 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"&
332 bbsimDmiPortFwd=50075
333 for i in {0..${olts.toInteger() - 1}}; do
334 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"&
335 ((bbsimDmiPortFwd++))
336 done
337 if [ ${withMonitoring} = true ] ; then
338 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"&
339 fi
Joey Armstrong7ba23ac2023-08-29 15:21:53 -0400340# ps aux | grep port-forward
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400341 """
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400342 // ---------------------------------
343 // Sanity check port-forward spawned
344 // ---------------------------------
345 script {
Joey Armstrong7ba23ac2023-08-29 15:21:53 -0400346 enter('Display port-forward procs')
Joey Armstrongebc18022023-08-26 13:20:49 -0400347 // String proc = 'kubectl.*port-forward' // was 'port-forward'
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400348 String proc = 'port-forward'
349 println("Display spawned ${proc}")
Joey Armstrong664c55a2023-08-28 14:22:33 -0400350 sh(label : 'pgrep_proc - check',
351 script : """
Joey Armstrong12a8c832023-08-28 16:50:24 -0400352pgrep --uid "\$(id -u)" --list-full --full "port-forward" || true
Joey Armstrong664c55a2023-08-28 14:22:33 -0400353""")
Joey Armstrong7ba23ac2023-08-29 15:21:53 -0400354 leave('Display port-forward procs')
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400355 }
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400356
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400357 // setting ONOS log level
358 script {
359 enter('setOnosLogLevels')
360 setOnosLogLevels([
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400361 onosNamespace: infraNamespace,
362 apps: [
363 'org.opencord.dhcpl2relay',
364 'org.opencord.olt',
365 'org.opencord.aaa',
366 'org.opencord.maclearner',
367 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
368 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
369 ],
370 logLevel: logLevel
371 ])
Joey Armstrong6146f7e2023-08-28 09:05:38 -0400372 leave('setOnosLogLevels')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400373 } // script
374 } // if (teardown)
375 } // stage('Deploy Voltha')
376
Joey Armstrongf060aee2023-08-22 21:55:26 -0400377 // -----------------------------------------------------------------------
378 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400379 stage("Run test ${testTarget} on workflow ${workflow}")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400380 {
Joey Armstrongebc18022023-08-26 13:20:49 -0400381 sh(
382 label : 'Monitor using mem_consumption.py',
383 script : """
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400384 echo -e "\n** Monitor using mem_consumption.py ?"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400385
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400386 if [ ${withMonitoring} = true ] ; then
Joey Armstrongf060aee2023-08-22 21:55:26 -0400387 cat <<EOM
388
389** -----------------------------------------------------------------------
390** Monitoring memory usage with mem_consumption.py
391** -----------------------------------------------------------------------
392EOM
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400393 mkdir -p "$WORKSPACE/voltha-pods-mem-consumption-${workflow}"
394 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400395
396 echo '** Installing python virtualenv'
397 make venv-activate-patched
398
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400399 set +u && source .venv/bin/activate && set -u
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400400 # Collect initial memory consumption
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400401 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 -0400402 fi
Joey Armstrongf060aee2023-08-22 21:55:26 -0400403
404 echo -e '** Monitor memory consumption: LEAVE\n'
Joey Armstrongebc18022023-08-26 13:20:49 -0400405 """)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400406
407 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400408 echo -e "\n** make testTarget=[${testTarget}]"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400409 mkdir -p ${logsDir}
410 export ROBOT_MISC_ARGS="-d ${logsDir} ${params.extraRobotArgs} "
411 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}"
412 export KVSTOREPREFIX=voltha/voltha_voltha
413
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400414 make -C "$WORKSPACE/voltha-system-tests" ${testTarget}
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400415 """
416
417 getPodsInfo("${logsDir}")
418
Joey Armstrongebc18022023-08-26 13:20:49 -0400419 sh(
420 label : 'Gather robot Framework logs',
421 script : """
Joey Armstrong54dec092023-08-03 18:21:38 -0400422 echo -e '\n** Gather robot Framework logs: ENTER'
Joey Armstrong7ba23ac2023-08-29 15:21:53 -0400423
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400424 # set +e
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400425 # collect logs collected in the Robot Framework StartLogging keyword
Joey Armstrong7ba23ac2023-08-29 15:21:53 -0400426 cd "${logsDir}"
427
428 echo "** Available logs:"
Joey Armstrongd1c45752023-08-29 16:56:05 -0400429 /bin/ls -l "$logsDir"
Joey Armstrong7ba23ac2023-08-29 15:21:53 -0400430 echo
431
Joey Armstrong2e274972023-08-29 17:39:18 -0400432 echo '** Bundle combined log'
433 gzip *-combined.log || true
434 rm -f *-combined.log || true
Joey Armstrong54dec092023-08-03 18:21:38 -0400435
436 echo -e '** Gather robot Framework logs: LEAVE\n'
Joey Armstrongebc18022023-08-26 13:20:49 -0400437 """)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400438
Joey Armstrongf060aee2023-08-22 21:55:26 -0400439 // -----------------------------------------------------------------------
440 // -----------------------------------------------------------------------
Joey Armstrongebc18022023-08-26 13:20:49 -0400441 sh(
442 label : 'Monitor pod-mem-consumption',
443 script : """
Joey Armstrong54dec092023-08-03 18:21:38 -0400444 echo -e '** Monitor pod-mem-consumption: ENTER'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400445 if [ ${withMonitoring} = true ] ; then
Joey Armstrongf060aee2023-08-22 21:55:26 -0400446 cat <<EOM
447
448** -----------------------------------------------------------------------
449** Monitoring pod-memory-consumption using mem_consumption.py
450** -----------------------------------------------------------------------
451EOM
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400452 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400453
454 echo '** Installing python virtualenv'
455 make venv-activate-patched
Joey Armstrong38a87832023-08-23 17:02:50 -0400456
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400457 set +u && source .venv/bin/activate && set -u
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400458 # Collect memory consumption of voltha pods once all the tests are complete
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400459 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 -0400460 fi
Joey Armstrong54dec092023-08-03 18:21:38 -0400461 echo -e '** Monitor pod-mem-consumption: LEAVE\n'
Joey Armstrongebc18022023-08-26 13:20:49 -0400462 """)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400463 } // stage
Joey Armstrong54dec092023-08-03 18:21:38 -0400464
465 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400466} // execute_test()
467
468// -----------------------------------------------------------------------
469// -----------------------------------------------------------------------
Joey Armstrong54dec092023-08-03 18:21:38 -0400470def collectArtifacts(exitStatus) {
Joey Armstrong6115fd62023-08-24 08:19:28 -0400471 script {
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400472 String iam = getIam('collectArtifacts')
473 println("${iam}: ENTER (exitStatus=${exitStatus})")
Joey Armstrong6115fd62023-08-24 08:19:28 -0400474 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400475
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400476 echo '''
477
478** -----------------------------------------------------------------------
479** collectArtifacts
480** -----------------------------------------------------------------------
481'''
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400482
Joey Armstrong642540a2023-08-10 10:26:36 -0400483 getPodsInfo("$WORKSPACE/${exitStatus}")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400484
Joey Armstrong642540a2023-08-10 10:26:36 -0400485 sh """
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400486 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400487 """
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400488
Joey Armstrong642540a2023-08-10 10:26:36 -0400489 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 -0400490
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400491 script {
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400492 println("${iam}: ENTER")
Joey Armstrong664c55a2023-08-28 14:22:33 -0400493 /*
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400494 pgrep_proc('kail-startup')
495 pkill_proc('kail')
Joey Armstrong664c55a2023-08-28 14:22:33 -0400496 */
497 sh(label : 'pgrep_proc - kill-pre',
498 script : """
Joey Armstronge9725b12023-08-28 18:15:12 -0400499pgrep --uid "\$(id -u)" --list-full --full 'kail-startup' || true
Joey Armstrong664c55a2023-08-28 14:22:33 -0400500""")
501 sh(label : 'pkill_proc - kail',
502 script : """
Joey Armstrong12a8c832023-08-28 16:50:24 -0400503if [[ \$(pgrep --count '_TAG=kail') -gt 0 ]]; then
504 pkill --uid "\$(id -u)" --echo --full 'kail'
505fi
Joey Armstrong664c55a2023-08-28 14:22:33 -0400506""")
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400507 println("${iam}: LEAVE")
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400508 }
Joey Armstrongdd0cd6b2023-08-25 17:27:56 -0400509
Joey Armstrong642540a2023-08-10 10:26:36 -0400510 println("${iam}: ENTER RobotPublisher")
511 step([$class: 'RobotPublisher',
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400512 disableArchiveOutput: false,
513 logFileName: '**/*/log*.html',
514 otherFiles: '',
515 outputFileName: '**/*/output*.xml',
516 outputPath: '.',
517 passThreshold: 100,
518 reportFileName: '**/*/report*.html',
519 unstableThreshold: 0,
520 onlyCritical: true])
Joey Armstrong642540a2023-08-10 10:26:36 -0400521 println("${iam}: LEAVE RobotPublisher")
522
523 println("${iam}: LEAVE (exitStatus=${exitStatus})")
524 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400525}
526
Joey Armstrong54dec092023-08-03 18:21:38 -0400527// -----------------------------------------------------------------------
528// Intent: main
529// -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400530pipeline {
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400531 /* no label, executor is determined by JJB */
532 agent {
533 label "${params.buildNode}"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400534 }
535
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400536 options {
537 timeout(time: "${timeout}", unit: 'MINUTES')
538 }
539
540 environment {
541 KUBECONFIG = "$HOME/.kube/kind-${clusterName}"
542 VOLTCONFIG = "$HOME/.volt/config"
543 PATH = "$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
544 DIAGS_PROFILE = 'VOLTHA_PROFILE'
545 SSHPASS = 'karaf'
546 }
547
548 stages {
549 stage('Download Code') {
550 steps {
551 getVolthaCode([
552 branch: "${branch}",
553 gerritProject: "${gerritProject}",
554 gerritRefspec: "${gerritRefspec}",
555 volthaSystemTestsChange: "${volthaSystemTestsChange}",
556 volthaHelmChartsChange: "${volthaHelmChartsChange}",
557 ])
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400558 }
559 }
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400560
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400561 stage('Build patch v1.1') {
562 // build the patch only if gerritProject is specified
563 when {
564 expression { return !gerritProject.isEmpty() }
565 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400566
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400567 steps {
568 // NOTE that the correct patch has already been checked out
569 // during the getVolthaCode step
570 buildVolthaComponent("${gerritProject}")
571 }
572 }
573
574 // -----------------------------------------------------------------------
575 // -----------------------------------------------------------------------
576 stage('Install Kail')
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400577 {
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400578 steps
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400579 {
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400580 script
581 {
582 String cmd = [
583 'make',
584 '--no-print-directory',
585 '-C', "$WORKSPACE/voltha-system-tests",
586 "KAIL_PATH=\"$WORKSPACE/bin\"",
587 'kail',
588 ].join(' ')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400589
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400590 println(" ** Running: ${cmd}")
591 sh("${cmd}")
592 } // script
593 } // steps
594 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400595
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400596 // -----------------------------------------------------------------------
597 // -----------------------------------------------------------------------
598 stage('Install Tools') {
599 steps {
600 script {
601 String branchName = branchName()
602 String iam = getIam('Install Tools')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400603
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400604 println("${iam}: ENTER (branch=$branch)")
605 installKind(branch) // needed early by stage(Cleanup)
606 println("${iam}: LEAVE (branch=$branch)")
607 } // script
608 } // steps
609 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400610
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400611 // -----------------------------------------------------------------------
612 // -----------------------------------------------------------------------
613 stage('Create K8s Cluster') {
614 steps {
615 script {
616 def clusterExists = sh(
617 returnStdout: true,
618 script: """kind get clusters | grep "${clusterName}" | wc -l""")
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400619
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400620 if (clusterExists.trim() == '0') {
621 createKubernetesCluster([nodes: 3, name: clusterName])
622 }
623 } // script
624 } // steps
625 } // stage('Create K8s Cluster')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400626
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400627 // -----------------------------------------------------------------------
628 // -----------------------------------------------------------------------
629 stage('Replace voltctl') {
630 // if the project is voltctl, override the downloaded one with the built one
631 when {
632 expression { return gerritProject == 'voltctl' }
633 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400634
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400635 // Hmmmm(?) where did the voltctl download happen ?
636 // Likely Makefile but would be helpful to document here.
637 steps {
638 script {
639 String iam = getIam('Replace voltctl')
Joey Armstrong6115fd62023-08-24 08:19:28 -0400640
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400641 println("${iam} Running: installVoltctl($branch)")
642 println("${iam}: ENTER")
643 installVoltctl("$branch")
644 println("${iam}: LEAVE")
645 } // script
646 } // step
647 } // stage
Joey Armstrong268442d2023-08-22 17:16:10 -0400648
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400649 // -----------------------------------------------------------------------
650 // -----------------------------------------------------------------------
651 stage('Load image in kind nodes')
652 {
653 when {
654 expression { return !gerritProject.isEmpty() }
655 }
656 steps {
657 loadToKind()
658 } // steps
659 } // stage
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400660
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400661 // -----------------------------------------------------------------------
662 // [TODO] verify testing output
663 // -----------------------------------------------------------------------
664 stage('Parse and execute tests')
665 {
666 steps {
667 script {
668 // Announce ourselves for log usability
669 enter('Parse and execute tests')
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400670
Joey Armstrongebc18022023-08-26 13:20:49 -0400671 def tests = readYaml text: testTargets // typeof == Map (?)
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400672 println("** [DEBUG]: tests=$tests")
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400673
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400674 // Display expected tests for times when output goes dark
675 tests.eachWithIndex { test, idx ->
676 String target = test['target']
677 println("** test[${idx}]: ${target}\n")
678 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400679
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400680 println('''
Joey Armstrongb29d5612023-08-24 12:53:46 -0400681** -----------------------------------------------------------------------
682** NOTE: For odd/silent job failures verify a few details
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400683** - All tests mentioned in the tests-to-run index were logged.
Joey Armstrongb29d5612023-08-24 12:53:46 -0400684** - Test suites display ENTER/LEAVE mesasge pairs.
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400685** - Processing terminated prematurely when LEAVE strings are missing.
Joey Armstrongb29d5612023-08-24 12:53:46 -0400686** -----------------------------------------------------------------------
Joey Armstrongbe7c9242023-08-24 16:20:31 -0400687''')
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400688 tests.eachWithIndex { test, idx ->
689 println "** readYaml test suite[$idx]) test=[${test}]"
Joey Armstrongf46b3ae2023-08-25 11:07:20 -0400690
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400691 String target = test['target']
692 String workflow = test['workflow']
693 String flags = test['flags']
694 Boolean teardown = test['teardown'].toBoolean()
695 Boolean logging = test['logging'].toBoolean()
696 String testLogging = (logging) ? 'True' : 'False'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400697
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400698 print("""
Joey Armstrong268442d2023-08-22 17:16:10 -0400699** -----------------------------------------------------------------------
Joey Armstrong38a87832023-08-23 17:02:50 -0400700** Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}
Joey Armstrong268442d2023-08-22 17:16:10 -0400701** -----------------------------------------------------------------------
Joey Armstrong38a87832023-08-23 17:02:50 -0400702""")
Joey Armstrong664c55a2023-08-28 14:22:33 -0400703
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400704 try {
Joey Armstrong6146f7e2023-08-28 09:05:38 -0400705 enter("execute_test (target=$target)")
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400706 execute_test(target, workflow, testLogging, teardown, flags)
707 }
Joey Armstrong9341c9a2023-08-28 12:09:19 -0400708 // groovylint-disable-next-line CatchException
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400709 catch (Exception err) {
Joey Armstrong9341c9a2023-08-28 12:09:19 -0400710 String iamexc = getIam(name)
711 println("** ${iamexc}: EXCEPTION ${err}")
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400712 }
713 finally {
714 leave("execute_test (target=$target)")
715 }
716 } // for
717 // Premature exit if this message is not logged
718 leave('Parse and execute tests')
Joey Armstrong54dec092023-08-03 18:21:38 -0400719 } // script
720 } // steps
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400721 } // stage
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400722 } // stages
723
724 post
725 {
726 aborted { collectArtifacts('aborted') }
727 failure { collectArtifacts('failed') }
728 always { collectArtifacts('always') }
729 }
730} // pipeline
731
Joey Armstrong664c55a2023-08-28 14:22:33 -0400732// [EOF]