blob: 1f820109a4936d5b0504a0980c3a48276cbf49cb [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// -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -040064Boolean isReleaseBranch(String name) {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040065 // List modifiers = ['-dev', '-pre', 'voltha-x.y.z-pre']
Joey Armstrong54dec092023-08-03 18:21:38 -040066 // if branchName in modifiers
67 return(name != 'master') // OR branchName.contains('-')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040068}
69
70// -----------------------------------------------------------------------
Joey Armstrong38a87832023-08-23 17:02:50 -040071// Intent:
Joey Armstrongf060aee2023-08-22 21:55:26 -040072// -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -040073void execute_test(testTarget, workflow, testLogging, teardown, testSpecificHelmFlags='') {
Joey Armstrong54dec092023-08-03 18:21:38 -040074 String infraNamespace = 'default'
75 String volthaNamespace = 'voltha'
76 String logsDir = "$WORKSPACE/${testTarget}"
Joey Armstrong7bcb5782023-06-07 12:25:57 -040077
78 stage('IAM')
79 {
80 script
81 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040082 // Announce ourselves for log usability
Joey Armstrong642540a2023-08-10 10:26:36 -040083 String iam = getIam('execute_test')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040084 println("${iam}: ENTER")
85 println("${iam}: LEAVE")
Joey Armstrong7bcb5782023-06-07 12:25:57 -040086 }
87 }
Joey Armstrong54dec092023-08-03 18:21:38 -040088
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040089 // -----------------------------------------------------------------------
Joey Armstrong008cfaf2023-08-18 14:49:06 -040090 // Intent: Cleanup stale port-forwarding
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040091 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -040092 stage('Cleanup') {
Joey Armstrong38a87832023-08-23 17:02:50 -040093 if (teardown) {
Joey Armstrong7bcb5782023-06-07 12:25:57 -040094 timeout(15) {
Joey Armstrong38a87832023-08-23 17:02:50 -040095 script {
Joey Armstrong54dec092023-08-03 18:21:38 -040096 helmTeardown(['default', infraNamespace, volthaNamespace])
Joey Armstrong7bcb5782023-06-07 12:25:57 -040097 }
Joey Armstrongf060aee2023-08-22 21:55:26 -040098 } // timeout
Joey Armstrong008cfaf2023-08-18 14:49:06 -040099
Joey Armstrongf060aee2023-08-22 21:55:26 -0400100 timeout(5) {
101 script {
102 String iam = getIam('Cleanup')
103 println("${iam}: ENTER")
Joey Armstrong268442d2023-08-22 17:16:10 -0400104
Joey Armstrongf060aee2023-08-22 21:55:26 -0400105 // remove orphaned port-forward from different namespaces
106 String proc = 'port-forw'
107 pgrep_proc(proc)
108 pkill_proc(proc)
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400109 pgrep_proc(proc) // proc count == 0
Joey Armstrongf060aee2023-08-22 21:55:26 -0400110 println("${iam}: LEAVE")
Joey Armstrong38a87832023-08-23 17:02:50 -0400111 } // script
Joey Armstrongf060aee2023-08-22 21:55:26 -0400112 } // timeout
113 } // teardown
Joey Armstrong38a87832023-08-23 17:02:50 -0400114 } // stage('Cleanup')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400115
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400116 // -----------------------------------------------------------------------
117 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400118 stage('Deploy common infrastructure') {
119 script {
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400120 local dashargs = [
121 'kpi_exporter.enabled=false',
122 'dashboards.xos=false',
123 'dashboards.onos=false',
124 'dashboards.aaa=false',
125 'dashboards.voltha=false',
126 ].join(',')
127
128 local promargs = [
129 'prometheus.alertmanager.enabled=false',
130 'prometheus.pushgateway.enabled=false',
131 ].join(',')
132
Joey Armstrong38a87832023-08-23 17:02:50 -0400133 sh("""
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400134 helm repo add onf https://charts.opencord.org
135 helm repo update
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400136
137 echo -e "\nwithMonitoring=[$withMonitoring]"
138 if [ ${withMonitoring} = true ] ; then
139 helm install nem-monitoring onf/nem-monitoring \
Joey Armstrong38a87832023-08-23 17:02:50 -0400140 --set ${promargs} \
141 --set ${dashargs}
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400142 fi
Joey Armstrong38a87832023-08-23 17:02:50 -0400143 """)
144 } // script
145 } // stage('Deploy Common Infra')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400146
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400147 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400148 // [TODO] Check onos_log output
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400149 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400150 stage('Deploy Voltha') {
151 if (teardown) {
152 timeout(10) {
153 script {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400154 String iam = getIam('Deploy Voltha')
Joey Armstrong38a87832023-08-23 17:02:50 -0400155 String onosLog = "${logsDir}/onos-voltha-startup-combined.log"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400156sh("""
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400157 mkdir -p ${logsDir}
Joey Armstrong38a87832023-08-23 17:02:50 -0400158 touch "$onosLog"
159 echo "** kail-startup ENTER: \$(date)" > "$onosLog"
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400160
161 # Intermixed output (tee -a &) may get conflusing but let(s) see
162 # what messages are logged during startup.
Joey Armstrong38a87832023-08-23 17:02:50 -0400163 # _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} >> "$onosLog" &
164 _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} | tee -a "$onosLog" &
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400165 """)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400166
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400167 // if we're downloading a voltha-helm-charts patch, then install from a local copy of the charts
168 Boolean localCharts = false
Joey Armstrong642540a2023-08-10 10:26:36 -0400169
Joey Armstrong54dec092023-08-03 18:21:38 -0400170 if (volthaHelmChartsChange != ''
171 || gerritProject == 'voltha-helm-charts'
172 || isReleaseBranch(branch) // branch != 'master'
173 ) {
174 localCharts = true
175 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400176
Joey Armstrong54dec092023-08-03 18:21:38 -0400177 String branchName = branchName()
Joey Armstrong38a87832023-08-23 17:02:50 -0400178 Boolean isRelease = isReleaseBranch(branch)
Joey Armstrong54dec092023-08-03 18:21:38 -0400179 println([
180 " ** localCharts=${localCharts}",
181 "branchName=${branchName}",
182 "branch=${branch}",
Joey Armstrong38a87832023-08-23 17:02:50 -0400183 "branch=isReleaseBranch=${isRelease}",
Joey Armstrong54dec092023-08-03 18:21:38 -0400184 ].join(', '))
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400185
Joey Armstrong54dec092023-08-03 18:21:38 -0400186 // -----------------------------------------------------------------------
187 // Rewrite localHelmFlags using array join, moving code around and
Joey Armstrong642540a2023-08-10 10:26:36 -0400188 // refactoring into standalone functions
Joey Armstrong54dec092023-08-03 18:21:38 -0400189 // -----------------------------------------------------------------------
190 // hudson.remoting.ProxyException: groovy.lang.MissingMethodException:
191 // No signature of method: java.lang.String.positive() is applicable for argument types: () values: []
192 // -----------------------------------------------------------------------
193 // NOTE temporary workaround expose ONOS node ports
194 // -----------------------------------------------------------------------
195 String localHelmFlags = [
196 extraHelmFlags.trim(),
197 "--set global.log_level=${logLevel.toUpperCase()}",
198 '--set onos-classic.onosSshPort=30115',
199 '--set onos-classic.onosApiPort=30120',
200 '--set onos-classic.onosOfPort=31653',
201 '--set onos-classic.individualOpenFlowNodePorts=true',
202 testSpecificHelmFlags
203 ].join(' ')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400204
Joey Armstrongf060aee2023-08-22 21:55:26 -0400205 println("** ${iam} localHelmFlags = ${localHelmFlags}")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400206
Joey Armstrong54dec092023-08-03 18:21:38 -0400207 if (gerritProject != '') {
208 localHelmFlags = "${localHelmFlags} " + getVolthaImageFlags("${gerritProject}")
209 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400210
Joey Armstrong38a87832023-08-23 17:02:50 -0400211 println("** ${iam}: ENTER")
Joey Armstrong54dec092023-08-03 18:21:38 -0400212 volthaDeploy([
213 infraNamespace: infraNamespace,
214 volthaNamespace: volthaNamespace,
215 workflow: workflow.toLowerCase(),
216 withMacLearning: enableMacLearning.toBoolean(),
217 extraHelmFlags: localHelmFlags,
218 localCharts: localCharts,
219 bbsimReplica: olts.toInteger(),
220 dockerRegistry: registry,
221 ])
Joey Armstrong38a87832023-08-23 17:02:50 -0400222 println("** ${iam}: LEAVE")
Joey Armstrong54dec092023-08-03 18:21:38 -0400223 } // script
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400224
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400225 // -----------------------------------------------------------------------
226 // Intent: Replacing P_IDS with pgrep/pkill is a step forward.
227 // Why not simply use a pid file, capture _TAG=kail-startup above
228 // Grep runs the risk of terminating stray commands (??-good <=> bad-??)
Joey Armstrong54dec092023-08-03 18:21:38 -0400229 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400230 script {
231 String proc = '_TAG=kail-startup'
Joey Armstrongdddbbf92023-08-22 16:00:41 -0400232
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400233 println("${iam}: ENTER")
234 println("${iam}: Shutdown process $proc")
235 pgrep_proc(proc)
236 pkill_proc(proc)
237 println("${iam}: LEAVE")
238 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400239
Joey Armstronged345862023-08-23 12:24:20 -0400240 // -----------------------------------------------------------------------
241 // Bundle onos-voltha / kail logs
242 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400243 sh("""
244cat <<EOM
245
246** -----------------------------------------------------------------------
247** Combine an compress voltha startup log(s)
248** -----------------------------------------------------------------------
249EOM
250 pushd "${logsDir}" || { echo "ERROR: pushd $logsDir failed"; exit 1; }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400251 gzip -k onos-voltha-startup-combined.log
252 rm onos-voltha-startup-combined.log
Joey Armstrongf060aee2023-08-22 21:55:26 -0400253 popd
254 """)
Joey Armstrong38a87832023-08-23 17:02:50 -0400255 } // timeout(10)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400256
Joey Armstrongf060aee2023-08-22 21:55:26 -0400257
258 // -----------------------------------------------------------------------
259 // -----------------------------------------------------------------------
260 sh """
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400261 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"&
262 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"&
263 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"&
264 bbsimDmiPortFwd=50075
265 for i in {0..${olts.toInteger() - 1}}; do
266 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"&
267 ((bbsimDmiPortFwd++))
268 done
269 if [ ${withMonitoring} = true ] ; then
270 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"&
271 fi
272 ps aux | grep port-forward
273 """
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400274 script {
275 String proc = 'port-forward'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400276
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400277 println("${iam}: ENTER")
278 println("Display spawned ${proc}")
279 pgrep_proc(proc)
280 println("${iam}: LEAVE")
281 }
Joey Armstrongf060aee2023-08-22 21:55:26 -0400282
283 // setting ONOS log level
284 script {
285 println('** setOnosLogLevels: ENTER')
Joey Armstrong54dec092023-08-03 18:21:38 -0400286 setOnosLogLevels([
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400287 onosNamespace: infraNamespace,
288 apps: [
289 'org.opencord.dhcpl2relay',
290 'org.opencord.olt',
291 'org.opencord.aaa',
292 'org.opencord.maclearner',
293 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
294 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
295 ],
296 logLevel: logLevel
297 ])
Joey Armstrongf060aee2023-08-22 21:55:26 -0400298 println('** setOnosLogLevels: LEAVE')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400299 } // script
300 } // if (teardown)
301 } // stage('Deploy Voltha')
302
Joey Armstrongf060aee2023-08-22 21:55:26 -0400303 // -----------------------------------------------------------------------
304 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400305 stage("Run test ${testTarget} on workflow ${workflow}")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400306 {
307 sh """
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400308 echo -e "\n** Monitor using mem_consumption.py ?"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400309
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400310 if [ ${withMonitoring} = true ] ; then
Joey Armstrongf060aee2023-08-22 21:55:26 -0400311 cat <<EOM
312
313** -----------------------------------------------------------------------
314** Monitoring memory usage with mem_consumption.py
315** -----------------------------------------------------------------------
316EOM
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400317 mkdir -p "$WORKSPACE/voltha-pods-mem-consumption-${workflow}"
318 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400319
320 echo '** Installing python virtualenv'
321 make venv-activate-patched
322
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400323 set +u && source .venv/bin/activate && set -u
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400324 # Collect initial memory consumption
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400325 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 -0400326 fi
Joey Armstrongf060aee2023-08-22 21:55:26 -0400327
328 echo -e '** Monitor memory consumption: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400329 """
330
331 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400332 echo -e "\n** make testTarget=[${testTarget}]"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400333 mkdir -p ${logsDir}
334 export ROBOT_MISC_ARGS="-d ${logsDir} ${params.extraRobotArgs} "
335 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}"
336 export KVSTOREPREFIX=voltha/voltha_voltha
337
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400338 make -C "$WORKSPACE/voltha-system-tests" ${testTarget}
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400339 """
340
341 getPodsInfo("${logsDir}")
342
343 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400344 echo -e '\n** Gather robot Framework logs: ENTER'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400345 # set +e
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400346 # collect logs collected in the Robot Framework StartLogging keyword
347 cd ${logsDir}
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400348 gzip *-combined.log
349 rm -f *-combined.log
Joey Armstrong54dec092023-08-03 18:21:38 -0400350
351 echo -e '** Gather robot Framework logs: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400352 """
353
Joey Armstrongf060aee2023-08-22 21:55:26 -0400354 // -----------------------------------------------------------------------
355 // -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400356 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400357 echo -e '** Monitor pod-mem-consumption: ENTER'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400358 if [ ${withMonitoring} = true ] ; then
Joey Armstrongf060aee2023-08-22 21:55:26 -0400359 cat <<EOM
360
361** -----------------------------------------------------------------------
362** Monitoring pod-memory-consumption using mem_consumption.py
363** -----------------------------------------------------------------------
364EOM
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400365 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400366
367 echo '** Installing python virtualenv'
368 make venv-activate-patched
Joey Armstrong38a87832023-08-23 17:02:50 -0400369
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400370 set +u && source .venv/bin/activate && set -u
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400371 # Collect memory consumption of voltha pods once all the tests are complete
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400372 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 -0400373 fi
Joey Armstrong54dec092023-08-03 18:21:38 -0400374 echo -e '** Monitor pod-mem-consumption: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400375 """
376 } // stage
Joey Armstrong54dec092023-08-03 18:21:38 -0400377
378 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400379} // execute_test()
380
381// -----------------------------------------------------------------------
382// -----------------------------------------------------------------------
Joey Armstrong54dec092023-08-03 18:21:38 -0400383def collectArtifacts(exitStatus) {
Joey Armstrong6115fd62023-08-24 08:19:28 -0400384 script {
385 String iam = getIam('collectArtifacts')
386 println("${iam}: ENTER (exitStatus=${exitStatus})")
387 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400388
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400389 echo '''
390
391** -----------------------------------------------------------------------
392** collectArtifacts
393** -----------------------------------------------------------------------
394'''
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400395
Joey Armstrong642540a2023-08-10 10:26:36 -0400396 getPodsInfo("$WORKSPACE/${exitStatus}")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400397
Joey Armstrong642540a2023-08-10 10:26:36 -0400398 sh """
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400399 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400400 """
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400401
Joey Armstrong642540a2023-08-10 10:26:36 -0400402 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 -0400403
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400404 script {
405 println("${iam}: ENTER")
406 pgrep_proc('kail-startup')
407 pkill_proc('kail')
408 println("${iam}: LEAVE")
409 }
410
Joey Armstrong642540a2023-08-10 10:26:36 -0400411 println("${iam}: ENTER RobotPublisher")
412 step([$class: 'RobotPublisher',
413 disableArchiveOutput: false,
414 logFileName: '**/*/log*.html',
415 otherFiles: '',
416 outputFileName: '**/*/output*.xml',
417 outputPath: '.',
418 passThreshold: 100,
419 reportFileName: '**/*/report*.html',
420 unstableThreshold: 0,
421 onlyCritical: true]);
422 println("${iam}: LEAVE RobotPublisher")
423
424 println("${iam}: LEAVE (exitStatus=${exitStatus})")
425 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400426}
427
Joey Armstrong54dec092023-08-03 18:21:38 -0400428// -----------------------------------------------------------------------
429// Intent: main
430// -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400431pipeline {
432
433 /* no label, executor is determined by JJB */
434 agent {
435 label "${params.buildNode}"
436 }
437 options {
438 timeout(time: "${timeout}", unit: 'MINUTES')
439 }
440 environment {
Joey Armstrong642540a2023-08-10 10:26:36 -0400441 KUBECONFIG = "$HOME/.kube/kind-${clusterName}"
442 VOLTCONFIG = "$HOME/.volt/config"
443 PATH = "$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
444 DIAGS_PROFILE = 'VOLTHA_PROFILE'
445 SSHPASS = 'karaf'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400446 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400447
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400448 stages {
449 stage('Download Code') {
450 steps {
451 getVolthaCode([
452 branch: "${branch}",
453 gerritProject: "${gerritProject}",
454 gerritRefspec: "${gerritRefspec}",
455 volthaSystemTestsChange: "${volthaSystemTestsChange}",
456 volthaHelmChartsChange: "${volthaHelmChartsChange}",
457 ])
458 }
459 }
460
461 stage('Build patch v1.1')
462 {
463 // build the patch only if gerritProject is specified
464 when
465 {
466 expression
467 {
468 return !gerritProject.isEmpty()
469 }
470 }
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400471
472 steps
473 {
474 // NOTE that the correct patch has already been checked out
475 // during the getVolthaCode step
476 buildVolthaComponent("${gerritProject}")
477 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400478 }
479
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400480 // -----------------------------------------------------------------------
481 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400482 stage('Install Kail')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400483 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400484 steps
485 {
486 script
487 {
488 String cmd = [
489 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400490 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400491 '-C', "$WORKSPACE/voltha-system-tests",
492 "KAIL_PATH=\"$WORKSPACE/bin\"",
493 'kail',
494 ].join(' ')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400495
Joey Armstrongf060aee2023-08-22 21:55:26 -0400496 println(" ** Running: ${cmd}")
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400497 sh("${cmd}")
498 } // script
499 } // steps
500 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400501
502 // -----------------------------------------------------------------------
503 // -----------------------------------------------------------------------
Joey Armstrong39f90382023-08-24 20:37:40 -0400504 stage('Install Tools') {
505 steps {
506 script {
507 String branchName = branchName()
508 String iam = getIam('Install Tools')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400509
Joey Armstrong39f90382023-08-24 20:37:40 -0400510 println("${iam}: ENTER (branch=$branch)")
511 installKind(branch) // needed early by stage(Cleanup)
512 println("${iam}: LEAVE (branch=$branch)")
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400513 } // script
514 } // steps
515 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400516
517 // -----------------------------------------------------------------------
518 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400519 stage('Create K8s Cluster') {
520 steps {
521 script {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400522 def clusterExists = sh(
Joey Armstrongf060aee2023-08-22 21:55:26 -0400523 returnStdout: true,
524 script: """kind get clusters | grep "${clusterName}" | wc -l""")
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400525
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400526 if (clusterExists.trim() == '0') {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400527 createKubernetesCluster([nodes: 3, name: clusterName])
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400528 }
Joey Armstrongf060aee2023-08-22 21:55:26 -0400529 } // script
530 } // steps
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400531 } // stage('Create K8s Cluster')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400532
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400533 // -----------------------------------------------------------------------
534 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400535 stage('Replace voltctl') {
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400536 // if the project is voltctl, override the downloaded one with the built one
537 when {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400538 expression { return gerritProject == 'voltctl' }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400539 }
540
541 // Hmmmm(?) where did the voltctl download happen ?
542 // Likely Makefile but would be helpful to document here.
Joey Armstrongf060aee2023-08-22 21:55:26 -0400543 steps {
Joey Armstrong6115fd62023-08-24 08:19:28 -0400544 script {
545 String iam = getIam('Replace voltctl')
546
547 println("${iam} Running: installVoltctl($branch)")
548 println("${iam}: ENTER")
549 installVoltctl("$branch")
550 println("${iam}: LEAVE")
551 } // script
552 } // steps
Joey Armstrong268442d2023-08-22 17:16:10 -0400553 } // stage
554
555 // -----------------------------------------------------------------------
556 // -----------------------------------------------------------------------
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400557 stage('Load image in kind nodes')
558 {
559 when {
560 expression { return !gerritProject.isEmpty() }
561 }
562 steps {
563 loadToKind()
564 } // steps
565 } // stage
566
567 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400568 // [TODO] verify testing output
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400569 // -----------------------------------------------------------------------
570 stage('Parse and execute tests')
571 {
572 steps {
573 script {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400574 // Announce ourselves for log usability
575 String iam = getIam('execute_test')
576 println("${iam}: ENTER")
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400577
578 def tests = readYaml text: testTargets
579
Joey Armstrongb29d5612023-08-24 12:53:46 -0400580 String buffer = []
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400581 tests.eachWithIndex { test, idx ->
582 String target = test['target']
Joey Armstrongbe7c9242023-08-24 16:20:31 -0400583 buffer.add(" test[${idx}]: ${target}\n")
Joey Armstrong38a87832023-08-23 17:02:50 -0400584 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400585
Joey Armstrongb29d5612023-08-24 12:53:46 -0400586 println("** Testing index: tests-to-run")
587 println(buffer)
Joey Armstrongbe7c9242023-08-24 16:20:31 -0400588 println('''
Joey Armstrongb29d5612023-08-24 12:53:46 -0400589** -----------------------------------------------------------------------
590** NOTE: For odd/silent job failures verify a few details
591** - All tests mentioned in the index have been processed.
592** - Test suites display ENTER/LEAVE mesasge pairs.
593** -----------------------------------------------------------------------
Joey Armstrongbe7c9242023-08-24 16:20:31 -0400594''')
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400595 tests.eachWithIndex { test, idx ->
596 println "** readYaml test suite[$idx]) test=[${test}]"
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400597
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400598 String target = test['target']
599 String workflow = test['workflow']
600 String flags = test['flags']
601 Boolean teardown = test['teardown'].toBoolean()
602 Boolean logging = test['logging'].toBoolean()
603 String testLogging = (logging) ? 'True' : 'False'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400604
Joey Armstrong268442d2023-08-22 17:16:10 -0400605 print("""
Joey Armstrong268442d2023-08-22 17:16:10 -0400606** -----------------------------------------------------------------------
Joey Armstrong38a87832023-08-23 17:02:50 -0400607** Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}
Joey Armstrong268442d2023-08-22 17:16:10 -0400608** -----------------------------------------------------------------------
Joey Armstrong38a87832023-08-23 17:02:50 -0400609""")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400610
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400611 try {
612 println "Executing test ${target}: ENTER"
613 execute_test(target, workflow, testLogging, teardown, flags)
614 }
615 catch (Exception err) {
616 println("** ${iam}: EXCEPTION ${err}")
617 }
618 finally {
619 println "Executing test ${target}: LEAVE"
620 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400621
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400622 } // for
Joey Armstrong642540a2023-08-10 10:26:36 -0400623
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400624 // Premature exit if this message is not logged
625 println("${iam}: LEAVE (testing ran to completion)")
Joey Armstrong54dec092023-08-03 18:21:38 -0400626 } // script
627 } // steps
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400628 } // stage
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400629 } // stages
630
631 post
632 {
633 aborted { collectArtifacts('aborted') }
634 failure { collectArtifacts('failed') }
635 always { collectArtifacts('always') }
636 }
637} // pipeline
638
639// EOF