blob: 351a22feca66d521e11055f234a242f0727f592f [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// -----------------------------------------------------------------------
Joey Armstrongaf4eef22023-08-25 16:14:45 -040042// Intent: Difficult at times to determine when pipeline jobs have
43// regenerated. Hardcode a version string that can be assigned
44// per-script to be sure latest repository changes are being used.
45// -----------------------------------------------------------------------
46String pipelineVer() {
47 String version = '4f87de8f31d588d8277dc5ea6fbb69e714c66079'
48 return(version)
49}
50
51// -----------------------------------------------------------------------
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040052// Intent: Due to lack of a reliable stack trace, construct a literal.
Joey Armstrongd0b5af02023-08-25 15:12:54 -040053// Jenkins will re-write the call stack for serialization.S
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040054// -----------------------------------------------------------------------
Joey Armstrongd0b5af02023-08-25 15:12:54 -040055// Note: Hardcoded version string used to visualize changes in jenkins UI
56// -----------------------------------------------------------------------
Joey Armstrongaf4eef22023-08-25 16:14:45 -040057String getIam(String func) {
Joey Armstrong54dec092023-08-03 18:21:38 -040058 String branchName = branchName()
Joey Armstrongaf4eef22023-08-25 16:14:45 -040059 String version = pipelineVer()
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040060 String src = [
61 'ci-management',
62 'jjb',
63 'pipeline',
64 'voltha',
Joey Armstrong54dec092023-08-03 18:21:38 -040065 branchName,
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040066 'bbsim-tests.groovy'
67 ].join('/')
68
Joey Armstrongd0b5af02023-08-25 15:12:54 -040069 String name = [src, version, func].join('::')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040070 return(name)
71}
72
73// -----------------------------------------------------------------------
Joey Armstrongaf4eef22023-08-25 16:14:45 -040074// Intent: Log progress message
75// -----------------------------------------------------------------------
76void enter(String name)
77{
78 // Announce ourselves for log usability
79 String iam = getIam(name)
80 println("${iam}: ENTER")
81 return
82}
83
84// -----------------------------------------------------------------------
85// Intent: Log progress message
86// -----------------------------------------------------------------------
87void leave(String name)
88{
89 // Announce ourselves for log usability
90 String iam = getIam(name)
91 println("${iam}: LEAVE")
92 return
93}
94
95// -----------------------------------------------------------------------
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040096// Intent: Determine if working on a release branch.
97// Note: Conditional is legacy, should also check for *-dev or *-pre
98// -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -040099Boolean isReleaseBranch(String name) {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400100 // List modifiers = ['-dev', '-pre', 'voltha-x.y.z-pre']
Joey Armstrong54dec092023-08-03 18:21:38 -0400101 // if branchName in modifiers
102 return(name != 'master') // OR branchName.contains('-')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400103}
104
105// -----------------------------------------------------------------------
Joey Armstrongaf4eef22023-08-25 16:14:45 -0400106// Intent: Iterate over a list of test suites and invoke.
Joey Armstrongf060aee2023-08-22 21:55:26 -0400107// -----------------------------------------------------------------------
Joey Armstrongaf4eef22023-08-25 16:14:45 -0400108void execute_test\
109(
110 String testTarget, // functional-single-kind-dt
111 String workflow, // dt
112 String testLogging, // 'True'
113 Boolean teardown, // true
114 String testSpecificHelmFlags=''
115) {
Joey Armstrong54dec092023-08-03 18:21:38 -0400116 String infraNamespace = 'default'
117 String volthaNamespace = 'voltha'
118 String logsDir = "$WORKSPACE/${testTarget}"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400119
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400120 // -----------------------------------------------------------------------
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400121 // Intent: Cleanup stale port-forwarding
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400122 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400123 stage('Cleanup') {
Joey Armstrong38a87832023-08-23 17:02:50 -0400124 if (teardown) {
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400125 timeout(15) {
Joey Armstrong38a87832023-08-23 17:02:50 -0400126 script {
Joey Armstrong54dec092023-08-03 18:21:38 -0400127 helmTeardown(['default', infraNamespace, volthaNamespace])
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400128 }
Joey Armstrongf060aee2023-08-22 21:55:26 -0400129 } // timeout
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400130
Joey Armstrongf060aee2023-08-22 21:55:26 -0400131 timeout(5) {
132 script {
133 String iam = getIam('Cleanup')
134 println("${iam}: ENTER")
Joey Armstrong268442d2023-08-22 17:16:10 -0400135
Joey Armstrongf060aee2023-08-22 21:55:26 -0400136 // remove orphaned port-forward from different namespaces
137 String proc = 'port-forw'
138 pgrep_proc(proc)
139 pkill_proc(proc)
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400140 pgrep_proc(proc) // proc count == 0
Joey Armstrongf060aee2023-08-22 21:55:26 -0400141 println("${iam}: LEAVE")
Joey Armstrong38a87832023-08-23 17:02:50 -0400142 } // script
Joey Armstrongf060aee2023-08-22 21:55:26 -0400143 } // timeout
144 } // teardown
Joey Armstrong38a87832023-08-23 17:02:50 -0400145 } // stage('Cleanup')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400146
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400147 // -----------------------------------------------------------------------
148 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400149 stage('Deploy common infrastructure') {
150 script {
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400151 local dashargs = [
152 'kpi_exporter.enabled=false',
153 'dashboards.xos=false',
154 'dashboards.onos=false',
155 'dashboards.aaa=false',
156 'dashboards.voltha=false',
157 ].join(',')
158
159 local promargs = [
160 'prometheus.alertmanager.enabled=false',
161 'prometheus.pushgateway.enabled=false',
162 ].join(',')
163
Joey Armstrong38a87832023-08-23 17:02:50 -0400164 sh("""
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400165 helm repo add onf https://charts.opencord.org
166 helm repo update
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400167
168 echo -e "\nwithMonitoring=[$withMonitoring]"
169 if [ ${withMonitoring} = true ] ; then
170 helm install nem-monitoring onf/nem-monitoring \
Joey Armstrong38a87832023-08-23 17:02:50 -0400171 --set ${promargs} \
172 --set ${dashargs}
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400173 fi
Joey Armstrong38a87832023-08-23 17:02:50 -0400174 """)
175 } // script
176 } // stage('Deploy Common Infra')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400177
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400178 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400179 // [TODO] Check onos_log output
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400180 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400181 stage('Deploy Voltha') {
182 if (teardown) {
183 timeout(10) {
184 script {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400185 String iam = getIam('Deploy Voltha')
Joey Armstrong38a87832023-08-23 17:02:50 -0400186 String onosLog = "${logsDir}/onos-voltha-startup-combined.log"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400187sh("""
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400188 mkdir -p ${logsDir}
Joey Armstrong38a87832023-08-23 17:02:50 -0400189 touch "$onosLog"
190 echo "** kail-startup ENTER: \$(date)" > "$onosLog"
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400191
192 # Intermixed output (tee -a &) may get conflusing but let(s) see
193 # what messages are logged during startup.
Joey Armstrong38a87832023-08-23 17:02:50 -0400194 # _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} >> "$onosLog" &
195 _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} | tee -a "$onosLog" &
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400196 """)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400197
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400198 // if we're downloading a voltha-helm-charts patch, then install from a local copy of the charts
199 Boolean localCharts = false
Joey Armstrong642540a2023-08-10 10:26:36 -0400200
Joey Armstrong54dec092023-08-03 18:21:38 -0400201 if (volthaHelmChartsChange != ''
202 || gerritProject == 'voltha-helm-charts'
203 || isReleaseBranch(branch) // branch != 'master'
204 ) {
205 localCharts = true
206 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400207
Joey Armstrong54dec092023-08-03 18:21:38 -0400208 String branchName = branchName()
Joey Armstrong38a87832023-08-23 17:02:50 -0400209 Boolean isRelease = isReleaseBranch(branch)
Joey Armstrong54dec092023-08-03 18:21:38 -0400210 println([
211 " ** localCharts=${localCharts}",
212 "branchName=${branchName}",
213 "branch=${branch}",
Joey Armstrong38a87832023-08-23 17:02:50 -0400214 "branch=isReleaseBranch=${isRelease}",
Joey Armstrong54dec092023-08-03 18:21:38 -0400215 ].join(', '))
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400216
Joey Armstrong54dec092023-08-03 18:21:38 -0400217 // -----------------------------------------------------------------------
218 // Rewrite localHelmFlags using array join, moving code around and
Joey Armstrong642540a2023-08-10 10:26:36 -0400219 // refactoring into standalone functions
Joey Armstrong54dec092023-08-03 18:21:38 -0400220 // -----------------------------------------------------------------------
221 // hudson.remoting.ProxyException: groovy.lang.MissingMethodException:
222 // No signature of method: java.lang.String.positive() is applicable for argument types: () values: []
223 // -----------------------------------------------------------------------
224 // NOTE temporary workaround expose ONOS node ports
225 // -----------------------------------------------------------------------
226 String localHelmFlags = [
227 extraHelmFlags.trim(),
228 "--set global.log_level=${logLevel.toUpperCase()}",
229 '--set onos-classic.onosSshPort=30115',
230 '--set onos-classic.onosApiPort=30120',
231 '--set onos-classic.onosOfPort=31653',
232 '--set onos-classic.individualOpenFlowNodePorts=true',
233 testSpecificHelmFlags
234 ].join(' ')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400235
Joey Armstrongf060aee2023-08-22 21:55:26 -0400236 println("** ${iam} localHelmFlags = ${localHelmFlags}")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400237
Joey Armstrong54dec092023-08-03 18:21:38 -0400238 if (gerritProject != '') {
239 localHelmFlags = "${localHelmFlags} " + getVolthaImageFlags("${gerritProject}")
240 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400241
Joey Armstrong38a87832023-08-23 17:02:50 -0400242 println("** ${iam}: ENTER")
Joey Armstrong54dec092023-08-03 18:21:38 -0400243 volthaDeploy([
244 infraNamespace: infraNamespace,
245 volthaNamespace: volthaNamespace,
246 workflow: workflow.toLowerCase(),
247 withMacLearning: enableMacLearning.toBoolean(),
248 extraHelmFlags: localHelmFlags,
249 localCharts: localCharts,
250 bbsimReplica: olts.toInteger(),
251 dockerRegistry: registry,
252 ])
Joey Armstrong38a87832023-08-23 17:02:50 -0400253 println("** ${iam}: LEAVE")
Joey Armstrong54dec092023-08-03 18:21:38 -0400254 } // script
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400255
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400256 // -----------------------------------------------------------------------
257 // Intent: Replacing P_IDS with pgrep/pkill is a step forward.
258 // Why not simply use a pid file, capture _TAG=kail-startup above
259 // Grep runs the risk of terminating stray commands (??-good <=> bad-??)
Joey Armstrong54dec092023-08-03 18:21:38 -0400260 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400261 script {
262 String proc = '_TAG=kail-startup'
Joey Armstrongdddbbf92023-08-22 16:00:41 -0400263
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400264 println("${iam}: ENTER")
265 println("${iam}: Shutdown process $proc")
266 pgrep_proc(proc)
267 pkill_proc(proc)
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400268 pgrep_proc(proc)
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400269 println("${iam}: LEAVE")
270 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400271
Joey Armstronged345862023-08-23 12:24:20 -0400272 // -----------------------------------------------------------------------
273 // Bundle onos-voltha / kail logs
274 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400275 sh("""
276cat <<EOM
277
278** -----------------------------------------------------------------------
279** Combine an compress voltha startup log(s)
280** -----------------------------------------------------------------------
281EOM
282 pushd "${logsDir}" || { echo "ERROR: pushd $logsDir failed"; exit 1; }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400283 gzip -k onos-voltha-startup-combined.log
284 rm onos-voltha-startup-combined.log
Joey Armstrongf060aee2023-08-22 21:55:26 -0400285 popd
286 """)
Joey Armstrong38a87832023-08-23 17:02:50 -0400287 } // timeout(10)
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400288
Joey Armstrongf060aee2023-08-22 21:55:26 -0400289
290 // -----------------------------------------------------------------------
291 // -----------------------------------------------------------------------
292 sh """
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400293 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"&
294 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"&
295 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"&
296 bbsimDmiPortFwd=50075
297 for i in {0..${olts.toInteger() - 1}}; do
298 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"&
299 ((bbsimDmiPortFwd++))
300 done
301 if [ ${withMonitoring} = true ] ; then
302 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"&
303 fi
304 ps aux | grep port-forward
305 """
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400306
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400307 script {
308 String proc = 'port-forward'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400309
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400310 println("${iam}: ENTER")
311 println("Display spawned ${proc}")
312 pgrep_proc(proc)
313 println("${iam}: LEAVE")
314 }
Joey Armstrongf060aee2023-08-22 21:55:26 -0400315
316 // setting ONOS log level
317 script {
318 println('** setOnosLogLevels: ENTER')
Joey Armstrong54dec092023-08-03 18:21:38 -0400319 setOnosLogLevels([
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400320 onosNamespace: infraNamespace,
321 apps: [
322 'org.opencord.dhcpl2relay',
323 'org.opencord.olt',
324 'org.opencord.aaa',
325 'org.opencord.maclearner',
326 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
327 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
328 ],
329 logLevel: logLevel
330 ])
Joey Armstrongf060aee2023-08-22 21:55:26 -0400331 println('** setOnosLogLevels: LEAVE')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400332 } // script
333 } // if (teardown)
334 } // stage('Deploy Voltha')
335
Joey Armstrongf060aee2023-08-22 21:55:26 -0400336 // -----------------------------------------------------------------------
337 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400338 stage("Run test ${testTarget} on workflow ${workflow}")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400339 {
340 sh """
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400341 echo -e "\n** Monitor using mem_consumption.py ?"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400342
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400343 if [ ${withMonitoring} = true ] ; then
Joey Armstrongf060aee2023-08-22 21:55:26 -0400344 cat <<EOM
345
346** -----------------------------------------------------------------------
347** Monitoring memory usage with mem_consumption.py
348** -----------------------------------------------------------------------
349EOM
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400350 mkdir -p "$WORKSPACE/voltha-pods-mem-consumption-${workflow}"
351 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400352
353 echo '** Installing python virtualenv'
354 make venv-activate-patched
355
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400356 set +u && source .venv/bin/activate && set -u
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400357 # Collect initial memory consumption
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400358 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 -0400359 fi
Joey Armstrongf060aee2023-08-22 21:55:26 -0400360
361 echo -e '** Monitor memory consumption: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400362 """
363
364 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400365 echo -e "\n** make testTarget=[${testTarget}]"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400366 mkdir -p ${logsDir}
367 export ROBOT_MISC_ARGS="-d ${logsDir} ${params.extraRobotArgs} "
368 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}"
369 export KVSTOREPREFIX=voltha/voltha_voltha
370
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400371 make -C "$WORKSPACE/voltha-system-tests" ${testTarget}
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400372 """
373
374 getPodsInfo("${logsDir}")
375
376 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400377 echo -e '\n** Gather robot Framework logs: ENTER'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400378 # set +e
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400379 # collect logs collected in the Robot Framework StartLogging keyword
380 cd ${logsDir}
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400381 gzip *-combined.log
382 rm -f *-combined.log
Joey Armstrong54dec092023-08-03 18:21:38 -0400383
384 echo -e '** Gather robot Framework logs: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400385 """
386
Joey Armstrongf060aee2023-08-22 21:55:26 -0400387 // -----------------------------------------------------------------------
388 // -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400389 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400390 echo -e '** Monitor pod-mem-consumption: ENTER'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400391 if [ ${withMonitoring} = true ] ; then
Joey Armstrongf060aee2023-08-22 21:55:26 -0400392 cat <<EOM
393
394** -----------------------------------------------------------------------
395** Monitoring pod-memory-consumption using mem_consumption.py
396** -----------------------------------------------------------------------
397EOM
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400398 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrongf060aee2023-08-22 21:55:26 -0400399
400 echo '** Installing python virtualenv'
401 make venv-activate-patched
Joey Armstrong38a87832023-08-23 17:02:50 -0400402
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400403 set +u && source .venv/bin/activate && set -u
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400404 # Collect memory consumption of voltha pods once all the tests are complete
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400405 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 -0400406 fi
Joey Armstrong54dec092023-08-03 18:21:38 -0400407 echo -e '** Monitor pod-mem-consumption: LEAVE\n'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400408 """
409 } // stage
Joey Armstrong54dec092023-08-03 18:21:38 -0400410
411 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400412} // execute_test()
413
414// -----------------------------------------------------------------------
415// -----------------------------------------------------------------------
Joey Armstrong54dec092023-08-03 18:21:38 -0400416def collectArtifacts(exitStatus) {
Joey Armstrong6115fd62023-08-24 08:19:28 -0400417 script {
418 String iam = getIam('collectArtifacts')
419 println("${iam}: ENTER (exitStatus=${exitStatus})")
420 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400421
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400422 echo '''
423
424** -----------------------------------------------------------------------
425** collectArtifacts
426** -----------------------------------------------------------------------
427'''
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400428
Joey Armstrong642540a2023-08-10 10:26:36 -0400429 getPodsInfo("$WORKSPACE/${exitStatus}")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400430
Joey Armstrong642540a2023-08-10 10:26:36 -0400431 sh """
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400432 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400433 """
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400434
Joey Armstrong642540a2023-08-10 10:26:36 -0400435 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 -0400436
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400437 script {
438 println("${iam}: ENTER")
439 pgrep_proc('kail-startup')
440 pkill_proc('kail')
441 println("${iam}: LEAVE")
442 }
443
Joey Armstrong642540a2023-08-10 10:26:36 -0400444 println("${iam}: ENTER RobotPublisher")
445 step([$class: 'RobotPublisher',
446 disableArchiveOutput: false,
447 logFileName: '**/*/log*.html',
448 otherFiles: '',
449 outputFileName: '**/*/output*.xml',
450 outputPath: '.',
451 passThreshold: 100,
452 reportFileName: '**/*/report*.html',
453 unstableThreshold: 0,
454 onlyCritical: true]);
455 println("${iam}: LEAVE RobotPublisher")
456
457 println("${iam}: LEAVE (exitStatus=${exitStatus})")
458 return
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400459}
460
Joey Armstrong54dec092023-08-03 18:21:38 -0400461// -----------------------------------------------------------------------
462// Intent: main
463// -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400464pipeline {
465
466 /* no label, executor is determined by JJB */
467 agent {
468 label "${params.buildNode}"
469 }
470 options {
471 timeout(time: "${timeout}", unit: 'MINUTES')
472 }
473 environment {
Joey Armstrong642540a2023-08-10 10:26:36 -0400474 KUBECONFIG = "$HOME/.kube/kind-${clusterName}"
475 VOLTCONFIG = "$HOME/.volt/config"
476 PATH = "$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
477 DIAGS_PROFILE = 'VOLTHA_PROFILE'
478 SSHPASS = 'karaf'
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400479 }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400480
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400481 stages {
482 stage('Download Code') {
483 steps {
484 getVolthaCode([
485 branch: "${branch}",
486 gerritProject: "${gerritProject}",
487 gerritRefspec: "${gerritRefspec}",
488 volthaSystemTestsChange: "${volthaSystemTestsChange}",
489 volthaHelmChartsChange: "${volthaHelmChartsChange}",
490 ])
491 }
492 }
493
494 stage('Build patch v1.1')
495 {
496 // build the patch only if gerritProject is specified
497 when
498 {
499 expression
500 {
501 return !gerritProject.isEmpty()
502 }
503 }
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400504
505 steps
506 {
507 // NOTE that the correct patch has already been checked out
508 // during the getVolthaCode step
509 buildVolthaComponent("${gerritProject}")
510 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400511 }
512
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400513 // -----------------------------------------------------------------------
514 // -----------------------------------------------------------------------
Joey Armstrong642540a2023-08-10 10:26:36 -0400515 stage('Install Kail')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400516 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400517 steps
518 {
519 script
520 {
521 String cmd = [
522 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400523 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400524 '-C', "$WORKSPACE/voltha-system-tests",
525 "KAIL_PATH=\"$WORKSPACE/bin\"",
526 'kail',
527 ].join(' ')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400528
Joey Armstrongf060aee2023-08-22 21:55:26 -0400529 println(" ** Running: ${cmd}")
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400530 sh("${cmd}")
531 } // script
532 } // steps
533 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400534
535 // -----------------------------------------------------------------------
536 // -----------------------------------------------------------------------
Joey Armstrong39f90382023-08-24 20:37:40 -0400537 stage('Install Tools') {
538 steps {
539 script {
540 String branchName = branchName()
541 String iam = getIam('Install Tools')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400542
Joey Armstrong39f90382023-08-24 20:37:40 -0400543 println("${iam}: ENTER (branch=$branch)")
544 installKind(branch) // needed early by stage(Cleanup)
545 println("${iam}: LEAVE (branch=$branch)")
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400546 } // script
547 } // steps
548 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400549
550 // -----------------------------------------------------------------------
551 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400552 stage('Create K8s Cluster') {
553 steps {
554 script {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400555 def clusterExists = sh(
Joey Armstrongf060aee2023-08-22 21:55:26 -0400556 returnStdout: true,
557 script: """kind get clusters | grep "${clusterName}" | wc -l""")
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400558
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400559 if (clusterExists.trim() == '0') {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400560 createKubernetesCluster([nodes: 3, name: clusterName])
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400561 }
Joey Armstrongf060aee2023-08-22 21:55:26 -0400562 } // script
563 } // steps
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400564 } // stage('Create K8s Cluster')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400565
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400566 // -----------------------------------------------------------------------
567 // -----------------------------------------------------------------------
Joey Armstrongec1ae0a2023-08-23 21:51:45 -0400568 stage('Replace voltctl') {
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400569 // if the project is voltctl, override the downloaded one with the built one
570 when {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400571 expression { return gerritProject == 'voltctl' }
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400572 }
573
574 // Hmmmm(?) where did the voltctl download happen ?
575 // Likely Makefile but would be helpful to document here.
Joey Armstrongf060aee2023-08-22 21:55:26 -0400576 steps {
Joey Armstrong6115fd62023-08-24 08:19:28 -0400577 script {
578 String iam = getIam('Replace voltctl')
579
580 println("${iam} Running: installVoltctl($branch)")
581 println("${iam}: ENTER")
582 installVoltctl("$branch")
583 println("${iam}: LEAVE")
584 } // script
585 } // steps
Joey Armstrong268442d2023-08-22 17:16:10 -0400586 } // stage
587
588 // -----------------------------------------------------------------------
589 // -----------------------------------------------------------------------
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400590 stage('Load image in kind nodes')
591 {
592 when {
593 expression { return !gerritProject.isEmpty() }
594 }
595 steps {
596 loadToKind()
597 } // steps
598 } // stage
599
600 // -----------------------------------------------------------------------
Joey Armstrongf060aee2023-08-22 21:55:26 -0400601 // [TODO] verify testing output
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400602 // -----------------------------------------------------------------------
603 stage('Parse and execute tests')
604 {
605 steps {
606 script {
Joey Armstrongf060aee2023-08-22 21:55:26 -0400607 // Announce ourselves for log usability
Joey Armstrongaf4eef22023-08-25 16:14:45 -0400608 enter('Parse and execute tests')
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400609
610 def tests = readYaml text: testTargets
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400611 println("** [DEBUG]: tests=$tests")
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400612
Joey Armstrongf46b3ae2023-08-25 11:07:20 -0400613 // Display expected tests for times when output goes dark
614 ArrayList buffer = [] as String
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400615 tests.eachWithIndex { test, idx ->
616 String target = test['target']
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400617 println(" ** Build test index [$idx]: target=$target")
Joey Armstrongbe7c9242023-08-24 16:20:31 -0400618 buffer.add(" test[${idx}]: ${target}\n")
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400619 println("** buffer contains: $buffer")
Joey Armstrong38a87832023-08-23 17:02:50 -0400620 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400621
Joey Armstrongb29d5612023-08-24 12:53:46 -0400622 println("** Testing index: tests-to-run")
Joey Armstrongf46b3ae2023-08-25 11:07:20 -0400623 println(buffer.join(''))
624
Joey Armstrongbe7c9242023-08-24 16:20:31 -0400625 println('''
Joey Armstrongb29d5612023-08-24 12:53:46 -0400626** -----------------------------------------------------------------------
627** NOTE: For odd/silent job failures verify a few details
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400628** - All tests mentioned in the tests-to-run index were logged.
Joey Armstrongb29d5612023-08-24 12:53:46 -0400629** - Test suites display ENTER/LEAVE mesasge pairs.
Joey Armstrong5d65efe2023-08-25 09:43:18 -0400630** - Processing terminated prematurely when LEAVE strings are missing.
Joey Armstrongb29d5612023-08-24 12:53:46 -0400631** -----------------------------------------------------------------------
Joey Armstrongbe7c9242023-08-24 16:20:31 -0400632''')
Joey Armstrongf46b3ae2023-08-25 11:07:20 -0400633
634 tests.eachWithIndex { test, idx ->
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400635 println "** readYaml test suite[$idx]) test=[${test}]"
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400636
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400637 String target = test['target']
638 String workflow = test['workflow']
639 String flags = test['flags']
640 Boolean teardown = test['teardown'].toBoolean()
641 Boolean logging = test['logging'].toBoolean()
642 String testLogging = (logging) ? 'True' : 'False'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400643
Joey Armstrong268442d2023-08-22 17:16:10 -0400644 print("""
Joey Armstrong268442d2023-08-22 17:16:10 -0400645** -----------------------------------------------------------------------
Joey Armstrong38a87832023-08-23 17:02:50 -0400646** Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}
Joey Armstrong268442d2023-08-22 17:16:10 -0400647** -----------------------------------------------------------------------
Joey Armstrong38a87832023-08-23 17:02:50 -0400648""")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400649
Joey Armstrongaf4eef22023-08-25 16:14:45 -0400650 try {
651 leave("execute_test (target=$target)")
652 execute_test(target, workflow, testLogging, teardown, flags)
653 }
654 catch (Exception err) {
655 println("** ${iam}: EXCEPTION ${err}")
656 }
657 finally {
658 leave("execute_test (target=$target)")
659 }
Joey Armstrong642540a2023-08-10 10:26:36 -0400660
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400661 } // for
Joey Armstrong642540a2023-08-10 10:26:36 -0400662
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400663 // Premature exit if this message is not logged
Joey Armstrongaf4eef22023-08-25 16:14:45 -0400664 leave('Parse and execute tests')
Joey Armstrong54dec092023-08-03 18:21:38 -0400665 } // script
666 } // steps
Joey Armstrong008cfaf2023-08-18 14:49:06 -0400667 } // stage
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400668 } // stages
669
670 post
671 {
672 aborted { collectArtifacts('aborted') }
673 failure { collectArtifacts('failed') }
674 always { collectArtifacts('always') }
675 }
676} // pipeline
677
678// EOF