blob: 389d4283ed70056c49f0ff6f120cacc07ceb75bd [file] [log] [blame]
Joey Armstrong7bcb5782023-06-07 12:25:57 -04001// Copyright 2021-2023 Open Networking Foundation (ONF) and the ONF Contributors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// voltha-2.x e2e tests for openonu-go
16// uses bbsim to simulate OLT/ONUs
17
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040018// [TODO] Update syntax below to the latest supported
Joey Armstrong7bcb5782023-06-07 12:25:57 -040019library identifier: 'cord-jenkins-libraries@master',
20 retriever: modernSCM([
21 $class: 'GitSCMSource',
22 remote: 'https://gerrit.opencord.org/ci-management.git'
23])
24
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040025//------------------//
26//---] GLOBAL [---//
27//------------------//
Joey Armstrong54dec092023-08-03 18:21:38 -040028String clusterName = 'kind-ci' // was def
Joey Armstrong7bcb5782023-06-07 12:25:57 -040029
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040030// -----------------------------------------------------------------------
31// Intent:
32// -----------------------------------------------------------------------
Joey Armstrong54dec092023-08-03 18:21:38 -040033String branchName() {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040034 String name = 'voltha-2.12'
35
36 // [TODO] Sanity check the target branch
37 // if (name != jenkins.branch) { fatal }
38 return(name)
39}
40
41// -----------------------------------------------------------------------
Joey Armstrongaf4eef22023-08-25 16:14:45 -040042// Intent: Difficult at times to determine when pipeline jobs have
43// regenerated. Hardcode a version string that can be assigned
44// per-script to be sure latest repository changes are being used.
45// -----------------------------------------------------------------------
46String pipelineVer() {
Joey Armstrong6146f7e2023-08-28 09:05:38 -040047 String version = '5addce3fac89095d103ac5c6eedff2bb02e9ec63'
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 Armstrong664c55a2023-08-28 14:22:33 -0400134 String proc = 'kubectl.*port-forward' // was 'port-forw'
135 /*
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400136 pgrep_proc(proc)
137 pkill_proc(proc)
Joey Armstrong664c55a2023-08-28 14:22:33 -0400138 pgrep_proc(proc) // todo: fatal unless (proc count==0)
139 */
Joey Armstrongebc18022023-08-26 13:20:49 -0400140
Joey Armstrong664c55a2023-08-28 14:22:33 -0400141 sh(label : 'pgrep_proc - kill-pre',
142 script : """
143pgrep --uid "$(uid -u)" --list-full --full 'kubectl.*port-forward'
144""")
145
146 sh(label : 'pkill_proc - kubectl.*port-forward',
147 script : """
148pkill --uid "$(uid -u)" --echo --full 'kubectl.*port-forward'
149""")
150
151 sh(label : 'pgrep_proc - kill-post',
152 script : """
153pgrep --uid "$(uid -u)" --list-full --full 'kubectl.*port-forward'
154""")
155
Joey Armstrong6146f7e2023-08-28 09:05:38 -0400156 leave('Cleanup')
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400157 } // script
158 } // timeout
Joey Armstrongf060aee2023-08-22 21:55:26 -0400159 } // teardown
Joey Armstrong38a87832023-08-23 17:02:50 -0400160 } // stage('Cleanup')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400161
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400162 // -----------------------------------------------------------------------
163 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400164 stage('Deploy common infrastructure') {
165 script {
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400166 local dashargs = [
167 'kpi_exporter.enabled=false',
168 'dashboards.xos=false',
169 'dashboards.onos=false',
170 'dashboards.aaa=false',
171 'dashboards.voltha=false',
172 ].join(',')
173
174 local promargs = [
175 'prometheus.alertmanager.enabled=false',
176 'prometheus.pushgateway.enabled=false',
177 ].join(',')
178
Joey Armstrong6146f7e2023-08-28 09:05:38 -0400179 sh(label : 'Deploy common infrastructure',
180 script : """
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400181 helm repo add onf https://charts.opencord.org
182 helm repo update
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400183
184 echo -e "\nwithMonitoring=[$withMonitoring]"
185 if [ ${withMonitoring} = true ] ; then
186 helm install nem-monitoring onf/nem-monitoring \
Joey Armstrong38a87832023-08-23 17:02:50 -0400187 --set ${promargs} \
188 --set ${dashargs}
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400189 fi
Joey Armstrong38a87832023-08-23 17:02:50 -0400190 """)
191 } // script
192 } // stage('Deploy Common Infra')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400193
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400194 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400195 // [TODO] Check onos_log output
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400196 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400197 stage('Deploy Voltha') {
198 if (teardown) {
199 timeout(10) {
200 script {
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400201 String iam = getIam('Deploy Voltha')
202 String onosLog = "${logsDir}/onos-voltha-startup-combined.log"
203 sh("""
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400204 mkdir -p ${logsDir}
Joey Armstrong38a87832023-08-23 17:02:50 -0400205 touch "$onosLog"
206 echo "** kail-startup ENTER: \$(date)" > "$onosLog"
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400207
208 # Intermixed output (tee -a &) may get conflusing but let(s) see
209 # what messages are logged during startup.
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400210 # _TAG=ka7il-startup kail -n ${infraNamespace} -n ${volthaNamespace} >> "$onosLog" &
Joey Armstrong38a87832023-08-23 17:02:50 -0400211 _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} | tee -a "$onosLog" &
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400212 """)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400213
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400214 // if we're downloading a voltha-helm-charts patch, then install from a local copy of the charts
215 Boolean localCharts = false
Joey Armstrong642540a2023-08-10 10:26:36 -0400216
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400217 if (volthaHelmChartsChange != ''
218 || gerritProject == 'voltha-helm-charts'
219 || isReleaseBranch(branch) // branch != 'master'
220 ) {
221 localCharts = true
222 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400223
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400224 String branchName = branchName()
225 Boolean isRelease = isReleaseBranch(branch)
226 println([
227 " ** localCharts=${localCharts}",
228 "branchName=${branchName}",
229 "branch=${branch}",
230 "branch=isReleaseBranch=${isRelease}",
231 ].join(', '))
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400232
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400233 // -----------------------------------------------------------------------
234 // Rewrite localHelmFlags using array join, moving code around and
235 // refactoring into standalone functions
236 // -----------------------------------------------------------------------
237 // NOTE temporary workaround expose ONOS node ports
238 // -----------------------------------------------------------------------
239 String localHelmFlags = [
240 extraHelmFlags.trim(),
241 "--set global.log_level=${logLevel.toUpperCase()}",
242 '--set onos-classic.onosSshPort=30115',
243 '--set onos-classic.onosApiPort=30120',
244 '--set onos-classic.onosOfPort=31653',
245 '--set onos-classic.individualOpenFlowNodePorts=true',
246 testSpecificHelmFlags
247 ].join(' ')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400248
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400249 println("** ${iam} localHelmFlags = ${localHelmFlags}")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400250
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400251 if (gerritProject != '') {
252 localHelmFlags = "${localHelmFlags} " + getVolthaImageFlags("${gerritProject}")
253 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400254
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400255 println("** ${iam}: ENTER")
256 volthaDeploy([
257 infraNamespace: infraNamespace,
258 volthaNamespace: volthaNamespace,
259 workflow: workflow.toLowerCase(),
260 withMacLearning: enableMacLearning.toBoolean(),
261 extraHelmFlags: localHelmFlags,
262 localCharts: localCharts,
263 bbsimReplica: olts.toInteger(),
264 dockerRegistry: registry,
265 ])
266 println("** ${iam}: LEAVE")
267 } // script
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400268
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400269 // -----------------------------------------------------------------------
270 // Intent: Replacing P_IDS with pgrep/pkill is a step forward.
271 // Why not simply use a pid file, capture _TAG=kail-startup above
272 // Grep runs the risk of terminating stray commands (??-good <=> bad-??)
273 // -----------------------------------------------------------------------
274 script {
275 String proc = '_TAG=kail-startup'
Joey Armstrongdddbbf92023-08-22 16:00:41 -0400276
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400277 println("${iam}: ENTER")
278 println("${iam}: Shutdown process $proc")
Joey Armstrong664c55a2023-08-28 14:22:33 -0400279 /*
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400280 pgrep_proc(proc)
281 pkill_proc(proc)
282 pgrep_proc(proc)
Joey Armstrong664c55a2023-08-28 14:22:33 -0400283 */
284
285 sh(label : 'pgrep_proc - kill-pre',
286 script : """
287pgrep --uid "$(uid -u)" --list-full --full '_TAG=kail-startup'
288""")
289
290 sh(label : 'pkill_proc - _TAG=kail-startup',
291 script : """
292pkill --uid "$(uid -u)" --echo --full '_TAG=kail-startup'
293""")
294
295 sh(label : 'pgrep_proc - kill-post',
296 script : """
297pgrep --uid "$(uid -u)" --list-full --full '_TAG=kail-startup'
298""")
299
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400300 println("${iam}: LEAVE")
301 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400302
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400303 // -----------------------------------------------------------------------
304 // Bundle onos-voltha / kail logs
305 // -----------------------------------------------------------------------
306 sh("""
Joey Armstrongf060aee2023-08-22 21:55:26 -0400307cat <<EOM
308
309** -----------------------------------------------------------------------
310** Combine an compress voltha startup log(s)
311** -----------------------------------------------------------------------
312EOM
313 pushd "${logsDir}" || { echo "ERROR: pushd $logsDir failed"; exit 1; }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400314 gzip -k onos-voltha-startup-combined.log
315 rm onos-voltha-startup-combined.log
Joey Armstrongf060aee2023-08-22 21:55:26 -0400316 popd
317 """)
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400318 } // timeout(10)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400319
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400320 // -----------------------------------------------------------------------
321 // -----------------------------------------------------------------------
322 sh """
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400323 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"&
324 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"&
325 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"&
326 bbsimDmiPortFwd=50075
327 for i in {0..${olts.toInteger() - 1}}; do
328 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"&
329 ((bbsimDmiPortFwd++))
330 done
331 if [ ${withMonitoring} = true ] ; then
332 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"&
333 fi
334 ps aux | grep port-forward
335 """
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400336 // ---------------------------------
337 // Sanity check port-forward spawned
338 // ---------------------------------
339 script {
340 enter('port-forward check')
Joey Armstrongebc18022023-08-26 13:20:49 -0400341 // String proc = 'kubectl.*port-forward' // was 'port-forward'
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400342 String proc = 'port-forward'
343 println("Display spawned ${proc}")
Joey Armstrong664c55a2023-08-28 14:22:33 -0400344 sh(label : 'pgrep_proc - check',
345 script : """
346pgrep --uid "$(uid -u)" --list-full --full "port-forward"
347""")
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400348 leave('port-forward check')
349 }
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400350
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400351 // setting ONOS log level
352 script {
353 enter('setOnosLogLevels')
354 setOnosLogLevels([
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400355 onosNamespace: infraNamespace,
356 apps: [
357 'org.opencord.dhcpl2relay',
358 'org.opencord.olt',
359 'org.opencord.aaa',
360 'org.opencord.maclearner',
361 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
362 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
363 ],
364 logLevel: logLevel
365 ])
Joey Armstrong6146f7e2023-08-28 09:05:38 -0400366 leave('setOnosLogLevels')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400367 } // script
368 } // if (teardown)
369 } // stage('Deploy Voltha')
370
Joey Armstrongf060aee2023-08-22 21:55:26 -0400371 // -----------------------------------------------------------------------
372 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400373 stage("Run test ${testTarget} on workflow ${workflow}")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400374 {
Joey Armstrongebc18022023-08-26 13:20:49 -0400375 sh(
376 label : 'Monitor using mem_consumption.py',
377 script : """
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400378 echo -e "\n** Monitor using mem_consumption.py ?"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400379
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400380 if [ ${withMonitoring} = true ] ; then
Joey Armstrongf060aee2023-08-22 21:55:26 -0400381 cat <<EOM
382
383** -----------------------------------------------------------------------
384** Monitoring memory usage with mem_consumption.py
385** -----------------------------------------------------------------------
386EOM
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400387 mkdir -p "$WORKSPACE/voltha-pods-mem-consumption-${workflow}"
388 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400389
390 echo '** Installing python virtualenv'
391 make venv-activate-patched
392
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400393 set +u && source .venv/bin/activate && set -u
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400394 # Collect initial memory consumption
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400395 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 -0400396 fi
Joey Armstrongf060aee2023-08-22 21:55:26 -0400397
398 echo -e '** Monitor memory consumption: LEAVE\n'
Joey Armstrongebc18022023-08-26 13:20:49 -0400399 """)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400400
401 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400402 echo -e "\n** make testTarget=[${testTarget}]"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400403 mkdir -p ${logsDir}
404 export ROBOT_MISC_ARGS="-d ${logsDir} ${params.extraRobotArgs} "
405 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}"
406 export KVSTOREPREFIX=voltha/voltha_voltha
407
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400408 make -C "$WORKSPACE/voltha-system-tests" ${testTarget}
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400409 """
410
411 getPodsInfo("${logsDir}")
412
Joey Armstrongebc18022023-08-26 13:20:49 -0400413 sh(
414 label : 'Gather robot Framework logs',
415 script : """
Joey Armstrong54dec092023-08-03 18:21:38 -0400416 echo -e '\n** Gather robot Framework logs: ENTER'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400417 # set +e
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400418 # collect logs collected in the Robot Framework StartLogging keyword
419 cd ${logsDir}
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400420 gzip *-combined.log
421 rm -f *-combined.log
Joey Armstrong54dec092023-08-03 18:21:38 -0400422
423 echo -e '** Gather robot Framework logs: LEAVE\n'
Joey Armstrongebc18022023-08-26 13:20:49 -0400424 """)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400425
Joey Armstrongf060aee2023-08-22 21:55:26 -0400426 // -----------------------------------------------------------------------
427 // -----------------------------------------------------------------------
Joey Armstrongebc18022023-08-26 13:20:49 -0400428 sh(
429 label : 'Monitor pod-mem-consumption',
430 script : """
Joey Armstrong54dec092023-08-03 18:21:38 -0400431 echo -e '** Monitor pod-mem-consumption: ENTER'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400432 if [ ${withMonitoring} = true ] ; then
Joey Armstrongf060aee2023-08-22 21:55:26 -0400433 cat <<EOM
434
435** -----------------------------------------------------------------------
436** Monitoring pod-memory-consumption using mem_consumption.py
437** -----------------------------------------------------------------------
438EOM
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400439 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400440
441 echo '** Installing python virtualenv'
442 make venv-activate-patched
Joey Armstrong38a87832023-08-23 17:02:50 -0400443
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400444 set +u && source .venv/bin/activate && set -u
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400445 # Collect memory consumption of voltha pods once all the tests are complete
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400446 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 -0400447 fi
Joey Armstrong54dec092023-08-03 18:21:38 -0400448 echo -e '** Monitor pod-mem-consumption: LEAVE\n'
Joey Armstrongebc18022023-08-26 13:20:49 -0400449 """)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400450 } // stage
Joey Armstrong54dec092023-08-03 18:21:38 -0400451
452 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400453} // execute_test()
454
455// -----------------------------------------------------------------------
456// -----------------------------------------------------------------------
Joey Armstrong54dec092023-08-03 18:21:38 -0400457def collectArtifacts(exitStatus) {
Joey Armstrong6115fd62023-08-24 08:19:28 -0400458 script {
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400459 String iam = getIam('collectArtifacts')
460 println("${iam}: ENTER (exitStatus=${exitStatus})")
Joey Armstrong6115fd62023-08-24 08:19:28 -0400461 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400462
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400463 echo '''
464
465** -----------------------------------------------------------------------
466** collectArtifacts
467** -----------------------------------------------------------------------
468'''
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400469
Joey Armstrong642540a2023-08-10 10:26:36 -0400470 getPodsInfo("$WORKSPACE/${exitStatus}")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400471
Joey Armstrong642540a2023-08-10 10:26:36 -0400472 sh """
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400473 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400474 """
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400475
Joey Armstrong642540a2023-08-10 10:26:36 -0400476 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 -0400477
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400478 script {
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400479 println("${iam}: ENTER")
Joey Armstrong664c55a2023-08-28 14:22:33 -0400480 /*
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400481 pgrep_proc('kail-startup')
482 pkill_proc('kail')
Joey Armstrong664c55a2023-08-28 14:22:33 -0400483 */
484 sh(label : 'pgrep_proc - kill-pre',
485 script : """
486pgrep --uid "$(uid -u)" --list-full --full "kail-startup',
487""")
488 sh(label : 'pkill_proc - kail',
489 script : """
490pkill --uid "$(uid -u)" --echo --full 'kail'
491""")
492
493 sh(label : 'pgrep_proc - kill-post',
494 script : """
495pgrep --uid "$(uid -u)" --list-full --full 'kail'
496""")
497
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400498 println("${iam}: LEAVE")
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400499 }
Joey Armstrongdd0cd6b2023-08-25 17:27:56 -0400500
Joey Armstrong642540a2023-08-10 10:26:36 -0400501 println("${iam}: ENTER RobotPublisher")
502 step([$class: 'RobotPublisher',
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400503 disableArchiveOutput: false,
504 logFileName: '**/*/log*.html',
505 otherFiles: '',
506 outputFileName: '**/*/output*.xml',
507 outputPath: '.',
508 passThreshold: 100,
509 reportFileName: '**/*/report*.html',
510 unstableThreshold: 0,
511 onlyCritical: true])
Joey Armstrong642540a2023-08-10 10:26:36 -0400512 println("${iam}: LEAVE RobotPublisher")
513
514 println("${iam}: LEAVE (exitStatus=${exitStatus})")
515 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400516}
517
Joey Armstrong54dec092023-08-03 18:21:38 -0400518// -----------------------------------------------------------------------
519// Intent: main
520// -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400521pipeline {
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400522 /* no label, executor is determined by JJB */
523 agent {
524 label "${params.buildNode}"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400525 }
526
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400527 options {
528 timeout(time: "${timeout}", unit: 'MINUTES')
529 }
530
531 environment {
532 KUBECONFIG = "$HOME/.kube/kind-${clusterName}"
533 VOLTCONFIG = "$HOME/.volt/config"
534 PATH = "$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
535 DIAGS_PROFILE = 'VOLTHA_PROFILE'
536 SSHPASS = 'karaf'
537 }
538
539 stages {
540 stage('Download Code') {
541 steps {
542 getVolthaCode([
543 branch: "${branch}",
544 gerritProject: "${gerritProject}",
545 gerritRefspec: "${gerritRefspec}",
546 volthaSystemTestsChange: "${volthaSystemTestsChange}",
547 volthaHelmChartsChange: "${volthaHelmChartsChange}",
548 ])
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400549 }
550 }
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400551
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400552 stage('Build patch v1.1') {
553 // build the patch only if gerritProject is specified
554 when {
555 expression { return !gerritProject.isEmpty() }
556 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400557
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400558 steps {
559 // NOTE that the correct patch has already been checked out
560 // during the getVolthaCode step
561 buildVolthaComponent("${gerritProject}")
562 }
563 }
564
565 // -----------------------------------------------------------------------
566 // -----------------------------------------------------------------------
567 stage('Install Kail')
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400568 {
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400569 steps
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400570 {
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400571 script
572 {
573 String cmd = [
574 'make',
575 '--no-print-directory',
576 '-C', "$WORKSPACE/voltha-system-tests",
577 "KAIL_PATH=\"$WORKSPACE/bin\"",
578 'kail',
579 ].join(' ')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400580
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400581 println(" ** Running: ${cmd}")
582 sh("${cmd}")
583 } // script
584 } // steps
585 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400586
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400587 // -----------------------------------------------------------------------
588 // -----------------------------------------------------------------------
589 stage('Install Tools') {
590 steps {
591 script {
592 String branchName = branchName()
593 String iam = getIam('Install Tools')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400594
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400595 println("${iam}: ENTER (branch=$branch)")
596 installKind(branch) // needed early by stage(Cleanup)
597 println("${iam}: LEAVE (branch=$branch)")
598 } // script
599 } // steps
600 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400601
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400602 // -----------------------------------------------------------------------
603 // -----------------------------------------------------------------------
604 stage('Create K8s Cluster') {
605 steps {
606 script {
607 def clusterExists = sh(
608 returnStdout: true,
609 script: """kind get clusters | grep "${clusterName}" | wc -l""")
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400610
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400611 if (clusterExists.trim() == '0') {
612 createKubernetesCluster([nodes: 3, name: clusterName])
613 }
614 } // script
615 } // steps
616 } // stage('Create K8s Cluster')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400617
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400618 // -----------------------------------------------------------------------
619 // -----------------------------------------------------------------------
620 stage('Replace voltctl') {
621 // if the project is voltctl, override the downloaded one with the built one
622 when {
623 expression { return gerritProject == 'voltctl' }
624 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400625
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400626 // Hmmmm(?) where did the voltctl download happen ?
627 // Likely Makefile but would be helpful to document here.
628 steps {
629 script {
630 String iam = getIam('Replace voltctl')
Joey Armstrong6115fd62023-08-24 08:19:28 -0400631
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400632 println("${iam} Running: installVoltctl($branch)")
633 println("${iam}: ENTER")
634 installVoltctl("$branch")
635 println("${iam}: LEAVE")
636 } // script
637 } // step
638 } // stage
Joey Armstrong268442d2023-08-22 17:16:10 -0400639
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400640 // -----------------------------------------------------------------------
641 // -----------------------------------------------------------------------
642 stage('Load image in kind nodes')
643 {
644 when {
645 expression { return !gerritProject.isEmpty() }
646 }
647 steps {
648 loadToKind()
649 } // steps
650 } // stage
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400651
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400652 // -----------------------------------------------------------------------
653 // [TODO] verify testing output
654 // -----------------------------------------------------------------------
655 stage('Parse and execute tests')
656 {
657 steps {
658 script {
659 // Announce ourselves for log usability
660 enter('Parse and execute tests')
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400661
Joey Armstrongebc18022023-08-26 13:20:49 -0400662 def tests = readYaml text: testTargets // typeof == Map (?)
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400663 println("** [DEBUG]: tests=$tests")
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400664
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400665 // Display expected tests for times when output goes dark
666 tests.eachWithIndex { test, idx ->
667 String target = test['target']
668 println("** test[${idx}]: ${target}\n")
669 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400670
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400671 println('''
Joey Armstrongb29d5612023-08-24 12:53:46 -0400672** -----------------------------------------------------------------------
673** NOTE: For odd/silent job failures verify a few details
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400674** - All tests mentioned in the tests-to-run index were logged.
Joey Armstrongb29d5612023-08-24 12:53:46 -0400675** - Test suites display ENTER/LEAVE mesasge pairs.
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400676** - Processing terminated prematurely when LEAVE strings are missing.
Joey Armstrongb29d5612023-08-24 12:53:46 -0400677** -----------------------------------------------------------------------
Joey Armstrongbe7c9242023-08-24 16:20:31 -0400678''')
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400679 tests.eachWithIndex { test, idx ->
680 println "** readYaml test suite[$idx]) test=[${test}]"
Joey Armstrongf46b3ae2023-08-25 11:07:20 -0400681
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400682 String target = test['target']
683 String workflow = test['workflow']
684 String flags = test['flags']
685 Boolean teardown = test['teardown'].toBoolean()
686 Boolean logging = test['logging'].toBoolean()
687 String testLogging = (logging) ? 'True' : 'False'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400688
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400689 print("""
Joey Armstrong268442d2023-08-22 17:16:10 -0400690** -----------------------------------------------------------------------
Joey Armstrong38a87832023-08-23 17:02:50 -0400691** Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}
Joey Armstrong268442d2023-08-22 17:16:10 -0400692** -----------------------------------------------------------------------
Joey Armstrong38a87832023-08-23 17:02:50 -0400693""")
Joey Armstrong664c55a2023-08-28 14:22:33 -0400694
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400695 try {
Joey Armstrong6146f7e2023-08-28 09:05:38 -0400696 enter("execute_test (target=$target)")
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400697 execute_test(target, workflow, testLogging, teardown, flags)
698 }
Joey Armstrong9341c9a2023-08-28 12:09:19 -0400699 // groovylint-disable-next-line CatchException
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400700 catch (Exception err) {
Joey Armstrong9341c9a2023-08-28 12:09:19 -0400701 String iamexc = getIam(name)
702 println("** ${iamexc}: EXCEPTION ${err}")
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400703 }
704 finally {
705 leave("execute_test (target=$target)")
706 }
707 } // for
708 // Premature exit if this message is not logged
709 leave('Parse and execute tests')
Joey Armstrong54dec092023-08-03 18:21:38 -0400710 } // script
711 } // steps
Joey Armstrong7229d9b2023-08-25 18:03:13 -0400712 } // stage
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400713 } // stages
714
715 post
716 {
717 aborted { collectArtifacts('aborted') }
718 failure { collectArtifacts('failed') }
719 always { collectArtifacts('always') }
720 }
721} // pipeline
722
Joey Armstrong664c55a2023-08-28 14:22:33 -0400723// [EOF]