blob: 25aaee993035803fda712b4cbd83ac234134c335 [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) {
Joey Armstrongb29d5612023-08-24 12:53:46 -040074
75 println("** RAW PROCESS OUTPUT:")
76 def stream = sh(returnStdout: true, scirpt: 'ps faaux')
77 println(stream)
78
Joey Armstrongec1ae0a2023-08-23 21:51:45 -040079 String cmd = [
80 'pgrep',
Joey Armstrongd9c04b62023-08-24 10:38:51 -040081 // '--older', 5, // switch not supported, nodes using older version
Joey Armstrongec1ae0a2023-08-23 21:51:45 -040082 '--list-full',
Joey Armstrongb29d5612023-08-24 12:53:46 -040083 "\"${proc}\"",
84 ';',
85 'echo', 'DONE',
86 ';',
87 'true',
Joey Armstrongec1ae0a2023-08-23 21:51:45 -040088 ].join(' ')
89
90 println("** Running: ${cmd}")
Joey Armstrongb29d5612023-08-24 12:53:46 -040091 sh(
92 returnStdout: true,
93 "set +euo pipefail && ${cmd}"
94 )
Joey Armstrongf060aee2023-08-22 21:55:26 -040095 return
96}
97
98// -----------------------------------------------------------------------
99// -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400100void pkill_proc(String proc) {
101 String cmd = [
102 'pkill',
Joey Armstrongd9c04b62023-08-24 10:38:51 -0400103 // switch not supported, nodes using older version
104 // NOTE: pkill should not kill it-self
105 // good old kill (ps | grep -v -e grep -e '$$-me') }
106 // '--older', 5,
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400107 '--echo',
Joey Armstrongb29d5612023-08-24 12:53:46 -0400108 "\"${proc}\"",
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400109 ].join(' ')
110
111 println("** Running: ${cmd}")
Joey Armstrongd9c04b62023-08-24 10:38:51 -0400112 sh(""" if [[ \$(pgrep --count "${proc}") -gt 0 ]]; then "$cmd"; fi" """)
Joey Armstrongf060aee2023-08-22 21:55:26 -0400113 return
114}
115
116// -----------------------------------------------------------------------
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400117// Intent:
118// -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400119void execute_test(testTarget, workflow, testLogging, teardown, testSpecificHelmFlags='') {
Joey Armstrong54dec092023-08-03 18:21:38 -0400120 String infraNamespace = 'default'
121 String volthaNamespace = 'voltha'
122 String logsDir = "$WORKSPACE/${testTarget}"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400123
124 stage('IAM')
125 {
126 script
127 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400128 // Announce ourselves for log usability
Joey Armstrong642540a2023-08-10 10:26:36 -0400129 String iam = getIam('execute_test')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400130 println("${iam}: ENTER")
131 println("${iam}: LEAVE")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400132 }
133 }
Joey Armstrong54dec092023-08-03 18:21:38 -0400134
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400135 // -----------------------------------------------------------------------
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400136 // Intent: Cleanup stale port-forwarding
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400137 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400138 stage('Cleanup') {
Joey Armstrong38a87832023-08-23 17:02:50 -0400139 if (teardown) {
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400140 timeout(15) {
Joey Armstrong38a87832023-08-23 17:02:50 -0400141 script {
Joey Armstrong54dec092023-08-03 18:21:38 -0400142 helmTeardown(['default', infraNamespace, volthaNamespace])
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400143 }
Joey Armstrongf060aee2023-08-22 21:55:26 -0400144 } // timeout
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400145
Joey Armstrongf060aee2023-08-22 21:55:26 -0400146 timeout(5) {
147 script {
148 String iam = getIam('Cleanup')
149 println("${iam}: ENTER")
Joey Armstrong268442d2023-08-22 17:16:10 -0400150
Joey Armstrongf060aee2023-08-22 21:55:26 -0400151 // remove orphaned port-forward from different namespaces
152 String proc = 'port-forw'
153 pgrep_proc(proc)
154 pkill_proc(proc)
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400155 pgrep_proc(proc) // proc count == 0
Joey Armstrongf060aee2023-08-22 21:55:26 -0400156 println("${iam}: LEAVE")
Joey Armstrong38a87832023-08-23 17:02:50 -0400157 } // script
Joey Armstrongf060aee2023-08-22 21:55:26 -0400158 } // timeout
159 } // teardown
Joey Armstrong38a87832023-08-23 17:02:50 -0400160 } // stage('Cleanup')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400161
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400162 // -----------------------------------------------------------------------
163 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400164 stage('Deploy common infrastructure') {
165 script {
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400166 local dashargs = [
167 'kpi_exporter.enabled=false',
168 'dashboards.xos=false',
169 'dashboards.onos=false',
170 'dashboards.aaa=false',
171 'dashboards.voltha=false',
172 ].join(',')
173
174 local promargs = [
175 'prometheus.alertmanager.enabled=false',
176 'prometheus.pushgateway.enabled=false',
177 ].join(',')
178
Joey Armstrong38a87832023-08-23 17:02:50 -0400179 sh("""
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400180 helm repo add onf https://charts.opencord.org
181 helm repo update
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400182
183 echo -e "\nwithMonitoring=[$withMonitoring]"
184 if [ ${withMonitoring} = true ] ; then
185 helm install nem-monitoring onf/nem-monitoring \
Joey Armstrong38a87832023-08-23 17:02:50 -0400186 --set ${promargs} \
187 --set ${dashargs}
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400188 fi
Joey Armstrong38a87832023-08-23 17:02:50 -0400189 """)
190 } // script
191 } // stage('Deploy Common Infra')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400192
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400193 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400194 // [TODO] Check onos_log output
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400195 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400196 stage('Deploy Voltha') {
197 if (teardown) {
198 timeout(10) {
199 script {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400200 String iam = getIam('Deploy Voltha')
Joey Armstrong38a87832023-08-23 17:02:50 -0400201 String onosLog = "${logsDir}/onos-voltha-startup-combined.log"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400202sh("""
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400203 mkdir -p ${logsDir}
Joey Armstrong38a87832023-08-23 17:02:50 -0400204 touch "$onosLog"
205 echo "** kail-startup ENTER: \$(date)" > "$onosLog"
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400206
207 # Intermixed output (tee -a &) may get conflusing but let(s) see
208 # what messages are logged during startup.
Joey Armstrong38a87832023-08-23 17:02:50 -0400209 # _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} >> "$onosLog" &
210 _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} | tee -a "$onosLog" &
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400211 """)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400212
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400213 // if we're downloading a voltha-helm-charts patch, then install from a local copy of the charts
214 Boolean localCharts = false
Joey Armstrong642540a2023-08-10 10:26:36 -0400215
Joey Armstrong54dec092023-08-03 18:21:38 -0400216 if (volthaHelmChartsChange != ''
217 || gerritProject == 'voltha-helm-charts'
218 || isReleaseBranch(branch) // branch != 'master'
219 ) {
220 localCharts = true
221 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400222
Joey Armstrong54dec092023-08-03 18:21:38 -0400223 String branchName = branchName()
Joey Armstrong38a87832023-08-23 17:02:50 -0400224 Boolean isRelease = isReleaseBranch(branch)
Joey Armstrong54dec092023-08-03 18:21:38 -0400225 println([
226 " ** localCharts=${localCharts}",
227 "branchName=${branchName}",
228 "branch=${branch}",
Joey Armstrong38a87832023-08-23 17:02:50 -0400229 "branch=isReleaseBranch=${isRelease}",
Joey Armstrong54dec092023-08-03 18:21:38 -0400230 ].join(', '))
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400231
Joey Armstrong54dec092023-08-03 18:21:38 -0400232 // -----------------------------------------------------------------------
233 // Rewrite localHelmFlags using array join, moving code around and
Joey Armstrong642540a2023-08-10 10:26:36 -0400234 // refactoring into standalone functions
Joey Armstrong54dec092023-08-03 18:21:38 -0400235 // -----------------------------------------------------------------------
236 // hudson.remoting.ProxyException: groovy.lang.MissingMethodException:
237 // No signature of method: java.lang.String.positive() is applicable for argument types: () values: []
238 // -----------------------------------------------------------------------
239 // NOTE temporary workaround expose ONOS node ports
240 // -----------------------------------------------------------------------
241 String localHelmFlags = [
242 extraHelmFlags.trim(),
243 "--set global.log_level=${logLevel.toUpperCase()}",
244 '--set onos-classic.onosSshPort=30115',
245 '--set onos-classic.onosApiPort=30120',
246 '--set onos-classic.onosOfPort=31653',
247 '--set onos-classic.individualOpenFlowNodePorts=true',
248 testSpecificHelmFlags
249 ].join(' ')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400250
Joey Armstrongf060aee2023-08-22 21:55:26 -0400251 println("** ${iam} localHelmFlags = ${localHelmFlags}")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400252
Joey Armstrong54dec092023-08-03 18:21:38 -0400253 if (gerritProject != '') {
254 localHelmFlags = "${localHelmFlags} " + getVolthaImageFlags("${gerritProject}")
255 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400256
Joey Armstrong38a87832023-08-23 17:02:50 -0400257 println("** ${iam}: ENTER")
Joey Armstrong54dec092023-08-03 18:21:38 -0400258 volthaDeploy([
259 infraNamespace: infraNamespace,
260 volthaNamespace: volthaNamespace,
261 workflow: workflow.toLowerCase(),
262 withMacLearning: enableMacLearning.toBoolean(),
263 extraHelmFlags: localHelmFlags,
264 localCharts: localCharts,
265 bbsimReplica: olts.toInteger(),
266 dockerRegistry: registry,
267 ])
Joey Armstrong38a87832023-08-23 17:02:50 -0400268 println("** ${iam}: LEAVE")
Joey Armstrong54dec092023-08-03 18:21:38 -0400269 } // script
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400270
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400271 // -----------------------------------------------------------------------
272 // Intent: Replacing P_IDS with pgrep/pkill is a step forward.
273 // Why not simply use a pid file, capture _TAG=kail-startup above
274 // Grep runs the risk of terminating stray commands (??-good <=> bad-??)
Joey Armstrong54dec092023-08-03 18:21:38 -0400275 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400276 script {
277 String proc = '_TAG=kail-startup'
Joey Armstrongdddbbf92023-08-22 16:00:41 -0400278
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400279 println("${iam}: ENTER")
280 println("${iam}: Shutdown process $proc")
281 pgrep_proc(proc)
282 pkill_proc(proc)
283 println("${iam}: LEAVE")
284 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400285
Joey Armstronged345862023-08-23 12:24:20 -0400286 // -----------------------------------------------------------------------
287 // Bundle onos-voltha / kail logs
288 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400289 sh("""
290cat <<EOM
291
292** -----------------------------------------------------------------------
293** Combine an compress voltha startup log(s)
294** -----------------------------------------------------------------------
295EOM
296 pushd "${logsDir}" || { echo "ERROR: pushd $logsDir failed"; exit 1; }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400297 gzip -k onos-voltha-startup-combined.log
298 rm onos-voltha-startup-combined.log
Joey Armstrongf060aee2023-08-22 21:55:26 -0400299 popd
300 """)
Joey Armstrong38a87832023-08-23 17:02:50 -0400301 } // timeout(10)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400302
Joey Armstrongf060aee2023-08-22 21:55:26 -0400303
304 // -----------------------------------------------------------------------
305 // -----------------------------------------------------------------------
306 sh """
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400307 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"&
308 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"&
309 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"&
310 bbsimDmiPortFwd=50075
311 for i in {0..${olts.toInteger() - 1}}; do
312 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"&
313 ((bbsimDmiPortFwd++))
314 done
315 if [ ${withMonitoring} = true ] ; then
316 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"&
317 fi
318 ps aux | grep port-forward
319 """
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400320 script {
321 String proc = 'port-forward'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400322
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400323 println("${iam}: ENTER")
324 println("Display spawned ${proc}")
325 pgrep_proc(proc)
326 println("${iam}: LEAVE")
327 }
Joey Armstrongf060aee2023-08-22 21:55:26 -0400328
329 // setting ONOS log level
330 script {
331 println('** setOnosLogLevels: ENTER')
Joey Armstrong54dec092023-08-03 18:21:38 -0400332 setOnosLogLevels([
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400333 onosNamespace: infraNamespace,
334 apps: [
335 'org.opencord.dhcpl2relay',
336 'org.opencord.olt',
337 'org.opencord.aaa',
338 'org.opencord.maclearner',
339 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
340 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
341 ],
342 logLevel: logLevel
343 ])
Joey Armstrongf060aee2023-08-22 21:55:26 -0400344 println('** setOnosLogLevels: LEAVE')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400345 } // script
346 } // if (teardown)
347 } // stage('Deploy Voltha')
348
Joey Armstrongf060aee2023-08-22 21:55:26 -0400349 // -----------------------------------------------------------------------
350 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400351 stage("Run test ${testTarget} on workflow ${workflow}")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400352 {
353 sh """
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400354 echo -e "\n** Monitor using mem_consumption.py ?"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400355
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400356 if [ ${withMonitoring} = true ] ; then
Joey Armstrongf060aee2023-08-22 21:55:26 -0400357 cat <<EOM
358
359** -----------------------------------------------------------------------
360** Monitoring memory usage with mem_consumption.py
361** -----------------------------------------------------------------------
362EOM
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400363 mkdir -p "$WORKSPACE/voltha-pods-mem-consumption-${workflow}"
364 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400365
366 echo '** Installing python virtualenv'
367 make venv-activate-patched
368
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400369 set +u && source .venv/bin/activate && set -u
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400370 # Collect initial memory consumption
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400371 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 -0400372 fi
Joey Armstrongf060aee2023-08-22 21:55:26 -0400373
374 echo -e '** Monitor memory consumption: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400375 """
376
377 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400378 echo -e "\n** make testTarget=[${testTarget}]"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400379 mkdir -p ${logsDir}
380 export ROBOT_MISC_ARGS="-d ${logsDir} ${params.extraRobotArgs} "
381 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}"
382 export KVSTOREPREFIX=voltha/voltha_voltha
383
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400384 make -C "$WORKSPACE/voltha-system-tests" ${testTarget}
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400385 """
386
387 getPodsInfo("${logsDir}")
388
389 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400390 echo -e '\n** Gather robot Framework logs: ENTER'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400391 # set +e
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400392 # collect logs collected in the Robot Framework StartLogging keyword
393 cd ${logsDir}
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400394 gzip *-combined.log
395 rm -f *-combined.log
Joey Armstrong54dec092023-08-03 18:21:38 -0400396
397 echo -e '** Gather robot Framework logs: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400398 """
399
Joey Armstrongf060aee2023-08-22 21:55:26 -0400400 // -----------------------------------------------------------------------
401 // -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400402 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400403 echo -e '** Monitor pod-mem-consumption: ENTER'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400404 if [ ${withMonitoring} = true ] ; then
Joey Armstrongf060aee2023-08-22 21:55:26 -0400405 cat <<EOM
406
407** -----------------------------------------------------------------------
408** Monitoring pod-memory-consumption using mem_consumption.py
409** -----------------------------------------------------------------------
410EOM
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400411 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400412
413 echo '** Installing python virtualenv'
414 make venv-activate-patched
Joey Armstrong38a87832023-08-23 17:02:50 -0400415
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400416 set +u && source .venv/bin/activate && set -u
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400417 # Collect memory consumption of voltha pods once all the tests are complete
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400418 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 -0400419 fi
Joey Armstrong54dec092023-08-03 18:21:38 -0400420 echo -e '** Monitor pod-mem-consumption: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400421 """
422 } // stage
Joey Armstrong54dec092023-08-03 18:21:38 -0400423
424 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400425} // execute_test()
426
427// -----------------------------------------------------------------------
428// -----------------------------------------------------------------------
Joey Armstrong54dec092023-08-03 18:21:38 -0400429def collectArtifacts(exitStatus) {
Joey Armstrong6115fd62023-08-24 08:19:28 -0400430 script {
431 String iam = getIam('collectArtifacts')
432 println("${iam}: ENTER (exitStatus=${exitStatus})")
433 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400434
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400435 echo '''
436
437** -----------------------------------------------------------------------
438** collectArtifacts
439** -----------------------------------------------------------------------
440'''
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400441
Joey Armstrong642540a2023-08-10 10:26:36 -0400442 getPodsInfo("$WORKSPACE/${exitStatus}")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400443
Joey Armstrong642540a2023-08-10 10:26:36 -0400444 sh """
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400445 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400446 """
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400447
Joey Armstrong642540a2023-08-10 10:26:36 -0400448 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 -0400449
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400450 script {
451 println("${iam}: ENTER")
452 pgrep_proc('kail-startup')
453 pkill_proc('kail')
454 println("${iam}: LEAVE")
455 }
456
Joey Armstrong642540a2023-08-10 10:26:36 -0400457 println("${iam}: ENTER RobotPublisher")
458 step([$class: 'RobotPublisher',
459 disableArchiveOutput: false,
460 logFileName: '**/*/log*.html',
461 otherFiles: '',
462 outputFileName: '**/*/output*.xml',
463 outputPath: '.',
464 passThreshold: 100,
465 reportFileName: '**/*/report*.html',
466 unstableThreshold: 0,
467 onlyCritical: true]);
468 println("${iam}: LEAVE RobotPublisher")
469
470 println("${iam}: LEAVE (exitStatus=${exitStatus})")
471 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400472}
473
Joey Armstrong54dec092023-08-03 18:21:38 -0400474// -----------------------------------------------------------------------
475// Intent: main
476// -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400477pipeline {
478
479 /* no label, executor is determined by JJB */
480 agent {
481 label "${params.buildNode}"
482 }
483 options {
484 timeout(time: "${timeout}", unit: 'MINUTES')
485 }
486 environment {
Joey Armstrong642540a2023-08-10 10:26:36 -0400487 KUBECONFIG = "$HOME/.kube/kind-${clusterName}"
488 VOLTCONFIG = "$HOME/.volt/config"
489 PATH = "$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
490 DIAGS_PROFILE = 'VOLTHA_PROFILE'
491 SSHPASS = 'karaf'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400492 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400493
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400494 stages {
495 stage('Download Code') {
496 steps {
497 getVolthaCode([
498 branch: "${branch}",
499 gerritProject: "${gerritProject}",
500 gerritRefspec: "${gerritRefspec}",
501 volthaSystemTestsChange: "${volthaSystemTestsChange}",
502 volthaHelmChartsChange: "${volthaHelmChartsChange}",
503 ])
504 }
505 }
506
507 stage('Build patch v1.1')
508 {
509 // build the patch only if gerritProject is specified
510 when
511 {
512 expression
513 {
514 return !gerritProject.isEmpty()
515 }
516 }
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400517
518 steps
519 {
520 // NOTE that the correct patch has already been checked out
521 // during the getVolthaCode step
522 buildVolthaComponent("${gerritProject}")
523 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400524 }
525
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400526 // -----------------------------------------------------------------------
527 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400528 stage('Install Kail')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400529 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400530 steps
531 {
532 script
533 {
534 String cmd = [
535 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400536 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400537 '-C', "$WORKSPACE/voltha-system-tests",
538 "KAIL_PATH=\"$WORKSPACE/bin\"",
539 'kail',
540 ].join(' ')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400541
Joey Armstrongf060aee2023-08-22 21:55:26 -0400542 println(" ** Running: ${cmd}")
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400543 sh("${cmd}")
544 } // script
545 } // steps
546 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400547
548 // -----------------------------------------------------------------------
549 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400550 stage('Install Kind')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400551 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400552 steps
553 {
554 script
555 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400556
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400557 String cmd = [
558 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400559 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400560 '-C', "$WORKSPACE/voltha-system-tests",
561 "KIND_PATH=\"$WORKSPACE/bin\"",
562 'install-command-kind',
563 ].join(' ')
Joey Armstrong642540a2023-08-10 10:26:36 -0400564
Joey Armstrongf060aee2023-08-22 21:55:26 -0400565 println(" ** Running: ${cmd}")
566 sh("${cmd}")
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400567 } // script
568 } // steps
569 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400570
571 // -----------------------------------------------------------------------
572 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400573 stage('Create K8s Cluster') {
574 steps {
575 script {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400576 def clusterExists = sh(
Joey Armstrongf060aee2023-08-22 21:55:26 -0400577 returnStdout: true,
578 script: """kind get clusters | grep "${clusterName}" | wc -l""")
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400579
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400580 if (clusterExists.trim() == '0') {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400581 createKubernetesCluster([nodes: 3, name: clusterName])
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400582 }
Joey Armstrongf060aee2023-08-22 21:55:26 -0400583 } // script
584 } // steps
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400585 } // stage('Create K8s Cluster')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400586
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400587 // -----------------------------------------------------------------------
588 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400589 stage('Replace voltctl') {
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400590 // if the project is voltctl, override the downloaded one with the built one
591 when {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400592 expression { return gerritProject == 'voltctl' }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400593 }
594
595 // Hmmmm(?) where did the voltctl download happen ?
596 // Likely Makefile but would be helpful to document here.
Joey Armstrongf060aee2023-08-22 21:55:26 -0400597 steps {
Joey Armstrong6115fd62023-08-24 08:19:28 -0400598 script {
599 String iam = getIam('Replace voltctl')
600
601 println("${iam} Running: installVoltctl($branch)")
602 println("${iam}: ENTER")
603 installVoltctl("$branch")
604 println("${iam}: LEAVE")
605 } // script
606 } // steps
Joey Armstrong268442d2023-08-22 17:16:10 -0400607 } // stage
608
609 // -----------------------------------------------------------------------
610 // -----------------------------------------------------------------------
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400611 stage('Load image in kind nodes')
612 {
613 when {
614 expression { return !gerritProject.isEmpty() }
615 }
616 steps {
617 loadToKind()
618 } // steps
619 } // stage
620
621 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400622 // [TODO] verify testing output
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400623 // -----------------------------------------------------------------------
624 stage('Parse and execute tests')
625 {
626 steps {
627 script {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400628 // Announce ourselves for log usability
629 String iam = getIam('execute_test')
630 println("${iam}: ENTER")
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400631
632 def tests = readYaml text: testTargets
633
Joey Armstrongb29d5612023-08-24 12:53:46 -0400634 String buffer = []
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400635 tests.eachWithIndex { test, idx ->
636 String target = test['target']
Joey Armstrongb29d5612023-08-24 12:53:46 -0400637 buffer += sprintf(" test[%02d]: %s\n", idx, target)
Joey Armstrong38a87832023-08-23 17:02:50 -0400638 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400639
Joey Armstrongb29d5612023-08-24 12:53:46 -0400640 println("** Testing index: tests-to-run")
641 println(buffer)
642 println("""
643** -----------------------------------------------------------------------
644** NOTE: For odd/silent job failures verify a few details
645** - All tests mentioned in the index have been processed.
646** - Test suites display ENTER/LEAVE mesasge pairs.
647** -----------------------------------------------------------------------
648""")
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400649 tests.eachWithIndex { test, idx ->
650 println "** readYaml test suite[$idx]) test=[${test}]"
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400651
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400652 String target = test['target']
653 String workflow = test['workflow']
654 String flags = test['flags']
655 Boolean teardown = test['teardown'].toBoolean()
656 Boolean logging = test['logging'].toBoolean()
657 String testLogging = (logging) ? 'True' : 'False'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400658
Joey Armstrong268442d2023-08-22 17:16:10 -0400659 print("""
Joey Armstrong268442d2023-08-22 17:16:10 -0400660** -----------------------------------------------------------------------
Joey Armstrong38a87832023-08-23 17:02:50 -0400661** Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}
Joey Armstrong268442d2023-08-22 17:16:10 -0400662** -----------------------------------------------------------------------
Joey Armstrong38a87832023-08-23 17:02:50 -0400663""")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400664
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400665 try {
666 println "Executing test ${target}: ENTER"
667 execute_test(target, workflow, testLogging, teardown, flags)
668 }
669 catch (Exception err) {
670 println("** ${iam}: EXCEPTION ${err}")
671 }
672 finally {
673 println "Executing test ${target}: LEAVE"
674 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400675
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400676 } // for
Joey Armstrong642540a2023-08-10 10:26:36 -0400677
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400678 // Premature exit if this message is not logged
679 println("${iam}: LEAVE (testing ran to completion)")
Joey Armstrong54dec092023-08-03 18:21:38 -0400680 } // script
681 } // steps
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400682 } // stage
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400683 } // stages
684
685 post
686 {
687 aborted { collectArtifacts('aborted') }
688 failure { collectArtifacts('failed') }
689 always { collectArtifacts('always') }
690 }
691} // pipeline
692
693// EOF