blob: 394357155e5b8aa8b8fa58888b43db592ae9995b [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 Armstrongb65ada32023-08-03 12:50:20 -0400138 // if we're downloading a voltha-helm-charts patch, then install from a local copy of the charts
139 Boolean localCharts = false
Joey Armstrong53cebea2023-07-26 10:35:53 -0400140
Joey Armstrongb65ada32023-08-03 12:50:20 -0400141 if (volthaHelmChartsChange != ''
142 || gerritProject == 'voltha-helm-charts'
Joey Armstrong97a8b882023-08-02 16:08:52 -0400143 || isReleaseBranch(branch) // branch != 'master'
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400144 ) {
Joey Armstrongb65ada32023-08-03 12:50:20 -0400145 localCharts = true
146 }
147
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 Armstrong8a960ee2023-08-03 15:00:00 -0400176 if (gerritProject != '') {
177 localHelmFlags = "${localHelmFlags} " + getVolthaImageFlags("${gerritProject}")
178 }
Hardik Windlassec9341b2021-06-07 11:58:29 +0000179
Joey Armstrong8a960ee2023-08-03 15:00:00 -0400180 println('volthaDeploy: ENTER')
181 volthaDeploy([
182 infraNamespace: infraNamespace,
183 volthaNamespace: volthaNamespace,
184 workflow: workflow.toLowerCase(),
185 withMacLearning: enableMacLearning.toBoolean(),
186 extraHelmFlags: localHelmFlags,
187 localCharts: localCharts,
188 bbsimReplica: olts.toInteger(),
189 dockerRegistry: registry,
190 ])
191 println('volthaDeploy: LEAVE')
Joey Armstrongb65ada32023-08-03 12:50:20 -0400192
Joey Armstrongb65ada32023-08-03 12:50:20 -0400193 } // script
Matteo Scandolofcfc60d2021-02-24 09:06:48 -0800194
Joey Armstrong97a8b882023-08-02 16:08:52 -0400195 // -----------------------------------------------------------------------
196 // Intent: Replacing P_IDS with pgrep/pkill is a step forward.
197 // Why not simply use a pid file, capture _TAG=kail-startup above
198 // Grep runs the risk of terminating stray commands (??-good <=> bad-??)
Joey Armstrongb65ada32023-08-03 12:50:20 -0400199 // -----------------------------------------------------------------------
200 script {
201 println('Try out pgrep/pkill commands')
202 def stream = sh(
203 returnStatus:false,
204 returnStdout:true,
205 script: '''pgrep --list-full kail-startup || true'''
206 )
207 println("** pgrep output: ${stream}")
208 }
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400209
Joey Armstrong97a8b882023-08-02 16:08:52 -0400210 // -----------------------------------------------------------------------
211 // stop logging
212 // -----------------------------------------------------------------------
Matteo Scandolod17de3a2021-04-09 15:47:52 -0700213 sh """
Hardik Windlassec9341b2021-06-07 11:58:29 +0000214 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-startup" | grep -v grep | awk '{print \$1}')"
215 if [ -n "\$P_IDS" ]; then
216 echo \$P_IDS
217 for P_ID in \$P_IDS; do
218 kill -9 \$P_ID
219 done
220 fi
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700221 cd ${logsDir}
Hardik Windlassec9341b2021-06-07 11:58:29 +0000222 gzip -k onos-voltha-startup-combined.log
223 rm onos-voltha-startup-combined.log
Matteo Scandolod17de3a2021-04-09 15:47:52 -0700224 """
Hardik Windlassec9341b2021-06-07 11:58:29 +0000225 }
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400226
227 sh """
Hardik Windlassec9341b2021-06-07 11:58:29 +0000228 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"&
229 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"&
230 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"&
231 bbsimDmiPortFwd=50075
232 for i in {0..${olts.toInteger() - 1}}; do
233 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"&
234 ((bbsimDmiPortFwd++))
235 done
Hardik Windlass3bb089a2022-03-22 17:56:03 +0000236 if [ ${withMonitoring} = true ] ; then
237 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"&
238 fi
Hardik Windlassec9341b2021-06-07 11:58:29 +0000239 ps aux | grep port-forward
240 """
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500241
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400242 // setting ONOS log level
243 script
Joey Armstrongb65ada32023-08-03 12:50:20 -0400244 {
245 println('** setOnosLogLevels: ENTER')
246 setOnosLogLevels([
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400247 onosNamespace: infraNamespace,
248 apps: [
249 'org.opencord.dhcpl2relay',
250 'org.opencord.olt',
251 'org.opencord.aaa',
252 'org.opencord.maclearner',
253 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
254 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
255 ],
256 logLevel: logLevel
257 ])
Joey Armstrongb65ada32023-08-03 12:50:20 -0400258 println('** setOnosLogLevels: LEAVE')
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400259 } // script
260 } // if (teardown)
261 } // stage('Deploy Voltha')
262
263 stage('Run test ' + testTarget + ' on ' + workflow + ' workFlow')
264 {
265 sh """
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000266 if [ ${withMonitoring} = true ] ; then
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500267 mkdir -p "$WORKSPACE/voltha-pods-mem-consumption-${workflow}"
268 cd "$WORKSPACE/voltha-system-tests"
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400269 make venv-activate-script
270 set +u && source .venv/bin/activate && set -u
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000271 # Collect initial memory consumption
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400272 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 +0000273 fi
Hardik Windlasse1660492022-03-14 15:12:46 +0000274 """
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400275
276 sh """
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700277 mkdir -p ${logsDir}
Hardik Windlassd62442d2021-11-30 10:51:20 +0000278 export ROBOT_MISC_ARGS="-d ${logsDir} ${params.extraRobotArgs} "
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700279 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 +0000280 export KVSTOREPREFIX=voltha/voltha_voltha
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800281
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400282 make -C "$WORKSPACE/voltha-system-tests" ${testTarget}
Hardik Windlass72947302021-06-14 10:36:57 +0000283 """
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400284
285 getPodsInfo("${logsDir}")
286
287 sh """
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400288 # set +e
Hardik Windlassdad8e5c2021-11-11 05:19:47 +0000289 # collect logs collected in the Robot Framework StartLogging keyword
290 cd ${logsDir}
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400291 gzip *-combined.log
292 rm -f *-combined.log
Hardik Windlassdad8e5c2021-11-11 05:19:47 +0000293 """
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400294
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000295 sh """
296 if [ ${withMonitoring} = true ] ; then
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500297 cd "$WORKSPACE/voltha-system-tests"
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400298 make venv-activate-script
299 set +u && source .venv/bin/activate && set -u
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000300 # Collect memory consumption of voltha pods once all the tests are complete
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400301 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 +0000302 fi
303 """
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400304 } // stage
Joey Armstrongb65ada32023-08-03 12:50:20 -0400305
306 return
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400307} // execute_test()
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800308
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400309// -----------------------------------------------------------------------
310// -----------------------------------------------------------------------
Joey Armstrongb65ada32023-08-03 12:50:20 -0400311def collectArtifacts(exitStatus) {
Joey Armstrong97a8b882023-08-02 16:08:52 -0400312 echo '''
313
314** -----------------------------------------------------------------------
315** collectArtifacts
316** -----------------------------------------------------------------------
317'''
318
Hardik Windlassec9341b2021-06-07 11:58:29 +0000319 getPodsInfo("$WORKSPACE/${exitStatus}")
Joey Armstrong97a8b882023-08-02 16:08:52 -0400320
Hardik Windlassec9341b2021-06-07 11:58:29 +0000321 sh """
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400322 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log
Hardik Windlassec9341b2021-06-07 11:58:29 +0000323 """
Joey Armstrong97a8b882023-08-02 16:08:52 -0400324
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000325 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 -0400326
Hardik Windlassec9341b2021-06-07 11:58:29 +0000327 sh '''
328 sync
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400329 [[ $(pgrep --count kail) -gt 0 ]] && pkill --echo kail
Hardik Windlassec9341b2021-06-07 11:58:29 +0000330 which voltctl
331 md5sum $(which voltctl)
332 '''
Joey Armstrong97a8b882023-08-02 16:08:52 -0400333
Hardik Windlassec9341b2021-06-07 11:58:29 +0000334 step([$class: 'RobotPublisher',
335 disableArchiveOutput: false,
Joey Armstrongb65ada32023-08-03 12:50:20 -0400336 logFileName: '**/*/log*.html',
Hardik Windlassec9341b2021-06-07 11:58:29 +0000337 otherFiles: '',
Joey Armstrongb65ada32023-08-03 12:50:20 -0400338 outputFileName: '**/*/output*.xml',
Hardik Windlassec9341b2021-06-07 11:58:29 +0000339 outputPath: '.',
340 passThreshold: 100,
Joey Armstrongb65ada32023-08-03 12:50:20 -0400341 reportFileName: '**/*/report*.html',
Andrea Campanellaabc09772021-06-16 12:08:57 +0200342 unstableThreshold: 0,
343 onlyCritical: true]);
Hardik Windlassec9341b2021-06-07 11:58:29 +0000344}
345
Joey Armstrongb65ada32023-08-03 12:50:20 -0400346// -----------------------------------------------------------------------
347// Intent: main
348// -----------------------------------------------------------------------
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800349pipeline {
350
351 /* no label, executor is determined by JJB */
352 agent {
353 label "${params.buildNode}"
354 }
355 options {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000356 timeout(time: "${timeout}", unit: 'MINUTES')
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800357 }
358 environment {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000359 KUBECONFIG="$HOME/.kube/kind-${clusterName}"
360 VOLTCONFIG="$HOME/.volt/config"
361 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
Joey Armstrongb65ada32023-08-03 12:50:20 -0400362 DIAGS_PROFILE='VOLTHA_PROFILE'
363 SSHPASS='karaf'
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800364 }
Hardik Windlassec9341b2021-06-07 11:58:29 +0000365 stages {
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800366 stage('Download Code') {
367 steps {
368 getVolthaCode([
369 branch: "${branch}",
370 gerritProject: "${gerritProject}",
371 gerritRefspec: "${gerritRefspec}",
372 volthaSystemTestsChange: "${volthaSystemTestsChange}",
373 volthaHelmChartsChange: "${volthaHelmChartsChange}",
374 ])
375 }
376 }
Joey Armstrong84adc542023-04-11 14:47:34 -0400377
378 stage('Build patch v1.1')
379 {
380 // build the patch only if gerritProject is specified
381 when
382 {
383 expression
384 {
385 return !gerritProject.isEmpty()
386 }
Hardik Windlassec9341b2021-06-07 11:58:29 +0000387 }
Joey Armstrong06a68372023-07-24 16:37:16 -0400388
Joey Armstrong97a8b882023-08-02 16:08:52 -0400389 steps
390 {
391 // NOTE that the correct patch has already been checked out
392 // during the getVolthaCode step
393 buildVolthaComponent("${gerritProject}")
Joey Armstrong06a68372023-07-24 16:37:16 -0400394 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800395 }
Joey Armstronged161f72023-04-11 13:16:59 -0400396
Joey Armstrong97a8b882023-08-02 16:08:52 -0400397 // -----------------------------------------------------------------------
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400398 // -----------------------------------------------------------------------
399 stage ('Install Kail')
400 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400401 steps
402 {
403 script
404 {
405 String cmd = [
406 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400407 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400408 '-C', "$WORKSPACE/voltha-system-tests",
409 "KAIL_PATH=\"$WORKSPACE/bin\"",
410 'kail',
411 ].join(' ')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400412
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400413 println(" ** Running: ${cmd}:\n")
414 sh("${cmd}")
415 } // script
416 } // steps
417 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400418
419 // -----------------------------------------------------------------------
Joey Armstrong97a8b882023-08-02 16:08:52 -0400420 // -----------------------------------------------------------------------
421 stage ('Install Kind')
422 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400423 steps
424 {
425 script
426 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400427
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400428 String cmd = [
429 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400430 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400431 '-C', "$WORKSPACE/voltha-system-tests",
432 "KIND_PATH=\"$WORKSPACE/bin\"",
433 'install-command-kind',
434 ].join(' ')
435
436 println(" ** Running: ${cmd}:\n")
437 sh("${cmd}")
438 } // script
439 } // steps
440 } // stage
Joey Armstrong97a8b882023-08-02 16:08:52 -0400441
442 // -----------------------------------------------------------------------
443 // -----------------------------------------------------------------------
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400444 stage('Create K8s Cluster')
445 {
Joey Armstrongf076c312023-08-01 17:17:10 -0400446 steps
447 {
448 script
Joey Armstrong84adc542023-04-11 14:47:34 -0400449 {
Joey Armstrong97a8b882023-08-02 16:08:52 -0400450 def clusterExists = sh(
Joey Armstrongf076c312023-08-01 17:17:10 -0400451 returnStdout: true,
452 script: """kind get clusters | grep "${clusterName}" | wc -l""")
Joey Armstrongbf492922023-04-13 17:05:09 -0400453
Joey Armstrongb65ada32023-08-03 12:50:20 -0400454 if (clusterExists.trim() == '0')
Joey Armstrongf076c312023-08-01 17:17:10 -0400455 {
456 createKubernetesCluster([nodes: 3, name: clusterName])
457 }
458 } // script
459 } // steps
460 } // stage('Create K8s Cluster')
Joey Armstrong84adc542023-04-11 14:47:34 -0400461
Joey Armstrong97a8b882023-08-02 16:08:52 -0400462 // -----------------------------------------------------------------------
463 // -----------------------------------------------------------------------
464 stage('Replace voltctl')
465 {
466 // if the project is voltctl, override the downloaded one with the built one
467 when {
468 expression {
Joey Armstrongb65ada32023-08-03 12:50:20 -0400469 return gerritProject == 'voltctl'
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400470 }
Matteo Scandolo29597f02021-02-12 10:53:57 -0800471 }
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400472
Joey Armstrong97a8b882023-08-02 16:08:52 -0400473 // Hmmmm(?) where did the voltctl download happen ?
474 // Likely Makefile but would be helpful to document here.
475 steps
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400476 {
Joey Armstrong97a8b882023-08-02 16:08:52 -0400477 println("${iam} Running: installVoltctl($branch)")
478 installVoltctl("$branch")
479 } // steps
480 } // stage
481
482 // -----------------------------------------------------------------------
483 // -----------------------------------------------------------------------
484 stage('Load image in kind nodes')
485 {
486 when {
487 expression {
488 return !gerritProject.isEmpty()
489 }
490 }
491 steps {
492 loadToKind()
493 } // steps
494 } // stage
495
496 // -----------------------------------------------------------------------
497 // -----------------------------------------------------------------------
498 stage('Parse and execute tests')
499 {
Joey Armstrongb65ada32023-08-03 12:50:20 -0400500 steps {
501 script {
502 def tests = readYaml text: testTargets
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400503
Joey Armstrongb65ada32023-08-03 12:50:20 -0400504 for(int i = 0;i<tests.size();i++) {
505 def test = tests[i]
506 def target = test['target']
507 def workflow = test['workflow']
508 def flags = test['flags']
509 def teardown = test['teardown'].toBoolean()
510 def logging = test['logging'].toBoolean()
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400511 def testLogging = 'False'
512 if (logging) {
513 testLogging = 'True'
514 }
515 println "Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}"
516 execute_test(target, workflow, testLogging, teardown, flags)
Joey Armstrongb65ada32023-08-03 12:50:20 -0400517 } // for
518 } // script
519 } // steps
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400520 } // stage
521 } // stages
Joey Armstrong84adc542023-04-11 14:47:34 -0400522
523 post
524 {
525 aborted { collectArtifacts('aborted') }
526 failure { collectArtifacts('failed') }
Joey Armstrongbf492922023-04-13 17:05:09 -0400527 always { collectArtifacts('always') }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800528 }
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400529} // pipeline
Joey Armstronged161f72023-04-11 13:16:59 -0400530
531// EOF