blob: 45349d96a4350a0a0a0128e0252dd126e97b5175 [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
Joey Armstrong268442d2023-08-22 17:16:10 -0400102 // -----------------------------------------------------------------------
103 // Verify pgrep/pkill behavior before replacing ps | kill -9
104 // -----------------------------------------------------------------------
105 script {
106 println('''
107
108** -----------------------------------------------------------------------
109** pgrep process list for port-forward (pre-pkill)
110** -----------------------------------------------------------------------
111''')
112 sh('''pgrep --list-full port-forward || true''')
113 }
114
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400115 // Comment timeout() if we hang (fix it VS mask problem)
116 // timeout(1) {
Joey Armstrong268442d2023-08-22 17:16:10 -0400117 // -----------------------------------------------------------------------
118 // -----------------------------------------------------------------------
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400119sh(returnStdout:true, script: '''
120 sync
121 cat <<EOM
122
123** -----------------------------------------------------------------------
124** remove orphaned port-forward from different namespacse
125** -----------------------------------------------------------------------
126EOM
127 [[ $(pgrep --count port-forward) -gt 0 ]] && pkill --echo 'port-forward'
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400128 ''')
Joey Armstrong268442d2023-08-22 17:16:10 -0400129
130 // -----------------------------------------------------------------------
131 // -----------------------------------------------------------------------
132 script {
133 println('''
134
135** -----------------------------------------------------------------------
136** pgrep process list for port-forward (post-pkill)
137** -----------------------------------------------------------------------
138''')
139 sh('''pgrep --list-full port-forward || true''')
140 }
141
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400142 } // timeout(15)
143 } // teardown()
144 // timeout(1)
145 } // stage(cleanup)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400146
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400147 // -----------------------------------------------------------------------
148 // -----------------------------------------------------------------------
149 stage('Deploy common infrastructure')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400150 {
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400151 script
152 {
153 local dashargs = [
154 'kpi_exporter.enabled=false',
155 'dashboards.xos=false',
156 'dashboards.onos=false',
157 'dashboards.aaa=false',
158 'dashboards.voltha=false',
159 ].join(',')
160
161 local promargs = [
162 'prometheus.alertmanager.enabled=false',
163 'prometheus.pushgateway.enabled=false',
164 ].join(',')
165
166 sh('''
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400167 helm repo add onf https://charts.opencord.org
168 helm repo update
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400169
170 echo -e "\nwithMonitoring=[$withMonitoring]"
171 if [ ${withMonitoring} = true ] ; then
172 helm install nem-monitoring onf/nem-monitoring \
173 --set $promargs \
174 --set $dashargs
175 fi
176 ''')
177
178 /*
179 sh '''
180 helm repo add onf https://charts.opencord.org
181 helm repo update
182
183 echo -e "\nwithMonitoring=[$withMonitoring]"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400184 if [ ${withMonitoring} = true ] ; then
185 helm install nem-monitoring onf/nem-monitoring \
186 --set prometheus.alertmanager.enabled=false,prometheus.pushgateway.enabled=false \
187 --set kpi_exporter.enabled=false,dashboards.xos=false,dashboards.onos=false,dashboards.aaa=false,dashboards.voltha=false
188 fi
189 '''
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400190 */
191 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400192 }
193
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400194 // -----------------------------------------------------------------------
195 // -----------------------------------------------------------------------
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400196 stage('Deploy Voltha')
197 {
198 if (teardown)
199 {
200 timeout(10)
201 {
202 script
203 {
Joey Armstrongdddbbf92023-08-22 16:00:41 -0400204 sh("""
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400205 mkdir -p ${logsDir}
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400206 onos_log="${logsDir}/onos-voltha-startup-combined.log"
Joey Armstrongdddbbf92023-08-22 16:00:41 -0400207 echo "** kail-startup ENTER: \$(date)" > "$onos_log"
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400208
209 # Intermixed output (tee -a &) may get conflusing but let(s) see
210 # what messages are logged during startup.
211 # _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} >> "$onos_log" &
212 _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} | tee -a "$onos_log" &
213 """)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400214
Joey Armstrongdddbbf92023-08-22 16:00:41 -0400215 // 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 -0400216 Boolean localCharts = false
Joey Armstrong642540a2023-08-10 10:26:36 -0400217
Joey Armstrong54dec092023-08-03 18:21:38 -0400218 if (volthaHelmChartsChange != ''
219 || gerritProject == 'voltha-helm-charts'
220 || isReleaseBranch(branch) // branch != 'master'
221 ) {
222 localCharts = true
223 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400224
Joey Armstrong54dec092023-08-03 18:21:38 -0400225 String branchName = branchName()
226 Boolean is_release = isReleaseBranch(branch)
227 println([
228 " ** localCharts=${localCharts}",
229 "branchName=${branchName}",
230 "branch=${branch}",
231 "branch=isReleaseBranch=${is_release}",
232 ].join(', '))
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400233
Joey Armstrong54dec092023-08-03 18:21:38 -0400234 // -----------------------------------------------------------------------
235 // Rewrite localHelmFlags using array join, moving code around and
Joey Armstrong642540a2023-08-10 10:26:36 -0400236 // refactoring into standalone functions
Joey Armstrong54dec092023-08-03 18:21:38 -0400237 // -----------------------------------------------------------------------
238 // hudson.remoting.ProxyException: groovy.lang.MissingMethodException:
239 // No signature of method: java.lang.String.positive() is applicable for argument types: () values: []
240 // -----------------------------------------------------------------------
241 // NOTE temporary workaround expose ONOS node ports
242 // -----------------------------------------------------------------------
243 String localHelmFlags = [
244 extraHelmFlags.trim(),
245 "--set global.log_level=${logLevel.toUpperCase()}",
246 '--set onos-classic.onosSshPort=30115',
247 '--set onos-classic.onosApiPort=30120',
248 '--set onos-classic.onosOfPort=31653',
249 '--set onos-classic.individualOpenFlowNodePorts=true',
250 testSpecificHelmFlags
251 ].join(' ')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400252
Joey Armstrong54dec092023-08-03 18:21:38 -0400253 println("** localHelmFlags = ${localHelmFlags}")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400254
Joey Armstrong54dec092023-08-03 18:21:38 -0400255 if (gerritProject != '') {
256 localHelmFlags = "${localHelmFlags} " + getVolthaImageFlags("${gerritProject}")
257 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400258
Joey Armstrong54dec092023-08-03 18:21:38 -0400259 println('volthaDeploy: ENTER')
260 volthaDeploy([
261 infraNamespace: infraNamespace,
262 volthaNamespace: volthaNamespace,
263 workflow: workflow.toLowerCase(),
264 withMacLearning: enableMacLearning.toBoolean(),
265 extraHelmFlags: localHelmFlags,
266 localCharts: localCharts,
267 bbsimReplica: olts.toInteger(),
268 dockerRegistry: registry,
269 ])
270 println('volthaDeploy: LEAVE')
271 } // script
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400272
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400273 // -----------------------------------------------------------------------
274 // Intent: Replacing P_IDS with pgrep/pkill is a step forward.
275 // Why not simply use a pid file, capture _TAG=kail-startup above
276 // Grep runs the risk of terminating stray commands (??-good <=> bad-??)
Joey Armstrong54dec092023-08-03 18:21:38 -0400277 // -----------------------------------------------------------------------
278 script {
Joey Armstrongdddbbf92023-08-22 16:00:41 -0400279 println('''
280
281** -----------------------------------------------------------------------
282** pgrep process list for kail-startup (WIP)
283** -----------------------------------------------------------------------
284''')
Joey Armstrong642540a2023-08-10 10:26:36 -0400285 sh('''pgrep --list-full kail-startup || true''')
Joey Armstrongdddbbf92023-08-22 16:00:41 -0400286
287 println('''
288
289** -----------------------------------------------------------------------
290** Raw ps process list for kail-startup (WIP)
291** -----------------------------------------------------------------------
292''')
293 sh('''ps e -ww -A | grep "_TAG=kail-startup"''')
Joey Armstrong54dec092023-08-03 18:21:38 -0400294 }
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400295
Joey Armstrong268442d2023-08-22 17:16:10 -0400296 // -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400297 // stop logging
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400298 // -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400299 sh """
300 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-startup" | grep -v grep | awk '{print \$1}')"
301 if [ -n "\$P_IDS" ]; then
302 echo \$P_IDS
303 for P_ID in \$P_IDS; do
304 kill -9 \$P_ID
305 done
306 fi
307 cd ${logsDir}
Joey Armstrongdddbbf92023-08-22 16:00:41 -0400308 echo "** kail-startup LEAVE: \$(date)" >> "${logsDir}/onos-voltha-startup-combined.log"
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400309
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400310 gzip -k onos-voltha-startup-combined.log
311 rm onos-voltha-startup-combined.log
312 """
313 }
314
315 sh """
316 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"&
317 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"&
318 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"&
319 bbsimDmiPortFwd=50075
320 for i in {0..${olts.toInteger() - 1}}; do
321 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"&
322 ((bbsimDmiPortFwd++))
323 done
324 if [ ${withMonitoring} = true ] ; then
325 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"&
326 fi
327 ps aux | grep port-forward
328 """
329
330 // setting ONOS log level
331 script
Joey Armstrong642540a2023-08-10 10:26:36 -0400332 {
Joey Armstrong54dec092023-08-03 18:21:38 -0400333 println('** setOnosLogLevels: ENTER')
334 setOnosLogLevels([
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400335 onosNamespace: infraNamespace,
336 apps: [
337 'org.opencord.dhcpl2relay',
338 'org.opencord.olt',
339 'org.opencord.aaa',
340 'org.opencord.maclearner',
341 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
342 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
343 ],
344 logLevel: logLevel
345 ])
Joey Armstrong54dec092023-08-03 18:21:38 -0400346 println('** setOnosLogLevels: LEAVE')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400347 } // script
348 } // if (teardown)
349 } // stage('Deploy Voltha')
350
Joey Armstrong642540a2023-08-10 10:26:36 -0400351 stage("Run test ${testTarget} on workflow ${workflow}")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400352 {
353 sh """
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400354 echo -e "\n** Monitor using mem_consumption.py ?"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400355 if [ ${withMonitoring} = true ] ; then
356 mkdir -p "$WORKSPACE/voltha-pods-mem-consumption-${workflow}"
357 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400358 make venv-activate-script
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400359 set +u && source .venv/bin/activate && set -u
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400360 # Collect initial memory consumption
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400361 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 -0400362 fi
363 """
364
365 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400366 echo -e "\n** make testTarget=[${testTarget}]"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400367 mkdir -p ${logsDir}
368 export ROBOT_MISC_ARGS="-d ${logsDir} ${params.extraRobotArgs} "
369 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}"
370 export KVSTOREPREFIX=voltha/voltha_voltha
371
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400372 make -C "$WORKSPACE/voltha-system-tests" ${testTarget}
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400373 """
374
375 getPodsInfo("${logsDir}")
376
377 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400378 echo -e '\n** Gather robot Framework logs: ENTER'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400379 # set +e
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400380 # collect logs collected in the Robot Framework StartLogging keyword
381 cd ${logsDir}
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400382 gzip *-combined.log
383 rm -f *-combined.log
Joey Armstrong54dec092023-08-03 18:21:38 -0400384
385 echo -e '** Gather robot Framework logs: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400386 """
387
388 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400389 echo -e '** Monitor pod-mem-consumption: ENTER'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400390 if [ ${withMonitoring} = true ] ; then
391 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400392 make venv-activate-script
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 memory consumption of voltha pods once all the tests are complete
Joey Armstrong0eb8bd82023-07-10 13:26:25 -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 Armstrong54dec092023-08-03 18:21:38 -0400397 echo -e '** Monitor pod-mem-consumption: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400398 """
399 } // stage
Joey Armstrong54dec092023-08-03 18:21:38 -0400400
401 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400402} // execute_test()
403
404// -----------------------------------------------------------------------
405// -----------------------------------------------------------------------
Joey Armstrong54dec092023-08-03 18:21:38 -0400406def collectArtifacts(exitStatus) {
Joey Armstrong642540a2023-08-10 10:26:36 -0400407 String iam = getIam('execute_test')
408
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400409 echo '''
410
411** -----------------------------------------------------------------------
412** collectArtifacts
413** -----------------------------------------------------------------------
414'''
Joey Armstrong642540a2023-08-10 10:26:36 -0400415 println("${iam}: ENTER (exitStatus=${exitStatus})")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400416
Joey Armstrong642540a2023-08-10 10:26:36 -0400417 getPodsInfo("$WORKSPACE/${exitStatus}")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400418
Joey Armstrong642540a2023-08-10 10:26:36 -0400419 sh """
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400420 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400421 """
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400422
Joey Armstrong642540a2023-08-10 10:26:36 -0400423 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 -0400424
Joey Armstrong642540a2023-08-10 10:26:36 -0400425 sh(returnStdout:true, script: '''
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400426 sync
Joey Armstrong642540a2023-08-10 10:26:36 -0400427 echo '** Running: pgrep --list-full kail-startup (ENTER)'
428 pgrep --list-full 'kail-startup' || true
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400429 [[ $(pgrep --count kail) -gt 0 ]] && pkill --echo kail
Joey Armstrong642540a2023-08-10 10:26:36 -0400430 echo '** Running: pgrep --list-full kail-startup (LEAVE)'
431 ''')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400432
Joey Armstrong642540a2023-08-10 10:26:36 -0400433 println("${iam}: ENTER RobotPublisher")
434 step([$class: 'RobotPublisher',
435 disableArchiveOutput: false,
436 logFileName: '**/*/log*.html',
437 otherFiles: '',
438 outputFileName: '**/*/output*.xml',
439 outputPath: '.',
440 passThreshold: 100,
441 reportFileName: '**/*/report*.html',
442 unstableThreshold: 0,
443 onlyCritical: true]);
444 println("${iam}: LEAVE RobotPublisher")
445
446 println("${iam}: LEAVE (exitStatus=${exitStatus})")
447 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400448}
449
Joey Armstrong54dec092023-08-03 18:21:38 -0400450// -----------------------------------------------------------------------
451// Intent: main
452// -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400453pipeline {
454
455 /* no label, executor is determined by JJB */
456 agent {
457 label "${params.buildNode}"
458 }
459 options {
460 timeout(time: "${timeout}", unit: 'MINUTES')
461 }
462 environment {
Joey Armstrong642540a2023-08-10 10:26:36 -0400463 KUBECONFIG = "$HOME/.kube/kind-${clusterName}"
464 VOLTCONFIG = "$HOME/.volt/config"
465 PATH = "$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
466 DIAGS_PROFILE = 'VOLTHA_PROFILE'
467 SSHPASS = 'karaf'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400468 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400469
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400470 stages {
471 stage('Download Code') {
472 steps {
473 getVolthaCode([
474 branch: "${branch}",
475 gerritProject: "${gerritProject}",
476 gerritRefspec: "${gerritRefspec}",
477 volthaSystemTestsChange: "${volthaSystemTestsChange}",
478 volthaHelmChartsChange: "${volthaHelmChartsChange}",
479 ])
480 }
481 }
482
483 stage('Build patch v1.1')
484 {
485 // build the patch only if gerritProject is specified
486 when
487 {
488 expression
489 {
490 return !gerritProject.isEmpty()
491 }
492 }
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400493
494 steps
495 {
496 // NOTE that the correct patch has already been checked out
497 // during the getVolthaCode step
498 buildVolthaComponent("${gerritProject}")
499 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400500 }
501
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400502 // -----------------------------------------------------------------------
503 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400504 stage('Install Kail')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400505 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400506 steps
507 {
508 script
509 {
510 String cmd = [
511 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400512 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400513 '-C', "$WORKSPACE/voltha-system-tests",
514 "KAIL_PATH=\"$WORKSPACE/bin\"",
515 'kail',
516 ].join(' ')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400517
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400518 println(" ** Running: ${cmd}:\n")
519 sh("${cmd}")
520 } // script
521 } // steps
522 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400523
524 // -----------------------------------------------------------------------
525 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400526 stage('Install Kind')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400527 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400528 steps
529 {
530 script
531 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400532
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400533 String cmd = [
534 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400535 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400536 '-C', "$WORKSPACE/voltha-system-tests",
537 "KIND_PATH=\"$WORKSPACE/bin\"",
538 'install-command-kind',
539 ].join(' ')
Joey Armstrong642540a2023-08-10 10:26:36 -0400540
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400541 println(" ** Running: ${cmd}:\n")
542 sh("${cmd}")
543 } // script
544 } // steps
545 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400546
547 // -----------------------------------------------------------------------
548 // -----------------------------------------------------------------------
549 stage('Create K8s Cluster')
550 {
551 steps
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400552 {
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400553 script
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400554 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400555 def clusterExists = sh(
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400556 returnStdout: true,
557 script: """kind get clusters | grep "${clusterName}" | wc -l"""
558 )
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400559
Joey Armstrong54dec092023-08-03 18:21:38 -0400560 if (clusterExists.trim() == '0')
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400561 {
562 createKubernetesCluster([nodes: 3, name: clusterName])
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400563 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400564 } // script
565 } // steps
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400566 } // stage('Create K8s Cluster')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400567
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400568 // -----------------------------------------------------------------------
569 // -----------------------------------------------------------------------
570 stage('Replace voltctl')
571 {
572 // if the project is voltctl, override the downloaded one with the built one
573 when {
574 expression { return gerritProject == 'voltctl' }
575 }
576
577 // Hmmmm(?) where did the voltctl download happen ?
578 // Likely Makefile but would be helpful to document here.
579 steps
580 {
581 println("${iam} Running: installVoltctl($branch)")
582 installVoltctl("$branch")
583 } // steps
584 } // stage
585
586 // -----------------------------------------------------------------------
587 // -----------------------------------------------------------------------
Joey Armstrong268442d2023-08-22 17:16:10 -0400588 stage('voltctl [DEBUG]')
589 {
590 steps
591 {
592 println("${iam} Display umask")
593 sh('umask')
594
595 println("${iam} Checking voltctl config permissions")
596 sh('/bin/ls -ld ~/.volt || true')
597
598 println("${iam} Running find")
599 sh('/bin/ls -l ~/.volt')
600 } // steps
601 } // stage
602
603 // -----------------------------------------------------------------------
604 // -----------------------------------------------------------------------
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400605 stage('Load image in kind nodes')
606 {
607 when {
608 expression { return !gerritProject.isEmpty() }
609 }
610 steps {
611 loadToKind()
612 } // steps
613 } // stage
614
615 // -----------------------------------------------------------------------
616 // -----------------------------------------------------------------------
617 stage('Parse and execute tests')
618 {
619 steps {
620 script {
621 // Announce ourselves for log usability
622 String iam = getIam('execute_test')
623 println("${iam}: ENTER")
624
625 def tests = readYaml text: testTargets
626
627 println("** $iam: Testing index: tests-to-run")
628 tests.eachWithIndex { test, idx ->
629 String target = test['target']
630 println("** $idx: $target")
Joey Armstrong642540a2023-08-10 10:26:36 -0400631 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400632 println("** NOTE: For odd failures compare tests-to-run with teste output")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400633
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400634 tests.eachWithIndex { test, idx ->
635 println "** readYaml test suite[$idx]) test=[${test}]"
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400636
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400637 String target = test['target']
638 String workflow = test['workflow']
639 String flags = test['flags']
640 Boolean teardown = test['teardown'].toBoolean()
641 Boolean logging = test['logging'].toBoolean()
642 String testLogging = (logging) ? 'True' : 'False'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400643
Joey Armstrong268442d2023-08-22 17:16:10 -0400644 print("""
645
646** -----------------------------------------------------------------------
647** Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}"
648** -----------------------------------------------------------------------
649
650)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400651
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400652 try {
653 println "Executing test ${target}: ENTER"
654 execute_test(target, workflow, testLogging, teardown, flags)
655 }
656 catch (Exception err) {
657 println("** ${iam}: EXCEPTION ${err}")
658 }
659 finally {
660 println "Executing test ${target}: LEAVE"
661 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400662
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400663 } // for
Joey Armstrong642540a2023-08-10 10:26:36 -0400664
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400665 // Premature exit if this message is not logged
666 println("${iam}: LEAVE (testing ran to completion)")
Joey Armstrong54dec092023-08-03 18:21:38 -0400667 } // script
668 } // steps
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400669 } // stage
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400670 } // stages
671
672 post
673 {
674 aborted { collectArtifacts('aborted') }
675 failure { collectArtifacts('failed') }
676 always { collectArtifacts('always') }
677 }
678} // pipeline
679
680// EOF