blob: 2fe0a16aff407a2768008694b7deb9bce804740c [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// -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -040072// -----------------------------------------------------------------------
73void pgrep_proc(String proc)
74{
75 println("** Running: pgrep --list-full ${proc}")
76 sh("""pgrep --list-full "${proc}" || true""")
77 return
78}
79
80// -----------------------------------------------------------------------
81// -----------------------------------------------------------------------
82void pkill_proc(String proc)
83{
84 println("** Running: pkill ${proc}")
85 sh(""" [[ \$(pgrep --count "${proc}") -gt 0 ]] && pkill --echo "${proc}" """)
86 return
87}
88
89// -----------------------------------------------------------------------
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040090// Intent:
91// -----------------------------------------------------------------------
Joey Armstrong54dec092023-08-03 18:21:38 -040092void execute_test(testTarget, workflow, testLogging, teardown, testSpecificHelmFlags='')
Joey Armstrong7bcb5782023-06-07 12:25:57 -040093{
Joey Armstrong54dec092023-08-03 18:21:38 -040094 String infraNamespace = 'default'
95 String volthaNamespace = 'voltha'
96 String logsDir = "$WORKSPACE/${testTarget}"
Joey Armstrong7bcb5782023-06-07 12:25:57 -040097
98 stage('IAM')
99 {
100 script
101 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400102 // Announce ourselves for log usability
Joey Armstrong642540a2023-08-10 10:26:36 -0400103 String iam = getIam('execute_test')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400104 println("${iam}: ENTER")
105 println("${iam}: LEAVE")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400106 }
107 }
Joey Armstrong54dec092023-08-03 18:21:38 -0400108
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400109 // -----------------------------------------------------------------------
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400110 // Intent: Cleanup stale port-forwarding
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400111 // -----------------------------------------------------------------------
112 stage('Cleanup')
113 {
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400114 if (teardown) {
115 timeout(15) {
116 script {
Joey Armstrong54dec092023-08-03 18:21:38 -0400117 helmTeardown(['default', infraNamespace, volthaNamespace])
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400118 }
Joey Armstrongf060aee2023-08-22 21:55:26 -0400119 } // timeout
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400120
Joey Armstrongf060aee2023-08-22 21:55:26 -0400121 timeout(5) {
122 script {
123 String iam = getIam('Cleanup')
124 println("${iam}: ENTER")
Joey Armstrong268442d2023-08-22 17:16:10 -0400125
Joey Armstrongf060aee2023-08-22 21:55:26 -0400126 // remove orphaned port-forward from different namespaces
127 String proc = 'port-forw'
128 pgrep_proc(proc)
129 pkill_proc(proc)
Joey Armstrong268442d2023-08-22 17:16:10 -0400130
Joey Armstrongf060aee2023-08-22 21:55:26 -0400131 // Sanity check processes terminated
132 sh("""
133[[ \$(pgrep --count "${proc}") -gt 0 ]] && { \
134 echo "ERROR: Detected zombie port-forwarding processes"
135 pgrep --list-full "${proc}" || true ; }
136""")
137 println("${iam}: LEAVE")
138 } // script
139 } // timeout
140 } // teardown
141 } // stage
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400142
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400143 // -----------------------------------------------------------------------
144 // -----------------------------------------------------------------------
145 stage('Deploy common infrastructure')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400146 {
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400147 script
148 {
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('''
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400163 helm repo add onf https://charts.opencord.org
164 helm repo update
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400165
166 echo -e "\nwithMonitoring=[$withMonitoring]"
167 if [ ${withMonitoring} = true ] ; then
168 helm install nem-monitoring onf/nem-monitoring \
169 --set $promargs \
170 --set $dashargs
171 fi
172 ''')
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400173 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400174 }
175
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400176 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400177 // [TODO] Check onos_log output
178 // [TODO] kail-startup pgrep/pkill
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400179 // -----------------------------------------------------------------------
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400180 stage('Deploy Voltha')
181 {
182 if (teardown)
183 {
184 timeout(10)
185 {
186 script
187 {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400188 String iam = getIam('Deploy Voltha')
189 String combinedLog = "${logsDir}/onos-voltha-startup-combined.log"
190sh("""
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400191 mkdir -p ${logsDir}
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400192 onos_log="${logsDir}/onos-voltha-startup-combined.log"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400193 touch "$onos_log
Joey Armstrongdddbbf92023-08-22 16:00:41 -0400194 echo "** kail-startup ENTER: \$(date)" > "$onos_log"
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400195
196 # Intermixed output (tee -a &) may get conflusing but let(s) see
197 # what messages are logged during startup.
198 # _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} >> "$onos_log" &
199 _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} | tee -a "$onos_log" &
200 """)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400201
Joey Armstrongdddbbf92023-08-22 16:00:41 -0400202 // 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 -0400203 Boolean localCharts = false
Joey Armstrong642540a2023-08-10 10:26:36 -0400204
Joey Armstrong54dec092023-08-03 18:21:38 -0400205 if (volthaHelmChartsChange != ''
206 || gerritProject == 'voltha-helm-charts'
207 || isReleaseBranch(branch) // branch != 'master'
208 ) {
209 localCharts = true
210 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400211
Joey Armstrong54dec092023-08-03 18:21:38 -0400212 String branchName = branchName()
213 Boolean is_release = isReleaseBranch(branch)
214 println([
215 " ** localCharts=${localCharts}",
216 "branchName=${branchName}",
217 "branch=${branch}",
218 "branch=isReleaseBranch=${is_release}",
219 ].join(', '))
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400220
Joey Armstrong54dec092023-08-03 18:21:38 -0400221 // -----------------------------------------------------------------------
222 // Rewrite localHelmFlags using array join, moving code around and
Joey Armstrong642540a2023-08-10 10:26:36 -0400223 // refactoring into standalone functions
Joey Armstrong54dec092023-08-03 18:21:38 -0400224 // -----------------------------------------------------------------------
225 // hudson.remoting.ProxyException: groovy.lang.MissingMethodException:
226 // No signature of method: java.lang.String.positive() is applicable for argument types: () values: []
227 // -----------------------------------------------------------------------
228 // NOTE temporary workaround expose ONOS node ports
229 // -----------------------------------------------------------------------
230 String localHelmFlags = [
231 extraHelmFlags.trim(),
232 "--set global.log_level=${logLevel.toUpperCase()}",
233 '--set onos-classic.onosSshPort=30115',
234 '--set onos-classic.onosApiPort=30120',
235 '--set onos-classic.onosOfPort=31653',
236 '--set onos-classic.individualOpenFlowNodePorts=true',
237 testSpecificHelmFlags
238 ].join(' ')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400239
Joey Armstrongf060aee2023-08-22 21:55:26 -0400240 println("** ${iam} localHelmFlags = ${localHelmFlags}")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400241
Joey Armstrong54dec092023-08-03 18:21:38 -0400242 if (gerritProject != '') {
243 localHelmFlags = "${localHelmFlags} " + getVolthaImageFlags("${gerritProject}")
244 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400245
Joey Armstrongf060aee2023-08-22 21:55:26 -0400246 println('** ${iam}: ENTER')
Joey Armstrong54dec092023-08-03 18:21:38 -0400247 volthaDeploy([
248 infraNamespace: infraNamespace,
249 volthaNamespace: volthaNamespace,
250 workflow: workflow.toLowerCase(),
251 withMacLearning: enableMacLearning.toBoolean(),
252 extraHelmFlags: localHelmFlags,
253 localCharts: localCharts,
254 bbsimReplica: olts.toInteger(),
255 dockerRegistry: registry,
256 ])
Joey Armstrongf060aee2023-08-22 21:55:26 -0400257 println('** ${iam}: LEAVE')
Joey Armstrong54dec092023-08-03 18:21:38 -0400258 } // script
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400259
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400260 // -----------------------------------------------------------------------
261 // Intent: Replacing P_IDS with pgrep/pkill is a step forward.
262 // Why not simply use a pid file, capture _TAG=kail-startup above
263 // Grep runs the risk of terminating stray commands (??-good <=> bad-??)
Joey Armstrong54dec092023-08-03 18:21:38 -0400264 // -----------------------------------------------------------------------
265 script {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400266 pgrep_proc('kail-startup')
Joey Armstrongdddbbf92023-08-22 16:00:41 -0400267
268 println('''
269
270** -----------------------------------------------------------------------
271** Raw ps process list for kail-startup (WIP)
272** -----------------------------------------------------------------------
273''')
274 sh('''ps e -ww -A | grep "_TAG=kail-startup"''')
Joey Armstronged345862023-08-23 12:24:20 -0400275 } // script
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400276
Joey Armstrongf060aee2023-08-22 21:55:26 -0400277 // -----------------------------------------------------------------------
Joey Armstronged345862023-08-23 12:24:20 -0400278 // stop logging
279 // [TODO] Replace this block with pgrep/pkill one-liner(s)
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400280 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400281 sh("""
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400282 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-startup" | grep -v grep | awk '{print \$1}')"
283 if [ -n "\$P_IDS" ]; then
284 echo \$P_IDS
285 for P_ID in \$P_IDS; do
286 kill -9 \$P_ID
287 done
288 fi
Joey Armstrongf060aee2023-08-22 21:55:26 -0400289""")
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400290
Joey Armstronged345862023-08-23 12:24:20 -0400291 // -----------------------------------------------------------------------
292 // Bundle onos-voltha / kail logs
293 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400294 sh("""
295cat <<EOM
296
297** -----------------------------------------------------------------------
298** Combine an compress voltha startup log(s)
299** -----------------------------------------------------------------------
300EOM
301 pushd "${logsDir}" || { echo "ERROR: pushd $logsDir failed"; exit 1; }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400302 gzip -k onos-voltha-startup-combined.log
303 rm onos-voltha-startup-combined.log
Joey Armstrongf060aee2023-08-22 21:55:26 -0400304 popd
305 """)
Joey Armstronged345862023-08-23 12:24:20 -0400306 } // timeout(10)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400307
Joey Armstrongf060aee2023-08-22 21:55:26 -0400308
309 // -----------------------------------------------------------------------
310 // -----------------------------------------------------------------------
311 sh """
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400312 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"&
313 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"&
314 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"&
315 bbsimDmiPortFwd=50075
316 for i in {0..${olts.toInteger() - 1}}; do
317 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"&
318 ((bbsimDmiPortFwd++))
319 done
320 if [ ${withMonitoring} = true ] ; then
321 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"&
322 fi
323 ps aux | grep port-forward
324 """
Joey Armstrongf060aee2023-08-22 21:55:26 -0400325 // [TODO] pgrep_proc('port-forward')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400326
Joey Armstrongf060aee2023-08-22 21:55:26 -0400327
328 // setting ONOS log level
329 script {
330 println('** setOnosLogLevels: ENTER')
Joey Armstrong54dec092023-08-03 18:21:38 -0400331 setOnosLogLevels([
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400332 onosNamespace: infraNamespace,
333 apps: [
334 'org.opencord.dhcpl2relay',
335 'org.opencord.olt',
336 'org.opencord.aaa',
337 'org.opencord.maclearner',
338 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
339 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
340 ],
341 logLevel: logLevel
342 ])
Joey Armstrongf060aee2023-08-22 21:55:26 -0400343 println('** setOnosLogLevels: LEAVE')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400344 } // script
345 } // if (teardown)
346 } // stage('Deploy Voltha')
347
Joey Armstrongf060aee2023-08-22 21:55:26 -0400348 // -----------------------------------------------------------------------
349 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400350 stage("Run test ${testTarget} on workflow ${workflow}")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400351 {
352 sh """
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400353 echo -e "\n** Monitor using mem_consumption.py ?"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400354
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400355 if [ ${withMonitoring} = true ] ; then
Joey Armstrongf060aee2023-08-22 21:55:26 -0400356 cat <<EOM
357
358** -----------------------------------------------------------------------
359** Monitoring memory usage with mem_consumption.py
360** -----------------------------------------------------------------------
361EOM
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400362 mkdir -p "$WORKSPACE/voltha-pods-mem-consumption-${workflow}"
363 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400364
365 echo '** Installing python virtualenv'
366 make venv-activate-patched
367
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400368 set +u && source .venv/bin/activate && set -u
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400369 # Collect initial memory consumption
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400370 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 -0400371 fi
Joey Armstrongf060aee2023-08-22 21:55:26 -0400372
373 echo -e '** Monitor memory consumption: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400374 """
375
376 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400377 echo -e "\n** make testTarget=[${testTarget}]"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400378 mkdir -p ${logsDir}
379 export ROBOT_MISC_ARGS="-d ${logsDir} ${params.extraRobotArgs} "
380 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}"
381 export KVSTOREPREFIX=voltha/voltha_voltha
382
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400383 make -C "$WORKSPACE/voltha-system-tests" ${testTarget}
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400384 """
385
386 getPodsInfo("${logsDir}")
387
388 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400389 echo -e '\n** Gather robot Framework logs: ENTER'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400390 # set +e
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400391 # collect logs collected in the Robot Framework StartLogging keyword
392 cd ${logsDir}
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400393 gzip *-combined.log
394 rm -f *-combined.log
Joey Armstrong54dec092023-08-03 18:21:38 -0400395
396 echo -e '** Gather robot Framework logs: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400397 """
398
Joey Armstrongf060aee2023-08-22 21:55:26 -0400399 // -----------------------------------------------------------------------
400 // -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400401 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400402 echo -e '** Monitor pod-mem-consumption: ENTER'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400403 if [ ${withMonitoring} = true ] ; then
Joey Armstrongf060aee2023-08-22 21:55:26 -0400404 cat <<EOM
405
406** -----------------------------------------------------------------------
407** Monitoring pod-memory-consumption using mem_consumption.py
408** -----------------------------------------------------------------------
409EOM
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400410 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400411
412 echo '** Installing python virtualenv'
413 make venv-activate-patched
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400414 set +u && source .venv/bin/activate && set -u
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400415 # Collect memory consumption of voltha pods once all the tests are complete
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400416 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 -0400417 fi
Joey Armstrong54dec092023-08-03 18:21:38 -0400418 echo -e '** Monitor pod-mem-consumption: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400419 """
420 } // stage
Joey Armstrong54dec092023-08-03 18:21:38 -0400421
422 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400423} // execute_test()
424
425// -----------------------------------------------------------------------
426// -----------------------------------------------------------------------
Joey Armstrong54dec092023-08-03 18:21:38 -0400427def collectArtifacts(exitStatus) {
Joey Armstrong642540a2023-08-10 10:26:36 -0400428 String iam = getIam('execute_test')
429
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400430 echo '''
431
432** -----------------------------------------------------------------------
433** collectArtifacts
434** -----------------------------------------------------------------------
435'''
Joey Armstrong642540a2023-08-10 10:26:36 -0400436 println("${iam}: ENTER (exitStatus=${exitStatus})")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400437
Joey Armstrong642540a2023-08-10 10:26:36 -0400438 getPodsInfo("$WORKSPACE/${exitStatus}")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400439
Joey Armstrong642540a2023-08-10 10:26:36 -0400440 sh """
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400441 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400442 """
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400443
Joey Armstrong642540a2023-08-10 10:26:36 -0400444 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 -0400445
Joey Armstrong642540a2023-08-10 10:26:36 -0400446 sh(returnStdout:true, script: '''
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400447 sync
Joey Armstrong642540a2023-08-10 10:26:36 -0400448 echo '** Running: pgrep --list-full kail-startup (ENTER)'
449 pgrep --list-full 'kail-startup' || true
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400450 [[ $(pgrep --count kail) -gt 0 ]] && pkill --echo kail
Joey Armstrong642540a2023-08-10 10:26:36 -0400451 echo '** Running: pgrep --list-full kail-startup (LEAVE)'
452 ''')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400453
Joey Armstrong642540a2023-08-10 10:26:36 -0400454 println("${iam}: ENTER RobotPublisher")
455 step([$class: 'RobotPublisher',
456 disableArchiveOutput: false,
457 logFileName: '**/*/log*.html',
458 otherFiles: '',
459 outputFileName: '**/*/output*.xml',
460 outputPath: '.',
461 passThreshold: 100,
462 reportFileName: '**/*/report*.html',
463 unstableThreshold: 0,
464 onlyCritical: true]);
465 println("${iam}: LEAVE RobotPublisher")
466
467 println("${iam}: LEAVE (exitStatus=${exitStatus})")
468 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400469}
470
Joey Armstrong54dec092023-08-03 18:21:38 -0400471// -----------------------------------------------------------------------
472// Intent: main
473// -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400474pipeline {
475
476 /* no label, executor is determined by JJB */
477 agent {
478 label "${params.buildNode}"
479 }
480 options {
481 timeout(time: "${timeout}", unit: 'MINUTES')
482 }
483 environment {
Joey Armstrong642540a2023-08-10 10:26:36 -0400484 KUBECONFIG = "$HOME/.kube/kind-${clusterName}"
485 VOLTCONFIG = "$HOME/.volt/config"
486 PATH = "$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
487 DIAGS_PROFILE = 'VOLTHA_PROFILE'
488 SSHPASS = 'karaf'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400489 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400490
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400491 stages {
492 stage('Download Code') {
493 steps {
494 getVolthaCode([
495 branch: "${branch}",
496 gerritProject: "${gerritProject}",
497 gerritRefspec: "${gerritRefspec}",
498 volthaSystemTestsChange: "${volthaSystemTestsChange}",
499 volthaHelmChartsChange: "${volthaHelmChartsChange}",
500 ])
501 }
502 }
503
504 stage('Build patch v1.1')
505 {
506 // build the patch only if gerritProject is specified
507 when
508 {
509 expression
510 {
511 return !gerritProject.isEmpty()
512 }
513 }
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400514
515 steps
516 {
517 // NOTE that the correct patch has already been checked out
518 // during the getVolthaCode step
519 buildVolthaComponent("${gerritProject}")
520 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400521 }
522
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400523 // -----------------------------------------------------------------------
524 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400525 stage('Install Kail')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400526 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400527 steps
528 {
529 script
530 {
531 String cmd = [
532 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400533 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400534 '-C', "$WORKSPACE/voltha-system-tests",
535 "KAIL_PATH=\"$WORKSPACE/bin\"",
536 'kail',
537 ].join(' ')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400538
Joey Armstrongf060aee2023-08-22 21:55:26 -0400539 println(" ** Running: ${cmd}")
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400540 sh("${cmd}")
541 } // script
542 } // steps
543 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400544
545 // -----------------------------------------------------------------------
546 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400547 stage('Install Kind')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400548 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400549 steps
550 {
551 script
552 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400553
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400554 String cmd = [
555 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400556 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400557 '-C', "$WORKSPACE/voltha-system-tests",
558 "KIND_PATH=\"$WORKSPACE/bin\"",
559 'install-command-kind',
560 ].join(' ')
Joey Armstrong642540a2023-08-10 10:26:36 -0400561
Joey Armstrongf060aee2023-08-22 21:55:26 -0400562 println(" ** Running: ${cmd}")
563 sh("${cmd}")
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400564 } // script
565 } // steps
566 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400567
568 // -----------------------------------------------------------------------
569 // -----------------------------------------------------------------------
570 stage('Create K8s Cluster')
571 {
572 steps
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400573 {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400574 script
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400575 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400576 def clusterExists = sh(
Joey Armstrongf060aee2023-08-22 21:55:26 -0400577 returnStdout: true,
578 script: """kind get clusters | grep "${clusterName}" | wc -l""")
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400579
Joey Armstrong54dec092023-08-03 18:21:38 -0400580 if (clusterExists.trim() == '0')
Joey Armstrongf060aee2023-08-22 21:55:26 -0400581 {
582 createKubernetesCluster([nodes: 3, name: clusterName])
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400583 }
Joey Armstrongf060aee2023-08-22 21:55:26 -0400584 } // script
585 } // steps
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400586 } // stage('Create K8s Cluster')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400587
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400588 // -----------------------------------------------------------------------
589 // -----------------------------------------------------------------------
590 stage('Replace voltctl')
591 {
592 // if the project is voltctl, override the downloaded one with the built one
593 when {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400594 expression { return gerritProject == 'voltctl' }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400595 }
596
597 // Hmmmm(?) where did the voltctl download happen ?
598 // Likely Makefile but would be helpful to document here.
599 steps
600 {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400601 println("${iam} Running: installVoltctl($branch)")
602 installVoltctl("$branch")
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400603 } // steps
604 } // stage
605
606 // -----------------------------------------------------------------------
607 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400608 stage('voltctl [DEBUG]') {
609 steps {
610 script {
611 String iam = getIam('execute_test')
612
613 println("${iam} Display umask")
614 sh('umask')
615
616 println("${iam} Checking voltctl config permissions")
617 sh('/bin/ls -ld ~/.volt ~/.volt/* || true')
618 } // script
Joey Armstrong268442d2023-08-22 17:16:10 -0400619 } // steps
620 } // stage
621
622 // -----------------------------------------------------------------------
623 // -----------------------------------------------------------------------
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400624 stage('Load image in kind nodes')
625 {
626 when {
627 expression { return !gerritProject.isEmpty() }
628 }
629 steps {
630 loadToKind()
631 } // steps
632 } // stage
633
634 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400635 // [TODO] verify testing output
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400636 // -----------------------------------------------------------------------
637 stage('Parse and execute tests')
638 {
639 steps {
640 script {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400641 // Announce ourselves for log usability
642 String iam = getIam('execute_test')
643 println("${iam}: ENTER")
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400644
645 def tests = readYaml text: testTargets
646
647 println("** $iam: Testing index: tests-to-run")
648 tests.eachWithIndex { test, idx ->
649 String target = test['target']
650 println("** $idx: $target")
Joey Armstrong642540a2023-08-10 10:26:36 -0400651 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400652 println("** NOTE: For odd failures compare tests-to-run with teste output")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400653
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400654 tests.eachWithIndex { test, idx ->
655 println "** readYaml test suite[$idx]) test=[${test}]"
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400656
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400657 String target = test['target']
658 String workflow = test['workflow']
659 String flags = test['flags']
660 Boolean teardown = test['teardown'].toBoolean()
661 Boolean logging = test['logging'].toBoolean()
662 String testLogging = (logging) ? 'True' : 'False'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400663
Joey Armstrong268442d2023-08-22 17:16:10 -0400664 print("""
Joey Armstrong268442d2023-08-22 17:16:10 -0400665** -----------------------------------------------------------------------
666** Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}"
667** -----------------------------------------------------------------------
Joey Armstrong268442d2023-08-22 17:16:10 -0400668)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400669
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400670 try {
671 println "Executing test ${target}: ENTER"
672 execute_test(target, workflow, testLogging, teardown, flags)
673 }
674 catch (Exception err) {
675 println("** ${iam}: EXCEPTION ${err}")
676 }
677 finally {
678 println "Executing test ${target}: LEAVE"
679 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400680
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400681 } // for
Joey Armstrong642540a2023-08-10 10:26:36 -0400682
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400683 // Premature exit if this message is not logged
684 println("${iam}: LEAVE (testing ran to completion)")
Joey Armstrong54dec092023-08-03 18:21:38 -0400685 } // script
686 } // steps
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400687 } // stage
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400688 } // stages
689
690 post
691 {
692 aborted { collectArtifacts('aborted') }
693 failure { collectArtifacts('failed') }
694 always { collectArtifacts('always') }
695 }
696} // pipeline
697
698// EOF