blob: 674b4b02f5072fab000faf9f912d7e92711a74af [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() {
Joey Armstrong5addce32023-08-26 21:00:45 -040047 String version = 'ebc180201844dad3a9a3d6551f3e257797e08ab7'
Joey Armstrong0251e962023-08-25 20:51:31 -040048 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
Joey Armstrongebc18022023-08-26 13:20:49 -0400133 String proc = 'kubectl .*port-forward' // was 'port-forw'
Joey Armstrong0251e962023-08-25 20:51:31 -0400134 pgrep_proc(proc)
135 pkill_proc(proc)
Joey Armstrongebc18022023-08-26 13:20:49 -0400136
137 // todo: fatal unless (proc count==0)
138 pgrep_proc(proc)
Joey Armstrong0251e962023-08-25 20:51:31 -0400139 enter('Cleanup')
140 } // script
141 } // timeout
142 } // teardown
143 } // stage('Cleanup')
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500144
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400145 // -----------------------------------------------------------------------
146 // -----------------------------------------------------------------------
Joey Armstrong0251e962023-08-25 20:51:31 -0400147 stage('Deploy common infrastructure') {
148 script {
149 local dashargs = [
150 'kpi_exporter.enabled=false',
151 'dashboards.xos=false',
152 'dashboards.onos=false',
153 'dashboards.aaa=false',
154 'dashboards.voltha=false',
155 ].join(',')
156
157 local promargs = [
158 'prometheus.alertmanager.enabled=false',
159 'prometheus.pushgateway.enabled=false',
160 ].join(',')
161
162 sh("""
Hardik Windlasse1660492022-03-14 15:12:46 +0000163 helm repo add onf https://charts.opencord.org
164 helm repo update
Joey Armstrong0251e962023-08-25 20:51:31 -0400165
166 echo -e "\nwithMonitoring=[$withMonitoring]"
Hardik Windlasse1660492022-03-14 15:12:46 +0000167 if [ ${withMonitoring} = true ] ; then
168 helm install nem-monitoring onf/nem-monitoring \
Joey Armstrong0251e962023-08-25 20:51:31 -0400169 --set ${promargs} \
170 --set ${dashargs}
Hardik Windlasse1660492022-03-14 15:12:46 +0000171 fi
Joey Armstrong0251e962023-08-25 20:51:31 -0400172 """)
173 } // script
174 } // stage('Deploy Common Infra')
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500175
Joey Armstrong0251e962023-08-25 20:51:31 -0400176 // -----------------------------------------------------------------------
177 // [TODO] Check onos_log output
178 // -----------------------------------------------------------------------
179 stage('Deploy Voltha') {
180 if (teardown) {
181 timeout(10) {
182 script {
183 String iam = getIam('Deploy Voltha')
184 String onosLog = "${logsDir}/onos-voltha-startup-combined.log"
185 sh("""
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700186 mkdir -p ${logsDir}
Joey Armstrong0251e962023-08-25 20:51:31 -0400187 touch "$onosLog"
188 echo "** kail-startup ENTER: \$(date)" > "$onosLog"
Hardik Windlassec9341b2021-06-07 11:58:29 +0000189
Joey Armstrong0251e962023-08-25 20:51:31 -0400190 # Intermixed output (tee -a &) may get conflusing but let(s) see
191 # what messages are logged during startup.
192 # _TAG=ka7il-startup kail -n ${infraNamespace} -n ${volthaNamespace} >> "$onosLog" &
193 _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} | tee -a "$onosLog" &
194 """)
Joey Armstrongf404b642023-08-04 14:39:13 -0400195
Joey Armstrong0251e962023-08-25 20:51:31 -0400196 // if we're downloading a voltha-helm-charts patch, then install from a local copy of the charts
197 Boolean localCharts = false
Joey Armstrongf404b642023-08-04 14:39:13 -0400198
Joey Armstrong0251e962023-08-25 20:51:31 -0400199 if (volthaHelmChartsChange != ''
200 || gerritProject == 'voltha-helm-charts'
201 || isReleaseBranch(branch) // branch != 'master'
202 ) {
203 localCharts = true
204 }
Hardik Windlassec9341b2021-06-07 11:58:29 +0000205
Joey Armstrong0251e962023-08-25 20:51:31 -0400206 String branchName = branchName()
207 Boolean isRelease = isReleaseBranch(branch)
208 println([
209 " ** localCharts=${localCharts}",
210 "branchName=${branchName}",
211 "branch=${branch}",
212 "branch=isReleaseBranch=${isRelease}",
213 ].join(', '))
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800214
Joey Armstrong0251e962023-08-25 20:51:31 -0400215 // -----------------------------------------------------------------------
216 // Rewrite localHelmFlags using array join, moving code around and
217 // refactoring into standalone functions
218 // -----------------------------------------------------------------------
219 // NOTE temporary workaround expose ONOS node ports
220 // -----------------------------------------------------------------------
221 String localHelmFlags = [
222 extraHelmFlags.trim(),
223 "--set global.log_level=${logLevel.toUpperCase()}",
224 '--set onos-classic.onosSshPort=30115',
225 '--set onos-classic.onosApiPort=30120',
226 '--set onos-classic.onosOfPort=31653',
227 '--set onos-classic.individualOpenFlowNodePorts=true',
228 testSpecificHelmFlags
229 ].join(' ')
Joey Armstrong28e86ee2023-08-03 15:22:29 -0400230
Joey Armstrong0251e962023-08-25 20:51:31 -0400231 println("** ${iam} localHelmFlags = ${localHelmFlags}")
Hardik Windlassec9341b2021-06-07 11:58:29 +0000232
Joey Armstrong0251e962023-08-25 20:51:31 -0400233 if (gerritProject != '') {
234 localHelmFlags = "${localHelmFlags} " + getVolthaImageFlags("${gerritProject}")
235 }
Matteo Scandolofcfc60d2021-02-24 09:06:48 -0800236
Joey Armstrong0251e962023-08-25 20:51:31 -0400237 println("** ${iam}: ENTER")
238 volthaDeploy([
239 infraNamespace: infraNamespace,
240 volthaNamespace: volthaNamespace,
241 workflow: workflow.toLowerCase(),
242 withMacLearning: enableMacLearning.toBoolean(),
243 extraHelmFlags: localHelmFlags,
244 localCharts: localCharts,
245 bbsimReplica: olts.toInteger(),
246 dockerRegistry: registry,
247 ])
248 println("** ${iam}: LEAVE")
249 } // script
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400250
Joey Armstrong0251e962023-08-25 20:51:31 -0400251 // -----------------------------------------------------------------------
252 // Intent: Replacing P_IDS with pgrep/pkill is a step forward.
253 // Why not simply use a pid file, capture _TAG=kail-startup above
254 // Grep runs the risk of terminating stray commands (??-good <=> bad-??)
255 // -----------------------------------------------------------------------
256 script {
257 String proc = '_TAG=kail-startup'
258
259 println("${iam}: ENTER")
260 println("${iam}: Shutdown process $proc")
261 pgrep_proc(proc)
262 pkill_proc(proc)
263 pgrep_proc(proc)
264 println("${iam}: LEAVE")
265 }
266
267 // -----------------------------------------------------------------------
268 // Bundle onos-voltha / kail logs
269 // -----------------------------------------------------------------------
270 sh("""
271cat <<EOM
272
273** -----------------------------------------------------------------------
274** Combine an compress voltha startup log(s)
275** -----------------------------------------------------------------------
276EOM
277 pushd "${logsDir}" || { echo "ERROR: pushd $logsDir failed"; exit 1; }
Hardik Windlassec9341b2021-06-07 11:58:29 +0000278 gzip -k onos-voltha-startup-combined.log
279 rm onos-voltha-startup-combined.log
Joey Armstrong0251e962023-08-25 20:51:31 -0400280 popd
281 """)
282 } // timeout(10)
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400283
Joey Armstrong0251e962023-08-25 20:51:31 -0400284 // -----------------------------------------------------------------------
285 // -----------------------------------------------------------------------
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400286 sh """
Hardik Windlassec9341b2021-06-07 11:58:29 +0000287 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"&
288 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"&
289 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"&
290 bbsimDmiPortFwd=50075
291 for i in {0..${olts.toInteger() - 1}}; do
292 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"&
293 ((bbsimDmiPortFwd++))
294 done
Hardik Windlass3bb089a2022-03-22 17:56:03 +0000295 if [ ${withMonitoring} = true ] ; then
296 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"&
297 fi
Hardik Windlassec9341b2021-06-07 11:58:29 +0000298 ps aux | grep port-forward
299 """
Joey Armstrong0251e962023-08-25 20:51:31 -0400300 // ---------------------------------
301 // Sanity check port-forward spawned
302 // ---------------------------------
303 script {
304 enter('port-forward check')
Joey Armstrongebc18022023-08-26 13:20:49 -0400305 // String proc = 'kubectl.*port-forward' // was 'port-forward'
Joey Armstrong0251e962023-08-25 20:51:31 -0400306 String proc = 'port-forward'
307 println("Display spawned ${proc}")
308 pgrep_proc(proc)
309 leave('port-forward check')
310 }
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500311
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400312 // setting ONOS log level
Joey Armstrong0251e962023-08-25 20:51:31 -0400313 script {
314 enter('setOnosLogLevels')
315 setOnosLogLevels([
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400316 onosNamespace: infraNamespace,
317 apps: [
318 'org.opencord.dhcpl2relay',
319 'org.opencord.olt',
320 'org.opencord.aaa',
321 'org.opencord.maclearner',
322 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
323 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
324 ],
325 logLevel: logLevel
326 ])
Joey Armstrong0251e962023-08-25 20:51:31 -0400327 enter('setOnosLogLevels')
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400328 } // script
329 } // if (teardown)
330 } // stage('Deploy Voltha')
331
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400332 // -----------------------------------------------------------------------
333 // -----------------------------------------------------------------------
Joey Armstrongfd896522023-08-04 13:30:48 -0400334 stage("Run test ${testTarget} on workflow ${workflow}")
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400335 {
336 sh """
Joey Armstrong0251e962023-08-25 20:51:31 -0400337 echo -e "\n** Monitor using mem_consumption.py ?"
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400338
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000339 if [ ${withMonitoring} = true ] ; then
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400340 cat <<EOM
341
342** -----------------------------------------------------------------------
343** Monitoring memory usage with mem_consumption.py
344** -----------------------------------------------------------------------
345EOM
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500346 mkdir -p "$WORKSPACE/voltha-pods-mem-consumption-${workflow}"
347 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400348
349 echo '** Installing python virtualenv'
350 make venv-activate-patched
351
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400352 set +u && source .venv/bin/activate && set -u
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000353 # Collect initial memory consumption
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400354 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 +0000355 fi
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400356
357 echo -e '** Monitor memory consumption: LEAVE\n'
Hardik Windlasse1660492022-03-14 15:12:46 +0000358 """
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400359
360 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400361 echo -e "\n** make testTarget=[${testTarget}]"
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700362 mkdir -p ${logsDir}
Hardik Windlassd62442d2021-11-30 10:51:20 +0000363 export ROBOT_MISC_ARGS="-d ${logsDir} ${params.extraRobotArgs} "
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700364 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 +0000365 export KVSTOREPREFIX=voltha/voltha_voltha
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800366
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400367 make -C "$WORKSPACE/voltha-system-tests" ${testTarget}
Hardik Windlass72947302021-06-14 10:36:57 +0000368 """
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400369
370 getPodsInfo("${logsDir}")
371
372 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400373 echo -e '\n** Gather robot Framework logs: ENTER'
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400374 # set +e
Hardik Windlassdad8e5c2021-11-11 05:19:47 +0000375 # collect logs collected in the Robot Framework StartLogging keyword
376 cd ${logsDir}
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400377 gzip *-combined.log
378 rm -f *-combined.log
Joey Armstrong54dec092023-08-03 18:21:38 -0400379
380 echo -e '** Gather robot Framework logs: LEAVE\n'
Hardik Windlassdad8e5c2021-11-11 05:19:47 +0000381 """
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400382
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400383 // -----------------------------------------------------------------------
384 // -----------------------------------------------------------------------
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000385 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400386 echo -e '** Monitor pod-mem-consumption: ENTER'
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000387 if [ ${withMonitoring} = true ] ; then
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400388 cat <<EOM
389
390** -----------------------------------------------------------------------
391** Monitoring pod-memory-consumption using mem_consumption.py
392** -----------------------------------------------------------------------
393EOM
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500394 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400395
396 echo '** Installing python virtualenv'
397 make venv-activate-patched
398
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400399 set +u && source .venv/bin/activate && set -u
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000400 # Collect memory consumption of voltha pods once all the tests are complete
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400401 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 +0000402 fi
Joey Armstrong54dec092023-08-03 18:21:38 -0400403 echo -e '** Monitor pod-mem-consumption: LEAVE\n'
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000404 """
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400405 } // stage
Joey Armstrongb65ada32023-08-03 12:50:20 -0400406
407 return
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400408} // execute_test()
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800409
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400410// -----------------------------------------------------------------------
411// -----------------------------------------------------------------------
Joey Armstrongb65ada32023-08-03 12:50:20 -0400412def collectArtifacts(exitStatus) {
Joey Armstrong0251e962023-08-25 20:51:31 -0400413 script {
414 String iam = getIam('collectArtifacts')
415 println("${iam}: ENTER (exitStatus=${exitStatus})")
416 }
Joey Armstrongcd419122023-08-07 14:56:39 -0400417
Joey Armstrong97a8b882023-08-02 16:08:52 -0400418 echo '''
419
420** -----------------------------------------------------------------------
421** collectArtifacts
422** -----------------------------------------------------------------------
423'''
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400424
Joey Armstrongcd419122023-08-07 14:56:39 -0400425 getPodsInfo("$WORKSPACE/${exitStatus}")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400426
Joey Armstrongcd419122023-08-07 14:56:39 -0400427 sh """
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400428 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log
Hardik Windlassec9341b2021-06-07 11:58:29 +0000429 """
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400430
Joey Armstrongcd419122023-08-07 14:56:39 -0400431 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 -0400432
Joey Armstrong0251e962023-08-25 20:51:31 -0400433 script {
434 println("${iam}: ENTER")
435 pgrep_proc('kail-startup')
436 pkill_proc('kail')
437 println("${iam}: LEAVE")
438 }
Joey Armstrong97a8b882023-08-02 16:08:52 -0400439
Joey Armstrongcd419122023-08-07 14:56:39 -0400440 println("${iam}: ENTER RobotPublisher")
441 step([$class: 'RobotPublisher',
Joey Armstrong0251e962023-08-25 20:51:31 -0400442 disableArchiveOutput: false,
443 logFileName: '**/*/log*.html',
444 otherFiles: '',
445 outputFileName: '**/*/output*.xml',
446 outputPath: '.',
447 passThreshold: 100,
448 reportFileName: '**/*/report*.html',
449 unstableThreshold: 0,
450 onlyCritical: true])
Joey Armstrongcd419122023-08-07 14:56:39 -0400451 println("${iam}: LEAVE RobotPublisher")
452
453 println("${iam}: LEAVE (exitStatus=${exitStatus})")
454 return
Hardik Windlassec9341b2021-06-07 11:58:29 +0000455}
456
Joey Armstrongb65ada32023-08-03 12:50:20 -0400457// -----------------------------------------------------------------------
458// Intent: main
459// -----------------------------------------------------------------------
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800460pipeline {
Joey Armstrong0251e962023-08-25 20:51:31 -0400461 /* no label, executor is determined by JJB */
462 agent {
463 label "${params.buildNode}"
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800464 }
Joey Armstrong84adc542023-04-11 14:47:34 -0400465
Joey Armstrong0251e962023-08-25 20:51:31 -0400466 options {
467 timeout(time: "${timeout}", unit: 'MINUTES')
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800468 }
Joey Armstronged161f72023-04-11 13:16:59 -0400469
Joey Armstrong0251e962023-08-25 20:51:31 -0400470 environment {
471 KUBECONFIG = "$HOME/.kube/kind-${clusterName}"
472 VOLTCONFIG = "$HOME/.volt/config"
473 PATH = "$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
474 DIAGS_PROFILE = 'VOLTHA_PROFILE'
475 SSHPASS = 'karaf'
476 }
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400477
Joey Armstrong0251e962023-08-25 20:51:31 -0400478 stages {
479 stage('Download Code') {
Joey Armstrongf404b642023-08-04 14:39:13 -0400480 steps {
Joey Armstrong0251e962023-08-25 20:51:31 -0400481 getVolthaCode([
482 branch: "${branch}",
483 gerritProject: "${gerritProject}",
484 gerritRefspec: "${gerritRefspec}",
485 volthaSystemTestsChange: "${volthaSystemTestsChange}",
486 volthaHelmChartsChange: "${volthaHelmChartsChange}",
487 ])
488 }
489 }
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400490
Joey Armstrong0251e962023-08-25 20:51:31 -0400491 stage('Build patch v1.1') {
492 // build the patch only if gerritProject is specified
493 when {
494 expression { return !gerritProject.isEmpty() }
495 }
496
497 steps {
498 // NOTE that the correct patch has already been checked out
499 // during the getVolthaCode step
500 buildVolthaComponent("${gerritProject}")
501 }
502 }
503
504 // -----------------------------------------------------------------------
505 // -----------------------------------------------------------------------
506 stage('Install Kail')
507 {
508 steps
509 {
510 script
511 {
512 String cmd = [
513 'make',
514 '--no-print-directory',
515 '-C', "$WORKSPACE/voltha-system-tests",
516 "KAIL_PATH=\"$WORKSPACE/bin\"",
517 'kail',
518 ].join(' ')
519
520 println(" ** Running: ${cmd}")
521 sh("${cmd}")
522 } // script
523 } // steps
524 } // stage
525
526 // -----------------------------------------------------------------------
527 // -----------------------------------------------------------------------
528 stage('Install Tools') {
529 steps {
530 script {
531 String branchName = branchName()
532 String iam = getIam('Install Tools')
533
534 println("${iam}: ENTER (branch=$branch)")
535 installKind(branch) // needed early by stage(Cleanup)
536 println("${iam}: LEAVE (branch=$branch)")
537 } // script
538 } // steps
539 } // stage
540
541 // -----------------------------------------------------------------------
542 // -----------------------------------------------------------------------
543 stage('Create K8s Cluster') {
544 steps {
545 script {
546 def clusterExists = sh(
547 returnStdout: true,
548 script: """kind get clusters | grep "${clusterName}" | wc -l""")
549
550 if (clusterExists.trim() == '0') {
551 createKubernetesCluster([nodes: 3, name: clusterName])
552 }
553 } // script
554 } // steps
555 } // stage('Create K8s Cluster')
556
557 // -----------------------------------------------------------------------
558 // -----------------------------------------------------------------------
559 stage('Replace voltctl') {
560 // if the project is voltctl, override the downloaded one with the built one
561 when {
562 expression { return gerritProject == 'voltctl' }
563 }
564
565 // Hmmmm(?) where did the voltctl download happen ?
566 // Likely Makefile but would be helpful to document here.
567 steps {
568 script {
569 String iam = getIam('Replace voltctl')
570
571 println("${iam} Running: installVoltctl($branch)")
572 println("${iam}: ENTER")
573 installVoltctl("$branch")
574 println("${iam}: LEAVE")
575 } // script
576 } // step
577 } // stage
578
579 // -----------------------------------------------------------------------
580 // -----------------------------------------------------------------------
581 stage('Load image in kind nodes')
582 {
583 when {
584 expression { return !gerritProject.isEmpty() }
585 }
586 steps {
587 loadToKind()
588 } // steps
589 } // stage
590
591 // -----------------------------------------------------------------------
592 // [TODO] verify testing output
593 // -----------------------------------------------------------------------
594 stage('Parse and execute tests')
595 {
596 steps {
597 script {
598 // Announce ourselves for log usability
599 enter('Parse and execute tests')
600
601 def tests = readYaml text: testTargets
602 println("** [DEBUG]: tests=$tests")
603
604 // Display expected tests for times when output goes dark
605 tests.eachWithIndex { test, idx ->
606 String target = test['target']
607 println("** test[${idx}]: ${target}\n")
608 }
609
610 println('''
611** -----------------------------------------------------------------------
612** NOTE: For odd/silent job failures verify a few details
613** - All tests mentioned in the tests-to-run index were logged.
614** - Test suites display ENTER/LEAVE mesasge pairs.
615** - Processing terminated prematurely when LEAVE strings are missing.
616** -----------------------------------------------------------------------
617''')
618 tests.eachWithIndex { test, idx ->
619 println "** readYaml test suite[$idx]) test=[${test}]"
620
Joey Armstrongf404b642023-08-04 14:39:13 -0400621 String target = test['target']
622 String workflow = test['workflow']
623 String flags = test['flags']
624 Boolean teardown = test['teardown'].toBoolean()
625 Boolean logging = test['logging'].toBoolean()
626 String testLogging = (logging) ? 'True' : 'False'
627
Joey Armstrong0251e962023-08-25 20:51:31 -0400628 print("""
Joey Armstrong268442d2023-08-22 17:16:10 -0400629** -----------------------------------------------------------------------
Joey Armstrong0251e962023-08-25 20:51:31 -0400630** Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}
Joey Armstrong268442d2023-08-22 17:16:10 -0400631** -----------------------------------------------------------------------
Joey Armstrong268442d2023-08-22 17:16:10 -0400632""")
633
Joey Armstrong0251e962023-08-25 20:51:31 -0400634 try {
635 leave("execute_test (target=$target)")
636 execute_test(target, workflow, testLogging, teardown, flags)
637 }
638 catch (Exception err) {
639 println("** ${iam}: EXCEPTION ${err}")
640 }
641 finally {
642 leave("execute_test (target=$target)")
643 }
Joey Armstrongb65ada32023-08-03 12:50:20 -0400644 } // for
Joey Armstrong0251e962023-08-25 20:51:31 -0400645 // Premature exit if this message is not logged
646 leave('Parse and execute tests')
Joey Armstrongb65ada32023-08-03 12:50:20 -0400647 } // script
648 } // steps
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400649 } // stage
650 } // stages
Joey Armstrong84adc542023-04-11 14:47:34 -0400651
652 post
653 {
654 aborted { collectArtifacts('aborted') }
655 failure { collectArtifacts('failed') }
Joey Armstrongbf492922023-04-13 17:05:09 -0400656 always { collectArtifacts('always') }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800657 }
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400658} // pipeline
Joey Armstronged161f72023-04-11 13:16:59 -0400659
Joey Armstrong0251e962023-08-25 20:51:31 -0400660// [EOF] - 2