blob: d2cd0229c1b8ef4fe5648a33c522a83eae7f8ccc [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
148 String branchName = branchName()
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400149 Boolean is_release = isReleaseBranch(branch)
Joey Armstrongb65ada32023-08-03 12:50:20 -0400150 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 Armstrongb65ada32023-08-03 12:50:20 -0400157 // NOTE temporary workaround expose ONOS node ports
158 String localHelmFlags = extraHelmFlags.trim()
Joey Armstrong97a8b882023-08-02 16:08:52 -0400159 + " --set global.log_level=${logLevel.toUpperCase()} "
Joey Armstrongb65ada32023-08-03 12:50:20 -0400160 + ' --set onos-classic.onosSshPort=30115 '
161 + ' --set onos-classic.onosApiPort=30120 '
162 + ' --set onos-classic.onosOfPort=31653 '
163 + ' --set onos-classic.individualOpenFlowNodePorts=true '
Joey Armstrong97a8b882023-08-02 16:08:52 -0400164 + testSpecificHelmFlags
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800165
Joey Armstrongb65ada32023-08-03 12:50:20 -0400166 if (gerritProject != '') {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000167 localHelmFlags = "${localHelmFlags} " + getVolthaImageFlags("${gerritProject}")
168 }
169
Joey Armstrongb65ada32023-08-03 12:50:20 -0400170 println('volthaDeploy: ENTER')
171
172 volthaDeploy([
Hardik Windlassec9341b2021-06-07 11:58:29 +0000173 infraNamespace: infraNamespace,
174 volthaNamespace: volthaNamespace,
175 workflow: workflow.toLowerCase(),
Hardik Windlass2b164342022-02-28 03:50:48 +0000176 withMacLearning: enableMacLearning.toBoolean(),
Hardik Windlassec9341b2021-06-07 11:58:29 +0000177 extraHelmFlags: localHelmFlags,
178 localCharts: localCharts,
179 bbsimReplica: olts.toInteger(),
180 dockerRegistry: registry,
Joey Armstrongb65ada32023-08-03 12:50:20 -0400181 ])
182
183 println('volthaDeploy: LEAVE')
184 } // script
Matteo Scandolofcfc60d2021-02-24 09:06:48 -0800185
Joey Armstrong97a8b882023-08-02 16:08:52 -0400186 // -----------------------------------------------------------------------
187 // Intent: Replacing P_IDS with pgrep/pkill is a step forward.
188 // Why not simply use a pid file, capture _TAG=kail-startup above
189 // Grep runs the risk of terminating stray commands (??-good <=> bad-??)
Joey Armstrongb65ada32023-08-03 12:50:20 -0400190 // -----------------------------------------------------------------------
191 script {
192 println('Try out pgrep/pkill commands')
193 def stream = sh(
194 returnStatus:false,
195 returnStdout:true,
196 script: '''pgrep --list-full kail-startup || true'''
197 )
198 println("** pgrep output: ${stream}")
199 }
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400200
Joey Armstrong97a8b882023-08-02 16:08:52 -0400201 // -----------------------------------------------------------------------
202 // stop logging
203 // -----------------------------------------------------------------------
Matteo Scandolod17de3a2021-04-09 15:47:52 -0700204 sh """
Hardik Windlassec9341b2021-06-07 11:58:29 +0000205 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-startup" | grep -v grep | awk '{print \$1}')"
206 if [ -n "\$P_IDS" ]; then
207 echo \$P_IDS
208 for P_ID in \$P_IDS; do
209 kill -9 \$P_ID
210 done
211 fi
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700212 cd ${logsDir}
Hardik Windlassec9341b2021-06-07 11:58:29 +0000213 gzip -k onos-voltha-startup-combined.log
214 rm onos-voltha-startup-combined.log
Matteo Scandolod17de3a2021-04-09 15:47:52 -0700215 """
Hardik Windlassec9341b2021-06-07 11:58:29 +0000216 }
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400217
218 sh """
Hardik Windlassec9341b2021-06-07 11:58:29 +0000219 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"&
220 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"&
221 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"&
222 bbsimDmiPortFwd=50075
223 for i in {0..${olts.toInteger() - 1}}; do
224 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"&
225 ((bbsimDmiPortFwd++))
226 done
Hardik Windlass3bb089a2022-03-22 17:56:03 +0000227 if [ ${withMonitoring} = true ] ; then
228 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"&
229 fi
Hardik Windlassec9341b2021-06-07 11:58:29 +0000230 ps aux | grep port-forward
231 """
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500232
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400233 // setting ONOS log level
234 script
Joey Armstrongb65ada32023-08-03 12:50:20 -0400235 {
236 println('** setOnosLogLevels: ENTER')
237 setOnosLogLevels([
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400238 onosNamespace: infraNamespace,
239 apps: [
240 'org.opencord.dhcpl2relay',
241 'org.opencord.olt',
242 'org.opencord.aaa',
243 'org.opencord.maclearner',
244 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
245 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
246 ],
247 logLevel: logLevel
248 ])
Joey Armstrongb65ada32023-08-03 12:50:20 -0400249 println('** setOnosLogLevels: LEAVE')
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400250 } // script
251 } // if (teardown)
252 } // stage('Deploy Voltha')
253
254 stage('Run test ' + testTarget + ' on ' + workflow + ' workFlow')
255 {
256 sh """
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000257 if [ ${withMonitoring} = true ] ; then
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500258 mkdir -p "$WORKSPACE/voltha-pods-mem-consumption-${workflow}"
259 cd "$WORKSPACE/voltha-system-tests"
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400260 make venv-activate-script
261 set +u && source .venv/bin/activate && set -u
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000262 # Collect initial memory consumption
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400263 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 +0000264 fi
Hardik Windlasse1660492022-03-14 15:12:46 +0000265 """
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400266
267 sh """
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700268 mkdir -p ${logsDir}
Hardik Windlassd62442d2021-11-30 10:51:20 +0000269 export ROBOT_MISC_ARGS="-d ${logsDir} ${params.extraRobotArgs} "
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700270 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 +0000271 export KVSTOREPREFIX=voltha/voltha_voltha
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800272
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400273 make -C "$WORKSPACE/voltha-system-tests" ${testTarget}
Hardik Windlass72947302021-06-14 10:36:57 +0000274 """
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400275
276 getPodsInfo("${logsDir}")
277
278 sh """
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400279 # set +e
Hardik Windlassdad8e5c2021-11-11 05:19:47 +0000280 # collect logs collected in the Robot Framework StartLogging keyword
281 cd ${logsDir}
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400282 gzip *-combined.log
283 rm -f *-combined.log
Hardik Windlassdad8e5c2021-11-11 05:19:47 +0000284 """
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400285
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000286 sh """
287 if [ ${withMonitoring} = true ] ; then
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500288 cd "$WORKSPACE/voltha-system-tests"
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400289 make venv-activate-script
290 set +u && source .venv/bin/activate && set -u
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000291 # Collect memory consumption of voltha pods once all the tests are complete
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400292 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 +0000293 fi
294 """
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400295 } // stage
Joey Armstrongb65ada32023-08-03 12:50:20 -0400296
297 return
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400298} // execute_test()
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800299
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400300// -----------------------------------------------------------------------
301// -----------------------------------------------------------------------
Joey Armstrongb65ada32023-08-03 12:50:20 -0400302def collectArtifacts(exitStatus) {
Joey Armstrong97a8b882023-08-02 16:08:52 -0400303 echo '''
304
305** -----------------------------------------------------------------------
306** collectArtifacts
307** -----------------------------------------------------------------------
308'''
309
Hardik Windlassec9341b2021-06-07 11:58:29 +0000310 getPodsInfo("$WORKSPACE/${exitStatus}")
Joey Armstrong97a8b882023-08-02 16:08:52 -0400311
Hardik Windlassec9341b2021-06-07 11:58:29 +0000312 sh """
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400313 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log
Hardik Windlassec9341b2021-06-07 11:58:29 +0000314 """
Joey Armstrong97a8b882023-08-02 16:08:52 -0400315
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000316 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 -0400317
Hardik Windlassec9341b2021-06-07 11:58:29 +0000318 sh '''
319 sync
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400320 [[ $(pgrep --count kail) -gt 0 ]] && pkill --echo kail
Hardik Windlassec9341b2021-06-07 11:58:29 +0000321 which voltctl
322 md5sum $(which voltctl)
323 '''
Joey Armstrong97a8b882023-08-02 16:08:52 -0400324
Hardik Windlassec9341b2021-06-07 11:58:29 +0000325 step([$class: 'RobotPublisher',
326 disableArchiveOutput: false,
Joey Armstrongb65ada32023-08-03 12:50:20 -0400327 logFileName: '**/*/log*.html',
Hardik Windlassec9341b2021-06-07 11:58:29 +0000328 otherFiles: '',
Joey Armstrongb65ada32023-08-03 12:50:20 -0400329 outputFileName: '**/*/output*.xml',
Hardik Windlassec9341b2021-06-07 11:58:29 +0000330 outputPath: '.',
331 passThreshold: 100,
Joey Armstrongb65ada32023-08-03 12:50:20 -0400332 reportFileName: '**/*/report*.html',
Andrea Campanellaabc09772021-06-16 12:08:57 +0200333 unstableThreshold: 0,
334 onlyCritical: true]);
Hardik Windlassec9341b2021-06-07 11:58:29 +0000335}
336
Joey Armstrongb65ada32023-08-03 12:50:20 -0400337// -----------------------------------------------------------------------
338// Intent: main
339// -----------------------------------------------------------------------
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800340pipeline {
341
342 /* no label, executor is determined by JJB */
343 agent {
344 label "${params.buildNode}"
345 }
346 options {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000347 timeout(time: "${timeout}", unit: 'MINUTES')
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800348 }
349 environment {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000350 KUBECONFIG="$HOME/.kube/kind-${clusterName}"
351 VOLTCONFIG="$HOME/.volt/config"
352 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
Joey Armstrongb65ada32023-08-03 12:50:20 -0400353 DIAGS_PROFILE='VOLTHA_PROFILE'
354 SSHPASS='karaf'
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800355 }
Hardik Windlassec9341b2021-06-07 11:58:29 +0000356 stages {
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800357 stage('Download Code') {
358 steps {
359 getVolthaCode([
360 branch: "${branch}",
361 gerritProject: "${gerritProject}",
362 gerritRefspec: "${gerritRefspec}",
363 volthaSystemTestsChange: "${volthaSystemTestsChange}",
364 volthaHelmChartsChange: "${volthaHelmChartsChange}",
365 ])
366 }
367 }
Joey Armstrong84adc542023-04-11 14:47:34 -0400368
369 stage('Build patch v1.1')
370 {
371 // build the patch only if gerritProject is specified
372 when
373 {
374 expression
375 {
376 return !gerritProject.isEmpty()
377 }
Hardik Windlassec9341b2021-06-07 11:58:29 +0000378 }
Joey Armstrong06a68372023-07-24 16:37:16 -0400379
Joey Armstrong97a8b882023-08-02 16:08:52 -0400380 steps
381 {
382 // NOTE that the correct patch has already been checked out
383 // during the getVolthaCode step
384 buildVolthaComponent("${gerritProject}")
Joey Armstrong06a68372023-07-24 16:37:16 -0400385 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800386 }
Joey Armstronged161f72023-04-11 13:16:59 -0400387
Joey Armstrong97a8b882023-08-02 16:08:52 -0400388 // -----------------------------------------------------------------------
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400389 // -----------------------------------------------------------------------
390 stage ('Install Kail')
391 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400392 steps
393 {
394 script
395 {
396 String cmd = [
397 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400398 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400399 '-C', "$WORKSPACE/voltha-system-tests",
400 "KAIL_PATH=\"$WORKSPACE/bin\"",
401 'kail',
402 ].join(' ')
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400403
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400404 println(" ** Running: ${cmd}:\n")
405 sh("${cmd}")
406 } // script
407 } // steps
408 } // stage
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400409
410 // -----------------------------------------------------------------------
Joey Armstrong97a8b882023-08-02 16:08:52 -0400411 // -----------------------------------------------------------------------
412 stage ('Install Kind')
413 {
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400414 steps
415 {
416 script
417 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400418
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400419 String cmd = [
420 'make',
Joey Armstrong9f184d32023-08-03 11:34:48 -0400421 '--no-print-directory',
Joey Armstrong2b2010d2023-08-02 21:47:20 -0400422 '-C', "$WORKSPACE/voltha-system-tests",
423 "KIND_PATH=\"$WORKSPACE/bin\"",
424 'install-command-kind',
425 ].join(' ')
426
427 println(" ** Running: ${cmd}:\n")
428 sh("${cmd}")
429 } // script
430 } // steps
431 } // stage
Joey Armstrong97a8b882023-08-02 16:08:52 -0400432
433 // -----------------------------------------------------------------------
434 // -----------------------------------------------------------------------
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400435 stage('Create K8s Cluster')
436 {
Joey Armstrongf076c312023-08-01 17:17:10 -0400437 steps
438 {
439 script
Joey Armstrong84adc542023-04-11 14:47:34 -0400440 {
Joey Armstrong97a8b882023-08-02 16:08:52 -0400441 def clusterExists = sh(
Joey Armstrongf076c312023-08-01 17:17:10 -0400442 returnStdout: true,
443 script: """kind get clusters | grep "${clusterName}" | wc -l""")
Joey Armstrongbf492922023-04-13 17:05:09 -0400444
Joey Armstrongb65ada32023-08-03 12:50:20 -0400445 if (clusterExists.trim() == '0')
Joey Armstrongf076c312023-08-01 17:17:10 -0400446 {
447 createKubernetesCluster([nodes: 3, name: clusterName])
448 }
449 } // script
450 } // steps
451 } // stage('Create K8s Cluster')
Joey Armstrong84adc542023-04-11 14:47:34 -0400452
Joey Armstrong97a8b882023-08-02 16:08:52 -0400453 // -----------------------------------------------------------------------
454 // -----------------------------------------------------------------------
455 stage('Replace voltctl')
456 {
457 // if the project is voltctl, override the downloaded one with the built one
458 when {
459 expression {
Joey Armstrongb65ada32023-08-03 12:50:20 -0400460 return gerritProject == 'voltctl'
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400461 }
Matteo Scandolo29597f02021-02-12 10:53:57 -0800462 }
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400463
Joey Armstrong97a8b882023-08-02 16:08:52 -0400464 // Hmmmm(?) where did the voltctl download happen ?
465 // Likely Makefile but would be helpful to document here.
466 steps
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400467 {
Joey Armstrong97a8b882023-08-02 16:08:52 -0400468 println("${iam} Running: installVoltctl($branch)")
469 installVoltctl("$branch")
470 } // steps
471 } // stage
472
473 // -----------------------------------------------------------------------
474 // -----------------------------------------------------------------------
475 stage('Load image in kind nodes')
476 {
477 when {
478 expression {
479 return !gerritProject.isEmpty()
480 }
481 }
482 steps {
483 loadToKind()
484 } // steps
485 } // stage
486
487 // -----------------------------------------------------------------------
488 // -----------------------------------------------------------------------
489 stage('Parse and execute tests')
490 {
Joey Armstrongb65ada32023-08-03 12:50:20 -0400491 steps {
492 script {
493 def tests = readYaml text: testTargets
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400494
Joey Armstrongb65ada32023-08-03 12:50:20 -0400495 for(int i = 0;i<tests.size();i++) {
496 def test = tests[i]
497 def target = test['target']
498 def workflow = test['workflow']
499 def flags = test['flags']
500 def teardown = test['teardown'].toBoolean()
501 def logging = test['logging'].toBoolean()
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400502 def testLogging = 'False'
503 if (logging) {
504 testLogging = 'True'
505 }
506 println "Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}"
507 execute_test(target, workflow, testLogging, teardown, flags)
Joey Armstrongb65ada32023-08-03 12:50:20 -0400508 } // for
509 } // script
510 } // steps
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400511 } // stage
512 } // stages
Joey Armstrong84adc542023-04-11 14:47:34 -0400513
514 post
515 {
516 aborted { collectArtifacts('aborted') }
517 failure { collectArtifacts('failed') }
Joey Armstrongbf492922023-04-13 17:05:09 -0400518 always { collectArtifacts('always') }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800519 }
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400520} // pipeline
Joey Armstronged161f72023-04-11 13:16:59 -0400521
522// EOF