blob: f26eb5af18ad96cda5b58e5de4761f68787f7fbe [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)
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400237 pgrep_proc(proc)
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400238 println("${iam}: LEAVE")
239 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400240
Joey Armstronged345862023-08-23 12:24:20 -0400241 // -----------------------------------------------------------------------
242 // Bundle onos-voltha / kail logs
243 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400244 sh("""
245cat <<EOM
246
247** -----------------------------------------------------------------------
248** Combine an compress voltha startup log(s)
249** -----------------------------------------------------------------------
250EOM
251 pushd "${logsDir}" || { echo "ERROR: pushd $logsDir failed"; exit 1; }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400252 gzip -k onos-voltha-startup-combined.log
253 rm onos-voltha-startup-combined.log
Joey Armstrongf060aee2023-08-22 21:55:26 -0400254 popd
255 """)
Joey Armstrong38a87832023-08-23 17:02:50 -0400256 } // timeout(10)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400257
Joey Armstrongf060aee2023-08-22 21:55:26 -0400258
259 // -----------------------------------------------------------------------
260 // -----------------------------------------------------------------------
261 sh """
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400262 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"&
263 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"&
264 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"&
265 bbsimDmiPortFwd=50075
266 for i in {0..${olts.toInteger() - 1}}; do
267 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"&
268 ((bbsimDmiPortFwd++))
269 done
270 if [ ${withMonitoring} = true ] ; then
271 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"&
272 fi
273 ps aux | grep port-forward
274 """
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400275
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400276 script {
277 String proc = 'port-forward'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400278
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400279 println("${iam}: ENTER")
280 println("Display spawned ${proc}")
281 pgrep_proc(proc)
282 println("${iam}: LEAVE")
283 }
Joey Armstrongf060aee2023-08-22 21:55:26 -0400284
285 // setting ONOS log level
286 script {
287 println('** setOnosLogLevels: ENTER')
Joey Armstrong54dec092023-08-03 18:21:38 -0400288 setOnosLogLevels([
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400289 onosNamespace: infraNamespace,
290 apps: [
291 'org.opencord.dhcpl2relay',
292 'org.opencord.olt',
293 'org.opencord.aaa',
294 'org.opencord.maclearner',
295 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
296 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
297 ],
298 logLevel: logLevel
299 ])
Joey Armstrongf060aee2023-08-22 21:55:26 -0400300 println('** setOnosLogLevels: LEAVE')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400301 } // script
302 } // if (teardown)
303 } // stage('Deploy Voltha')
304
Joey Armstrongf060aee2023-08-22 21:55:26 -0400305 // -----------------------------------------------------------------------
306 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400307 stage("Run test ${testTarget} on workflow ${workflow}")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400308 {
309 sh """
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400310 echo -e "\n** Monitor using mem_consumption.py ?"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400311
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400312 if [ ${withMonitoring} = true ] ; then
Joey Armstrongf060aee2023-08-22 21:55:26 -0400313 cat <<EOM
314
315** -----------------------------------------------------------------------
316** Monitoring memory usage with mem_consumption.py
317** -----------------------------------------------------------------------
318EOM
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400319 mkdir -p "$WORKSPACE/voltha-pods-mem-consumption-${workflow}"
320 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400321
322 echo '** Installing python virtualenv'
323 make venv-activate-patched
324
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400325 set +u && source .venv/bin/activate && set -u
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400326 # Collect initial memory consumption
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400327 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 -0400328 fi
Joey Armstrongf060aee2023-08-22 21:55:26 -0400329
330 echo -e '** Monitor memory consumption: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400331 """
332
333 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400334 echo -e "\n** make testTarget=[${testTarget}]"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400335 mkdir -p ${logsDir}
336 export ROBOT_MISC_ARGS="-d ${logsDir} ${params.extraRobotArgs} "
337 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}"
338 export KVSTOREPREFIX=voltha/voltha_voltha
339
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400340 make -C "$WORKSPACE/voltha-system-tests" ${testTarget}
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400341 """
342
343 getPodsInfo("${logsDir}")
344
345 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400346 echo -e '\n** Gather robot Framework logs: ENTER'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400347 # set +e
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400348 # collect logs collected in the Robot Framework StartLogging keyword
349 cd ${logsDir}
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400350 gzip *-combined.log
351 rm -f *-combined.log
Joey Armstrong54dec092023-08-03 18:21:38 -0400352
353 echo -e '** Gather robot Framework logs: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400354 """
355
Joey Armstrongf060aee2023-08-22 21:55:26 -0400356 // -----------------------------------------------------------------------
357 // -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400358 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400359 echo -e '** Monitor pod-mem-consumption: ENTER'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400360 if [ ${withMonitoring} = true ] ; then
Joey Armstrongf060aee2023-08-22 21:55:26 -0400361 cat <<EOM
362
363** -----------------------------------------------------------------------
364** Monitoring pod-memory-consumption using mem_consumption.py
365** -----------------------------------------------------------------------
366EOM
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400367 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400368
369 echo '** Installing python virtualenv'
370 make venv-activate-patched
Joey Armstrong38a87832023-08-23 17:02:50 -0400371
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400372 set +u && source .venv/bin/activate && set -u
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400373 # Collect memory consumption of voltha pods once all the tests are complete
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400374 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 -0400375 fi
Joey Armstrong54dec092023-08-03 18:21:38 -0400376 echo -e '** Monitor pod-mem-consumption: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400377 """
378 } // stage
Joey Armstrong54dec092023-08-03 18:21:38 -0400379
380 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400381} // execute_test()
382
383// -----------------------------------------------------------------------
384// -----------------------------------------------------------------------
Joey Armstrong54dec092023-08-03 18:21:38 -0400385def collectArtifacts(exitStatus) {
Joey Armstrong6115fd62023-08-24 08:19:28 -0400386 script {
387 String iam = getIam('collectArtifacts')
388 println("${iam}: ENTER (exitStatus=${exitStatus})")
389 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400390
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400391 echo '''
392
393** -----------------------------------------------------------------------
394** collectArtifacts
395** -----------------------------------------------------------------------
396'''
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400397
Joey Armstrong642540a2023-08-10 10:26:36 -0400398 getPodsInfo("$WORKSPACE/${exitStatus}")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400399
Joey Armstrong642540a2023-08-10 10:26:36 -0400400 sh """
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400401 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400402 """
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400403
Joey Armstrong642540a2023-08-10 10:26:36 -0400404 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 -0400405
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400406 script {
407 println("${iam}: ENTER")
408 pgrep_proc('kail-startup')
409 pkill_proc('kail')
410 println("${iam}: LEAVE")
411 }
412
Joey Armstrong642540a2023-08-10 10:26:36 -0400413 println("${iam}: ENTER RobotPublisher")
414 step([$class: 'RobotPublisher',
415 disableArchiveOutput: false,
416 logFileName: '**/*/log*.html',
417 otherFiles: '',
418 outputFileName: '**/*/output*.xml',
419 outputPath: '.',
420 passThreshold: 100,
421 reportFileName: '**/*/report*.html',
422 unstableThreshold: 0,
423 onlyCritical: true]);
424 println("${iam}: LEAVE RobotPublisher")
425
426 println("${iam}: LEAVE (exitStatus=${exitStatus})")
427 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400428}
429
Joey Armstrong54dec092023-08-03 18:21:38 -0400430// -----------------------------------------------------------------------
431// Intent: main
432// -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400433pipeline {
434
435 /* no label, executor is determined by JJB */
436 agent {
437 label "${params.buildNode}"
438 }
439 options {
440 timeout(time: "${timeout}", unit: 'MINUTES')
441 }
442 environment {
Joey Armstrong642540a2023-08-10 10:26:36 -0400443 KUBECONFIG = "$HOME/.kube/kind-${clusterName}"
444 VOLTCONFIG = "$HOME/.volt/config"
445 PATH = "$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
446 DIAGS_PROFILE = 'VOLTHA_PROFILE'
447 SSHPASS = 'karaf'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400448 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400449
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400450 stages {
451 stage('Download Code') {
452 steps {
453 getVolthaCode([
454 branch: "${branch}",
455 gerritProject: "${gerritProject}",
456 gerritRefspec: "${gerritRefspec}",
457 volthaSystemTestsChange: "${volthaSystemTestsChange}",
458 volthaHelmChartsChange: "${volthaHelmChartsChange}",
459 ])
460 }
461 }
462
463 stage('Build patch v1.1')
464 {
465 // build the patch only if gerritProject is specified
466 when
467 {
468 expression
469 {
470 return !gerritProject.isEmpty()
471 }
472 }
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400473
474 steps
475 {
476 // NOTE that the correct patch has already been checked out
477 // during the getVolthaCode step
478 buildVolthaComponent("${gerritProject}")
479 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400480 }
481
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400482 // -----------------------------------------------------------------------
483 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400484 stage('Install Kail')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400485 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400486 steps
487 {
488 script
489 {
490 String cmd = [
491 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400492 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400493 '-C', "$WORKSPACE/voltha-system-tests",
494 "KAIL_PATH=\"$WORKSPACE/bin\"",
495 'kail',
496 ].join(' ')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400497
Joey Armstrongf060aee2023-08-22 21:55:26 -0400498 println(" ** Running: ${cmd}")
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400499 sh("${cmd}")
500 } // script
501 } // steps
502 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400503
504 // -----------------------------------------------------------------------
505 // -----------------------------------------------------------------------
Joey Armstrong39f90382023-08-24 20:37:40 -0400506 stage('Install Tools') {
507 steps {
508 script {
509 String branchName = branchName()
510 String iam = getIam('Install Tools')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400511
Joey Armstrong39f90382023-08-24 20:37:40 -0400512 println("${iam}: ENTER (branch=$branch)")
513 installKind(branch) // needed early by stage(Cleanup)
514 println("${iam}: LEAVE (branch=$branch)")
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400515 } // script
516 } // steps
517 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400518
519 // -----------------------------------------------------------------------
520 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400521 stage('Create K8s Cluster') {
522 steps {
523 script {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400524 def clusterExists = sh(
Joey Armstrongf060aee2023-08-22 21:55:26 -0400525 returnStdout: true,
526 script: """kind get clusters | grep "${clusterName}" | wc -l""")
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400527
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400528 if (clusterExists.trim() == '0') {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400529 createKubernetesCluster([nodes: 3, name: clusterName])
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400530 }
Joey Armstrongf060aee2023-08-22 21:55:26 -0400531 } // script
532 } // steps
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400533 } // stage('Create K8s Cluster')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400534
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400535 // -----------------------------------------------------------------------
536 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400537 stage('Replace voltctl') {
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400538 // if the project is voltctl, override the downloaded one with the built one
539 when {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400540 expression { return gerritProject == 'voltctl' }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400541 }
542
543 // Hmmmm(?) where did the voltctl download happen ?
544 // Likely Makefile but would be helpful to document here.
Joey Armstrongf060aee2023-08-22 21:55:26 -0400545 steps {
Joey Armstrong6115fd62023-08-24 08:19:28 -0400546 script {
547 String iam = getIam('Replace voltctl')
548
549 println("${iam} Running: installVoltctl($branch)")
550 println("${iam}: ENTER")
551 installVoltctl("$branch")
552 println("${iam}: LEAVE")
553 } // script
554 } // steps
Joey Armstrong268442d2023-08-22 17:16:10 -0400555 } // stage
556
557 // -----------------------------------------------------------------------
558 // -----------------------------------------------------------------------
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400559 stage('Load image in kind nodes')
560 {
561 when {
562 expression { return !gerritProject.isEmpty() }
563 }
564 steps {
565 loadToKind()
566 } // steps
567 } // stage
568
569 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400570 // [TODO] verify testing output
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400571 // -----------------------------------------------------------------------
572 stage('Parse and execute tests')
573 {
574 steps {
575 script {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400576 // Announce ourselves for log usability
577 String iam = getIam('execute_test')
578 println("${iam}: ENTER")
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400579
580 def tests = readYaml text: testTargets
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400581 println("** [DEBUG]: tests=$tests")
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400582
Joey Armstrongb29d5612023-08-24 12:53:46 -0400583 String buffer = []
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400584 tests.eachWithIndex { test, idx ->
585 String target = test['target']
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400586 println(" ** Build test index [$idx]: target=$target")
Joey Armstrongbe7c9242023-08-24 16:20:31 -0400587 buffer.add(" test[${idx}]: ${target}\n")
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400588 println("** buffer contains: $buffer")
Joey Armstrong38a87832023-08-23 17:02:50 -0400589 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400590
Joey Armstrongb29d5612023-08-24 12:53:46 -0400591 println("** Testing index: tests-to-run")
592 println(buffer)
Joey Armstrongbe7c9242023-08-24 16:20:31 -0400593 println('''
Joey Armstrongb29d5612023-08-24 12:53:46 -0400594** -----------------------------------------------------------------------
595** NOTE: For odd/silent job failures verify a few details
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400596** - All tests mentioned in the tests-to-run index were logged.
Joey Armstrongb29d5612023-08-24 12:53:46 -0400597** - Test suites display ENTER/LEAVE mesasge pairs.
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400598** - Processing terminated prematurely when LEAVE strings are missing.
Joey Armstrongb29d5612023-08-24 12:53:46 -0400599** -----------------------------------------------------------------------
Joey Armstrongbe7c9242023-08-24 16:20:31 -0400600''')
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400601 tests.eachWithIndex { test, idx ->
602 println "** readYaml test suite[$idx]) test=[${test}]"
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400603
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400604 String target = test['target']
605 String workflow = test['workflow']
606 String flags = test['flags']
607 Boolean teardown = test['teardown'].toBoolean()
608 Boolean logging = test['logging'].toBoolean()
609 String testLogging = (logging) ? 'True' : 'False'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400610
Joey Armstrong268442d2023-08-22 17:16:10 -0400611 print("""
Joey Armstrong268442d2023-08-22 17:16:10 -0400612** -----------------------------------------------------------------------
Joey Armstrong38a87832023-08-23 17:02:50 -0400613** Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}
Joey Armstrong268442d2023-08-22 17:16:10 -0400614** -----------------------------------------------------------------------
Joey Armstrong38a87832023-08-23 17:02:50 -0400615""")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400616
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400617 try {
618 println "Executing test ${target}: ENTER"
619 execute_test(target, workflow, testLogging, teardown, flags)
620 }
621 catch (Exception err) {
622 println("** ${iam}: EXCEPTION ${err}")
623 }
624 finally {
625 println "Executing test ${target}: LEAVE"
626 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400627
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400628 } // for
Joey Armstrong642540a2023-08-10 10:26:36 -0400629
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400630 // Premature exit if this message is not logged
631 println("${iam}: LEAVE (testing ran to completion)")
Joey Armstrong54dec092023-08-03 18:21:38 -0400632 } // script
633 } // steps
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400634 } // stage
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400635 } // stages
636
637 post
638 {
639 aborted { collectArtifacts('aborted') }
640 failure { collectArtifacts('failed') }
641 always { collectArtifacts('always') }
642 }
643} // pipeline
644
645// EOF