blob: 0023c04c3ac13fd6d83d0e8720890a390607e547 [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 Armstrong54dec092023-08-03 18:21:38 -0400275 }
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400276
Joey Armstrongf060aee2023-08-22 21:55:26 -0400277 // -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400278 // stop logging
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400279 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400280 sh("""
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400281 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-startup" | grep -v grep | awk '{print \$1}')"
282 if [ -n "\$P_IDS" ]; then
283 echo \$P_IDS
284 for P_ID in \$P_IDS; do
285 kill -9 \$P_ID
286 done
287 fi
Joey Armstrongf060aee2023-08-22 21:55:26 -0400288""")
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400289
Joey Armstrongf060aee2023-08-22 21:55:26 -0400290 sh("""
291cat <<EOM
292
293** -----------------------------------------------------------------------
294** Combine an compress voltha startup log(s)
295** -----------------------------------------------------------------------
296EOM
297 pushd "${logsDir}" || { echo "ERROR: pushd $logsDir failed"; exit 1; }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400298 gzip -k onos-voltha-startup-combined.log
299 rm onos-voltha-startup-combined.log
Joey Armstrongf060aee2023-08-22 21:55:26 -0400300 popd
301 """)
302 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400303
Joey Armstrongf060aee2023-08-22 21:55:26 -0400304
305 // -----------------------------------------------------------------------
306 // -----------------------------------------------------------------------
307 sh """
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400308 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"&
309 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"&
310 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"&
311 bbsimDmiPortFwd=50075
312 for i in {0..${olts.toInteger() - 1}}; do
313 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"&
314 ((bbsimDmiPortFwd++))
315 done
316 if [ ${withMonitoring} = true ] ; then
317 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"&
318 fi
319 ps aux | grep port-forward
320 """
Joey Armstrongf060aee2023-08-22 21:55:26 -0400321 // [TODO] pgrep_proc('port-forward')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400322
Joey Armstrongf060aee2023-08-22 21:55:26 -0400323
324 // setting ONOS log level
325 script {
326 println('** setOnosLogLevels: ENTER')
Joey Armstrong54dec092023-08-03 18:21:38 -0400327 setOnosLogLevels([
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400328 onosNamespace: infraNamespace,
329 apps: [
330 'org.opencord.dhcpl2relay',
331 'org.opencord.olt',
332 'org.opencord.aaa',
333 'org.opencord.maclearner',
334 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
335 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
336 ],
337 logLevel: logLevel
338 ])
Joey Armstrongf060aee2023-08-22 21:55:26 -0400339 println('** setOnosLogLevels: LEAVE')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400340 } // script
341 } // if (teardown)
342 } // stage('Deploy Voltha')
343
Joey Armstrongf060aee2023-08-22 21:55:26 -0400344 // -----------------------------------------------------------------------
345 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400346 stage("Run test ${testTarget} on workflow ${workflow}")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400347 {
348 sh """
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400349 echo -e "\n** Monitor using mem_consumption.py ?"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400350
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400351 if [ ${withMonitoring} = true ] ; then
Joey Armstrongf060aee2023-08-22 21:55:26 -0400352 cat <<EOM
353
354** -----------------------------------------------------------------------
355** Monitoring memory usage with mem_consumption.py
356** -----------------------------------------------------------------------
357EOM
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400358 mkdir -p "$WORKSPACE/voltha-pods-mem-consumption-${workflow}"
359 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400360
361 echo '** Installing python virtualenv'
362 make venv-activate-patched
363
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400364 set +u && source .venv/bin/activate && set -u
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400365 # Collect initial memory consumption
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400366 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 -0400367 fi
Joey Armstrongf060aee2023-08-22 21:55:26 -0400368
369 echo -e '** Monitor memory consumption: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400370 """
371
372 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400373 echo -e "\n** make testTarget=[${testTarget}]"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400374 mkdir -p ${logsDir}
375 export ROBOT_MISC_ARGS="-d ${logsDir} ${params.extraRobotArgs} "
376 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}"
377 export KVSTOREPREFIX=voltha/voltha_voltha
378
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400379 make -C "$WORKSPACE/voltha-system-tests" ${testTarget}
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400380 """
381
382 getPodsInfo("${logsDir}")
383
384 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400385 echo -e '\n** Gather robot Framework logs: ENTER'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400386 # set +e
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400387 # collect logs collected in the Robot Framework StartLogging keyword
388 cd ${logsDir}
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400389 gzip *-combined.log
390 rm -f *-combined.log
Joey Armstrong54dec092023-08-03 18:21:38 -0400391
392 echo -e '** Gather robot Framework logs: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400393 """
394
Joey Armstrongf060aee2023-08-22 21:55:26 -0400395 // -----------------------------------------------------------------------
396 // -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400397 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400398 echo -e '** Monitor pod-mem-consumption: ENTER'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400399 if [ ${withMonitoring} = true ] ; then
Joey Armstrongf060aee2023-08-22 21:55:26 -0400400 cat <<EOM
401
402** -----------------------------------------------------------------------
403** Monitoring pod-memory-consumption using mem_consumption.py
404** -----------------------------------------------------------------------
405EOM
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400406 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400407
408 echo '** Installing python virtualenv'
409 make venv-activate-patched
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400410 set +u && source .venv/bin/activate && set -u
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400411 # Collect memory consumption of voltha pods once all the tests are complete
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400412 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 -0400413 fi
Joey Armstrong54dec092023-08-03 18:21:38 -0400414 echo -e '** Monitor pod-mem-consumption: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400415 """
416 } // stage
Joey Armstrong54dec092023-08-03 18:21:38 -0400417
418 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400419} // execute_test()
420
421// -----------------------------------------------------------------------
422// -----------------------------------------------------------------------
Joey Armstrong54dec092023-08-03 18:21:38 -0400423def collectArtifacts(exitStatus) {
Joey Armstrong642540a2023-08-10 10:26:36 -0400424 String iam = getIam('execute_test')
425
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400426 echo '''
427
428** -----------------------------------------------------------------------
429** collectArtifacts
430** -----------------------------------------------------------------------
431'''
Joey Armstrong642540a2023-08-10 10:26:36 -0400432 println("${iam}: ENTER (exitStatus=${exitStatus})")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400433
Joey Armstrong642540a2023-08-10 10:26:36 -0400434 getPodsInfo("$WORKSPACE/${exitStatus}")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400435
Joey Armstrong642540a2023-08-10 10:26:36 -0400436 sh """
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400437 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400438 """
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400439
Joey Armstrong642540a2023-08-10 10:26:36 -0400440 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 -0400441
Joey Armstrong642540a2023-08-10 10:26:36 -0400442 sh(returnStdout:true, script: '''
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400443 sync
Joey Armstrong642540a2023-08-10 10:26:36 -0400444 echo '** Running: pgrep --list-full kail-startup (ENTER)'
445 pgrep --list-full 'kail-startup' || true
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400446 [[ $(pgrep --count kail) -gt 0 ]] && pkill --echo kail
Joey Armstrong642540a2023-08-10 10:26:36 -0400447 echo '** Running: pgrep --list-full kail-startup (LEAVE)'
448 ''')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400449
Joey Armstrong642540a2023-08-10 10:26:36 -0400450 println("${iam}: ENTER RobotPublisher")
451 step([$class: 'RobotPublisher',
452 disableArchiveOutput: false,
453 logFileName: '**/*/log*.html',
454 otherFiles: '',
455 outputFileName: '**/*/output*.xml',
456 outputPath: '.',
457 passThreshold: 100,
458 reportFileName: '**/*/report*.html',
459 unstableThreshold: 0,
460 onlyCritical: true]);
461 println("${iam}: LEAVE RobotPublisher")
462
463 println("${iam}: LEAVE (exitStatus=${exitStatus})")
464 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400465}
466
Joey Armstrong54dec092023-08-03 18:21:38 -0400467// -----------------------------------------------------------------------
468// Intent: main
469// -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400470pipeline {
471
472 /* no label, executor is determined by JJB */
473 agent {
474 label "${params.buildNode}"
475 }
476 options {
477 timeout(time: "${timeout}", unit: 'MINUTES')
478 }
479 environment {
Joey Armstrong642540a2023-08-10 10:26:36 -0400480 KUBECONFIG = "$HOME/.kube/kind-${clusterName}"
481 VOLTCONFIG = "$HOME/.volt/config"
482 PATH = "$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
483 DIAGS_PROFILE = 'VOLTHA_PROFILE'
484 SSHPASS = 'karaf'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400485 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400486
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400487 stages {
488 stage('Download Code') {
489 steps {
490 getVolthaCode([
491 branch: "${branch}",
492 gerritProject: "${gerritProject}",
493 gerritRefspec: "${gerritRefspec}",
494 volthaSystemTestsChange: "${volthaSystemTestsChange}",
495 volthaHelmChartsChange: "${volthaHelmChartsChange}",
496 ])
497 }
498 }
499
500 stage('Build patch v1.1')
501 {
502 // build the patch only if gerritProject is specified
503 when
504 {
505 expression
506 {
507 return !gerritProject.isEmpty()
508 }
509 }
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400510
511 steps
512 {
513 // NOTE that the correct patch has already been checked out
514 // during the getVolthaCode step
515 buildVolthaComponent("${gerritProject}")
516 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400517 }
518
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400519 // -----------------------------------------------------------------------
520 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400521 stage('Install Kail')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400522 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400523 steps
524 {
525 script
526 {
527 String cmd = [
528 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400529 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400530 '-C', "$WORKSPACE/voltha-system-tests",
531 "KAIL_PATH=\"$WORKSPACE/bin\"",
532 'kail',
533 ].join(' ')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400534
Joey Armstrongf060aee2023-08-22 21:55:26 -0400535 println(" ** Running: ${cmd}")
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400536 sh("${cmd}")
537 } // script
538 } // steps
539 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400540
541 // -----------------------------------------------------------------------
542 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400543 stage('Install Kind')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400544 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400545 steps
546 {
547 script
548 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400549
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400550 String cmd = [
551 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400552 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400553 '-C', "$WORKSPACE/voltha-system-tests",
554 "KIND_PATH=\"$WORKSPACE/bin\"",
555 'install-command-kind',
556 ].join(' ')
Joey Armstrong642540a2023-08-10 10:26:36 -0400557
Joey Armstrongf060aee2023-08-22 21:55:26 -0400558 println(" ** Running: ${cmd}")
559 sh("${cmd}")
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400560 } // script
561 } // steps
562 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400563
564 // -----------------------------------------------------------------------
565 // -----------------------------------------------------------------------
566 stage('Create K8s Cluster')
567 {
568 steps
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400569 {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400570 script
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400571 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400572 def clusterExists = sh(
Joey Armstrongf060aee2023-08-22 21:55:26 -0400573 returnStdout: true,
574 script: """kind get clusters | grep "${clusterName}" | wc -l""")
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400575
Joey Armstrong54dec092023-08-03 18:21:38 -0400576 if (clusterExists.trim() == '0')
Joey Armstrongf060aee2023-08-22 21:55:26 -0400577 {
578 createKubernetesCluster([nodes: 3, name: clusterName])
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400579 }
Joey Armstrongf060aee2023-08-22 21:55:26 -0400580 } // script
581 } // steps
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400582 } // stage('Create K8s Cluster')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400583
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400584 // -----------------------------------------------------------------------
585 // -----------------------------------------------------------------------
586 stage('Replace voltctl')
587 {
588 // if the project is voltctl, override the downloaded one with the built one
589 when {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400590 expression { return gerritProject == 'voltctl' }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400591 }
592
593 // Hmmmm(?) where did the voltctl download happen ?
594 // Likely Makefile but would be helpful to document here.
595 steps
596 {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400597 println("${iam} Running: installVoltctl($branch)")
598 installVoltctl("$branch")
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400599 } // steps
600 } // stage
601
602 // -----------------------------------------------------------------------
603 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400604 stage('voltctl [DEBUG]') {
605 steps {
606 script {
607 String iam = getIam('execute_test')
608
609 println("${iam} Display umask")
610 sh('umask')
611
612 println("${iam} Checking voltctl config permissions")
613 sh('/bin/ls -ld ~/.volt ~/.volt/* || true')
614 } // script
Joey Armstrong268442d2023-08-22 17:16:10 -0400615 } // steps
616 } // stage
617
618 // -----------------------------------------------------------------------
619 // -----------------------------------------------------------------------
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400620 stage('Load image in kind nodes')
621 {
622 when {
623 expression { return !gerritProject.isEmpty() }
624 }
625 steps {
626 loadToKind()
627 } // steps
628 } // stage
629
630 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400631 // [TODO] verify testing output
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400632 // -----------------------------------------------------------------------
633 stage('Parse and execute tests')
634 {
635 steps {
636 script {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400637 // Announce ourselves for log usability
638 String iam = getIam('execute_test')
639 println("${iam}: ENTER")
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400640
641 def tests = readYaml text: testTargets
642
643 println("** $iam: Testing index: tests-to-run")
644 tests.eachWithIndex { test, idx ->
645 String target = test['target']
646 println("** $idx: $target")
Joey Armstrong642540a2023-08-10 10:26:36 -0400647 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400648 println("** NOTE: For odd failures compare tests-to-run with teste output")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400649
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400650 tests.eachWithIndex { test, idx ->
651 println "** readYaml test suite[$idx]) test=[${test}]"
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400652
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400653 String target = test['target']
654 String workflow = test['workflow']
655 String flags = test['flags']
656 Boolean teardown = test['teardown'].toBoolean()
657 Boolean logging = test['logging'].toBoolean()
658 String testLogging = (logging) ? 'True' : 'False'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400659
Joey Armstrong268442d2023-08-22 17:16:10 -0400660 print("""
Joey Armstrong268442d2023-08-22 17:16:10 -0400661** -----------------------------------------------------------------------
662** Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}"
663** -----------------------------------------------------------------------
Joey Armstrong268442d2023-08-22 17:16:10 -0400664)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400665
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400666 try {
667 println "Executing test ${target}: ENTER"
668 execute_test(target, workflow, testLogging, teardown, flags)
669 }
670 catch (Exception err) {
671 println("** ${iam}: EXCEPTION ${err}")
672 }
673 finally {
674 println "Executing test ${target}: LEAVE"
675 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400676
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400677 } // for
Joey Armstrong642540a2023-08-10 10:26:36 -0400678
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400679 // Premature exit if this message is not logged
680 println("${iam}: LEAVE (testing ran to completion)")
Joey Armstrong54dec092023-08-03 18:21:38 -0400681 } // script
682 } // steps
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400683 } // stage
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400684 } // stages
685
686 post
687 {
688 aborted { collectArtifacts('aborted') }
689 failure { collectArtifacts('failed') }
690 always { collectArtifacts('always') }
691 }
692} // pipeline
693
694// EOF