blob: c8307bfe5b92cc5b1b39070cc7a4ca56646d77e1 [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 Armstrongb65ada32023-08-03 12:50:20 -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
140
141 if (volthaHelmChartsChange != ''
142 || gerritProject == 'voltha-helm-charts'
143 || isReleaseBranch(branch) // branch != 'master'
144 ) {
145 localCharts = true
146 }
Joey Armstrongb65ada32023-08-03 12:50:20 -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
159 // refactoring into standalone functions
160 // -----------------------------------------------------------------------
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')
203 def stream = sh(
204 returnStatus:false,
205 returnStdout:true,
206 script: '''pgrep --list-full kail-startup || true'''
207 )
208 println("** pgrep output: ${stream}")
209 }
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400210
Joey Armstrong97a8b882023-08-02 16:08:52 -0400211 // -----------------------------------------------------------------------
212 // stop logging
213 // -----------------------------------------------------------------------
Matteo Scandolod17de3a2021-04-09 15:47:52 -0700214 sh """
Hardik Windlassec9341b2021-06-07 11:58:29 +0000215 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-startup" | grep -v grep | awk '{print \$1}')"
216 if [ -n "\$P_IDS" ]; then
217 echo \$P_IDS
218 for P_ID in \$P_IDS; do
219 kill -9 \$P_ID
220 done
221 fi
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700222 cd ${logsDir}
Hardik Windlassec9341b2021-06-07 11:58:29 +0000223 gzip -k onos-voltha-startup-combined.log
224 rm onos-voltha-startup-combined.log
Matteo Scandolod17de3a2021-04-09 15:47:52 -0700225 """
Hardik Windlassec9341b2021-06-07 11:58:29 +0000226 }
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400227
228 sh """
Hardik Windlassec9341b2021-06-07 11:58:29 +0000229 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"&
230 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"&
231 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"&
232 bbsimDmiPortFwd=50075
233 for i in {0..${olts.toInteger() - 1}}; do
234 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"&
235 ((bbsimDmiPortFwd++))
236 done
Hardik Windlass3bb089a2022-03-22 17:56:03 +0000237 if [ ${withMonitoring} = true ] ; then
238 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"&
239 fi
Hardik Windlassec9341b2021-06-07 11:58:29 +0000240 ps aux | grep port-forward
241 """
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500242
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400243 // setting ONOS log level
244 script
Joey Armstrongb65ada32023-08-03 12:50:20 -0400245 {
246 println('** setOnosLogLevels: ENTER')
247 setOnosLogLevels([
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400248 onosNamespace: infraNamespace,
249 apps: [
250 'org.opencord.dhcpl2relay',
251 'org.opencord.olt',
252 'org.opencord.aaa',
253 'org.opencord.maclearner',
254 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
255 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
256 ],
257 logLevel: logLevel
258 ])
Joey Armstrongb65ada32023-08-03 12:50:20 -0400259 println('** setOnosLogLevels: LEAVE')
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400260 } // script
261 } // if (teardown)
262 } // stage('Deploy Voltha')
263
Joey Armstrongfd896522023-08-04 13:30:48 -0400264 stage("Run test ${testTarget} on workflow ${workflow}")
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400265 {
266 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400267 echo -e "\n** Monitor using mem_consumption.py ?"
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000268 if [ ${withMonitoring} = true ] ; then
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500269 mkdir -p "$WORKSPACE/voltha-pods-mem-consumption-${workflow}"
270 cd "$WORKSPACE/voltha-system-tests"
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400271 make venv-activate-script
272 set +u && source .venv/bin/activate && set -u
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000273 # Collect initial memory consumption
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400274 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 +0000275 fi
Hardik Windlasse1660492022-03-14 15:12:46 +0000276 """
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400277
278 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400279 echo -e "\n** make testTarget=[${testTarget}]"
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700280 mkdir -p ${logsDir}
Hardik Windlassd62442d2021-11-30 10:51:20 +0000281 export ROBOT_MISC_ARGS="-d ${logsDir} ${params.extraRobotArgs} "
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700282 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 +0000283 export KVSTOREPREFIX=voltha/voltha_voltha
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800284
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400285 make -C "$WORKSPACE/voltha-system-tests" ${testTarget}
Hardik Windlass72947302021-06-14 10:36:57 +0000286 """
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400287
288 getPodsInfo("${logsDir}")
289
290 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400291 echo -e '\n** Gather robot Framework logs: ENTER'
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400292 # set +e
Hardik Windlassdad8e5c2021-11-11 05:19:47 +0000293 # collect logs collected in the Robot Framework StartLogging keyword
294 cd ${logsDir}
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400295 gzip *-combined.log
296 rm -f *-combined.log
Joey Armstrong54dec092023-08-03 18:21:38 -0400297
298 echo -e '** Gather robot Framework logs: LEAVE\n'
Hardik Windlassdad8e5c2021-11-11 05:19:47 +0000299 """
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400300
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000301 sh """
Joey Armstrong54dec092023-08-03 18:21:38 -0400302 echo -e '** Monitor pod-mem-consumption: ENTER'
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000303 if [ ${withMonitoring} = true ] ; then
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500304 cd "$WORKSPACE/voltha-system-tests"
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400305 make venv-activate-script
306 set +u && source .venv/bin/activate && set -u
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000307 # Collect memory consumption of voltha pods once all the tests are complete
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400308 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 +0000309 fi
Joey Armstrong54dec092023-08-03 18:21:38 -0400310 echo -e '** Monitor pod-mem-consumption: LEAVE\n'
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000311 """
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400312 } // stage
Joey Armstrongb65ada32023-08-03 12:50:20 -0400313
314 return
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400315} // execute_test()
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800316
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400317// -----------------------------------------------------------------------
318// -----------------------------------------------------------------------
Joey Armstrongb65ada32023-08-03 12:50:20 -0400319def collectArtifacts(exitStatus) {
Joey Armstrong97a8b882023-08-02 16:08:52 -0400320 echo '''
321
322** -----------------------------------------------------------------------
323** collectArtifacts
324** -----------------------------------------------------------------------
325'''
326
Hardik Windlassec9341b2021-06-07 11:58:29 +0000327 getPodsInfo("$WORKSPACE/${exitStatus}")
Joey Armstrong97a8b882023-08-02 16:08:52 -0400328
Hardik Windlassec9341b2021-06-07 11:58:29 +0000329 sh """
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400330 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log
Hardik Windlassec9341b2021-06-07 11:58:29 +0000331 """
Joey Armstrong97a8b882023-08-02 16:08:52 -0400332
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000333 archiveArtifacts artifacts: '**/*.log,**/*.gz,**/*.txt,**/*.html,**/voltha-pods-mem-consumption-att/*,**/voltha-pods-mem-consumption-dt/*,**/voltha-pods-mem-consumption-tt/*'
Joey Armstrong97a8b882023-08-02 16:08:52 -0400334
Hardik Windlassec9341b2021-06-07 11:58:29 +0000335 sh '''
336 sync
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400337 [[ $(pgrep --count kail) -gt 0 ]] && pkill --echo kail
Hardik Windlassec9341b2021-06-07 11:58:29 +0000338 '''
Joey Armstrong97a8b882023-08-02 16:08:52 -0400339
Hardik Windlassec9341b2021-06-07 11:58:29 +0000340 step([$class: 'RobotPublisher',
341 disableArchiveOutput: false,
Joey Armstrongb65ada32023-08-03 12:50:20 -0400342 logFileName: '**/*/log*.html',
Hardik Windlassec9341b2021-06-07 11:58:29 +0000343 otherFiles: '',
Joey Armstrongb65ada32023-08-03 12:50:20 -0400344 outputFileName: '**/*/output*.xml',
Hardik Windlassec9341b2021-06-07 11:58:29 +0000345 outputPath: '.',
346 passThreshold: 100,
Joey Armstrongb65ada32023-08-03 12:50:20 -0400347 reportFileName: '**/*/report*.html',
Andrea Campanellaabc09772021-06-16 12:08:57 +0200348 unstableThreshold: 0,
349 onlyCritical: true]);
Hardik Windlassec9341b2021-06-07 11:58:29 +0000350}
351
Joey Armstrongb65ada32023-08-03 12:50:20 -0400352// -----------------------------------------------------------------------
353// Intent: main
354// -----------------------------------------------------------------------
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800355pipeline {
356
357 /* no label, executor is determined by JJB */
358 agent {
359 label "${params.buildNode}"
360 }
361 options {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000362 timeout(time: "${timeout}", unit: 'MINUTES')
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800363 }
364 environment {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000365 KUBECONFIG="$HOME/.kube/kind-${clusterName}"
366 VOLTCONFIG="$HOME/.volt/config"
367 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
Joey Armstrongb65ada32023-08-03 12:50:20 -0400368 DIAGS_PROFILE='VOLTHA_PROFILE'
369 SSHPASS='karaf'
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800370 }
Hardik Windlassec9341b2021-06-07 11:58:29 +0000371 stages {
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800372 stage('Download Code') {
373 steps {
374 getVolthaCode([
375 branch: "${branch}",
376 gerritProject: "${gerritProject}",
377 gerritRefspec: "${gerritRefspec}",
378 volthaSystemTestsChange: "${volthaSystemTestsChange}",
379 volthaHelmChartsChange: "${volthaHelmChartsChange}",
380 ])
381 }
382 }
Joey Armstrong84adc542023-04-11 14:47:34 -0400383
384 stage('Build patch v1.1')
385 {
386 // build the patch only if gerritProject is specified
387 when
388 {
389 expression
390 {
391 return !gerritProject.isEmpty()
392 }
Hardik Windlassec9341b2021-06-07 11:58:29 +0000393 }
Joey Armstrong06a68372023-07-24 16:37:16 -0400394
Joey Armstrong97a8b882023-08-02 16:08:52 -0400395 steps
396 {
397 // NOTE that the correct patch has already been checked out
398 // during the getVolthaCode step
399 buildVolthaComponent("${gerritProject}")
Joey Armstrong06a68372023-07-24 16:37:16 -0400400 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800401 }
Joey Armstronged161f72023-04-11 13:16:59 -0400402
Joey Armstrong97a8b882023-08-02 16:08:52 -0400403 // -----------------------------------------------------------------------
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400404 // -----------------------------------------------------------------------
405 stage ('Install Kail')
406 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400407 steps
408 {
409 script
410 {
411 String cmd = [
412 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400413 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400414 '-C', "$WORKSPACE/voltha-system-tests",
415 "KAIL_PATH=\"$WORKSPACE/bin\"",
416 'kail',
417 ].join(' ')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400418
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400419 println(" ** Running: ${cmd}:\n")
420 sh("${cmd}")
421 } // script
422 } // steps
423 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400424
425 // -----------------------------------------------------------------------
Joey Armstrong97a8b882023-08-02 16:08:52 -0400426 // -----------------------------------------------------------------------
427 stage ('Install Kind')
428 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400429 steps
430 {
431 script
432 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400433
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400434 String cmd = [
435 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400436 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400437 '-C', "$WORKSPACE/voltha-system-tests",
438 "KIND_PATH=\"$WORKSPACE/bin\"",
439 'install-command-kind',
440 ].join(' ')
441
442 println(" ** Running: ${cmd}:\n")
443 sh("${cmd}")
444 } // script
445 } // steps
446 } // stage
Joey Armstrong97a8b882023-08-02 16:08:52 -0400447
448 // -----------------------------------------------------------------------
449 // -----------------------------------------------------------------------
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400450 stage('Create K8s Cluster')
451 {
Joey Armstrongf076c312023-08-01 17:17:10 -0400452 steps
453 {
454 script
Joey Armstrong84adc542023-04-11 14:47:34 -0400455 {
Joey Armstrong97a8b882023-08-02 16:08:52 -0400456 def clusterExists = sh(
Joey Armstrongf076c312023-08-01 17:17:10 -0400457 returnStdout: true,
458 script: """kind get clusters | grep "${clusterName}" | wc -l""")
Joey Armstrongbf492922023-04-13 17:05:09 -0400459
Joey Armstrongb65ada32023-08-03 12:50:20 -0400460 if (clusterExists.trim() == '0')
Joey Armstrongf076c312023-08-01 17:17:10 -0400461 {
462 createKubernetesCluster([nodes: 3, name: clusterName])
463 }
464 } // script
465 } // steps
466 } // stage('Create K8s Cluster')
Joey Armstrong84adc542023-04-11 14:47:34 -0400467
Joey Armstrong97a8b882023-08-02 16:08:52 -0400468 // -----------------------------------------------------------------------
469 // -----------------------------------------------------------------------
470 stage('Replace voltctl')
471 {
472 // if the project is voltctl, override the downloaded one with the built one
473 when {
474 expression {
Joey Armstrongb65ada32023-08-03 12:50:20 -0400475 return gerritProject == 'voltctl'
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400476 }
Matteo Scandolo29597f02021-02-12 10:53:57 -0800477 }
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400478
Joey Armstrong97a8b882023-08-02 16:08:52 -0400479 // Hmmmm(?) where did the voltctl download happen ?
480 // Likely Makefile but would be helpful to document here.
481 steps
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400482 {
Joey Armstrong97a8b882023-08-02 16:08:52 -0400483 println("${iam} Running: installVoltctl($branch)")
484 installVoltctl("$branch")
485 } // steps
486 } // stage
487
488 // -----------------------------------------------------------------------
489 // -----------------------------------------------------------------------
490 stage('Load image in kind nodes')
491 {
492 when {
493 expression {
494 return !gerritProject.isEmpty()
495 }
496 }
497 steps {
498 loadToKind()
499 } // steps
500 } // stage
501
502 // -----------------------------------------------------------------------
503 // -----------------------------------------------------------------------
504 stage('Parse and execute tests')
505 {
Joey Armstrongb65ada32023-08-03 12:50:20 -0400506 steps {
507 script {
508 def tests = readYaml text: testTargets
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400509
Joey Armstrongb65ada32023-08-03 12:50:20 -0400510 for(int i = 0;i<tests.size();i++) {
511 def test = tests[i]
512 def target = test['target']
513 def workflow = test['workflow']
514 def flags = test['flags']
515 def teardown = test['teardown'].toBoolean()
516 def logging = test['logging'].toBoolean()
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400517 def testLogging = 'False'
518 if (logging) {
519 testLogging = 'True'
520 }
521 println "Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}"
Joey Armstrong54dec092023-08-03 18:21:38 -0400522 println "Executing test ${target}: ENTER"
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400523 execute_test(target, workflow, testLogging, teardown, flags)
Joey Armstrong54dec092023-08-03 18:21:38 -0400524 println "Executing test ${target}: LEAVE"
Joey Armstrongb65ada32023-08-03 12:50:20 -0400525 } // for
526 } // script
527 } // steps
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400528 } // stage
529 } // stages
Joey Armstrong84adc542023-04-11 14:47:34 -0400530
531 post
532 {
533 aborted { collectArtifacts('aborted') }
534 failure { collectArtifacts('failed') }
Joey Armstrongbf492922023-04-13 17:05:09 -0400535 always { collectArtifacts('always') }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800536 }
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400537} // pipeline
Joey Armstronged161f72023-04-11 13:16:59 -0400538
539// EOF