blob: 32065dded83c7cd250d77d7b7e7dba37c6e38e30 [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 pgrep_proc(String proc) {
74 String cmd = [
75 'pgrep',
Joey Armstrongd9c04b62023-08-24 10:38:51 -040076 // '--older', 5, // switch not supported, nodes using older version
Joey Armstrongec1ae0a2023-08-23 21:51:45 -040077 '--list-full',
78 proc,
79 ].join(' ')
80
81 println("** Running: ${cmd}")
82 sh("set +euo pipefail && ${cmd}")
Joey Armstrongf060aee2023-08-22 21:55:26 -040083 return
84}
85
86// -----------------------------------------------------------------------
87// -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -040088void pkill_proc(String proc) {
89 String cmd = [
90 'pkill',
Joey Armstrongd9c04b62023-08-24 10:38:51 -040091 // switch not supported, nodes using older version
92 // NOTE: pkill should not kill it-self
93 // good old kill (ps | grep -v -e grep -e '$$-me') }
94 // '--older', 5,
Joey Armstrongec1ae0a2023-08-23 21:51:45 -040095 '--echo',
96 proc,
97 ].join(' ')
98
99 println("** Running: ${cmd}")
Joey Armstrongd9c04b62023-08-24 10:38:51 -0400100 sh(""" if [[ \$(pgrep --count "${proc}") -gt 0 ]]; then "$cmd"; fi" """)
Joey Armstrongf060aee2023-08-22 21:55:26 -0400101 return
102}
103
104// -----------------------------------------------------------------------
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400105// Intent:
106// -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400107void execute_test(testTarget, workflow, testLogging, teardown, testSpecificHelmFlags='') {
Joey Armstrong54dec092023-08-03 18:21:38 -0400108 String infraNamespace = 'default'
109 String volthaNamespace = 'voltha'
110 String logsDir = "$WORKSPACE/${testTarget}"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400111
112 stage('IAM')
113 {
114 script
115 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400116 // Announce ourselves for log usability
Joey Armstrong642540a2023-08-10 10:26:36 -0400117 String iam = getIam('execute_test')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400118 println("${iam}: ENTER")
119 println("${iam}: LEAVE")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400120 }
121 }
Joey Armstrong54dec092023-08-03 18:21:38 -0400122
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400123 // -----------------------------------------------------------------------
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400124 // Intent: Cleanup stale port-forwarding
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400125 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400126 stage('Cleanup') {
Joey Armstrong38a87832023-08-23 17:02:50 -0400127 if (teardown) {
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400128 timeout(15) {
Joey Armstrong38a87832023-08-23 17:02:50 -0400129 script {
Joey Armstrong54dec092023-08-03 18:21:38 -0400130 helmTeardown(['default', infraNamespace, volthaNamespace])
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400131 }
Joey Armstrongf060aee2023-08-22 21:55:26 -0400132 } // timeout
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400133
Joey Armstrongf060aee2023-08-22 21:55:26 -0400134 timeout(5) {
135 script {
136 String iam = getIam('Cleanup')
137 println("${iam}: ENTER")
Joey Armstrong268442d2023-08-22 17:16:10 -0400138
Joey Armstrongf060aee2023-08-22 21:55:26 -0400139 // remove orphaned port-forward from different namespaces
140 String proc = 'port-forw'
141 pgrep_proc(proc)
142 pkill_proc(proc)
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400143 pgrep_proc(proc) // proc count == 0
Joey Armstrongf060aee2023-08-22 21:55:26 -0400144 println("${iam}: LEAVE")
Joey Armstrong38a87832023-08-23 17:02:50 -0400145 } // script
Joey Armstrongf060aee2023-08-22 21:55:26 -0400146 } // timeout
147 } // teardown
Joey Armstrong38a87832023-08-23 17:02:50 -0400148 } // stage('Cleanup')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400149
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400150 // -----------------------------------------------------------------------
151 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400152 stage('Deploy common infrastructure') {
153 script {
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400154 local dashargs = [
155 'kpi_exporter.enabled=false',
156 'dashboards.xos=false',
157 'dashboards.onos=false',
158 'dashboards.aaa=false',
159 'dashboards.voltha=false',
160 ].join(',')
161
162 local promargs = [
163 'prometheus.alertmanager.enabled=false',
164 'prometheus.pushgateway.enabled=false',
165 ].join(',')
166
Joey Armstrong38a87832023-08-23 17:02:50 -0400167 sh("""
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400168 helm repo add onf https://charts.opencord.org
169 helm repo update
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400170
171 echo -e "\nwithMonitoring=[$withMonitoring]"
172 if [ ${withMonitoring} = true ] ; then
173 helm install nem-monitoring onf/nem-monitoring \
Joey Armstrong38a87832023-08-23 17:02:50 -0400174 --set ${promargs} \
175 --set ${dashargs}
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400176 fi
Joey Armstrong38a87832023-08-23 17:02:50 -0400177 """)
178 } // script
179 } // stage('Deploy Common Infra')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400180
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400181 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400182 // [TODO] Check onos_log output
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400183 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400184 stage('Deploy Voltha') {
185 if (teardown) {
186 timeout(10) {
187 script {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400188 String iam = getIam('Deploy Voltha')
Joey Armstrong38a87832023-08-23 17:02:50 -0400189 String onosLog = "${logsDir}/onos-voltha-startup-combined.log"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400190sh("""
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400191 mkdir -p ${logsDir}
Joey Armstrong38a87832023-08-23 17:02:50 -0400192 touch "$onosLog"
193 echo "** kail-startup ENTER: \$(date)" > "$onosLog"
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400194
195 # Intermixed output (tee -a &) may get conflusing but let(s) see
196 # what messages are logged during startup.
Joey Armstrong38a87832023-08-23 17:02:50 -0400197 # _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} >> "$onosLog" &
198 _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} | tee -a "$onosLog" &
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400199 """)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400200
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400201 // if we're downloading a voltha-helm-charts patch, then install from a local copy of the charts
202 Boolean localCharts = false
Joey Armstrong642540a2023-08-10 10:26:36 -0400203
Joey Armstrong54dec092023-08-03 18:21:38 -0400204 if (volthaHelmChartsChange != ''
205 || gerritProject == 'voltha-helm-charts'
206 || isReleaseBranch(branch) // branch != 'master'
207 ) {
208 localCharts = true
209 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400210
Joey Armstrong54dec092023-08-03 18:21:38 -0400211 String branchName = branchName()
Joey Armstrong38a87832023-08-23 17:02:50 -0400212 Boolean isRelease = isReleaseBranch(branch)
Joey Armstrong54dec092023-08-03 18:21:38 -0400213 println([
214 " ** localCharts=${localCharts}",
215 "branchName=${branchName}",
216 "branch=${branch}",
Joey Armstrong38a87832023-08-23 17:02:50 -0400217 "branch=isReleaseBranch=${isRelease}",
Joey Armstrong54dec092023-08-03 18:21:38 -0400218 ].join(', '))
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400219
Joey Armstrong54dec092023-08-03 18:21:38 -0400220 // -----------------------------------------------------------------------
221 // Rewrite localHelmFlags using array join, moving code around and
Joey Armstrong642540a2023-08-10 10:26:36 -0400222 // refactoring into standalone functions
Joey Armstrong54dec092023-08-03 18:21:38 -0400223 // -----------------------------------------------------------------------
224 // hudson.remoting.ProxyException: groovy.lang.MissingMethodException:
225 // No signature of method: java.lang.String.positive() is applicable for argument types: () values: []
226 // -----------------------------------------------------------------------
227 // NOTE temporary workaround expose ONOS node ports
228 // -----------------------------------------------------------------------
229 String localHelmFlags = [
230 extraHelmFlags.trim(),
231 "--set global.log_level=${logLevel.toUpperCase()}",
232 '--set onos-classic.onosSshPort=30115',
233 '--set onos-classic.onosApiPort=30120',
234 '--set onos-classic.onosOfPort=31653',
235 '--set onos-classic.individualOpenFlowNodePorts=true',
236 testSpecificHelmFlags
237 ].join(' ')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400238
Joey Armstrongf060aee2023-08-22 21:55:26 -0400239 println("** ${iam} localHelmFlags = ${localHelmFlags}")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400240
Joey Armstrong54dec092023-08-03 18:21:38 -0400241 if (gerritProject != '') {
242 localHelmFlags = "${localHelmFlags} " + getVolthaImageFlags("${gerritProject}")
243 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400244
Joey Armstrong38a87832023-08-23 17:02:50 -0400245 println("** ${iam}: ENTER")
Joey Armstrong54dec092023-08-03 18:21:38 -0400246 volthaDeploy([
247 infraNamespace: infraNamespace,
248 volthaNamespace: volthaNamespace,
249 workflow: workflow.toLowerCase(),
250 withMacLearning: enableMacLearning.toBoolean(),
251 extraHelmFlags: localHelmFlags,
252 localCharts: localCharts,
253 bbsimReplica: olts.toInteger(),
254 dockerRegistry: registry,
255 ])
Joey Armstrong38a87832023-08-23 17:02:50 -0400256 println("** ${iam}: LEAVE")
Joey Armstrong54dec092023-08-03 18:21:38 -0400257 } // script
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400258
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400259 // -----------------------------------------------------------------------
260 // Intent: Replacing P_IDS with pgrep/pkill is a step forward.
261 // Why not simply use a pid file, capture _TAG=kail-startup above
262 // Grep runs the risk of terminating stray commands (??-good <=> bad-??)
Joey Armstrong54dec092023-08-03 18:21:38 -0400263 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400264 script {
265 String proc = '_TAG=kail-startup'
Joey Armstrongdddbbf92023-08-22 16:00:41 -0400266
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400267 println("${iam}: ENTER")
268 println("${iam}: Shutdown process $proc")
269 pgrep_proc(proc)
270 pkill_proc(proc)
271 println("${iam}: LEAVE")
272 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400273
Joey Armstronged345862023-08-23 12:24:20 -0400274 // -----------------------------------------------------------------------
275 // Bundle onos-voltha / kail logs
276 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400277 sh("""
278cat <<EOM
279
280** -----------------------------------------------------------------------
281** Combine an compress voltha startup log(s)
282** -----------------------------------------------------------------------
283EOM
284 pushd "${logsDir}" || { echo "ERROR: pushd $logsDir failed"; exit 1; }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400285 gzip -k onos-voltha-startup-combined.log
286 rm onos-voltha-startup-combined.log
Joey Armstrongf060aee2023-08-22 21:55:26 -0400287 popd
288 """)
Joey Armstrong38a87832023-08-23 17:02:50 -0400289 } // timeout(10)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400290
Joey Armstrongf060aee2023-08-22 21:55:26 -0400291
292 // -----------------------------------------------------------------------
293 // -----------------------------------------------------------------------
294 sh """
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400295 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"&
296 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"&
297 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"&
298 bbsimDmiPortFwd=50075
299 for i in {0..${olts.toInteger() - 1}}; do
300 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"&
301 ((bbsimDmiPortFwd++))
302 done
303 if [ ${withMonitoring} = true ] ; then
304 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"&
305 fi
306 ps aux | grep port-forward
307 """
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400308 script {
309 String proc = 'port-forward'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400310
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400311 println("${iam}: ENTER")
312 println("Display spawned ${proc}")
313 pgrep_proc(proc)
314 println("${iam}: LEAVE")
315 }
Joey Armstrongf060aee2023-08-22 21:55:26 -0400316
317 // setting ONOS log level
318 script {
319 println('** setOnosLogLevels: ENTER')
Joey Armstrong54dec092023-08-03 18:21:38 -0400320 setOnosLogLevels([
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400321 onosNamespace: infraNamespace,
322 apps: [
323 'org.opencord.dhcpl2relay',
324 'org.opencord.olt',
325 'org.opencord.aaa',
326 'org.opencord.maclearner',
327 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
328 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
329 ],
330 logLevel: logLevel
331 ])
Joey Armstrongf060aee2023-08-22 21:55:26 -0400332 println('** setOnosLogLevels: LEAVE')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400333 } // script
334 } // if (teardown)
335 } // stage('Deploy Voltha')
336
Joey Armstrongf060aee2023-08-22 21:55:26 -0400337 // -----------------------------------------------------------------------
338 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400339 stage("Run test ${testTarget} on workflow ${workflow}")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400340 {
341 sh """
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400342 echo -e "\n** Monitor using mem_consumption.py ?"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400343
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400344 if [ ${withMonitoring} = true ] ; then
Joey Armstrongf060aee2023-08-22 21:55:26 -0400345 cat <<EOM
346
347** -----------------------------------------------------------------------
348** Monitoring memory usage with mem_consumption.py
349** -----------------------------------------------------------------------
350EOM
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400351 mkdir -p "$WORKSPACE/voltha-pods-mem-consumption-${workflow}"
352 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400353
354 echo '** Installing python virtualenv'
355 make venv-activate-patched
356
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400357 set +u && source .venv/bin/activate && set -u
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400358 # Collect initial memory consumption
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400359 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 -0400360 fi
Joey Armstrongf060aee2023-08-22 21:55:26 -0400361
362 echo -e '** Monitor memory consumption: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400363 """
364
365 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400366 echo -e "\n** make testTarget=[${testTarget}]"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400367 mkdir -p ${logsDir}
368 export ROBOT_MISC_ARGS="-d ${logsDir} ${params.extraRobotArgs} "
369 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}"
370 export KVSTOREPREFIX=voltha/voltha_voltha
371
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400372 make -C "$WORKSPACE/voltha-system-tests" ${testTarget}
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400373 """
374
375 getPodsInfo("${logsDir}")
376
377 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400378 echo -e '\n** Gather robot Framework logs: ENTER'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400379 # set +e
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400380 # collect logs collected in the Robot Framework StartLogging keyword
381 cd ${logsDir}
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400382 gzip *-combined.log
383 rm -f *-combined.log
Joey Armstrong54dec092023-08-03 18:21:38 -0400384
385 echo -e '** Gather robot Framework logs: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400386 """
387
Joey Armstrongf060aee2023-08-22 21:55:26 -0400388 // -----------------------------------------------------------------------
389 // -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400390 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400391 echo -e '** Monitor pod-mem-consumption: ENTER'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400392 if [ ${withMonitoring} = true ] ; then
Joey Armstrongf060aee2023-08-22 21:55:26 -0400393 cat <<EOM
394
395** -----------------------------------------------------------------------
396** Monitoring pod-memory-consumption using mem_consumption.py
397** -----------------------------------------------------------------------
398EOM
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400399 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400400
401 echo '** Installing python virtualenv'
402 make venv-activate-patched
Joey Armstrong38a87832023-08-23 17:02:50 -0400403
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400404 set +u && source .venv/bin/activate && set -u
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400405 # Collect memory consumption of voltha pods once all the tests are complete
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400406 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 -0400407 fi
Joey Armstrong54dec092023-08-03 18:21:38 -0400408 echo -e '** Monitor pod-mem-consumption: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400409 """
410 } // stage
Joey Armstrong54dec092023-08-03 18:21:38 -0400411
412 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400413} // execute_test()
414
415// -----------------------------------------------------------------------
416// -----------------------------------------------------------------------
Joey Armstrong54dec092023-08-03 18:21:38 -0400417def collectArtifacts(exitStatus) {
Joey Armstrong6115fd62023-08-24 08:19:28 -0400418 script {
419 String iam = getIam('collectArtifacts')
420 println("${iam}: ENTER (exitStatus=${exitStatus})")
421 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400422
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400423 echo '''
424
425** -----------------------------------------------------------------------
426** collectArtifacts
427** -----------------------------------------------------------------------
428'''
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400429
Joey Armstrong642540a2023-08-10 10:26:36 -0400430 getPodsInfo("$WORKSPACE/${exitStatus}")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400431
Joey Armstrong642540a2023-08-10 10:26:36 -0400432 sh """
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400433 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400434 """
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400435
Joey Armstrong642540a2023-08-10 10:26:36 -0400436 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 -0400437
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400438 script {
439 println("${iam}: ENTER")
440 pgrep_proc('kail-startup')
441 pkill_proc('kail')
442 println("${iam}: LEAVE")
443 }
444
Joey Armstrong642540a2023-08-10 10:26:36 -0400445 println("${iam}: ENTER RobotPublisher")
446 step([$class: 'RobotPublisher',
447 disableArchiveOutput: false,
448 logFileName: '**/*/log*.html',
449 otherFiles: '',
450 outputFileName: '**/*/output*.xml',
451 outputPath: '.',
452 passThreshold: 100,
453 reportFileName: '**/*/report*.html',
454 unstableThreshold: 0,
455 onlyCritical: true]);
456 println("${iam}: LEAVE RobotPublisher")
457
458 println("${iam}: LEAVE (exitStatus=${exitStatus})")
459 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400460}
461
Joey Armstrong54dec092023-08-03 18:21:38 -0400462// -----------------------------------------------------------------------
463// Intent: main
464// -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400465pipeline {
466
467 /* no label, executor is determined by JJB */
468 agent {
469 label "${params.buildNode}"
470 }
471 options {
472 timeout(time: "${timeout}", unit: 'MINUTES')
473 }
474 environment {
Joey Armstrong642540a2023-08-10 10:26:36 -0400475 KUBECONFIG = "$HOME/.kube/kind-${clusterName}"
476 VOLTCONFIG = "$HOME/.volt/config"
477 PATH = "$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
478 DIAGS_PROFILE = 'VOLTHA_PROFILE'
479 SSHPASS = 'karaf'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400480 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400481
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400482 stages {
483 stage('Download Code') {
484 steps {
485 getVolthaCode([
486 branch: "${branch}",
487 gerritProject: "${gerritProject}",
488 gerritRefspec: "${gerritRefspec}",
489 volthaSystemTestsChange: "${volthaSystemTestsChange}",
490 volthaHelmChartsChange: "${volthaHelmChartsChange}",
491 ])
492 }
493 }
494
495 stage('Build patch v1.1')
496 {
497 // build the patch only if gerritProject is specified
498 when
499 {
500 expression
501 {
502 return !gerritProject.isEmpty()
503 }
504 }
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400505
506 steps
507 {
508 // NOTE that the correct patch has already been checked out
509 // during the getVolthaCode step
510 buildVolthaComponent("${gerritProject}")
511 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400512 }
513
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400514 // -----------------------------------------------------------------------
515 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400516 stage('Install Kail')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400517 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400518 steps
519 {
520 script
521 {
522 String cmd = [
523 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400524 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400525 '-C', "$WORKSPACE/voltha-system-tests",
526 "KAIL_PATH=\"$WORKSPACE/bin\"",
527 'kail',
528 ].join(' ')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400529
Joey Armstrongf060aee2023-08-22 21:55:26 -0400530 println(" ** Running: ${cmd}")
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400531 sh("${cmd}")
532 } // script
533 } // steps
534 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400535
536 // -----------------------------------------------------------------------
537 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400538 stage('Install Kind')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400539 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400540 steps
541 {
542 script
543 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400544
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400545 String cmd = [
546 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400547 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400548 '-C', "$WORKSPACE/voltha-system-tests",
549 "KIND_PATH=\"$WORKSPACE/bin\"",
550 'install-command-kind',
551 ].join(' ')
Joey Armstrong642540a2023-08-10 10:26:36 -0400552
Joey Armstrongf060aee2023-08-22 21:55:26 -0400553 println(" ** Running: ${cmd}")
554 sh("${cmd}")
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400555 } // script
556 } // steps
557 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400558
559 // -----------------------------------------------------------------------
560 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400561 stage('Create K8s Cluster') {
562 steps {
563 script {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400564 def clusterExists = sh(
Joey Armstrongf060aee2023-08-22 21:55:26 -0400565 returnStdout: true,
566 script: """kind get clusters | grep "${clusterName}" | wc -l""")
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400567
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400568 if (clusterExists.trim() == '0') {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400569 createKubernetesCluster([nodes: 3, name: clusterName])
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400570 }
Joey Armstrongf060aee2023-08-22 21:55:26 -0400571 } // script
572 } // steps
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400573 } // stage('Create K8s Cluster')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400574
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400575 // -----------------------------------------------------------------------
576 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400577 stage('Replace voltctl') {
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400578 // if the project is voltctl, override the downloaded one with the built one
579 when {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400580 expression { return gerritProject == 'voltctl' }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400581 }
582
583 // Hmmmm(?) where did the voltctl download happen ?
584 // Likely Makefile but would be helpful to document here.
Joey Armstrongf060aee2023-08-22 21:55:26 -0400585 steps {
Joey Armstrong6115fd62023-08-24 08:19:28 -0400586 script {
587 String iam = getIam('Replace voltctl')
588
589 println("${iam} Running: installVoltctl($branch)")
590 println("${iam}: ENTER")
591 installVoltctl("$branch")
592 println("${iam}: LEAVE")
593 } // script
594 } // steps
Joey Armstrong268442d2023-08-22 17:16:10 -0400595 } // stage
596
597 // -----------------------------------------------------------------------
598 // -----------------------------------------------------------------------
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400599 stage('Load image in kind nodes')
600 {
601 when {
602 expression { return !gerritProject.isEmpty() }
603 }
604 steps {
605 loadToKind()
606 } // steps
607 } // stage
608
609 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400610 // [TODO] verify testing output
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400611 // -----------------------------------------------------------------------
612 stage('Parse and execute tests')
613 {
614 steps {
615 script {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400616 // Announce ourselves for log usability
617 String iam = getIam('execute_test')
618 println("${iam}: ENTER")
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400619
620 def tests = readYaml text: testTargets
621
622 println("** $iam: Testing index: tests-to-run")
623 tests.eachWithIndex { test, idx ->
624 String target = test['target']
625 println("** $idx: $target")
Joey Armstrong38a87832023-08-23 17:02:50 -0400626 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400627 println("** NOTE: For odd failures compare tests-to-run with teste output")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400628
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400629 tests.eachWithIndex { test, idx ->
630 println "** readYaml test suite[$idx]) test=[${test}]"
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400631
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400632 String target = test['target']
633 String workflow = test['workflow']
634 String flags = test['flags']
635 Boolean teardown = test['teardown'].toBoolean()
636 Boolean logging = test['logging'].toBoolean()
637 String testLogging = (logging) ? 'True' : 'False'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400638
Joey Armstrong268442d2023-08-22 17:16:10 -0400639 print("""
Joey Armstrong268442d2023-08-22 17:16:10 -0400640** -----------------------------------------------------------------------
Joey Armstrong38a87832023-08-23 17:02:50 -0400641** Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}
Joey Armstrong268442d2023-08-22 17:16:10 -0400642** -----------------------------------------------------------------------
Joey Armstrong38a87832023-08-23 17:02:50 -0400643""")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400644
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400645 try {
646 println "Executing test ${target}: ENTER"
647 execute_test(target, workflow, testLogging, teardown, flags)
648 }
649 catch (Exception err) {
650 println("** ${iam}: EXCEPTION ${err}")
651 }
652 finally {
653 println "Executing test ${target}: LEAVE"
654 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400655
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400656 } // for
Joey Armstrong642540a2023-08-10 10:26:36 -0400657
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400658 // Premature exit if this message is not logged
659 println("${iam}: LEAVE (testing ran to completion)")
Joey Armstrong54dec092023-08-03 18:21:38 -0400660 } // script
661 } // steps
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400662 } // stage
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400663 } // stages
664
665 post
666 {
667 aborted { collectArtifacts('aborted') }
668 failure { collectArtifacts('failed') }
669 always { collectArtifacts('always') }
670 }
671} // pipeline
672
673// EOF