blob: 46cb252c37068a8ba2d705ae38d2bb086e72e433 [file] [log] [blame]
Joey Armstrong8c6f6482023-01-12 12:31:44 -05001// Copyright 2021-2023 Open Networking Foundation (ONF) and the ONF Contributors
Matteo Scandolo42f6e572021-01-25 15:11:34 -08002//
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
Hardik Windlassec9341b2021-06-07 11:58:29 +000015// voltha-2.x e2e tests for openonu-go
Matteo Scandolo42f6e572021-01-25 15:11:34 -080016// uses bbsim to simulate OLT/ONUs
17
Joey Armstronge5aae1c2023-07-24 14:11:20 -040018// [TODO] Update syntax below to the latest supported
Matteo Scandoloa156b572021-02-04 11:52:18 -080019library identifier: 'cord-jenkins-libraries@master',
20 retriever: modernSCM([
21 $class: 'GitSCMSource',
22 remote: 'https://gerrit.opencord.org/ci-management.git'
23])
24
Joey Armstronge5aae1c2023-07-24 14:11:20 -040025//------------------//
26//---] GLOBAL [---//
27//------------------//
Joey Armstrongb65ada32023-08-03 12:50:20 -040028String clusterName = 'kind-ci' // was def
Joey Armstrongf076c312023-08-01 17:17:10 -040029
30// -----------------------------------------------------------------------
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040031// Intent:
Joey Armstrongf076c312023-08-01 17:17:10 -040032// -----------------------------------------------------------------------
Joey Armstrongb65ada32023-08-03 12:50:20 -040033String branchName() {
Joey Armstrongf076c312023-08-01 17:17:10 -040034 String name = 'master'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040035
36 // [TODO] Sanity check the target branch
37 // if (name != jenkins.branch) { fatal }
Joey Armstrongf076c312023-08-01 17:17:10 -040038 return(name)
39}
Hardik Windlassec9341b2021-06-07 11:58:29 +000040
Joey Armstronge5aae1c2023-07-24 14:11:20 -040041// -----------------------------------------------------------------------
Joey Armstrong0251e962023-08-25 20:51:31 -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() {
47 String version = '757ba9ea12d8d815c10301b7f265f3fcd7c41d26'
48 return(version)
49}
50
51// -----------------------------------------------------------------------
Joey Armstrong06a68372023-07-24 16:37:16 -040052// Intent: Due to lack of a reliable stack trace, construct a literal.
Joey Armstrong0251e962023-08-25 20:51:31 -040053// Jenkins will re-write the call stack for serialization.S
54// -----------------------------------------------------------------------
55// Note: Hardcoded version string used to visualize changes in jenkins UI
Joey Armstrong06a68372023-07-24 16:37:16 -040056// -----------------------------------------------------------------------
Joey Armstrong97a8b882023-08-02 16:08:52 -040057String getIam(String func) {
Joey Armstrongb65ada32023-08-03 12:50:20 -040058 String branchName = branchName()
Joey Armstrong0251e962023-08-25 20:51:31 -040059 String version = pipelineVer()
Joey Armstrong06a68372023-07-24 16:37:16 -040060 String src = [
61 'ci-management',
62 'jjb',
63 'pipeline',
64 'voltha',
Joey Armstrongb65ada32023-08-03 12:50:20 -040065 branchName,
Joey Armstrong06a68372023-07-24 16:37:16 -040066 'bbsim-tests.groovy'
67 ].join('/')
68
Joey Armstrong0251e962023-08-25 20:51:31 -040069 String name = [src, version, func].join('::')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040070 return(name)
Joey Armstrong06a68372023-07-24 16:37:16 -040071}
72
73// -----------------------------------------------------------------------
Joey Armstrong0251e962023-08-25 20:51:31 -040074// Intent: Log progress message
75// -----------------------------------------------------------------------
76void enter(String name) {
77 // 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// -----------------------------------------------------------------------
86void leave(String name) {
87 // Announce ourselves for log usability
88 String iam = getIam(name)
89 println("${iam}: LEAVE")
90 return
91}
92
93// -----------------------------------------------------------------------
Joey Armstronge5aae1c2023-07-24 14:11:20 -040094// Intent: Determine if working on a release branch.
95// Note: Conditional is legacy, should also check for *-dev or *-pre
96// -----------------------------------------------------------------------
Joey Armstrong0251e962023-08-25 20:51:31 -040097Boolean isReleaseBranch(String name) {
Joey Armstronge5aae1c2023-07-24 14:11:20 -040098 // List modifiers = ['-dev', '-pre', 'voltha-x.y.z-pre']
Joey Armstrongb65ada32023-08-03 12:50:20 -040099 // if branchName in modifiers
100 return(name != 'master') // OR branchName.contains('-')
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400101}
102
103// -----------------------------------------------------------------------
Joey Armstrong0251e962023-08-25 20:51:31 -0400104// Intent: Iterate over a list of test suites and invoke.
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400105// -----------------------------------------------------------------------
Joey Armstrong0251e962023-08-25 20:51:31 -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 Armstrongb65ada32023-08-03 12:50:20 -0400114 String infraNamespace = 'default'
115 String volthaNamespace = 'voltha'
116 String logsDir = "$WORKSPACE/${testTarget}"
Joey Armstrong293e16b2022-11-26 20:16:33 -0500117
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400118 // -----------------------------------------------------------------------
Joey Armstrong268442d2023-08-22 17:16:10 -0400119 // Intent: Cleanup stale port-forwarding
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400120 // -----------------------------------------------------------------------
Joey Armstrong0251e962023-08-25 20:51:31 -0400121 stage('Cleanup') {
122 if (teardown) {
Joey Armstrong84adc542023-04-11 14:47:34 -0400123 timeout(15) {
Joey Armstrong0251e962023-08-25 20:51:31 -0400124 script {
Joey Armstrongb65ada32023-08-03 12:50:20 -0400125 helmTeardown(['default', infraNamespace, volthaNamespace])
Joey Armstrong84adc542023-04-11 14:47:34 -0400126 }
Joey Armstrong0251e962023-08-25 20:51:31 -0400127 } // timeout
128
129 timeout(5) {
130 script {
131 enter('Cleanup')
132 // remove orphaned port-forward from different namespaces
133 String proc = 'port-forw'
134 pgrep_proc(proc)
135 pkill_proc(proc)
136 pgrep_proc(proc) // proc count == 0
137 enter('Cleanup')
138 } // script
139 } // timeout
140 } // teardown
141 } // stage('Cleanup')
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500142
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400143 // -----------------------------------------------------------------------
144 // -----------------------------------------------------------------------
Joey Armstrong0251e962023-08-25 20:51:31 -0400145 stage('Deploy common infrastructure') {
146 script {
147 local dashargs = [
148 'kpi_exporter.enabled=false',
149 'dashboards.xos=false',
150 'dashboards.onos=false',
151 'dashboards.aaa=false',
152 'dashboards.voltha=false',
153 ].join(',')
154
155 local promargs = [
156 'prometheus.alertmanager.enabled=false',
157 'prometheus.pushgateway.enabled=false',
158 ].join(',')
159
160 sh("""
Hardik Windlasse1660492022-03-14 15:12:46 +0000161 helm repo add onf https://charts.opencord.org
162 helm repo update
Joey Armstrong0251e962023-08-25 20:51:31 -0400163
164 echo -e "\nwithMonitoring=[$withMonitoring]"
Hardik Windlasse1660492022-03-14 15:12:46 +0000165 if [ ${withMonitoring} = true ] ; then
166 helm install nem-monitoring onf/nem-monitoring \
Joey Armstrong0251e962023-08-25 20:51:31 -0400167 --set ${promargs} \
168 --set ${dashargs}
Hardik Windlasse1660492022-03-14 15:12:46 +0000169 fi
Joey Armstrong0251e962023-08-25 20:51:31 -0400170 """)
171 } // script
172 } // stage('Deploy Common Infra')
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500173
Joey Armstrong0251e962023-08-25 20:51:31 -0400174 // -----------------------------------------------------------------------
175 // [TODO] Check onos_log output
176 // -----------------------------------------------------------------------
177 stage('Deploy Voltha') {
178 if (teardown) {
179 timeout(10) {
180 script {
181 String iam = getIam('Deploy Voltha')
182 String onosLog = "${logsDir}/onos-voltha-startup-combined.log"
183 sh("""
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700184 mkdir -p ${logsDir}
Joey Armstrong0251e962023-08-25 20:51:31 -0400185 touch "$onosLog"
186 echo "** kail-startup ENTER: \$(date)" > "$onosLog"
Hardik Windlassec9341b2021-06-07 11:58:29 +0000187
Joey Armstrong0251e962023-08-25 20:51:31 -0400188 # Intermixed output (tee -a &) may get conflusing but let(s) see
189 # what messages are logged during startup.
190 # _TAG=ka7il-startup kail -n ${infraNamespace} -n ${volthaNamespace} >> "$onosLog" &
191 _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} | tee -a "$onosLog" &
192 """)
Joey Armstrongf404b642023-08-04 14:39:13 -0400193
Joey Armstrong0251e962023-08-25 20:51:31 -0400194 // if we're downloading a voltha-helm-charts patch, then install from a local copy of the charts
195 Boolean localCharts = false
Joey Armstrongf404b642023-08-04 14:39:13 -0400196
Joey Armstrong0251e962023-08-25 20:51:31 -0400197 if (volthaHelmChartsChange != ''
198 || gerritProject == 'voltha-helm-charts'
199 || isReleaseBranch(branch) // branch != 'master'
200 ) {
201 localCharts = true
202 }
Hardik Windlassec9341b2021-06-07 11:58:29 +0000203
Joey Armstrong0251e962023-08-25 20:51:31 -0400204 String branchName = branchName()
205 Boolean isRelease = isReleaseBranch(branch)
206 println([
207 " ** localCharts=${localCharts}",
208 "branchName=${branchName}",
209 "branch=${branch}",
210 "branch=isReleaseBranch=${isRelease}",
211 ].join(', '))
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800212
Joey Armstrong0251e962023-08-25 20:51:31 -0400213 // -----------------------------------------------------------------------
214 // Rewrite localHelmFlags using array join, moving code around and
215 // refactoring into standalone functions
216 // -----------------------------------------------------------------------
217 // NOTE temporary workaround expose ONOS node ports
218 // -----------------------------------------------------------------------
219 String localHelmFlags = [
220 extraHelmFlags.trim(),
221 "--set global.log_level=${logLevel.toUpperCase()}",
222 '--set onos-classic.onosSshPort=30115',
223 '--set onos-classic.onosApiPort=30120',
224 '--set onos-classic.onosOfPort=31653',
225 '--set onos-classic.individualOpenFlowNodePorts=true',
226 testSpecificHelmFlags
227 ].join(' ')
Joey Armstrong28e86ee2023-08-03 15:22:29 -0400228
Joey Armstrong0251e962023-08-25 20:51:31 -0400229 println("** ${iam} localHelmFlags = ${localHelmFlags}")
Hardik Windlassec9341b2021-06-07 11:58:29 +0000230
Joey Armstrong0251e962023-08-25 20:51:31 -0400231 if (gerritProject != '') {
232 localHelmFlags = "${localHelmFlags} " + getVolthaImageFlags("${gerritProject}")
233 }
Matteo Scandolofcfc60d2021-02-24 09:06:48 -0800234
Joey Armstrong0251e962023-08-25 20:51:31 -0400235 println("** ${iam}: ENTER")
236 volthaDeploy([
237 infraNamespace: infraNamespace,
238 volthaNamespace: volthaNamespace,
239 workflow: workflow.toLowerCase(),
240 withMacLearning: enableMacLearning.toBoolean(),
241 extraHelmFlags: localHelmFlags,
242 localCharts: localCharts,
243 bbsimReplica: olts.toInteger(),
244 dockerRegistry: registry,
245 ])
246 println("** ${iam}: LEAVE")
247 } // script
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400248
Joey Armstrong0251e962023-08-25 20:51:31 -0400249 // -----------------------------------------------------------------------
250 // Intent: Replacing P_IDS with pgrep/pkill is a step forward.
251 // Why not simply use a pid file, capture _TAG=kail-startup above
252 // Grep runs the risk of terminating stray commands (??-good <=> bad-??)
253 // -----------------------------------------------------------------------
254 script {
255 String proc = '_TAG=kail-startup'
256
257 println("${iam}: ENTER")
258 println("${iam}: Shutdown process $proc")
259 pgrep_proc(proc)
260 pkill_proc(proc)
261 pgrep_proc(proc)
262 println("${iam}: LEAVE")
263 }
264
265 // -----------------------------------------------------------------------
266 // Bundle onos-voltha / kail logs
267 // -----------------------------------------------------------------------
268 sh("""
269cat <<EOM
270
271** -----------------------------------------------------------------------
272** Combine an compress voltha startup log(s)
273** -----------------------------------------------------------------------
274EOM
275 pushd "${logsDir}" || { echo "ERROR: pushd $logsDir failed"; exit 1; }
Hardik Windlassec9341b2021-06-07 11:58:29 +0000276 gzip -k onos-voltha-startup-combined.log
277 rm onos-voltha-startup-combined.log
Joey Armstrong0251e962023-08-25 20:51:31 -0400278 popd
279 """)
280 } // timeout(10)
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400281
Joey Armstrong0251e962023-08-25 20:51:31 -0400282 // -----------------------------------------------------------------------
283 // -----------------------------------------------------------------------
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400284 sh """
Hardik Windlassec9341b2021-06-07 11:58:29 +0000285 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"&
286 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"&
287 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"&
288 bbsimDmiPortFwd=50075
289 for i in {0..${olts.toInteger() - 1}}; do
290 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"&
291 ((bbsimDmiPortFwd++))
292 done
Hardik Windlass3bb089a2022-03-22 17:56:03 +0000293 if [ ${withMonitoring} = true ] ; then
294 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"&
295 fi
Hardik Windlassec9341b2021-06-07 11:58:29 +0000296 ps aux | grep port-forward
297 """
Joey Armstrong0251e962023-08-25 20:51:31 -0400298 // ---------------------------------
299 // Sanity check port-forward spawned
300 // ---------------------------------
301 script {
302 enter('port-forward check')
303 String proc = 'port-forward'
304 println("Display spawned ${proc}")
305 pgrep_proc(proc)
306 leave('port-forward check')
307 }
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500308
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400309 // setting ONOS log level
Joey Armstrong0251e962023-08-25 20:51:31 -0400310 script {
311 enter('setOnosLogLevels')
312 setOnosLogLevels([
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400313 onosNamespace: infraNamespace,
314 apps: [
315 'org.opencord.dhcpl2relay',
316 'org.opencord.olt',
317 'org.opencord.aaa',
318 'org.opencord.maclearner',
319 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
320 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
321 ],
322 logLevel: logLevel
323 ])
Joey Armstrong0251e962023-08-25 20:51:31 -0400324 enter('setOnosLogLevels')
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400325 } // script
326 } // if (teardown)
327 } // stage('Deploy Voltha')
328
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400329 // -----------------------------------------------------------------------
330 // -----------------------------------------------------------------------
Joey Armstrongfd896522023-08-04 13:30:48 -0400331 stage("Run test ${testTarget} on workflow ${workflow}")
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400332 {
333 sh """
Joey Armstrong0251e962023-08-25 20:51:31 -0400334 echo -e "\n** Monitor using mem_consumption.py ?"
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400335
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000336 if [ ${withMonitoring} = true ] ; then
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400337 cat <<EOM
338
339** -----------------------------------------------------------------------
340** Monitoring memory usage with mem_consumption.py
341** -----------------------------------------------------------------------
342EOM
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500343 mkdir -p "$WORKSPACE/voltha-pods-mem-consumption-${workflow}"
344 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400345
346 echo '** Installing python virtualenv'
347 make venv-activate-patched
348
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400349 set +u && source .venv/bin/activate && set -u
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000350 # Collect initial memory consumption
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400351 python scripts/mem_consumption.py -o $WORKSPACE/voltha-pods-mem-consumption-${workflow} -a 0.0.0.0:31301 -n ${volthaNamespace}
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000352 fi
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400353
354 echo -e '** Monitor memory consumption: LEAVE\n'
Hardik Windlasse1660492022-03-14 15:12:46 +0000355 """
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400356
357 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400358 echo -e "\n** make testTarget=[${testTarget}]"
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700359 mkdir -p ${logsDir}
Hardik Windlassd62442d2021-11-30 10:51:20 +0000360 export ROBOT_MISC_ARGS="-d ${logsDir} ${params.extraRobotArgs} "
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700361 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}"
Hardik Windlass72947302021-06-14 10:36:57 +0000362 export KVSTOREPREFIX=voltha/voltha_voltha
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800363
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400364 make -C "$WORKSPACE/voltha-system-tests" ${testTarget}
Hardik Windlass72947302021-06-14 10:36:57 +0000365 """
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400366
367 getPodsInfo("${logsDir}")
368
369 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400370 echo -e '\n** Gather robot Framework logs: ENTER'
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400371 # set +e
Hardik Windlassdad8e5c2021-11-11 05:19:47 +0000372 # collect logs collected in the Robot Framework StartLogging keyword
373 cd ${logsDir}
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400374 gzip *-combined.log
375 rm -f *-combined.log
Joey Armstrong54dec092023-08-03 18:21:38 -0400376
377 echo -e '** Gather robot Framework logs: LEAVE\n'
Hardik Windlassdad8e5c2021-11-11 05:19:47 +0000378 """
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400379
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400380 // -----------------------------------------------------------------------
381 // -----------------------------------------------------------------------
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000382 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400383 echo -e '** Monitor pod-mem-consumption: ENTER'
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000384 if [ ${withMonitoring} = true ] ; then
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400385 cat <<EOM
386
387** -----------------------------------------------------------------------
388** Monitoring pod-memory-consumption using mem_consumption.py
389** -----------------------------------------------------------------------
390EOM
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500391 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400392
393 echo '** Installing python virtualenv'
394 make venv-activate-patched
395
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400396 set +u && source .venv/bin/activate && set -u
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000397 # Collect memory consumption of voltha pods once all the tests are complete
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400398 python scripts/mem_consumption.py -o $WORKSPACE/voltha-pods-mem-consumption-${workflow} -a 0.0.0.0:31301 -n ${volthaNamespace}
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000399 fi
Joey Armstrong54dec092023-08-03 18:21:38 -0400400 echo -e '** Monitor pod-mem-consumption: LEAVE\n'
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000401 """
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400402 } // stage
Joey Armstrongb65ada32023-08-03 12:50:20 -0400403
404 return
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400405} // execute_test()
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800406
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400407// -----------------------------------------------------------------------
408// -----------------------------------------------------------------------
Joey Armstrongb65ada32023-08-03 12:50:20 -0400409def collectArtifacts(exitStatus) {
Joey Armstrong0251e962023-08-25 20:51:31 -0400410 script {
411 String iam = getIam('collectArtifacts')
412 println("${iam}: ENTER (exitStatus=${exitStatus})")
413 }
Joey Armstrongcd419122023-08-07 14:56:39 -0400414
Joey Armstrong97a8b882023-08-02 16:08:52 -0400415 echo '''
416
417** -----------------------------------------------------------------------
418** collectArtifacts
419** -----------------------------------------------------------------------
420'''
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400421
Joey Armstrongcd419122023-08-07 14:56:39 -0400422 getPodsInfo("$WORKSPACE/${exitStatus}")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400423
Joey Armstrongcd419122023-08-07 14:56:39 -0400424 sh """
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400425 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log
Hardik Windlassec9341b2021-06-07 11:58:29 +0000426 """
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400427
Joey Armstrongcd419122023-08-07 14:56:39 -0400428 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 -0400429
Joey Armstrong0251e962023-08-25 20:51:31 -0400430 script {
431 println("${iam}: ENTER")
432 pgrep_proc('kail-startup')
433 pkill_proc('kail')
434 println("${iam}: LEAVE")
435 }
Joey Armstrong97a8b882023-08-02 16:08:52 -0400436
Joey Armstrongcd419122023-08-07 14:56:39 -0400437 println("${iam}: ENTER RobotPublisher")
438 step([$class: 'RobotPublisher',
Joey Armstrong0251e962023-08-25 20:51:31 -0400439 disableArchiveOutput: false,
440 logFileName: '**/*/log*.html',
441 otherFiles: '',
442 outputFileName: '**/*/output*.xml',
443 outputPath: '.',
444 passThreshold: 100,
445 reportFileName: '**/*/report*.html',
446 unstableThreshold: 0,
447 onlyCritical: true])
Joey Armstrongcd419122023-08-07 14:56:39 -0400448 println("${iam}: LEAVE RobotPublisher")
449
450 println("${iam}: LEAVE (exitStatus=${exitStatus})")
451 return
Hardik Windlassec9341b2021-06-07 11:58:29 +0000452}
453
Joey Armstrongb65ada32023-08-03 12:50:20 -0400454// -----------------------------------------------------------------------
455// Intent: main
456// -----------------------------------------------------------------------
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800457pipeline {
Joey Armstrong0251e962023-08-25 20:51:31 -0400458 /* no label, executor is determined by JJB */
459 agent {
460 label "${params.buildNode}"
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800461 }
Joey Armstrong84adc542023-04-11 14:47:34 -0400462
Joey Armstrong0251e962023-08-25 20:51:31 -0400463 options {
464 timeout(time: "${timeout}", unit: 'MINUTES')
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800465 }
Joey Armstronged161f72023-04-11 13:16:59 -0400466
Joey Armstrong0251e962023-08-25 20:51:31 -0400467 environment {
468 KUBECONFIG = "$HOME/.kube/kind-${clusterName}"
469 VOLTCONFIG = "$HOME/.volt/config"
470 PATH = "$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
471 DIAGS_PROFILE = 'VOLTHA_PROFILE'
472 SSHPASS = 'karaf'
473 }
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400474
Joey Armstrong0251e962023-08-25 20:51:31 -0400475 stages {
476 stage('Download Code') {
Joey Armstrongf404b642023-08-04 14:39:13 -0400477 steps {
Joey Armstrong0251e962023-08-25 20:51:31 -0400478 getVolthaCode([
479 branch: "${branch}",
480 gerritProject: "${gerritProject}",
481 gerritRefspec: "${gerritRefspec}",
482 volthaSystemTestsChange: "${volthaSystemTestsChange}",
483 volthaHelmChartsChange: "${volthaHelmChartsChange}",
484 ])
485 }
486 }
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400487
Joey Armstrong0251e962023-08-25 20:51:31 -0400488 stage('Build patch v1.1') {
489 // build the patch only if gerritProject is specified
490 when {
491 expression { return !gerritProject.isEmpty() }
492 }
493
494 steps {
495 // NOTE that the correct patch has already been checked out
496 // during the getVolthaCode step
497 buildVolthaComponent("${gerritProject}")
498 }
499 }
500
501 // -----------------------------------------------------------------------
502 // -----------------------------------------------------------------------
503 stage('Install Kail')
504 {
505 steps
506 {
507 script
508 {
509 String cmd = [
510 'make',
511 '--no-print-directory',
512 '-C', "$WORKSPACE/voltha-system-tests",
513 "KAIL_PATH=\"$WORKSPACE/bin\"",
514 'kail',
515 ].join(' ')
516
517 println(" ** Running: ${cmd}")
518 sh("${cmd}")
519 } // script
520 } // steps
521 } // stage
522
523 // -----------------------------------------------------------------------
524 // -----------------------------------------------------------------------
525 stage('Install Tools') {
526 steps {
527 script {
528 String branchName = branchName()
529 String iam = getIam('Install Tools')
530
531 println("${iam}: ENTER (branch=$branch)")
532 installKind(branch) // needed early by stage(Cleanup)
533 println("${iam}: LEAVE (branch=$branch)")
534 } // script
535 } // steps
536 } // stage
537
538 // -----------------------------------------------------------------------
539 // -----------------------------------------------------------------------
540 stage('Create K8s Cluster') {
541 steps {
542 script {
543 def clusterExists = sh(
544 returnStdout: true,
545 script: """kind get clusters | grep "${clusterName}" | wc -l""")
546
547 if (clusterExists.trim() == '0') {
548 createKubernetesCluster([nodes: 3, name: clusterName])
549 }
550 } // script
551 } // steps
552 } // stage('Create K8s Cluster')
553
554 // -----------------------------------------------------------------------
555 // -----------------------------------------------------------------------
556 stage('Replace voltctl') {
557 // if the project is voltctl, override the downloaded one with the built one
558 when {
559 expression { return gerritProject == 'voltctl' }
560 }
561
562 // Hmmmm(?) where did the voltctl download happen ?
563 // Likely Makefile but would be helpful to document here.
564 steps {
565 script {
566 String iam = getIam('Replace voltctl')
567
568 println("${iam} Running: installVoltctl($branch)")
569 println("${iam}: ENTER")
570 installVoltctl("$branch")
571 println("${iam}: LEAVE")
572 } // script
573 } // step
574 } // stage
575
576 // -----------------------------------------------------------------------
577 // -----------------------------------------------------------------------
578 stage('Load image in kind nodes')
579 {
580 when {
581 expression { return !gerritProject.isEmpty() }
582 }
583 steps {
584 loadToKind()
585 } // steps
586 } // stage
587
588 // -----------------------------------------------------------------------
589 // [TODO] verify testing output
590 // -----------------------------------------------------------------------
591 stage('Parse and execute tests')
592 {
593 steps {
594 script {
595 // Announce ourselves for log usability
596 enter('Parse and execute tests')
597
598 def tests = readYaml text: testTargets
599 println("** [DEBUG]: tests=$tests")
600
601 // Display expected tests for times when output goes dark
602 tests.eachWithIndex { test, idx ->
603 String target = test['target']
604 println("** test[${idx}]: ${target}\n")
605 }
606
607 println('''
608** -----------------------------------------------------------------------
609** NOTE: For odd/silent job failures verify a few details
610** - All tests mentioned in the tests-to-run index were logged.
611** - Test suites display ENTER/LEAVE mesasge pairs.
612** - Processing terminated prematurely when LEAVE strings are missing.
613** -----------------------------------------------------------------------
614''')
615 tests.eachWithIndex { test, idx ->
616 println "** readYaml test suite[$idx]) test=[${test}]"
617
Joey Armstrongf404b642023-08-04 14:39:13 -0400618 String target = test['target']
619 String workflow = test['workflow']
620 String flags = test['flags']
621 Boolean teardown = test['teardown'].toBoolean()
622 Boolean logging = test['logging'].toBoolean()
623 String testLogging = (logging) ? 'True' : 'False'
624
Joey Armstrong0251e962023-08-25 20:51:31 -0400625 print("""
Joey Armstrong268442d2023-08-22 17:16:10 -0400626** -----------------------------------------------------------------------
Joey Armstrong0251e962023-08-25 20:51:31 -0400627** Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}
Joey Armstrong268442d2023-08-22 17:16:10 -0400628** -----------------------------------------------------------------------
Joey Armstrong268442d2023-08-22 17:16:10 -0400629""")
630
Joey Armstrong0251e962023-08-25 20:51:31 -0400631 try {
632 leave("execute_test (target=$target)")
633 execute_test(target, workflow, testLogging, teardown, flags)
634 }
635 catch (Exception err) {
636 println("** ${iam}: EXCEPTION ${err}")
637 }
638 finally {
639 leave("execute_test (target=$target)")
640 }
Joey Armstrongb65ada32023-08-03 12:50:20 -0400641 } // for
Joey Armstrong0251e962023-08-25 20:51:31 -0400642 // Premature exit if this message is not logged
643 leave('Parse and execute tests')
Joey Armstrongb65ada32023-08-03 12:50:20 -0400644 } // script
645 } // steps
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400646 } // stage
647 } // stages
Joey Armstrong84adc542023-04-11 14:47:34 -0400648
649 post
650 {
651 aborted { collectArtifacts('aborted') }
652 failure { collectArtifacts('failed') }
Joey Armstrongbf492922023-04-13 17:05:09 -0400653 always { collectArtifacts('always') }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800654 }
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400655} // pipeline
Joey Armstronged161f72023-04-11 13:16:59 -0400656
Joey Armstrong0251e962023-08-25 20:51:31 -0400657// [EOF] - 2