blob: b41110985ce2adc4d21630a7945c05fd6c4b7bff [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.
Joey Armstrongd0b5af02023-08-25 15:12:54 -040043// Jenkins will re-write the call stack for serialization.S
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040044// -----------------------------------------------------------------------
Joey Armstrongd0b5af02023-08-25 15:12:54 -040045// Note: Hardcoded version string used to visualize changes in jenkins UI
46// -----------------------------------------------------------------------
47tring getIam(String func, Boolean verbose=True) {
Joey Armstrong54dec092023-08-03 18:21:38 -040048 String branchName = branchName()
Joey Armstrongd0b5af02023-08-25 15:12:54 -040049 String version = '4f87de8f31d588d8277dc5ea6fbb69e714c66079'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040050 String src = [
51 'ci-management',
52 'jjb',
53 'pipeline',
54 'voltha',
Joey Armstrong54dec092023-08-03 18:21:38 -040055 branchName,
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040056 'bbsim-tests.groovy'
57 ].join('/')
58
Joey Armstrongd0b5af02023-08-25 15:12:54 -040059 String name = [src, version, func].join('::')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040060 return(name)
61}
62
63// -----------------------------------------------------------------------
64// Intent: Determine if working on a release branch.
65// Note: Conditional is legacy, should also check for *-dev or *-pre
66// -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -040067Boolean isReleaseBranch(String name) {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040068 // List modifiers = ['-dev', '-pre', 'voltha-x.y.z-pre']
Joey Armstrong54dec092023-08-03 18:21:38 -040069 // if branchName in modifiers
70 return(name != 'master') // OR branchName.contains('-')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040071}
72
73// -----------------------------------------------------------------------
Joey Armstrong38a87832023-08-23 17:02:50 -040074// Intent:
Joey Armstrongf060aee2023-08-22 21:55:26 -040075// -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -040076void execute_test(testTarget, workflow, testLogging, teardown, testSpecificHelmFlags='') {
Joey Armstrong54dec092023-08-03 18:21:38 -040077 String infraNamespace = 'default'
78 String volthaNamespace = 'voltha'
79 String logsDir = "$WORKSPACE/${testTarget}"
Joey Armstrong7bcb5782023-06-07 12:25:57 -040080
81 stage('IAM')
82 {
83 script
84 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040085 // Announce ourselves for log usability
Joey Armstrong642540a2023-08-10 10:26:36 -040086 String iam = getIam('execute_test')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040087 println("${iam}: ENTER")
88 println("${iam}: LEAVE")
Joey Armstrong7bcb5782023-06-07 12:25:57 -040089 }
90 }
Joey Armstrong54dec092023-08-03 18:21:38 -040091
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040092 // -----------------------------------------------------------------------
Joey Armstrong008cfaf2023-08-18 14:49:06 -040093 // Intent: Cleanup stale port-forwarding
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040094 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -040095 stage('Cleanup') {
Joey Armstrong38a87832023-08-23 17:02:50 -040096 if (teardown) {
Joey Armstrong7bcb5782023-06-07 12:25:57 -040097 timeout(15) {
Joey Armstrong38a87832023-08-23 17:02:50 -040098 script {
Joey Armstrong54dec092023-08-03 18:21:38 -040099 helmTeardown(['default', infraNamespace, volthaNamespace])
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400100 }
Joey Armstrongf060aee2023-08-22 21:55:26 -0400101 } // timeout
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400102
Joey Armstrongf060aee2023-08-22 21:55:26 -0400103 timeout(5) {
104 script {
105 String iam = getIam('Cleanup')
106 println("${iam}: ENTER")
Joey Armstrong268442d2023-08-22 17:16:10 -0400107
Joey Armstrongf060aee2023-08-22 21:55:26 -0400108 // remove orphaned port-forward from different namespaces
109 String proc = 'port-forw'
110 pgrep_proc(proc)
111 pkill_proc(proc)
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400112 pgrep_proc(proc) // proc count == 0
Joey Armstrongf060aee2023-08-22 21:55:26 -0400113 println("${iam}: LEAVE")
Joey Armstrong38a87832023-08-23 17:02:50 -0400114 } // script
Joey Armstrongf060aee2023-08-22 21:55:26 -0400115 } // timeout
116 } // teardown
Joey Armstrong38a87832023-08-23 17:02:50 -0400117 } // stage('Cleanup')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400118
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400119 // -----------------------------------------------------------------------
120 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400121 stage('Deploy common infrastructure') {
122 script {
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400123 local dashargs = [
124 'kpi_exporter.enabled=false',
125 'dashboards.xos=false',
126 'dashboards.onos=false',
127 'dashboards.aaa=false',
128 'dashboards.voltha=false',
129 ].join(',')
130
131 local promargs = [
132 'prometheus.alertmanager.enabled=false',
133 'prometheus.pushgateway.enabled=false',
134 ].join(',')
135
Joey Armstrong38a87832023-08-23 17:02:50 -0400136 sh("""
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400137 helm repo add onf https://charts.opencord.org
138 helm repo update
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400139
140 echo -e "\nwithMonitoring=[$withMonitoring]"
141 if [ ${withMonitoring} = true ] ; then
142 helm install nem-monitoring onf/nem-monitoring \
Joey Armstrong38a87832023-08-23 17:02:50 -0400143 --set ${promargs} \
144 --set ${dashargs}
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400145 fi
Joey Armstrong38a87832023-08-23 17:02:50 -0400146 """)
147 } // script
148 } // stage('Deploy Common Infra')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400149
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400150 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400151 // [TODO] Check onos_log output
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400152 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400153 stage('Deploy Voltha') {
154 if (teardown) {
155 timeout(10) {
156 script {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400157 String iam = getIam('Deploy Voltha')
Joey Armstrong38a87832023-08-23 17:02:50 -0400158 String onosLog = "${logsDir}/onos-voltha-startup-combined.log"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400159sh("""
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400160 mkdir -p ${logsDir}
Joey Armstrong38a87832023-08-23 17:02:50 -0400161 touch "$onosLog"
162 echo "** kail-startup ENTER: \$(date)" > "$onosLog"
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400163
164 # Intermixed output (tee -a &) may get conflusing but let(s) see
165 # what messages are logged during startup.
Joey Armstrong38a87832023-08-23 17:02:50 -0400166 # _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} >> "$onosLog" &
167 _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} | tee -a "$onosLog" &
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400168 """)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400169
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400170 // if we're downloading a voltha-helm-charts patch, then install from a local copy of the charts
171 Boolean localCharts = false
Joey Armstrong642540a2023-08-10 10:26:36 -0400172
Joey Armstrong54dec092023-08-03 18:21:38 -0400173 if (volthaHelmChartsChange != ''
174 || gerritProject == 'voltha-helm-charts'
175 || isReleaseBranch(branch) // branch != 'master'
176 ) {
177 localCharts = true
178 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400179
Joey Armstrong54dec092023-08-03 18:21:38 -0400180 String branchName = branchName()
Joey Armstrong38a87832023-08-23 17:02:50 -0400181 Boolean isRelease = isReleaseBranch(branch)
Joey Armstrong54dec092023-08-03 18:21:38 -0400182 println([
183 " ** localCharts=${localCharts}",
184 "branchName=${branchName}",
185 "branch=${branch}",
Joey Armstrong38a87832023-08-23 17:02:50 -0400186 "branch=isReleaseBranch=${isRelease}",
Joey Armstrong54dec092023-08-03 18:21:38 -0400187 ].join(', '))
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400188
Joey Armstrong54dec092023-08-03 18:21:38 -0400189 // -----------------------------------------------------------------------
190 // Rewrite localHelmFlags using array join, moving code around and
Joey Armstrong642540a2023-08-10 10:26:36 -0400191 // refactoring into standalone functions
Joey Armstrong54dec092023-08-03 18:21:38 -0400192 // -----------------------------------------------------------------------
193 // hudson.remoting.ProxyException: groovy.lang.MissingMethodException:
194 // No signature of method: java.lang.String.positive() is applicable for argument types: () values: []
195 // -----------------------------------------------------------------------
196 // NOTE temporary workaround expose ONOS node ports
197 // -----------------------------------------------------------------------
198 String localHelmFlags = [
199 extraHelmFlags.trim(),
200 "--set global.log_level=${logLevel.toUpperCase()}",
201 '--set onos-classic.onosSshPort=30115',
202 '--set onos-classic.onosApiPort=30120',
203 '--set onos-classic.onosOfPort=31653',
204 '--set onos-classic.individualOpenFlowNodePorts=true',
205 testSpecificHelmFlags
206 ].join(' ')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400207
Joey Armstrongf060aee2023-08-22 21:55:26 -0400208 println("** ${iam} localHelmFlags = ${localHelmFlags}")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400209
Joey Armstrong54dec092023-08-03 18:21:38 -0400210 if (gerritProject != '') {
211 localHelmFlags = "${localHelmFlags} " + getVolthaImageFlags("${gerritProject}")
212 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400213
Joey Armstrong38a87832023-08-23 17:02:50 -0400214 println("** ${iam}: ENTER")
Joey Armstrong54dec092023-08-03 18:21:38 -0400215 volthaDeploy([
216 infraNamespace: infraNamespace,
217 volthaNamespace: volthaNamespace,
218 workflow: workflow.toLowerCase(),
219 withMacLearning: enableMacLearning.toBoolean(),
220 extraHelmFlags: localHelmFlags,
221 localCharts: localCharts,
222 bbsimReplica: olts.toInteger(),
223 dockerRegistry: registry,
224 ])
Joey Armstrong38a87832023-08-23 17:02:50 -0400225 println("** ${iam}: LEAVE")
Joey Armstrong54dec092023-08-03 18:21:38 -0400226 } // script
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400227
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400228 // -----------------------------------------------------------------------
229 // Intent: Replacing P_IDS with pgrep/pkill is a step forward.
230 // Why not simply use a pid file, capture _TAG=kail-startup above
231 // Grep runs the risk of terminating stray commands (??-good <=> bad-??)
Joey Armstrong54dec092023-08-03 18:21:38 -0400232 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400233 script {
234 String proc = '_TAG=kail-startup'
Joey Armstrongdddbbf92023-08-22 16:00:41 -0400235
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400236 println("${iam}: ENTER")
237 println("${iam}: Shutdown process $proc")
238 pgrep_proc(proc)
239 pkill_proc(proc)
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400240 pgrep_proc(proc)
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400241 println("${iam}: LEAVE")
242 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400243
Joey Armstronged345862023-08-23 12:24:20 -0400244 // -----------------------------------------------------------------------
245 // Bundle onos-voltha / kail logs
246 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400247 sh("""
248cat <<EOM
249
250** -----------------------------------------------------------------------
251** Combine an compress voltha startup log(s)
252** -----------------------------------------------------------------------
253EOM
254 pushd "${logsDir}" || { echo "ERROR: pushd $logsDir failed"; exit 1; }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400255 gzip -k onos-voltha-startup-combined.log
256 rm onos-voltha-startup-combined.log
Joey Armstrongf060aee2023-08-22 21:55:26 -0400257 popd
258 """)
Joey Armstrong38a87832023-08-23 17:02:50 -0400259 } // timeout(10)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400260
Joey Armstrongf060aee2023-08-22 21:55:26 -0400261
262 // -----------------------------------------------------------------------
263 // -----------------------------------------------------------------------
264 sh """
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400265 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"&
266 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"&
267 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"&
268 bbsimDmiPortFwd=50075
269 for i in {0..${olts.toInteger() - 1}}; do
270 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"&
271 ((bbsimDmiPortFwd++))
272 done
273 if [ ${withMonitoring} = true ] ; then
274 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"&
275 fi
276 ps aux | grep port-forward
277 """
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400278
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400279 script {
280 String proc = 'port-forward'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400281
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400282 println("${iam}: ENTER")
283 println("Display spawned ${proc}")
284 pgrep_proc(proc)
285 println("${iam}: LEAVE")
286 }
Joey Armstrongf060aee2023-08-22 21:55:26 -0400287
288 // setting ONOS log level
289 script {
290 println('** setOnosLogLevels: ENTER')
Joey Armstrong54dec092023-08-03 18:21:38 -0400291 setOnosLogLevels([
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400292 onosNamespace: infraNamespace,
293 apps: [
294 'org.opencord.dhcpl2relay',
295 'org.opencord.olt',
296 'org.opencord.aaa',
297 'org.opencord.maclearner',
298 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
299 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
300 ],
301 logLevel: logLevel
302 ])
Joey Armstrongf060aee2023-08-22 21:55:26 -0400303 println('** setOnosLogLevels: LEAVE')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400304 } // script
305 } // if (teardown)
306 } // stage('Deploy Voltha')
307
Joey Armstrongf060aee2023-08-22 21:55:26 -0400308 // -----------------------------------------------------------------------
309 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400310 stage("Run test ${testTarget} on workflow ${workflow}")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400311 {
312 sh """
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400313 echo -e "\n** Monitor using mem_consumption.py ?"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400314
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400315 if [ ${withMonitoring} = true ] ; then
Joey Armstrongf060aee2023-08-22 21:55:26 -0400316 cat <<EOM
317
318** -----------------------------------------------------------------------
319** Monitoring memory usage with mem_consumption.py
320** -----------------------------------------------------------------------
321EOM
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400322 mkdir -p "$WORKSPACE/voltha-pods-mem-consumption-${workflow}"
323 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400324
325 echo '** Installing python virtualenv'
326 make venv-activate-patched
327
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400328 set +u && source .venv/bin/activate && set -u
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400329 # Collect initial memory consumption
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400330 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 -0400331 fi
Joey Armstrongf060aee2023-08-22 21:55:26 -0400332
333 echo -e '** Monitor memory consumption: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400334 """
335
336 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400337 echo -e "\n** make testTarget=[${testTarget}]"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400338 mkdir -p ${logsDir}
339 export ROBOT_MISC_ARGS="-d ${logsDir} ${params.extraRobotArgs} "
340 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}"
341 export KVSTOREPREFIX=voltha/voltha_voltha
342
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400343 make -C "$WORKSPACE/voltha-system-tests" ${testTarget}
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400344 """
345
346 getPodsInfo("${logsDir}")
347
348 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400349 echo -e '\n** Gather robot Framework logs: ENTER'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400350 # set +e
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400351 # collect logs collected in the Robot Framework StartLogging keyword
352 cd ${logsDir}
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400353 gzip *-combined.log
354 rm -f *-combined.log
Joey Armstrong54dec092023-08-03 18:21:38 -0400355
356 echo -e '** Gather robot Framework logs: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400357 """
358
Joey Armstrongf060aee2023-08-22 21:55:26 -0400359 // -----------------------------------------------------------------------
360 // -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400361 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400362 echo -e '** Monitor pod-mem-consumption: ENTER'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400363 if [ ${withMonitoring} = true ] ; then
Joey Armstrongf060aee2023-08-22 21:55:26 -0400364 cat <<EOM
365
366** -----------------------------------------------------------------------
367** Monitoring pod-memory-consumption using mem_consumption.py
368** -----------------------------------------------------------------------
369EOM
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400370 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400371
372 echo '** Installing python virtualenv'
373 make venv-activate-patched
Joey Armstrong38a87832023-08-23 17:02:50 -0400374
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400375 set +u && source .venv/bin/activate && set -u
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400376 # Collect memory consumption of voltha pods once all the tests are complete
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400377 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 -0400378 fi
Joey Armstrong54dec092023-08-03 18:21:38 -0400379 echo -e '** Monitor pod-mem-consumption: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400380 """
381 } // stage
Joey Armstrong54dec092023-08-03 18:21:38 -0400382
383 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400384} // execute_test()
385
386// -----------------------------------------------------------------------
387// -----------------------------------------------------------------------
Joey Armstrong54dec092023-08-03 18:21:38 -0400388def collectArtifacts(exitStatus) {
Joey Armstrong6115fd62023-08-24 08:19:28 -0400389 script {
390 String iam = getIam('collectArtifacts')
391 println("${iam}: ENTER (exitStatus=${exitStatus})")
392 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400393
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400394 echo '''
395
396** -----------------------------------------------------------------------
397** collectArtifacts
398** -----------------------------------------------------------------------
399'''
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400400
Joey Armstrong642540a2023-08-10 10:26:36 -0400401 getPodsInfo("$WORKSPACE/${exitStatus}")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400402
Joey Armstrong642540a2023-08-10 10:26:36 -0400403 sh """
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400404 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400405 """
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400406
Joey Armstrong642540a2023-08-10 10:26:36 -0400407 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 -0400408
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400409 script {
410 println("${iam}: ENTER")
411 pgrep_proc('kail-startup')
412 pkill_proc('kail')
413 println("${iam}: LEAVE")
414 }
415
Joey Armstrong642540a2023-08-10 10:26:36 -0400416 println("${iam}: ENTER RobotPublisher")
417 step([$class: 'RobotPublisher',
418 disableArchiveOutput: false,
419 logFileName: '**/*/log*.html',
420 otherFiles: '',
421 outputFileName: '**/*/output*.xml',
422 outputPath: '.',
423 passThreshold: 100,
424 reportFileName: '**/*/report*.html',
425 unstableThreshold: 0,
426 onlyCritical: true]);
427 println("${iam}: LEAVE RobotPublisher")
428
429 println("${iam}: LEAVE (exitStatus=${exitStatus})")
430 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400431}
432
Joey Armstrong54dec092023-08-03 18:21:38 -0400433// -----------------------------------------------------------------------
434// Intent: main
435// -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400436pipeline {
437
438 /* no label, executor is determined by JJB */
439 agent {
440 label "${params.buildNode}"
441 }
442 options {
443 timeout(time: "${timeout}", unit: 'MINUTES')
444 }
445 environment {
Joey Armstrong642540a2023-08-10 10:26:36 -0400446 KUBECONFIG = "$HOME/.kube/kind-${clusterName}"
447 VOLTCONFIG = "$HOME/.volt/config"
448 PATH = "$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
449 DIAGS_PROFILE = 'VOLTHA_PROFILE'
450 SSHPASS = 'karaf'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400451 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400452
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400453 stages {
454 stage('Download Code') {
455 steps {
456 getVolthaCode([
457 branch: "${branch}",
458 gerritProject: "${gerritProject}",
459 gerritRefspec: "${gerritRefspec}",
460 volthaSystemTestsChange: "${volthaSystemTestsChange}",
461 volthaHelmChartsChange: "${volthaHelmChartsChange}",
462 ])
463 }
464 }
465
466 stage('Build patch v1.1')
467 {
468 // build the patch only if gerritProject is specified
469 when
470 {
471 expression
472 {
473 return !gerritProject.isEmpty()
474 }
475 }
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400476
477 steps
478 {
479 // NOTE that the correct patch has already been checked out
480 // during the getVolthaCode step
481 buildVolthaComponent("${gerritProject}")
482 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400483 }
484
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400485 // -----------------------------------------------------------------------
486 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400487 stage('Install Kail')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400488 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400489 steps
490 {
491 script
492 {
493 String cmd = [
494 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400495 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400496 '-C', "$WORKSPACE/voltha-system-tests",
497 "KAIL_PATH=\"$WORKSPACE/bin\"",
498 'kail',
499 ].join(' ')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400500
Joey Armstrongf060aee2023-08-22 21:55:26 -0400501 println(" ** Running: ${cmd}")
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400502 sh("${cmd}")
503 } // script
504 } // steps
505 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400506
507 // -----------------------------------------------------------------------
508 // -----------------------------------------------------------------------
Joey Armstrong39f90382023-08-24 20:37:40 -0400509 stage('Install Tools') {
510 steps {
511 script {
512 String branchName = branchName()
513 String iam = getIam('Install Tools')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400514
Joey Armstrong39f90382023-08-24 20:37:40 -0400515 println("${iam}: ENTER (branch=$branch)")
516 installKind(branch) // needed early by stage(Cleanup)
517 println("${iam}: LEAVE (branch=$branch)")
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400518 } // script
519 } // steps
520 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400521
522 // -----------------------------------------------------------------------
523 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400524 stage('Create K8s Cluster') {
525 steps {
526 script {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400527 def clusterExists = sh(
Joey Armstrongf060aee2023-08-22 21:55:26 -0400528 returnStdout: true,
529 script: """kind get clusters | grep "${clusterName}" | wc -l""")
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400530
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400531 if (clusterExists.trim() == '0') {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400532 createKubernetesCluster([nodes: 3, name: clusterName])
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400533 }
Joey Armstrongf060aee2023-08-22 21:55:26 -0400534 } // script
535 } // steps
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400536 } // stage('Create K8s Cluster')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400537
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400538 // -----------------------------------------------------------------------
539 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400540 stage('Replace voltctl') {
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400541 // if the project is voltctl, override the downloaded one with the built one
542 when {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400543 expression { return gerritProject == 'voltctl' }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400544 }
545
546 // Hmmmm(?) where did the voltctl download happen ?
547 // Likely Makefile but would be helpful to document here.
Joey Armstrongf060aee2023-08-22 21:55:26 -0400548 steps {
Joey Armstrong6115fd62023-08-24 08:19:28 -0400549 script {
550 String iam = getIam('Replace voltctl')
551
552 println("${iam} Running: installVoltctl($branch)")
553 println("${iam}: ENTER")
554 installVoltctl("$branch")
555 println("${iam}: LEAVE")
556 } // script
557 } // steps
Joey Armstrong268442d2023-08-22 17:16:10 -0400558 } // stage
559
560 // -----------------------------------------------------------------------
561 // -----------------------------------------------------------------------
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400562 stage('Load image in kind nodes')
563 {
564 when {
565 expression { return !gerritProject.isEmpty() }
566 }
567 steps {
568 loadToKind()
569 } // steps
570 } // stage
571
572 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400573 // [TODO] verify testing output
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400574 // -----------------------------------------------------------------------
575 stage('Parse and execute tests')
576 {
577 steps {
578 script {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400579 // Announce ourselves for log usability
580 String iam = getIam('execute_test')
581 println("${iam}: ENTER")
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400582
583 def tests = readYaml text: testTargets
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400584 println("** [DEBUG]: tests=$tests")
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400585
Joey Armstrongf46b3ae2023-08-25 11:07:20 -0400586 // Display expected tests for times when output goes dark
587 ArrayList buffer = [] as String
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400588 tests.eachWithIndex { test, idx ->
589 String target = test['target']
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400590 println(" ** Build test index [$idx]: target=$target")
Joey Armstrongbe7c9242023-08-24 16:20:31 -0400591 buffer.add(" test[${idx}]: ${target}\n")
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400592 println("** buffer contains: $buffer")
Joey Armstrong38a87832023-08-23 17:02:50 -0400593 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400594
Joey Armstrongb29d5612023-08-24 12:53:46 -0400595 println("** Testing index: tests-to-run")
Joey Armstrongf46b3ae2023-08-25 11:07:20 -0400596 println(buffer.join(''))
597
Joey Armstrongbe7c9242023-08-24 16:20:31 -0400598 println('''
Joey Armstrongb29d5612023-08-24 12:53:46 -0400599** -----------------------------------------------------------------------
600** NOTE: For odd/silent job failures verify a few details
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400601** - All tests mentioned in the tests-to-run index were logged.
Joey Armstrongb29d5612023-08-24 12:53:46 -0400602** - Test suites display ENTER/LEAVE mesasge pairs.
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400603** - Processing terminated prematurely when LEAVE strings are missing.
Joey Armstrongb29d5612023-08-24 12:53:46 -0400604** -----------------------------------------------------------------------
Joey Armstrongbe7c9242023-08-24 16:20:31 -0400605''')
Joey Armstrongf46b3ae2023-08-25 11:07:20 -0400606
607 tests.eachWithIndex { test, idx ->
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400608 println "** readYaml test suite[$idx]) test=[${test}]"
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400609
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400610 String target = test['target']
611 String workflow = test['workflow']
612 String flags = test['flags']
613 Boolean teardown = test['teardown'].toBoolean()
614 Boolean logging = test['logging'].toBoolean()
615 String testLogging = (logging) ? 'True' : 'False'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400616
Joey Armstrong268442d2023-08-22 17:16:10 -0400617 print("""
Joey Armstrong268442d2023-08-22 17:16:10 -0400618** -----------------------------------------------------------------------
Joey Armstrong38a87832023-08-23 17:02:50 -0400619** Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}
Joey Armstrong268442d2023-08-22 17:16:10 -0400620** -----------------------------------------------------------------------
Joey Armstrong38a87832023-08-23 17:02:50 -0400621""")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400622
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400623 try {
624 println "Executing test ${target}: ENTER"
625 execute_test(target, workflow, testLogging, teardown, flags)
626 }
627 catch (Exception err) {
628 println("** ${iam}: EXCEPTION ${err}")
629 }
630 finally {
631 println "Executing test ${target}: LEAVE"
632 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400633
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400634 } // for
Joey Armstrong642540a2023-08-10 10:26:36 -0400635
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400636 // Premature exit if this message is not logged
637 println("${iam}: LEAVE (testing ran to completion)")
Joey Armstrong54dec092023-08-03 18:21:38 -0400638 } // script
639 } // steps
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400640 } // stage
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400641 } // stages
642
643 post
644 {
645 aborted { collectArtifacts('aborted') }
646 failure { collectArtifacts('failed') }
647 always { collectArtifacts('always') }
648 }
649} // pipeline
650
651// EOF