blob: ebeaa4d2e8d24f321743761dd226f10d4f6f6eb6 [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 Armstrong38a87832023-08-23 17:02:50 -040072// Intent:
Joey Armstrongf060aee2023-08-22 21:55:26 -040073// -----------------------------------------------------------------------
74void pgrep_proc(String proc)
75{
76 println("** Running: pgrep --list-full ${proc}")
77 sh("""pgrep --list-full "${proc}" || true""")
78 return
79}
80
81// -----------------------------------------------------------------------
82// -----------------------------------------------------------------------
83void pkill_proc(String proc)
84{
85 println("** Running: pkill ${proc}")
86 sh(""" [[ \$(pgrep --count "${proc}") -gt 0 ]] && pkill --echo "${proc}" """)
87 return
88}
89
90// -----------------------------------------------------------------------
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040091// Intent:
92// -----------------------------------------------------------------------
Joey Armstrong54dec092023-08-03 18:21:38 -040093void execute_test(testTarget, workflow, testLogging, teardown, testSpecificHelmFlags='')
Joey Armstrong7bcb5782023-06-07 12:25:57 -040094{
Joey Armstrong54dec092023-08-03 18:21:38 -040095 String infraNamespace = 'default'
96 String volthaNamespace = 'voltha'
97 String logsDir = "$WORKSPACE/${testTarget}"
Joey Armstrong7bcb5782023-06-07 12:25:57 -040098
99 stage('IAM')
100 {
101 script
102 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400103 // Announce ourselves for log usability
Joey Armstrong642540a2023-08-10 10:26:36 -0400104 String iam = getIam('execute_test')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400105 println("${iam}: ENTER")
106 println("${iam}: LEAVE")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400107 }
108 }
Joey Armstrong54dec092023-08-03 18:21:38 -0400109
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400110 // -----------------------------------------------------------------------
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400111 // Intent: Cleanup stale port-forwarding
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400112 // -----------------------------------------------------------------------
113 stage('Cleanup')
114 {
Joey Armstrong38a87832023-08-23 17:02:50 -0400115 if (teardown) {
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400116 timeout(15) {
Joey Armstrong38a87832023-08-23 17:02:50 -0400117 script {
Joey Armstrong54dec092023-08-03 18:21:38 -0400118 helmTeardown(['default', infraNamespace, volthaNamespace])
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400119 }
Joey Armstrongf060aee2023-08-22 21:55:26 -0400120 } // timeout
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400121
Joey Armstrongf060aee2023-08-22 21:55:26 -0400122 timeout(5) {
123 script {
124 String iam = getIam('Cleanup')
125 println("${iam}: ENTER")
Joey Armstrong268442d2023-08-22 17:16:10 -0400126
Joey Armstrongf060aee2023-08-22 21:55:26 -0400127 // remove orphaned port-forward from different namespaces
128 String proc = 'port-forw'
129 pgrep_proc(proc)
130 pkill_proc(proc)
Joey Armstrong268442d2023-08-22 17:16:10 -0400131
Joey Armstrongf060aee2023-08-22 21:55:26 -0400132 // Sanity check processes terminated
133 sh("""
134[[ \$(pgrep --count "${proc}") -gt 0 ]] && { \
135 echo "ERROR: Detected zombie port-forwarding processes"
136 pgrep --list-full "${proc}" || true ; }
137""")
138 println("${iam}: LEAVE")
Joey Armstrong38a87832023-08-23 17:02:50 -0400139 } // script
Joey Armstrongf060aee2023-08-22 21:55:26 -0400140 } // timeout
141 } // teardown
Joey Armstrong38a87832023-08-23 17:02:50 -0400142 } // stage('Cleanup')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400143
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400144 // -----------------------------------------------------------------------
145 // -----------------------------------------------------------------------
146 stage('Deploy common infrastructure')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400147 {
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400148 script
149 {
150 local dashargs = [
151 'kpi_exporter.enabled=false',
152 'dashboards.xos=false',
153 'dashboards.onos=false',
154 'dashboards.aaa=false',
155 'dashboards.voltha=false',
156 ].join(',')
157
158 local promargs = [
159 'prometheus.alertmanager.enabled=false',
160 'prometheus.pushgateway.enabled=false',
161 ].join(',')
162
Joey Armstrong38a87832023-08-23 17:02:50 -0400163 sh("""
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400164 helm repo add onf https://charts.opencord.org
165 helm repo update
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400166
167 echo -e "\nwithMonitoring=[$withMonitoring]"
168 if [ ${withMonitoring} = true ] ; then
169 helm install nem-monitoring onf/nem-monitoring \
Joey Armstrong38a87832023-08-23 17:02:50 -0400170 --set ${promargs} \
171 --set ${dashargs}
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400172 fi
Joey Armstrong38a87832023-08-23 17:02:50 -0400173 """)
174 } // script
175 } // stage('Deploy Common Infra')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400176
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400177 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400178 // [TODO] Check onos_log output
179 // [TODO] kail-startup pgrep/pkill
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400180 // -----------------------------------------------------------------------
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400181 stage('Deploy Voltha')
182 {
183 if (teardown)
184 {
185 timeout(10)
186 {
187 script
188 {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400189 String iam = getIam('Deploy Voltha')
Joey Armstrong38a87832023-08-23 17:02:50 -0400190 String onosLog = "${logsDir}/onos-voltha-startup-combined.log"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400191sh("""
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400192 mkdir -p ${logsDir}
Joey Armstrong38a87832023-08-23 17:02:50 -0400193 touch "$onosLog"
194 echo "** kail-startup ENTER: \$(date)" > "$onosLog"
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.
Joey Armstrong38a87832023-08-23 17:02:50 -0400198 # _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} >> "$onosLog" &
199 _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} | tee -a "$onosLog" &
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400200 """)
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()
Joey Armstrong38a87832023-08-23 17:02:50 -0400213 Boolean isRelease = isReleaseBranch(branch)
Joey Armstrong54dec092023-08-03 18:21:38 -0400214 println([
215 " ** localCharts=${localCharts}",
216 "branchName=${branchName}",
217 "branch=${branch}",
Joey Armstrong38a87832023-08-23 17:02:50 -0400218 "branch=isReleaseBranch=${isRelease}",
Joey Armstrong54dec092023-08-03 18:21:38 -0400219 ].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 Armstrong38a87832023-08-23 17:02:50 -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 Armstrong38a87832023-08-23 17:02:50 -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 Armstrong38a87832023-08-23 17:02:50 -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 Armstrong38a87832023-08-23 17:02:50 -0400414
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400415 set +u && source .venv/bin/activate && set -u
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400416 # Collect memory consumption of voltha pods once all the tests are complete
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400417 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 -0400418 fi
Joey Armstrong54dec092023-08-03 18:21:38 -0400419 echo -e '** Monitor pod-mem-consumption: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400420 """
421 } // stage
Joey Armstrong54dec092023-08-03 18:21:38 -0400422
423 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400424} // execute_test()
425
426// -----------------------------------------------------------------------
427// -----------------------------------------------------------------------
Joey Armstrong54dec092023-08-03 18:21:38 -0400428def collectArtifacts(exitStatus) {
Joey Armstrong642540a2023-08-10 10:26:36 -0400429 String iam = getIam('execute_test')
430
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400431 echo '''
432
433** -----------------------------------------------------------------------
434** collectArtifacts
435** -----------------------------------------------------------------------
436'''
Joey Armstrong642540a2023-08-10 10:26:36 -0400437 println("${iam}: ENTER (exitStatus=${exitStatus})")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400438
Joey Armstrong642540a2023-08-10 10:26:36 -0400439 getPodsInfo("$WORKSPACE/${exitStatus}")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400440
Joey Armstrong642540a2023-08-10 10:26:36 -0400441 sh """
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400442 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400443 """
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400444
Joey Armstrong642540a2023-08-10 10:26:36 -0400445 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 -0400446
Joey Armstrong642540a2023-08-10 10:26:36 -0400447 sh(returnStdout:true, script: '''
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400448 sync
Joey Armstrong642540a2023-08-10 10:26:36 -0400449 echo '** Running: pgrep --list-full kail-startup (ENTER)'
450 pgrep --list-full 'kail-startup' || true
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400451 [[ $(pgrep --count kail) -gt 0 ]] && pkill --echo kail
Joey Armstrong642540a2023-08-10 10:26:36 -0400452 echo '** Running: pgrep --list-full kail-startup (LEAVE)'
453 ''')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400454
Joey Armstrong642540a2023-08-10 10:26:36 -0400455 println("${iam}: ENTER RobotPublisher")
456 step([$class: 'RobotPublisher',
457 disableArchiveOutput: false,
458 logFileName: '**/*/log*.html',
459 otherFiles: '',
460 outputFileName: '**/*/output*.xml',
461 outputPath: '.',
462 passThreshold: 100,
463 reportFileName: '**/*/report*.html',
464 unstableThreshold: 0,
465 onlyCritical: true]);
466 println("${iam}: LEAVE RobotPublisher")
467
468 println("${iam}: LEAVE (exitStatus=${exitStatus})")
469 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400470}
471
Joey Armstrong54dec092023-08-03 18:21:38 -0400472// -----------------------------------------------------------------------
473// Intent: main
474// -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400475pipeline {
476
477 /* no label, executor is determined by JJB */
478 agent {
479 label "${params.buildNode}"
480 }
481 options {
482 timeout(time: "${timeout}", unit: 'MINUTES')
483 }
484 environment {
Joey Armstrong642540a2023-08-10 10:26:36 -0400485 KUBECONFIG = "$HOME/.kube/kind-${clusterName}"
486 VOLTCONFIG = "$HOME/.volt/config"
487 PATH = "$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
488 DIAGS_PROFILE = 'VOLTHA_PROFILE'
489 SSHPASS = 'karaf'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400490 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400491
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400492 stages {
493 stage('Download Code') {
494 steps {
495 getVolthaCode([
496 branch: "${branch}",
497 gerritProject: "${gerritProject}",
498 gerritRefspec: "${gerritRefspec}",
499 volthaSystemTestsChange: "${volthaSystemTestsChange}",
500 volthaHelmChartsChange: "${volthaHelmChartsChange}",
501 ])
502 }
503 }
504
505 stage('Build patch v1.1')
506 {
507 // build the patch only if gerritProject is specified
508 when
509 {
510 expression
511 {
512 return !gerritProject.isEmpty()
513 }
514 }
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400515
516 steps
517 {
518 // NOTE that the correct patch has already been checked out
519 // during the getVolthaCode step
520 buildVolthaComponent("${gerritProject}")
521 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400522 }
523
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400524 // -----------------------------------------------------------------------
525 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400526 stage('Install Kail')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400527 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400528 steps
529 {
530 script
531 {
532 String cmd = [
533 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400534 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400535 '-C', "$WORKSPACE/voltha-system-tests",
536 "KAIL_PATH=\"$WORKSPACE/bin\"",
537 'kail',
538 ].join(' ')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400539
Joey Armstrongf060aee2023-08-22 21:55:26 -0400540 println(" ** Running: ${cmd}")
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400541 sh("${cmd}")
542 } // script
543 } // steps
544 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400545
546 // -----------------------------------------------------------------------
547 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400548 stage('Install Kind')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400549 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400550 steps
551 {
552 script
553 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400554
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400555 String cmd = [
556 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400557 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400558 '-C', "$WORKSPACE/voltha-system-tests",
559 "KIND_PATH=\"$WORKSPACE/bin\"",
560 'install-command-kind',
561 ].join(' ')
Joey Armstrong642540a2023-08-10 10:26:36 -0400562
Joey Armstrongf060aee2023-08-22 21:55:26 -0400563 println(" ** Running: ${cmd}")
564 sh("${cmd}")
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400565 } // script
566 } // steps
567 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400568
569 // -----------------------------------------------------------------------
570 // -----------------------------------------------------------------------
571 stage('Create K8s Cluster')
572 {
573 steps
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400574 {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400575 script
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400576 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400577 def clusterExists = sh(
Joey Armstrongf060aee2023-08-22 21:55:26 -0400578 returnStdout: true,
579 script: """kind get clusters | grep "${clusterName}" | wc -l""")
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400580
Joey Armstrong54dec092023-08-03 18:21:38 -0400581 if (clusterExists.trim() == '0')
Joey Armstrongf060aee2023-08-22 21:55:26 -0400582 {
583 createKubernetesCluster([nodes: 3, name: clusterName])
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400584 }
Joey Armstrongf060aee2023-08-22 21:55:26 -0400585 } // script
586 } // steps
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400587 } // stage('Create K8s Cluster')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400588
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400589 // -----------------------------------------------------------------------
590 // -----------------------------------------------------------------------
591 stage('Replace voltctl')
592 {
593 // if the project is voltctl, override the downloaded one with the built one
594 when {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400595 expression { return gerritProject == 'voltctl' }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400596 }
597
598 // Hmmmm(?) where did the voltctl download happen ?
599 // Likely Makefile but would be helpful to document here.
600 steps
601 {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400602 println("${iam} Running: installVoltctl($branch)")
603 installVoltctl("$branch")
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400604 } // steps
605 } // stage
606
607 // -----------------------------------------------------------------------
608 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400609 stage('voltctl [DEBUG]') {
610 steps {
611 script {
612 String iam = getIam('execute_test')
613
614 println("${iam} Display umask")
615 sh('umask')
616
617 println("${iam} Checking voltctl config permissions")
618 sh('/bin/ls -ld ~/.volt ~/.volt/* || true')
619 } // script
Joey Armstrong268442d2023-08-22 17:16:10 -0400620 } // steps
621 } // stage
622
623 // -----------------------------------------------------------------------
624 // -----------------------------------------------------------------------
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400625 stage('Load image in kind nodes')
626 {
627 when {
628 expression { return !gerritProject.isEmpty() }
629 }
630 steps {
631 loadToKind()
632 } // steps
633 } // stage
634
635 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400636 // [TODO] verify testing output
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400637 // -----------------------------------------------------------------------
638 stage('Parse and execute tests')
639 {
640 steps {
641 script {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400642 // Announce ourselves for log usability
643 String iam = getIam('execute_test')
644 println("${iam}: ENTER")
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400645
646 def tests = readYaml text: testTargets
647
648 println("** $iam: Testing index: tests-to-run")
649 tests.eachWithIndex { test, idx ->
650 String target = test['target']
651 println("** $idx: $target")
Joey Armstrong38a87832023-08-23 17:02:50 -0400652 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400653 println("** NOTE: For odd failures compare tests-to-run with teste output")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400654
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400655 tests.eachWithIndex { test, idx ->
656 println "** readYaml test suite[$idx]) test=[${test}]"
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400657
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400658 String target = test['target']
659 String workflow = test['workflow']
660 String flags = test['flags']
661 Boolean teardown = test['teardown'].toBoolean()
662 Boolean logging = test['logging'].toBoolean()
663 String testLogging = (logging) ? 'True' : 'False'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400664
Joey Armstrong268442d2023-08-22 17:16:10 -0400665 print("""
Joey Armstrong268442d2023-08-22 17:16:10 -0400666** -----------------------------------------------------------------------
Joey Armstrong38a87832023-08-23 17:02:50 -0400667** Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}
Joey Armstrong268442d2023-08-22 17:16:10 -0400668** -----------------------------------------------------------------------
Joey Armstrong38a87832023-08-23 17:02:50 -0400669""")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400670
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400671 try {
672 println "Executing test ${target}: ENTER"
673 execute_test(target, workflow, testLogging, teardown, flags)
674 }
675 catch (Exception err) {
676 println("** ${iam}: EXCEPTION ${err}")
677 }
678 finally {
679 println "Executing test ${target}: LEAVE"
680 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400681
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400682 } // for
Joey Armstrong642540a2023-08-10 10:26:36 -0400683
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400684 // Premature exit if this message is not logged
685 println("${iam}: LEAVE (testing ran to completion)")
Joey Armstrong54dec092023-08-03 18:21:38 -0400686 } // script
687 } // steps
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400688 } // stage
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400689 } // stages
690
691 post
692 {
693 aborted { collectArtifacts('aborted') }
694 failure { collectArtifacts('failed') }
695 always { collectArtifacts('always') }
696 }
697} // pipeline
698
699// EOF