blob: 5f573cf86af90a372451c02dc4fc39f87370d0df [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 Armstrong008cfaf2023-08-18 14:49:06 -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"
180 echo "** kail-startup ENTER: $(date)" > "$onos_log"
181
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 Armstrong54dec092023-08-03 18:21:38 -0400188 // if we're downloading a voltha-helm-charts patch, then install from a local copy of the charts
189 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 {
252 println('Try out pgrep/pkill commands')
Joey Armstrong642540a2023-08-10 10:26:36 -0400253 sh('''pgrep --list-full kail-startup || true''')
Joey Armstrong54dec092023-08-03 18:21:38 -0400254 }
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400255
256 // -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400257 // stop logging
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400258 // -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400259 sh """
260 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-startup" | grep -v grep | awk '{print \$1}')"
261 if [ -n "\$P_IDS" ]; then
262 echo \$P_IDS
263 for P_ID in \$P_IDS; do
264 kill -9 \$P_ID
265 done
266 fi
267 cd ${logsDir}
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400268 echo "** kail-startup LEAVE: $(date)" >> "${logsDir}/onos-voltha-startup-combined.log"
269
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400270 gzip -k onos-voltha-startup-combined.log
271 rm onos-voltha-startup-combined.log
272 """
273 }
274
275 sh """
276 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"&
277 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"&
278 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"&
279 bbsimDmiPortFwd=50075
280 for i in {0..${olts.toInteger() - 1}}; do
281 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"&
282 ((bbsimDmiPortFwd++))
283 done
284 if [ ${withMonitoring} = true ] ; then
285 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"&
286 fi
287 ps aux | grep port-forward
288 """
289
290 // setting ONOS log level
291 script
Joey Armstrong642540a2023-08-10 10:26:36 -0400292 {
Joey Armstrong54dec092023-08-03 18:21:38 -0400293 println('** setOnosLogLevels: ENTER')
294 setOnosLogLevels([
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400295 onosNamespace: infraNamespace,
296 apps: [
297 'org.opencord.dhcpl2relay',
298 'org.opencord.olt',
299 'org.opencord.aaa',
300 'org.opencord.maclearner',
301 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
302 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
303 ],
304 logLevel: logLevel
305 ])
Joey Armstrong54dec092023-08-03 18:21:38 -0400306 println('** setOnosLogLevels: LEAVE')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400307 } // script
308 } // if (teardown)
309 } // stage('Deploy Voltha')
310
Joey Armstrong642540a2023-08-10 10:26:36 -0400311 stage("Run test ${testTarget} on workflow ${workflow}")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400312 {
313 sh """
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400314 echo -e "\n** Monitor using mem_consumption.py ?"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400315 if [ ${withMonitoring} = true ] ; then
316 mkdir -p "$WORKSPACE/voltha-pods-mem-consumption-${workflow}"
317 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400318 make venv-activate-script
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400319 set +u && source .venv/bin/activate && set -u
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400320 # Collect initial memory consumption
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400321 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 -0400322 fi
323 """
324
325 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400326 echo -e "\n** make testTarget=[${testTarget}]"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400327 mkdir -p ${logsDir}
328 export ROBOT_MISC_ARGS="-d ${logsDir} ${params.extraRobotArgs} "
329 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}"
330 export KVSTOREPREFIX=voltha/voltha_voltha
331
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400332 make -C "$WORKSPACE/voltha-system-tests" ${testTarget}
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400333 """
334
335 getPodsInfo("${logsDir}")
336
337 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400338 echo -e '\n** Gather robot Framework logs: ENTER'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400339 # set +e
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400340 # collect logs collected in the Robot Framework StartLogging keyword
341 cd ${logsDir}
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400342 gzip *-combined.log
343 rm -f *-combined.log
Joey Armstrong54dec092023-08-03 18:21:38 -0400344
345 echo -e '** Gather robot Framework logs: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400346 """
347
348 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400349 echo -e '** Monitor pod-mem-consumption: ENTER'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400350 if [ ${withMonitoring} = true ] ; then
351 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400352 make venv-activate-script
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400353 set +u && source .venv/bin/activate && set -u
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400354 # Collect memory consumption of voltha pods once all the tests are complete
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400355 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 -0400356 fi
Joey Armstrong54dec092023-08-03 18:21:38 -0400357 echo -e '** Monitor pod-mem-consumption: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400358 """
359 } // stage
Joey Armstrong54dec092023-08-03 18:21:38 -0400360
361 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400362} // execute_test()
363
364// -----------------------------------------------------------------------
365// -----------------------------------------------------------------------
Joey Armstrong54dec092023-08-03 18:21:38 -0400366def collectArtifacts(exitStatus) {
Joey Armstrong642540a2023-08-10 10:26:36 -0400367 String iam = getIam('execute_test')
368
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400369 echo '''
370
371** -----------------------------------------------------------------------
372** collectArtifacts
373** -----------------------------------------------------------------------
374'''
Joey Armstrong642540a2023-08-10 10:26:36 -0400375 println("${iam}: ENTER (exitStatus=${exitStatus})")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400376
Joey Armstrong642540a2023-08-10 10:26:36 -0400377 getPodsInfo("$WORKSPACE/${exitStatus}")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400378
Joey Armstrong642540a2023-08-10 10:26:36 -0400379 sh """
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400380 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400381 """
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400382
Joey Armstrong642540a2023-08-10 10:26:36 -0400383 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 -0400384
Joey Armstrong642540a2023-08-10 10:26:36 -0400385 sh(returnStdout:true, script: '''
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400386 sync
Joey Armstrong642540a2023-08-10 10:26:36 -0400387 echo '** Running: pgrep --list-full kail-startup (ENTER)'
388 pgrep --list-full 'kail-startup' || true
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400389 [[ $(pgrep --count kail) -gt 0 ]] && pkill --echo kail
Joey Armstrong642540a2023-08-10 10:26:36 -0400390 echo '** Running: pgrep --list-full kail-startup (LEAVE)'
391 ''')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400392
Joey Armstrong642540a2023-08-10 10:26:36 -0400393 println("${iam}: ENTER RobotPublisher")
394 step([$class: 'RobotPublisher',
395 disableArchiveOutput: false,
396 logFileName: '**/*/log*.html',
397 otherFiles: '',
398 outputFileName: '**/*/output*.xml',
399 outputPath: '.',
400 passThreshold: 100,
401 reportFileName: '**/*/report*.html',
402 unstableThreshold: 0,
403 onlyCritical: true]);
404 println("${iam}: LEAVE RobotPublisher")
405
406 println("${iam}: LEAVE (exitStatus=${exitStatus})")
407 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400408}
409
Joey Armstrong54dec092023-08-03 18:21:38 -0400410// -----------------------------------------------------------------------
411// Intent: main
412// -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400413pipeline {
414
415 /* no label, executor is determined by JJB */
416 agent {
417 label "${params.buildNode}"
418 }
419 options {
420 timeout(time: "${timeout}", unit: 'MINUTES')
421 }
422 environment {
Joey Armstrong642540a2023-08-10 10:26:36 -0400423 KUBECONFIG = "$HOME/.kube/kind-${clusterName}"
424 VOLTCONFIG = "$HOME/.volt/config"
425 PATH = "$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
426 DIAGS_PROFILE = 'VOLTHA_PROFILE'
427 SSHPASS = 'karaf'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400428 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400429
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400430 stages {
431 stage('Download Code') {
432 steps {
433 getVolthaCode([
434 branch: "${branch}",
435 gerritProject: "${gerritProject}",
436 gerritRefspec: "${gerritRefspec}",
437 volthaSystemTestsChange: "${volthaSystemTestsChange}",
438 volthaHelmChartsChange: "${volthaHelmChartsChange}",
439 ])
440 }
441 }
442
443 stage('Build patch v1.1')
444 {
445 // build the patch only if gerritProject is specified
446 when
447 {
448 expression
449 {
450 return !gerritProject.isEmpty()
451 }
452 }
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400453
454 steps
455 {
456 // NOTE that the correct patch has already been checked out
457 // during the getVolthaCode step
458 buildVolthaComponent("${gerritProject}")
459 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400460 }
461
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400462 // -----------------------------------------------------------------------
463 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400464 stage('Install Kail')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400465 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400466 steps
467 {
468 script
469 {
470 String cmd = [
471 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400472 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400473 '-C', "$WORKSPACE/voltha-system-tests",
474 "KAIL_PATH=\"$WORKSPACE/bin\"",
475 'kail',
476 ].join(' ')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400477
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400478 println(" ** Running: ${cmd}:\n")
479 sh("${cmd}")
480 } // script
481 } // steps
482 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400483
484 // -----------------------------------------------------------------------
485 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400486 stage('Install Kind')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400487 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400488 steps
489 {
490 script
491 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400492
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400493 String cmd = [
494 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400495 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400496 '-C', "$WORKSPACE/voltha-system-tests",
497 "KIND_PATH=\"$WORKSPACE/bin\"",
498 'install-command-kind',
499 ].join(' ')
Joey Armstrong642540a2023-08-10 10:26:36 -0400500
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400501 println(" ** Running: ${cmd}:\n")
502 sh("${cmd}")
503 } // script
504 } // steps
505 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400506
507 // -----------------------------------------------------------------------
508 // -----------------------------------------------------------------------
509 stage('Create K8s Cluster')
510 {
511 steps
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400512 {
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400513 script
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400514 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400515 def clusterExists = sh(
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400516 returnStdout: true,
517 script: """kind get clusters | grep "${clusterName}" | wc -l"""
518 )
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400519
Joey Armstrong54dec092023-08-03 18:21:38 -0400520 if (clusterExists.trim() == '0')
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400521 {
522 createKubernetesCluster([nodes: 3, name: clusterName])
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400523 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400524 } // script
525 } // steps
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400526 } // stage('Create K8s Cluster')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400527
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400528 // -----------------------------------------------------------------------
529 // -----------------------------------------------------------------------
530 stage('Replace voltctl')
531 {
532 // if the project is voltctl, override the downloaded one with the built one
533 when {
534 expression { return gerritProject == 'voltctl' }
535 }
536
537 // Hmmmm(?) where did the voltctl download happen ?
538 // Likely Makefile but would be helpful to document here.
539 steps
540 {
541 println("${iam} Running: installVoltctl($branch)")
542 installVoltctl("$branch")
543 } // steps
544 } // stage
545
546 // -----------------------------------------------------------------------
547 // -----------------------------------------------------------------------
548 stage('Load image in kind nodes')
549 {
550 when {
551 expression { return !gerritProject.isEmpty() }
552 }
553 steps {
554 loadToKind()
555 } // steps
556 } // stage
557
558 // -----------------------------------------------------------------------
559 // -----------------------------------------------------------------------
560 stage('Parse and execute tests')
561 {
562 steps {
563 script {
564 // Announce ourselves for log usability
565 String iam = getIam('execute_test')
566 println("${iam}: ENTER")
567
568 def tests = readYaml text: testTargets
569
570 println("** $iam: Testing index: tests-to-run")
571 tests.eachWithIndex { test, idx ->
572 String target = test['target']
573 println("** $idx: $target")
Joey Armstrong642540a2023-08-10 10:26:36 -0400574 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400575 println("** NOTE: For odd failures compare tests-to-run with teste output")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400576
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400577 tests.eachWithIndex { test, idx ->
578 println "** readYaml test suite[$idx]) test=[${test}]"
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400579
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400580 String target = test['target']
581 String workflow = test['workflow']
582 String flags = test['flags']
583 Boolean teardown = test['teardown'].toBoolean()
584 Boolean logging = test['logging'].toBoolean()
585 String testLogging = (logging) ? 'True' : 'False'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400586
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400587 println([
588 "Executing test ${target}",
589 "on workflow ${workflow}",
590 "with logging ${testLogging}",
591 "and extra flags ${flags}",
592 ].join(' ')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400593
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400594 try {
595 println "Executing test ${target}: ENTER"
596 execute_test(target, workflow, testLogging, teardown, flags)
597 }
598 catch (Exception err) {
599 println("** ${iam}: EXCEPTION ${err}")
600 }
601 finally {
602 println "Executing test ${target}: LEAVE"
603 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400604
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400605 } // for
Joey Armstrong642540a2023-08-10 10:26:36 -0400606
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400607 // Premature exit if this message is not logged
608 println("${iam}: LEAVE (testing ran to completion)")
Joey Armstrong54dec092023-08-03 18:21:38 -0400609 } // script
610 } // steps
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400611 } // stage
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400612 } // stages
613
614 post
615 {
616 aborted { collectArtifacts('aborted') }
617 failure { collectArtifacts('failed') }
618 always { collectArtifacts('always') }
619 }
620} // pipeline
621
622// EOF