blob: a8663afd439bf785f16dc9ecb5c1d61e44e36b93 [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// -----------------------------------------------------------------------
64Boolean isReleaseBranch(String name)
65{
66 // List modifiers = ['-dev', '-pre', 'voltha-x.y.z-pre']
Joey Armstrong54dec092023-08-03 18:21:38 -040067 // if branchName in modifiers
68 return(name != 'master') // OR branchName.contains('-')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040069}
70
71// -----------------------------------------------------------------------
72// Intent:
73// -----------------------------------------------------------------------
Joey Armstrong54dec092023-08-03 18:21:38 -040074void execute_test(testTarget, workflow, testLogging, teardown, testSpecificHelmFlags='')
Joey Armstrong7bcb5782023-06-07 12:25:57 -040075{
Joey Armstrong54dec092023-08-03 18:21:38 -040076 String infraNamespace = 'default'
77 String volthaNamespace = 'voltha'
78 String logsDir = "$WORKSPACE/${testTarget}"
Joey Armstrong7bcb5782023-06-07 12:25:57 -040079
80 stage('IAM')
81 {
82 script
83 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040084 // Announce ourselves for log usability
Joey Armstrong642540a2023-08-10 10:26:36 -040085 String iam = getIam('execute_test')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040086 println("${iam}: ENTER")
87 println("${iam}: LEAVE")
Joey Armstrong7bcb5782023-06-07 12:25:57 -040088 }
89 }
Joey Armstrong54dec092023-08-03 18:21:38 -040090
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040091 // -----------------------------------------------------------------------
Joey Armstrong008cfaf2023-08-18 14:49:06 -040092 // Intent: Cleanup stale port-forwarding
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040093 // -----------------------------------------------------------------------
94 stage('Cleanup')
95 {
Joey Armstrong7bcb5782023-06-07 12:25:57 -040096 if (teardown) {
97 timeout(15) {
98 script {
Joey Armstrong54dec092023-08-03 18:21:38 -040099 helmTeardown(['default', infraNamespace, volthaNamespace])
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400100 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400101
102 // Comment timeout() if we hang (fix it VS mask problem)
103 // timeout(1) {
104sh(returnStdout:true, script: '''
105 sync
106 cat <<EOM
107
108** -----------------------------------------------------------------------
109** remove orphaned port-forward from different namespacse
110** -----------------------------------------------------------------------
111EOM
112 [[ $(pgrep --count port-forward) -gt 0 ]] && pkill --echo 'port-forward'
113 pgrep --list-full port-forward || true
114 ''')
115 } // timeout(15)
116 } // teardown()
117 // timeout(1)
118 } // stage(cleanup)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400119
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400120 // -----------------------------------------------------------------------
121 // -----------------------------------------------------------------------
122 stage('Deploy common infrastructure')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400123 {
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400124 script
125 {
126 local dashargs = [
127 'kpi_exporter.enabled=false',
128 'dashboards.xos=false',
129 'dashboards.onos=false',
130 'dashboards.aaa=false',
131 'dashboards.voltha=false',
132 ].join(',')
133
134 local promargs = [
135 'prometheus.alertmanager.enabled=false',
136 'prometheus.pushgateway.enabled=false',
137 ].join(',')
138
139 sh('''
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400140 helm repo add onf https://charts.opencord.org
141 helm repo update
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400142
143 echo -e "\nwithMonitoring=[$withMonitoring]"
144 if [ ${withMonitoring} = true ] ; then
145 helm install nem-monitoring onf/nem-monitoring \
146 --set $promargs \
147 --set $dashargs
148 fi
149 ''')
150
151 /*
152 sh '''
153 helm repo add onf https://charts.opencord.org
154 helm repo update
155
156 echo -e "\nwithMonitoring=[$withMonitoring]"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400157 if [ ${withMonitoring} = true ] ; then
158 helm install nem-monitoring onf/nem-monitoring \
159 --set prometheus.alertmanager.enabled=false,prometheus.pushgateway.enabled=false \
160 --set kpi_exporter.enabled=false,dashboards.xos=false,dashboards.onos=false,dashboards.aaa=false,dashboards.voltha=false
161 fi
162 '''
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400163 */
164 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400165 }
166
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400167 // -----------------------------------------------------------------------
168 // -----------------------------------------------------------------------
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400169 stage('Deploy Voltha')
170 {
171 if (teardown)
172 {
173 timeout(10)
174 {
175 script
176 {
Joey Armstrongdddbbf92023-08-22 16:00:41 -0400177 sh("""
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400178 mkdir -p ${logsDir}
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400179 onos_log="${logsDir}/onos-voltha-startup-combined.log"
Joey Armstrongdddbbf92023-08-22 16:00:41 -0400180 echo "** kail-startup ENTER: \$(date)" > "$onos_log"
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400181
182 # Intermixed output (tee -a &) may get conflusing but let(s) see
183 # what messages are logged during startup.
184 # _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} >> "$onos_log" &
185 _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} | tee -a "$onos_log" &
186 """)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400187
Joey Armstrongdddbbf92023-08-22 16:00:41 -0400188 // if we're downloading a voltha-helm-charts patch, then install from a local copy of the charts
Joey Armstrong54dec092023-08-03 18:21:38 -0400189 Boolean localCharts = false
Joey Armstrong642540a2023-08-10 10:26:36 -0400190
Joey Armstrong54dec092023-08-03 18:21:38 -0400191 if (volthaHelmChartsChange != ''
192 || gerritProject == 'voltha-helm-charts'
193 || isReleaseBranch(branch) // branch != 'master'
194 ) {
195 localCharts = true
196 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400197
Joey Armstrong54dec092023-08-03 18:21:38 -0400198 String branchName = branchName()
199 Boolean is_release = isReleaseBranch(branch)
200 println([
201 " ** localCharts=${localCharts}",
202 "branchName=${branchName}",
203 "branch=${branch}",
204 "branch=isReleaseBranch=${is_release}",
205 ].join(', '))
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400206
Joey Armstrong54dec092023-08-03 18:21:38 -0400207 // -----------------------------------------------------------------------
208 // Rewrite localHelmFlags using array join, moving code around and
Joey Armstrong642540a2023-08-10 10:26:36 -0400209 // refactoring into standalone functions
Joey Armstrong54dec092023-08-03 18:21:38 -0400210 // -----------------------------------------------------------------------
211 // hudson.remoting.ProxyException: groovy.lang.MissingMethodException:
212 // No signature of method: java.lang.String.positive() is applicable for argument types: () values: []
213 // -----------------------------------------------------------------------
214 // NOTE temporary workaround expose ONOS node ports
215 // -----------------------------------------------------------------------
216 String localHelmFlags = [
217 extraHelmFlags.trim(),
218 "--set global.log_level=${logLevel.toUpperCase()}",
219 '--set onos-classic.onosSshPort=30115',
220 '--set onos-classic.onosApiPort=30120',
221 '--set onos-classic.onosOfPort=31653',
222 '--set onos-classic.individualOpenFlowNodePorts=true',
223 testSpecificHelmFlags
224 ].join(' ')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400225
Joey Armstrong54dec092023-08-03 18:21:38 -0400226 println("** localHelmFlags = ${localHelmFlags}")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400227
Joey Armstrong54dec092023-08-03 18:21:38 -0400228 if (gerritProject != '') {
229 localHelmFlags = "${localHelmFlags} " + getVolthaImageFlags("${gerritProject}")
230 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400231
Joey Armstrong54dec092023-08-03 18:21:38 -0400232 println('volthaDeploy: ENTER')
233 volthaDeploy([
234 infraNamespace: infraNamespace,
235 volthaNamespace: volthaNamespace,
236 workflow: workflow.toLowerCase(),
237 withMacLearning: enableMacLearning.toBoolean(),
238 extraHelmFlags: localHelmFlags,
239 localCharts: localCharts,
240 bbsimReplica: olts.toInteger(),
241 dockerRegistry: registry,
242 ])
243 println('volthaDeploy: LEAVE')
244 } // script
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400245
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400246 // -----------------------------------------------------------------------
247 // Intent: Replacing P_IDS with pgrep/pkill is a step forward.
248 // Why not simply use a pid file, capture _TAG=kail-startup above
249 // Grep runs the risk of terminating stray commands (??-good <=> bad-??)
Joey Armstrong54dec092023-08-03 18:21:38 -0400250 // -----------------------------------------------------------------------
251 script {
Joey Armstrongdddbbf92023-08-22 16:00:41 -0400252 println('''
253
254** -----------------------------------------------------------------------
255** pgrep process list for kail-startup (WIP)
256** -----------------------------------------------------------------------
257''')
Joey Armstrong642540a2023-08-10 10:26:36 -0400258 sh('''pgrep --list-full kail-startup || true''')
Joey Armstrongdddbbf92023-08-22 16:00:41 -0400259
260 println('''
261
262** -----------------------------------------------------------------------
263** Raw ps process list for kail-startup (WIP)
264** -----------------------------------------------------------------------
265''')
266 sh('''ps e -ww -A | grep "_TAG=kail-startup"''')
Joey Armstrong54dec092023-08-03 18:21:38 -0400267 }
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400268
Joey Armstrongdddbbf92023-08-22 16:00:41 -0400269 / -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400270 // stop logging
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400271 // -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400272 sh """
273 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-startup" | grep -v grep | awk '{print \$1}')"
274 if [ -n "\$P_IDS" ]; then
275 echo \$P_IDS
276 for P_ID in \$P_IDS; do
277 kill -9 \$P_ID
278 done
279 fi
280 cd ${logsDir}
Joey Armstrongdddbbf92023-08-22 16:00:41 -0400281 echo "** kail-startup LEAVE: \$(date)" >> "${logsDir}/onos-voltha-startup-combined.log"
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400282
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400283 gzip -k onos-voltha-startup-combined.log
284 rm onos-voltha-startup-combined.log
285 """
286 }
287
288 sh """
289 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"&
290 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"&
291 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"&
292 bbsimDmiPortFwd=50075
293 for i in {0..${olts.toInteger() - 1}}; do
294 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"&
295 ((bbsimDmiPortFwd++))
296 done
297 if [ ${withMonitoring} = true ] ; then
298 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"&
299 fi
300 ps aux | grep port-forward
301 """
302
303 // setting ONOS log level
304 script
Joey Armstrong642540a2023-08-10 10:26:36 -0400305 {
Joey Armstrong54dec092023-08-03 18:21:38 -0400306 println('** setOnosLogLevels: ENTER')
307 setOnosLogLevels([
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400308 onosNamespace: infraNamespace,
309 apps: [
310 'org.opencord.dhcpl2relay',
311 'org.opencord.olt',
312 'org.opencord.aaa',
313 'org.opencord.maclearner',
314 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
315 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
316 ],
317 logLevel: logLevel
318 ])
Joey Armstrong54dec092023-08-03 18:21:38 -0400319 println('** setOnosLogLevels: LEAVE')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400320 } // script
321 } // if (teardown)
322 } // stage('Deploy Voltha')
323
Joey Armstrong642540a2023-08-10 10:26:36 -0400324 stage("Run test ${testTarget} on workflow ${workflow}")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400325 {
326 sh """
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400327 echo -e "\n** Monitor using mem_consumption.py ?"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400328 if [ ${withMonitoring} = true ] ; then
329 mkdir -p "$WORKSPACE/voltha-pods-mem-consumption-${workflow}"
330 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400331 make venv-activate-script
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400332 set +u && source .venv/bin/activate && set -u
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400333 # Collect initial memory consumption
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400334 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 -0400335 fi
336 """
337
338 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400339 echo -e "\n** make testTarget=[${testTarget}]"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400340 mkdir -p ${logsDir}
341 export ROBOT_MISC_ARGS="-d ${logsDir} ${params.extraRobotArgs} "
342 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}"
343 export KVSTOREPREFIX=voltha/voltha_voltha
344
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400345 make -C "$WORKSPACE/voltha-system-tests" ${testTarget}
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400346 """
347
348 getPodsInfo("${logsDir}")
349
350 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400351 echo -e '\n** Gather robot Framework logs: ENTER'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400352 # set +e
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400353 # collect logs collected in the Robot Framework StartLogging keyword
354 cd ${logsDir}
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400355 gzip *-combined.log
356 rm -f *-combined.log
Joey Armstrong54dec092023-08-03 18:21:38 -0400357
358 echo -e '** Gather robot Framework logs: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400359 """
360
361 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400362 echo -e '** Monitor pod-mem-consumption: ENTER'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400363 if [ ${withMonitoring} = true ] ; then
364 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400365 make venv-activate-script
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400366 set +u && source .venv/bin/activate && set -u
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400367 # Collect memory consumption of voltha pods once all the tests are complete
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400368 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 -0400369 fi
Joey Armstrong54dec092023-08-03 18:21:38 -0400370 echo -e '** Monitor pod-mem-consumption: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400371 """
372 } // stage
Joey Armstrong54dec092023-08-03 18:21:38 -0400373
374 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400375} // execute_test()
376
377// -----------------------------------------------------------------------
378// -----------------------------------------------------------------------
Joey Armstrong54dec092023-08-03 18:21:38 -0400379def collectArtifacts(exitStatus) {
Joey Armstrong642540a2023-08-10 10:26:36 -0400380 String iam = getIam('execute_test')
381
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400382 echo '''
383
384** -----------------------------------------------------------------------
385** collectArtifacts
386** -----------------------------------------------------------------------
387'''
Joey Armstrong642540a2023-08-10 10:26:36 -0400388 println("${iam}: ENTER (exitStatus=${exitStatus})")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400389
Joey Armstrong642540a2023-08-10 10:26:36 -0400390 getPodsInfo("$WORKSPACE/${exitStatus}")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400391
Joey Armstrong642540a2023-08-10 10:26:36 -0400392 sh """
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400393 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400394 """
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400395
Joey Armstrong642540a2023-08-10 10:26:36 -0400396 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 -0400397
Joey Armstrong642540a2023-08-10 10:26:36 -0400398 sh(returnStdout:true, script: '''
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400399 sync
Joey Armstrong642540a2023-08-10 10:26:36 -0400400 echo '** Running: pgrep --list-full kail-startup (ENTER)'
401 pgrep --list-full 'kail-startup' || true
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400402 [[ $(pgrep --count kail) -gt 0 ]] && pkill --echo kail
Joey Armstrong642540a2023-08-10 10:26:36 -0400403 echo '** Running: pgrep --list-full kail-startup (LEAVE)'
404 ''')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400405
Joey Armstrong642540a2023-08-10 10:26:36 -0400406 println("${iam}: ENTER RobotPublisher")
407 step([$class: 'RobotPublisher',
408 disableArchiveOutput: false,
409 logFileName: '**/*/log*.html',
410 otherFiles: '',
411 outputFileName: '**/*/output*.xml',
412 outputPath: '.',
413 passThreshold: 100,
414 reportFileName: '**/*/report*.html',
415 unstableThreshold: 0,
416 onlyCritical: true]);
417 println("${iam}: LEAVE RobotPublisher")
418
419 println("${iam}: LEAVE (exitStatus=${exitStatus})")
420 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400421}
422
Joey Armstrong54dec092023-08-03 18:21:38 -0400423// -----------------------------------------------------------------------
424// Intent: main
425// -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400426pipeline {
427
428 /* no label, executor is determined by JJB */
429 agent {
430 label "${params.buildNode}"
431 }
432 options {
433 timeout(time: "${timeout}", unit: 'MINUTES')
434 }
435 environment {
Joey Armstrong642540a2023-08-10 10:26:36 -0400436 KUBECONFIG = "$HOME/.kube/kind-${clusterName}"
437 VOLTCONFIG = "$HOME/.volt/config"
438 PATH = "$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
439 DIAGS_PROFILE = 'VOLTHA_PROFILE'
440 SSHPASS = 'karaf'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400441 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400442
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400443 stages {
444 stage('Download Code') {
445 steps {
446 getVolthaCode([
447 branch: "${branch}",
448 gerritProject: "${gerritProject}",
449 gerritRefspec: "${gerritRefspec}",
450 volthaSystemTestsChange: "${volthaSystemTestsChange}",
451 volthaHelmChartsChange: "${volthaHelmChartsChange}",
452 ])
453 }
454 }
455
456 stage('Build patch v1.1')
457 {
458 // build the patch only if gerritProject is specified
459 when
460 {
461 expression
462 {
463 return !gerritProject.isEmpty()
464 }
465 }
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400466
467 steps
468 {
469 // NOTE that the correct patch has already been checked out
470 // during the getVolthaCode step
471 buildVolthaComponent("${gerritProject}")
472 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400473 }
474
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400475 // -----------------------------------------------------------------------
476 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400477 stage('Install Kail')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400478 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400479 steps
480 {
481 script
482 {
483 String cmd = [
484 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400485 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400486 '-C', "$WORKSPACE/voltha-system-tests",
487 "KAIL_PATH=\"$WORKSPACE/bin\"",
488 'kail',
489 ].join(' ')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400490
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400491 println(" ** Running: ${cmd}:\n")
492 sh("${cmd}")
493 } // script
494 } // steps
495 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400496
497 // -----------------------------------------------------------------------
498 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400499 stage('Install Kind')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400500 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400501 steps
502 {
503 script
504 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400505
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400506 String cmd = [
507 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400508 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400509 '-C', "$WORKSPACE/voltha-system-tests",
510 "KIND_PATH=\"$WORKSPACE/bin\"",
511 'install-command-kind',
512 ].join(' ')
Joey Armstrong642540a2023-08-10 10:26:36 -0400513
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400514 println(" ** Running: ${cmd}:\n")
515 sh("${cmd}")
516 } // script
517 } // steps
518 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400519
520 // -----------------------------------------------------------------------
521 // -----------------------------------------------------------------------
522 stage('Create K8s Cluster')
523 {
524 steps
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400525 {
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400526 script
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400527 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400528 def clusterExists = sh(
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400529 returnStdout: true,
530 script: """kind get clusters | grep "${clusterName}" | wc -l"""
531 )
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400532
Joey Armstrong54dec092023-08-03 18:21:38 -0400533 if (clusterExists.trim() == '0')
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400534 {
535 createKubernetesCluster([nodes: 3, name: clusterName])
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400536 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400537 } // script
538 } // steps
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400539 } // stage('Create K8s Cluster')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400540
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400541 // -----------------------------------------------------------------------
542 // -----------------------------------------------------------------------
543 stage('Replace voltctl')
544 {
545 // if the project is voltctl, override the downloaded one with the built one
546 when {
547 expression { return gerritProject == 'voltctl' }
548 }
549
550 // Hmmmm(?) where did the voltctl download happen ?
551 // Likely Makefile but would be helpful to document here.
552 steps
553 {
554 println("${iam} Running: installVoltctl($branch)")
555 installVoltctl("$branch")
556 } // steps
557 } // stage
558
559 // -----------------------------------------------------------------------
560 // -----------------------------------------------------------------------
561 stage('Load image in kind nodes')
562 {
563 when {
564 expression { return !gerritProject.isEmpty() }
565 }
566 steps {
567 loadToKind()
568 } // steps
569 } // stage
570
571 // -----------------------------------------------------------------------
572 // -----------------------------------------------------------------------
573 stage('Parse and execute tests')
574 {
575 steps {
576 script {
577 // Announce ourselves for log usability
578 String iam = getIam('execute_test')
579 println("${iam}: ENTER")
580
581 def tests = readYaml text: testTargets
582
583 println("** $iam: Testing index: tests-to-run")
584 tests.eachWithIndex { test, idx ->
585 String target = test['target']
586 println("** $idx: $target")
Joey Armstrong642540a2023-08-10 10:26:36 -0400587 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400588 println("** NOTE: For odd failures compare tests-to-run with teste output")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400589
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400590 tests.eachWithIndex { test, idx ->
591 println "** readYaml test suite[$idx]) test=[${test}]"
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400592
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400593 String target = test['target']
594 String workflow = test['workflow']
595 String flags = test['flags']
596 Boolean teardown = test['teardown'].toBoolean()
597 Boolean logging = test['logging'].toBoolean()
598 String testLogging = (logging) ? 'True' : 'False'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400599
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400600 println([
601 "Executing test ${target}",
602 "on workflow ${workflow}",
603 "with logging ${testLogging}",
604 "and extra flags ${flags}",
605 ].join(' ')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400606
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400607 try {
608 println "Executing test ${target}: ENTER"
609 execute_test(target, workflow, testLogging, teardown, flags)
610 }
611 catch (Exception err) {
612 println("** ${iam}: EXCEPTION ${err}")
613 }
614 finally {
615 println "Executing test ${target}: LEAVE"
616 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400617
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400618 } // for
Joey Armstrong642540a2023-08-10 10:26:36 -0400619
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400620 // Premature exit if this message is not logged
621 println("${iam}: LEAVE (testing ran to completion)")
Joey Armstrong54dec092023-08-03 18:21:38 -0400622 } // script
623 } // steps
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400624 } // stage
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400625 } // stages
626
627 post
628 {
629 aborted { collectArtifacts('aborted') }
630 failure { collectArtifacts('failed') }
631 always { collectArtifacts('always') }
632 }
633} // pipeline
634
635// EOF