blob: 3ffe2238f8bb57478446175ffa1dbe6d7541903e [file] [log] [blame]
Joey Armstrong8c6f6482023-01-12 12:31:44 -05001// Copyright 2021-2023 Open Networking Foundation (ONF) and the ONF Contributors
Matteo Scandolo42f6e572021-01-25 15:11:34 -08002//
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
Hardik Windlassec9341b2021-06-07 11:58:29 +000015// voltha-2.x e2e tests for openonu-go
Matteo Scandolo42f6e572021-01-25 15:11:34 -080016// uses bbsim to simulate OLT/ONUs
17
Joey Armstronge5aae1c2023-07-24 14:11:20 -040018// [TODO] Update syntax below to the latest supported
Matteo Scandoloa156b572021-02-04 11:52:18 -080019library identifier: 'cord-jenkins-libraries@master',
20 retriever: modernSCM([
21 $class: 'GitSCMSource',
22 remote: 'https://gerrit.opencord.org/ci-management.git'
23])
24
Joey Armstronge5aae1c2023-07-24 14:11:20 -040025//------------------//
26//---] GLOBAL [---//
27//------------------//
Joey Armstrongb65ada32023-08-03 12:50:20 -040028String clusterName = 'kind-ci' // was def
Joey Armstrongf076c312023-08-01 17:17:10 -040029
30// -----------------------------------------------------------------------
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040031// Intent:
Joey Armstrongf076c312023-08-01 17:17:10 -040032// -----------------------------------------------------------------------
Joey Armstrongb65ada32023-08-03 12:50:20 -040033String branchName() {
Joey Armstrongf076c312023-08-01 17:17:10 -040034 String name = 'master'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040035
36 // [TODO] Sanity check the target branch
37 // if (name != jenkins.branch) { fatal }
Joey Armstrongf076c312023-08-01 17:17:10 -040038 return(name)
39}
Hardik Windlassec9341b2021-06-07 11:58:29 +000040
Joey Armstronge5aae1c2023-07-24 14:11:20 -040041// -----------------------------------------------------------------------
Joey Armstrong06a68372023-07-24 16:37:16 -040042// Intent: Due to lack of a reliable stack trace, construct a literal.
43// Jenkins will re-write the call stack for serialization.
44// -----------------------------------------------------------------------
Joey Armstrong97a8b882023-08-02 16:08:52 -040045String getIam(String func) {
Joey Armstrongb65ada32023-08-03 12:50:20 -040046 String branchName = branchName()
Joey Armstrong06a68372023-07-24 16:37:16 -040047 String src = [
48 'ci-management',
49 'jjb',
50 'pipeline',
51 'voltha',
Joey Armstrongb65ada32023-08-03 12:50:20 -040052 branchName,
Joey Armstrong06a68372023-07-24 16:37:16 -040053 'bbsim-tests.groovy'
54 ].join('/')
55
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040056 String name = [src, func].join('::')
57 return(name)
Joey Armstrong06a68372023-07-24 16:37:16 -040058}
59
60// -----------------------------------------------------------------------
Joey Armstronge5aae1c2023-07-24 14:11:20 -040061// Intent: Determine if working on a release branch.
62// Note: Conditional is legacy, should also check for *-dev or *-pre
63// -----------------------------------------------------------------------
64Boolean isReleaseBranch(String name)
65{
66 // List modifiers = ['-dev', '-pre', 'voltha-x.y.z-pre']
Joey Armstrongb65ada32023-08-03 12:50:20 -040067 // if branchName in modifiers
68 return(name != 'master') // OR branchName.contains('-')
Joey Armstronge5aae1c2023-07-24 14:11:20 -040069}
70
71// -----------------------------------------------------------------------
72// Intent:
73// -----------------------------------------------------------------------
Joey Armstrongb65ada32023-08-03 12:50:20 -040074void execute_test(testTarget, workflow, testLogging, teardown, testSpecificHelmFlags='')
Joey Armstrong2d5a7c12023-04-13 09:37:42 -040075{
Joey Armstrongb65ada32023-08-03 12:50:20 -040076 String infraNamespace = 'default'
77 String volthaNamespace = 'voltha'
78 String logsDir = "$WORKSPACE/${testTarget}"
Joey Armstrong293e16b2022-11-26 20:16:33 -050079
80 stage('IAM')
81 {
Joey Armstrong84adc542023-04-11 14:47:34 -040082 script
83 {
Joey Armstrong97a8b882023-08-02 16:08:52 -040084 // Announce ourselves for log usability
Joey Armstrongf404b642023-08-04 14:39:13 -040085 String iam = getIam('execute_test')
Joey Armstrong97a8b882023-08-02 16:08:52 -040086 println("${iam}: ENTER")
87 println("${iam}: LEAVE")
Joey Armstrong84adc542023-04-11 14:47:34 -040088 }
Joey Armstrong293e16b2022-11-26 20:16:33 -050089 }
Joey Armstrongb65ada32023-08-03 12:50:20 -040090
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040091 // -----------------------------------------------------------------------
92 // -----------------------------------------------------------------------
Joey Armstrongf076c312023-08-01 17:17:10 -040093 stage('Cleanup')
94 {
Joey Armstrong84adc542023-04-11 14:47:34 -040095 if (teardown) {
96 timeout(15) {
97 script {
Joey Armstrongb65ada32023-08-03 12:50:20 -040098 helmTeardown(['default', infraNamespace, volthaNamespace])
Joey Armstrong84adc542023-04-11 14:47:34 -040099 }
100 timeout(1) {
101 sh returnStdout: false, script: '''
Hardik Windlassec9341b2021-06-07 11:58:29 +0000102 # remove orphaned port-forward from different namespaces
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400103 ps aux | grep port-forw | grep -v grep | awk '{print $2}' | xargs --no-run-if-empty kill -9
Hardik Windlassec9341b2021-06-07 11:58:29 +0000104 '''
Joey Armstrong84adc542023-04-11 14:47:34 -0400105 }
106 }
107 }
Hardik Windlassec9341b2021-06-07 11:58:29 +0000108 }
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500109
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400110 // -----------------------------------------------------------------------
111 // -----------------------------------------------------------------------
Joey Armstrong06a68372023-07-24 16:37:16 -0400112 stage('Deploy common infrastructure')
113 {
Joey Armstrong84adc542023-04-11 14:47:34 -0400114 sh '''
Hardik Windlasse1660492022-03-14 15:12:46 +0000115 helm repo add onf https://charts.opencord.org
116 helm repo update
117 if [ ${withMonitoring} = true ] ; then
118 helm install nem-monitoring onf/nem-monitoring \
119 --set prometheus.alertmanager.enabled=false,prometheus.pushgateway.enabled=false \
120 --set kpi_exporter.enabled=false,dashboards.xos=false,dashboards.onos=false,dashboards.aaa=false,dashboards.voltha=false
121 fi
122 '''
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500123 }
124
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400125 stage('Deploy Voltha')
126 {
Joey Armstrong97a8b882023-08-02 16:08:52 -0400127 if (teardown)
128 {
129 timeout(10)
130 {
131 script
132 {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000133 sh """
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700134 mkdir -p ${logsDir}
135 _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} > ${logsDir}/onos-voltha-startup-combined.log &
Hardik Windlassec9341b2021-06-07 11:58:29 +0000136 """
137
Joey Armstrong54dec092023-08-03 18:21:38 -0400138 // if we're downloading a voltha-helm-charts patch, then install from a local copy of the charts
139 Boolean localCharts = false
Joey Armstrongf404b642023-08-04 14:39:13 -0400140
Joey Armstrong54dec092023-08-03 18:21:38 -0400141 if (volthaHelmChartsChange != ''
142 || gerritProject == 'voltha-helm-charts'
143 || isReleaseBranch(branch) // branch != 'master'
144 ) {
145 localCharts = true
146 }
Joey Armstrongf404b642023-08-04 14:39:13 -0400147
Joey Armstrong8a960ee2023-08-03 15:00:00 -0400148 String branchName = branchName()
149 Boolean is_release = isReleaseBranch(branch)
150 println([
151 " ** localCharts=${localCharts}",
152 "branchName=${branchName}",
153 "branch=${branch}",
154 "branch=isReleaseBranch=${is_release}",
155 ].join(', '))
Hardik Windlassec9341b2021-06-07 11:58:29 +0000156
Joey Armstrong8a960ee2023-08-03 15:00:00 -0400157 // -----------------------------------------------------------------------
158 // Rewrite localHelmFlags using array join, moving code around and
Joey Armstrongf404b642023-08-04 14:39:13 -0400159 // refactoring into standalone functions
Joey Armstrong8a960ee2023-08-03 15:00:00 -0400160 // -----------------------------------------------------------------------
161 // hudson.remoting.ProxyException: groovy.lang.MissingMethodException:
162 // No signature of method: java.lang.String.positive() is applicable for argument types: () values: []
163 // -----------------------------------------------------------------------
164 // NOTE temporary workaround expose ONOS node ports
165 // -----------------------------------------------------------------------
166 String localHelmFlags = [
167 extraHelmFlags.trim(),
168 "--set global.log_level=${logLevel.toUpperCase()}",
169 '--set onos-classic.onosSshPort=30115',
170 '--set onos-classic.onosApiPort=30120',
171 '--set onos-classic.onosOfPort=31653',
172 '--set onos-classic.individualOpenFlowNodePorts=true',
173 testSpecificHelmFlags
174 ].join(' ')
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800175
Joey Armstrong28e86ee2023-08-03 15:22:29 -0400176 println("** localHelmFlags = ${localHelmFlags}")
177
Joey Armstrong8a960ee2023-08-03 15:00:00 -0400178 if (gerritProject != '') {
179 localHelmFlags = "${localHelmFlags} " + getVolthaImageFlags("${gerritProject}")
180 }
Hardik Windlassec9341b2021-06-07 11:58:29 +0000181
Joey Armstrong8a960ee2023-08-03 15:00:00 -0400182 println('volthaDeploy: ENTER')
183 volthaDeploy([
184 infraNamespace: infraNamespace,
185 volthaNamespace: volthaNamespace,
186 workflow: workflow.toLowerCase(),
187 withMacLearning: enableMacLearning.toBoolean(),
188 extraHelmFlags: localHelmFlags,
189 localCharts: localCharts,
190 bbsimReplica: olts.toInteger(),
191 dockerRegistry: registry,
Joey Armstrong54dec092023-08-03 18:21:38 -0400192 ])
Joey Armstrong8a960ee2023-08-03 15:00:00 -0400193 println('volthaDeploy: LEAVE')
Joey Armstrongb65ada32023-08-03 12:50:20 -0400194 } // script
Matteo Scandolofcfc60d2021-02-24 09:06:48 -0800195
Joey Armstrong97a8b882023-08-02 16:08:52 -0400196 // -----------------------------------------------------------------------
197 // Intent: Replacing P_IDS with pgrep/pkill is a step forward.
198 // Why not simply use a pid file, capture _TAG=kail-startup above
199 // Grep runs the risk of terminating stray commands (??-good <=> bad-??)
Joey Armstrongb65ada32023-08-03 12:50:20 -0400200 // -----------------------------------------------------------------------
201 script {
202 println('Try out pgrep/pkill commands')
Joey Armstrongf404b642023-08-04 14:39:13 -0400203 sh('''pgrep --list-full kail-startup || true''')
Joey Armstrongb65ada32023-08-03 12:50:20 -0400204 }
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400205
Joey Armstrong97a8b882023-08-02 16:08:52 -0400206 // -----------------------------------------------------------------------
207 // stop logging
208 // -----------------------------------------------------------------------
Matteo Scandolod17de3a2021-04-09 15:47:52 -0700209 sh """
Hardik Windlassec9341b2021-06-07 11:58:29 +0000210 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-startup" | grep -v grep | awk '{print \$1}')"
211 if [ -n "\$P_IDS" ]; then
212 echo \$P_IDS
213 for P_ID in \$P_IDS; do
214 kill -9 \$P_ID
215 done
216 fi
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700217 cd ${logsDir}
Hardik Windlassec9341b2021-06-07 11:58:29 +0000218 gzip -k onos-voltha-startup-combined.log
219 rm onos-voltha-startup-combined.log
Matteo Scandolod17de3a2021-04-09 15:47:52 -0700220 """
Hardik Windlassec9341b2021-06-07 11:58:29 +0000221 }
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400222
223 sh """
Hardik Windlassec9341b2021-06-07 11:58:29 +0000224 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"&
225 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"&
226 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"&
227 bbsimDmiPortFwd=50075
228 for i in {0..${olts.toInteger() - 1}}; do
229 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"&
230 ((bbsimDmiPortFwd++))
231 done
Hardik Windlass3bb089a2022-03-22 17:56:03 +0000232 if [ ${withMonitoring} = true ] ; then
233 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"&
234 fi
Hardik Windlassec9341b2021-06-07 11:58:29 +0000235 ps aux | grep port-forward
236 """
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500237
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400238 // setting ONOS log level
239 script
Joey Armstrongf404b642023-08-04 14:39:13 -0400240 {
Joey Armstrongb65ada32023-08-03 12:50:20 -0400241 println('** setOnosLogLevels: ENTER')
242 setOnosLogLevels([
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400243 onosNamespace: infraNamespace,
244 apps: [
245 'org.opencord.dhcpl2relay',
246 'org.opencord.olt',
247 'org.opencord.aaa',
248 'org.opencord.maclearner',
249 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
250 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
251 ],
252 logLevel: logLevel
253 ])
Joey Armstrongb65ada32023-08-03 12:50:20 -0400254 println('** setOnosLogLevels: LEAVE')
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400255 } // script
256 } // if (teardown)
257 } // stage('Deploy Voltha')
258
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400259 // -----------------------------------------------------------------------
260 // -----------------------------------------------------------------------
Joey Armstrongfd896522023-08-04 13:30:48 -0400261 stage("Run test ${testTarget} on workflow ${workflow}")
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400262 {
263 sh """
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400264 echo -e '** Monitor memory consumption: ENTER'
265
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000266 if [ ${withMonitoring} = true ] ; then
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400267 cat <<EOM
268
269** -----------------------------------------------------------------------
270** Monitoring memory usage with mem_consumption.py
271** -----------------------------------------------------------------------
272EOM
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500273 mkdir -p "$WORKSPACE/voltha-pods-mem-consumption-${workflow}"
274 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400275
276 echo '** Installing python virtualenv'
277 make venv-activate-patched
278
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400279 set +u && source .venv/bin/activate && set -u
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000280 # Collect initial memory consumption
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400281 python scripts/mem_consumption.py -o $WORKSPACE/voltha-pods-mem-consumption-${workflow} -a 0.0.0.0:31301 -n ${volthaNamespace}
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000282 fi
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400283
284 echo -e '** Monitor memory consumption: LEAVE\n'
Hardik Windlasse1660492022-03-14 15:12:46 +0000285 """
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400286
287 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400288 echo -e "\n** make testTarget=[${testTarget}]"
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700289 mkdir -p ${logsDir}
Hardik Windlassd62442d2021-11-30 10:51:20 +0000290 export ROBOT_MISC_ARGS="-d ${logsDir} ${params.extraRobotArgs} "
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700291 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}"
Hardik Windlass72947302021-06-14 10:36:57 +0000292 export KVSTOREPREFIX=voltha/voltha_voltha
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800293
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400294 make -C "$WORKSPACE/voltha-system-tests" ${testTarget}
Hardik Windlass72947302021-06-14 10:36:57 +0000295 """
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400296
297 getPodsInfo("${logsDir}")
298
299 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400300 echo -e '\n** Gather robot Framework logs: ENTER'
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400301 # set +e
Hardik Windlassdad8e5c2021-11-11 05:19:47 +0000302 # collect logs collected in the Robot Framework StartLogging keyword
303 cd ${logsDir}
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400304 gzip *-combined.log
305 rm -f *-combined.log
Joey Armstrong54dec092023-08-03 18:21:38 -0400306
307 echo -e '** Gather robot Framework logs: LEAVE\n'
Hardik Windlassdad8e5c2021-11-11 05:19:47 +0000308 """
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400309
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400310 // -----------------------------------------------------------------------
311 // -----------------------------------------------------------------------
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000312 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400313 echo -e '** Monitor pod-mem-consumption: ENTER'
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000314 if [ ${withMonitoring} = true ] ; then
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400315 cat <<EOM
316
317** -----------------------------------------------------------------------
318** Monitoring pod-memory-consumption using mem_consumption.py
319** -----------------------------------------------------------------------
320EOM
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500321 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400322
323 echo '** Installing python virtualenv'
324 make venv-activate-patched
325
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400326 set +u && source .venv/bin/activate && set -u
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000327 # Collect memory consumption of voltha pods once all the tests are complete
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400328 python scripts/mem_consumption.py -o $WORKSPACE/voltha-pods-mem-consumption-${workflow} -a 0.0.0.0:31301 -n ${volthaNamespace}
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000329 fi
Joey Armstrong54dec092023-08-03 18:21:38 -0400330 echo -e '** Monitor pod-mem-consumption: LEAVE\n'
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000331 """
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400332 } // stage
Joey Armstrongb65ada32023-08-03 12:50:20 -0400333
334 return
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400335} // execute_test()
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800336
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400337// -----------------------------------------------------------------------
338// -----------------------------------------------------------------------
Joey Armstrongb65ada32023-08-03 12:50:20 -0400339def collectArtifacts(exitStatus) {
Joey Armstrongcd419122023-08-07 14:56:39 -0400340 String iam = getIam('execute_test')
341
Joey Armstrong97a8b882023-08-02 16:08:52 -0400342 echo '''
343
344** -----------------------------------------------------------------------
345** collectArtifacts
346** -----------------------------------------------------------------------
347'''
Joey Armstrongcd419122023-08-07 14:56:39 -0400348 println("${iam}: ENTER (exitStatus=${exitStatus})")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400349
Joey Armstrongcd419122023-08-07 14:56:39 -0400350 getPodsInfo("$WORKSPACE/${exitStatus}")
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400351
Joey Armstrongcd419122023-08-07 14:56:39 -0400352 sh """
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400353 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log
Hardik Windlassec9341b2021-06-07 11:58:29 +0000354 """
Joey Armstrong66fcb4e2023-08-11 12:09:24 -0400355
Joey Armstrongcd419122023-08-07 14:56:39 -0400356 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 -0400357
Joey Armstrongcd419122023-08-07 14:56:39 -0400358 sh(returnStdout:true, script: '''
Hardik Windlassec9341b2021-06-07 11:58:29 +0000359 sync
Joey Armstrongcd419122023-08-07 14:56:39 -0400360 echo '** Running: pgrep --list-full kail-startup (ENTER)'
361 pgrep --list-full 'kail-startup' || true
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400362 [[ $(pgrep --count kail) -gt 0 ]] && pkill --echo kail
Joey Armstrongcd419122023-08-07 14:56:39 -0400363 echo '** Running: pgrep --list-full kail-startup (LEAVE)'
Joey Armstrongf404b642023-08-04 14:39:13 -0400364 ''')
Joey Armstrong97a8b882023-08-02 16:08:52 -0400365
Joey Armstrongcd419122023-08-07 14:56:39 -0400366 println("${iam}: ENTER RobotPublisher")
367 step([$class: 'RobotPublisher',
368 disableArchiveOutput: false,
369 logFileName: '**/*/log*.html',
370 otherFiles: '',
371 outputFileName: '**/*/output*.xml',
372 outputPath: '.',
373 passThreshold: 100,
374 reportFileName: '**/*/report*.html',
375 unstableThreshold: 0,
376 onlyCritical: true]);
377 println("${iam}: LEAVE RobotPublisher")
378
379 println("${iam}: LEAVE (exitStatus=${exitStatus})")
380 return
Hardik Windlassec9341b2021-06-07 11:58:29 +0000381}
382
Joey Armstrongb65ada32023-08-03 12:50:20 -0400383// -----------------------------------------------------------------------
384// Intent: main
385// -----------------------------------------------------------------------
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800386pipeline {
387
388 /* no label, executor is determined by JJB */
389 agent {
390 label "${params.buildNode}"
391 }
392 options {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000393 timeout(time: "${timeout}", unit: 'MINUTES')
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800394 }
395 environment {
Joey Armstrongf404b642023-08-04 14:39:13 -0400396 KUBECONFIG = "$HOME/.kube/kind-${clusterName}"
397 VOLTCONFIG = "$HOME/.volt/config"
398 PATH = "$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
399 DIAGS_PROFILE = 'VOLTHA_PROFILE'
400 SSHPASS = 'karaf'
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800401 }
Hardik Windlassec9341b2021-06-07 11:58:29 +0000402 stages {
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800403 stage('Download Code') {
404 steps {
405 getVolthaCode([
406 branch: "${branch}",
407 gerritProject: "${gerritProject}",
408 gerritRefspec: "${gerritRefspec}",
409 volthaSystemTestsChange: "${volthaSystemTestsChange}",
410 volthaHelmChartsChange: "${volthaHelmChartsChange}",
411 ])
412 }
413 }
Joey Armstrong84adc542023-04-11 14:47:34 -0400414
415 stage('Build patch v1.1')
416 {
417 // build the patch only if gerritProject is specified
418 when
419 {
420 expression
421 {
422 return !gerritProject.isEmpty()
423 }
Hardik Windlassec9341b2021-06-07 11:58:29 +0000424 }
Joey Armstrong06a68372023-07-24 16:37:16 -0400425
Joey Armstrong97a8b882023-08-02 16:08:52 -0400426 steps
427 {
428 // NOTE that the correct patch has already been checked out
429 // during the getVolthaCode step
430 buildVolthaComponent("${gerritProject}")
Joey Armstrong06a68372023-07-24 16:37:16 -0400431 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800432 }
Joey Armstronged161f72023-04-11 13:16:59 -0400433
Joey Armstrong97a8b882023-08-02 16:08:52 -0400434 // -----------------------------------------------------------------------
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400435 // -----------------------------------------------------------------------
Joey Armstrongf404b642023-08-04 14:39:13 -0400436 stage('Install Kail')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400437 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400438 steps
439 {
440 script
441 {
442 String cmd = [
443 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400444 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400445 '-C', "$WORKSPACE/voltha-system-tests",
446 "KAIL_PATH=\"$WORKSPACE/bin\"",
447 'kail',
448 ].join(' ')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400449
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400450 println(" ** Running: ${cmd}:\n")
451 sh("${cmd}")
452 } // script
453 } // steps
454 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400455
456 // -----------------------------------------------------------------------
Joey Armstrong97a8b882023-08-02 16:08:52 -0400457 // -----------------------------------------------------------------------
Joey Armstrongf404b642023-08-04 14:39:13 -0400458 stage('Install Kind')
Joey Armstrong97a8b882023-08-02 16:08:52 -0400459 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400460 steps
461 {
462 script
463 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400464
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400465 String cmd = [
466 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400467 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400468 '-C', "$WORKSPACE/voltha-system-tests",
469 "KIND_PATH=\"$WORKSPACE/bin\"",
470 'install-command-kind',
471 ].join(' ')
Joey Armstrongf404b642023-08-04 14:39:13 -0400472
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400473 println(" ** Running: ${cmd}:\n")
474 sh("${cmd}")
475 } // script
476 } // steps
477 } // stage
Joey Armstrong97a8b882023-08-02 16:08:52 -0400478
479 // -----------------------------------------------------------------------
480 // -----------------------------------------------------------------------
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400481 stage('Create K8s Cluster')
482 {
Joey Armstrongf076c312023-08-01 17:17:10 -0400483 steps
484 {
485 script
Joey Armstrong84adc542023-04-11 14:47:34 -0400486 {
Joey Armstrong97a8b882023-08-02 16:08:52 -0400487 def clusterExists = sh(
Joey Armstrongf076c312023-08-01 17:17:10 -0400488 returnStdout: true,
489 script: """kind get clusters | grep "${clusterName}" | wc -l""")
Joey Armstrongbf492922023-04-13 17:05:09 -0400490
Joey Armstrongb65ada32023-08-03 12:50:20 -0400491 if (clusterExists.trim() == '0')
Joey Armstrongf076c312023-08-01 17:17:10 -0400492 {
493 createKubernetesCluster([nodes: 3, name: clusterName])
494 }
495 } // script
496 } // steps
497 } // stage('Create K8s Cluster')
Joey Armstrong84adc542023-04-11 14:47:34 -0400498
Joey Armstrongcd419122023-08-07 14:56:39 -0400499 // -----------------------------------------------------------------------
500 // -----------------------------------------------------------------------
501 stage('Replace voltctl')
502 {
Joey Armstrongf404b642023-08-04 14:39:13 -0400503 // if the project is voltctl, override the downloaded one with the built one
504 when {
505 expression {
506 return gerritProject == 'voltctl'
507 }
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400508 }
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400509
Joey Armstrongf404b642023-08-04 14:39:13 -0400510 // Hmmmm(?) where did the voltctl download happen ?
511 // Likely Makefile but would be helpful to document here.
512 steps
513 {
514 println("${iam} Running: installVoltctl($branch)")
515 installVoltctl("$branch")
516 } // steps
517 } // stage
Joey Armstrong97a8b882023-08-02 16:08:52 -0400518
Joey Armstrongf404b642023-08-04 14:39:13 -0400519 // -----------------------------------------------------------------------
520 // -----------------------------------------------------------------------
521 stage('Load image in kind nodes')
522 {
523 when {
524 expression {
525 return !gerritProject.isEmpty()
526 }
Joey Armstrong97a8b882023-08-02 16:08:52 -0400527 }
Joey Armstrongf404b642023-08-04 14:39:13 -0400528 steps {
529 loadToKind()
530 } // steps
531 } // stage
Joey Armstrong97a8b882023-08-02 16:08:52 -0400532
Joey Armstrongf404b642023-08-04 14:39:13 -0400533 // -----------------------------------------------------------------------
534 // -----------------------------------------------------------------------
535 stage('Parse and execute tests')
536 {
537 steps {
538 script {
539 def tests = readYaml text: testTargets
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400540
Joey Armstrongf404b642023-08-04 14:39:13 -0400541 tests.eachWithIndex { test, idx ->
542 println "** readYaml test suite[$idx]) test=[${test}]"
543 // def test = tests[i]
544 String target = test['target']
545 String workflow = test['workflow']
546 String flags = test['flags']
547 Boolean teardown = test['teardown'].toBoolean()
548 Boolean logging = test['logging'].toBoolean()
549 String testLogging = (logging) ? 'True' : 'False'
550
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400551 println "Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}"
Joey Armstrong54dec092023-08-03 18:21:38 -0400552 println "Executing test ${target}: ENTER"
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400553 execute_test(target, workflow, testLogging, teardown, flags)
Joey Armstrong54dec092023-08-03 18:21:38 -0400554 println "Executing test ${target}: LEAVE"
Joey Armstrongb65ada32023-08-03 12:50:20 -0400555 } // for
Joey Armstrongf404b642023-08-04 14:39:13 -0400556
Joey Armstrongcd419122023-08-07 14:56:39 -0400557 String iam = getIam('Parse and execute tests')
Joey Armstrongf404b642023-08-04 14:39:13 -0400558 println("** ${iam} ran to completion")
Joey Armstrongb65ada32023-08-03 12:50:20 -0400559 } // script
560 } // steps
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400561 } // stage
562 } // stages
Joey Armstrong84adc542023-04-11 14:47:34 -0400563
564 post
565 {
566 aborted { collectArtifacts('aborted') }
567 failure { collectArtifacts('failed') }
Joey Armstrongbf492922023-04-13 17:05:09 -0400568 always { collectArtifacts('always') }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800569 }
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400570} // pipeline
Joey Armstronged161f72023-04-11 13:16:59 -0400571
572// EOF