blob: 8ff8e6bf07f4ef6d87a9dc440bb6e8abd02ad575 [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 Armstrong97a8b882023-08-02 16:08:52 -040028def clusterName = 'kind-ci'
Joey Armstrongf076c312023-08-01 17:17:10 -040029
30// -----------------------------------------------------------------------
31// -----------------------------------------------------------------------
32String getBranchName() {
33 String name = 'master'
34 return(name)
35}
Hardik Windlassec9341b2021-06-07 11:58:29 +000036
Joey Armstronge5aae1c2023-07-24 14:11:20 -040037// -----------------------------------------------------------------------
Joey Armstrong06a68372023-07-24 16:37:16 -040038// Intent: Due to lack of a reliable stack trace, construct a literal.
39// Jenkins will re-write the call stack for serialization.
40// -----------------------------------------------------------------------
Joey Armstrong97a8b882023-08-02 16:08:52 -040041String getIam(String func) {
Joey Armstrongf076c312023-08-01 17:17:10 -040042 String branch_name = getBranchName()
Joey Armstrong06a68372023-07-24 16:37:16 -040043 String src = [
44 'ci-management',
45 'jjb',
46 'pipeline',
47 'voltha',
Joey Armstrong97a8b882023-08-02 16:08:52 -040048 branch_name,
Joey Armstrong06a68372023-07-24 16:37:16 -040049 'bbsim-tests.groovy'
50 ].join('/')
51
52 String iam = [src, func].join('::')
53 return iam
54}
55
56// -----------------------------------------------------------------------
Joey Armstronge5aae1c2023-07-24 14:11:20 -040057// Intent: Determine if working on a release branch.
58// Note: Conditional is legacy, should also check for *-dev or *-pre
59// -----------------------------------------------------------------------
60Boolean isReleaseBranch(String name)
61{
62 // List modifiers = ['-dev', '-pre', 'voltha-x.y.z-pre']
63 // if branch_name in modifiers
64 return(name != 'master') // OR branch_name.contains('-')
65}
66
67// -----------------------------------------------------------------------
Joey Armstrong06a68372023-07-24 16:37:16 -040068// Intent: Phase helper method
69// -----------------------------------------------------------------------
Joey Armstrong46bfeea2023-07-31 10:39:25 -040070// NOTE: installKind temporarily disabled:
71// o error makes little sense, install.Kind.{groovy,sh} exist in vars/
72// o jenkins shared library -- checked out on server disk is stale
73// 2 changesets behind current ?!?!
74// o Disable call for now to revive the pipeline.
75// 10:26:05 org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
76// 10:26:05 WorkflowScript: 73: unexpected token: installKind @ line 73, column 2.
77// 10:26:05 installKind(name)
78// 10:26:05 ^
79// -----------------------------------------------------------------------
Joey Armstrong53cebea2023-07-26 10:35:53 -040080Boolean install_kind(String name)
Joey Armstrong06a68372023-07-24 16:37:16 -040081{
82 String iam = getIam('installKind')
83 Boolean ans = False
84
85 println("** ${iam}: ENTER")
86 try
87 {
Joey Armstrong97a8b882023-08-02 16:08:52 -040088 println("** ${iam} Running installKind(name): ENTER")
89 installKind(name)
90 println("** ${iam} Running installKind(name): LEAVE")
91 ans = True // iff
Joey Armstrong06a68372023-07-24 16:37:16 -040092 }
93 catch (Exception err)
94 {
Joey Armstrong97a8b882023-08-02 16:08:52 -040095 ans = False
96 println("** ${iam}: EXCEPTION ${err}")
97 throw err
Joey Armstrong06a68372023-07-24 16:37:16 -040098 }
99 finally
100 {
Joey Armstrong97a8b882023-08-02 16:08:52 -0400101 println("** ${iam}: ENTER")
Joey Armstrong06a68372023-07-24 16:37:16 -0400102 }
Joey Armstrong53cebea2023-07-26 10:35:53 -0400103
Joey Armstrong06a68372023-07-24 16:37:16 -0400104 return(ans)
105}
106
107// -----------------------------------------------------------------------
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400108// Intent:
109// -----------------------------------------------------------------------
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400110def execute_test(testTarget, workflow, testLogging, teardown, testSpecificHelmFlags = "")
111{
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500112 def infraNamespace = "default"
113 def volthaNamespace = "voltha"
114 def logsDir = "$WORKSPACE/${testTarget}"
Joey Armstrong293e16b2022-11-26 20:16:33 -0500115
116 stage('IAM')
117 {
Joey Armstrong84adc542023-04-11 14:47:34 -0400118 script
119 {
Joey Armstrong97a8b882023-08-02 16:08:52 -0400120 // Announce ourselves for log usability
121 String iam = getIam('execute_test')
122 println("${iam}: ENTER")
123 println("${iam}: LEAVE")
Joey Armstrong84adc542023-04-11 14:47:34 -0400124 }
Joey Armstrong293e16b2022-11-26 20:16:33 -0500125 }
Joey Armstrongf076c312023-08-01 17:17:10 -0400126
127 stage('Cleanup')
128 {
Joey Armstrong84adc542023-04-11 14:47:34 -0400129 if (teardown) {
130 timeout(15) {
131 script {
132 helmTeardown(["default", infraNamespace, volthaNamespace])
133 }
134 timeout(1) {
135 sh returnStdout: false, script: '''
Hardik Windlassec9341b2021-06-07 11:58:29 +0000136 # remove orphaned port-forward from different namespaces
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400137 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 +0000138 '''
Joey Armstrong84adc542023-04-11 14:47:34 -0400139 }
140 }
141 }
Hardik Windlassec9341b2021-06-07 11:58:29 +0000142 }
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500143
Joey Armstrong53cebea2023-07-26 10:35:53 -0400144 stage ('Install Kail')
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500145 {
Joey Armstrong84adc542023-04-11 14:47:34 -0400146 // VOL-4926 - Is voltha-system-tests available ?
147 String cmd = [
148 'make',
149 '-C', "$WORKSPACE/voltha-system-tests",
150 "KAIL_PATH=\"$WORKSPACE/bin\"",
151 'kail',
152 ].join(' ')
153 println(" ** Running: ${cmd}:\n")
Joey Armstrongbeef4cd2023-01-18 09:59:58 -0500154 sh("${cmd}")
Joey Armstrong53cebea2023-07-26 10:35:53 -0400155 // if (! my_install_kail())
Joey Armstrong97a8b882023-08-02 16:08:52 -0400156 // throw new Exception('installKail() failed')
Joey Armstrong53cebea2023-07-26 10:35:53 -0400157 }
Joey Armstrong06a68372023-07-24 16:37:16 -0400158
Joey Armstrong06a68372023-07-24 16:37:16 -0400159 stage('Deploy common infrastructure')
160 {
Joey Armstrong84adc542023-04-11 14:47:34 -0400161 sh '''
Hardik Windlasse1660492022-03-14 15:12:46 +0000162 helm repo add onf https://charts.opencord.org
163 helm repo update
164 if [ ${withMonitoring} = true ] ; then
165 helm install nem-monitoring onf/nem-monitoring \
166 --set prometheus.alertmanager.enabled=false,prometheus.pushgateway.enabled=false \
167 --set kpi_exporter.enabled=false,dashboards.xos=false,dashboards.onos=false,dashboards.aaa=false,dashboards.voltha=false
168 fi
169 '''
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500170 }
171
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400172 stage('Deploy Voltha')
173 {
Joey Armstrong97a8b882023-08-02 16:08:52 -0400174 if (teardown)
175 {
176 timeout(10)
177 {
178 script
179 {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000180 sh """
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700181 mkdir -p ${logsDir}
182 _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} > ${logsDir}/onos-voltha-startup-combined.log &
Hardik Windlassec9341b2021-06-07 11:58:29 +0000183 """
184
185 // if we're downloading a voltha-helm-charts patch, then install from a local copy of the charts
186 def localCharts = false
Joey Armstrong53cebea2023-07-26 10:35:53 -0400187
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400188 if (volthaHelmChartsChange != ""
Joey Armstrong97a8b882023-08-02 16:08:52 -0400189 || gerritProject == "voltha-helm-charts"
190 || isReleaseBranch(branch) // branch != 'master'
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400191 ) {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000192 localCharts = true
193 }
Joey Armstrong97a8b882023-08-02 16:08:52 -0400194 String branch_name = getBranchName()
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400195 Boolean is_release = isReleaseBranch(branch)
Joey Armstrong97a8b882023-08-02 16:08:52 -0400196 println([
197 " ** localCharts=${localCharts}",
198 "branch_name=${branch_name}",
199 "branch=${branch}",
200 "branch=isReleaseBranch=${is_release}",
201 ].join(', '))
Hardik Windlassec9341b2021-06-07 11:58:29 +0000202
203 // NOTE temporary workaround expose ONOS node ports
Joey Armstrong97a8b882023-08-02 16:08:52 -0400204 def localHelmFlags = extraHelmFlags.trim()
205 + " --set global.log_level=${logLevel.toUpperCase()} "
206 + " --set onos-classic.onosSshPort=30115 "
207 + " --set onos-classic.onosApiPort=30120 "
208 + " --set onos-classic.onosOfPort=31653 "
209 + " --set onos-classic.individualOpenFlowNodePorts=true "
210 + testSpecificHelmFlags
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800211
Hardik Windlassec9341b2021-06-07 11:58:29 +0000212 if (gerritProject != "") {
213 localHelmFlags = "${localHelmFlags} " + getVolthaImageFlags("${gerritProject}")
214 }
215
216 volthaDeploy([
217 infraNamespace: infraNamespace,
218 volthaNamespace: volthaNamespace,
219 workflow: workflow.toLowerCase(),
Hardik Windlass2b164342022-02-28 03:50:48 +0000220 withMacLearning: enableMacLearning.toBoolean(),
Hardik Windlassec9341b2021-06-07 11:58:29 +0000221 extraHelmFlags: localHelmFlags,
222 localCharts: localCharts,
223 bbsimReplica: olts.toInteger(),
224 dockerRegistry: registry,
225 ])
Matteo Scandolod17de3a2021-04-09 15:47:52 -0700226 }
Matteo Scandolofcfc60d2021-02-24 09:06:48 -0800227
Joey Armstrong97a8b882023-08-02 16:08:52 -0400228 // -----------------------------------------------------------------------
229 // Intent: Replacing P_IDS with pgrep/pkill is a step forward.
230 // Why not simply use a pid file, capture _TAG=kail-startup above
231 // Grep runs the risk of terminating stray commands (??-good <=> bad-??)
232 // -----------------------------------------------------------------------
233 echo 'Try out pgrep/pkill commands'
234 def stream = sh(
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400235 returnStatus:false,
236 returnStdout:true,
Joey Armstrong97a8b882023-08-02 16:08:52 -0400237 script: '''pgrep --list-full kail-startup || true'''
238 )
239 println("** pgrep output: ${stream}")
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400240
Joey Armstrong97a8b882023-08-02 16:08:52 -0400241 // -----------------------------------------------------------------------
242 // stop logging
243 // -----------------------------------------------------------------------
Matteo Scandolod17de3a2021-04-09 15:47:52 -0700244 sh """
Hardik Windlassec9341b2021-06-07 11:58:29 +0000245 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-startup" | grep -v grep | awk '{print \$1}')"
246 if [ -n "\$P_IDS" ]; then
247 echo \$P_IDS
248 for P_ID in \$P_IDS; do
249 kill -9 \$P_ID
250 done
251 fi
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700252 cd ${logsDir}
Hardik Windlassec9341b2021-06-07 11:58:29 +0000253 gzip -k onos-voltha-startup-combined.log
254 rm onos-voltha-startup-combined.log
Matteo Scandolod17de3a2021-04-09 15:47:52 -0700255 """
Hardik Windlassec9341b2021-06-07 11:58:29 +0000256 }
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400257
258 sh """
Hardik Windlassec9341b2021-06-07 11:58:29 +0000259 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"&
260 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"&
261 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"&
262 bbsimDmiPortFwd=50075
263 for i in {0..${olts.toInteger() - 1}}; do
264 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"&
265 ((bbsimDmiPortFwd++))
266 done
Hardik Windlass3bb089a2022-03-22 17:56:03 +0000267 if [ ${withMonitoring} = true ] ; then
268 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"&
269 fi
Hardik Windlassec9341b2021-06-07 11:58:29 +0000270 ps aux | grep port-forward
271 """
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500272
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400273 // setting ONOS log level
274 script
275 {
276 setOnosLogLevels([
277 onosNamespace: infraNamespace,
278 apps: [
279 'org.opencord.dhcpl2relay',
280 'org.opencord.olt',
281 'org.opencord.aaa',
282 'org.opencord.maclearner',
283 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
284 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
285 ],
286 logLevel: logLevel
287 ])
288 } // script
289 } // if (teardown)
290 } // stage('Deploy Voltha')
291
292 stage('Run test ' + testTarget + ' on ' + workflow + ' workFlow')
293 {
294 sh """
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000295 if [ ${withMonitoring} = true ] ; then
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500296 mkdir -p "$WORKSPACE/voltha-pods-mem-consumption-${workflow}"
297 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 initial memory consumption
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
Hardik Windlasse1660492022-03-14 15:12:46 +0000303 """
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400304
305 sh """
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700306 mkdir -p ${logsDir}
Hardik Windlassd62442d2021-11-30 10:51:20 +0000307 export ROBOT_MISC_ARGS="-d ${logsDir} ${params.extraRobotArgs} "
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700308 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 +0000309 export KVSTOREPREFIX=voltha/voltha_voltha
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800310
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400311 make -C "$WORKSPACE/voltha-system-tests" ${testTarget}
Hardik Windlass72947302021-06-14 10:36:57 +0000312 """
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400313
314 getPodsInfo("${logsDir}")
315
316 sh """
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400317 # set +e
Hardik Windlassdad8e5c2021-11-11 05:19:47 +0000318 # collect logs collected in the Robot Framework StartLogging keyword
319 cd ${logsDir}
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400320 gzip *-combined.log
321 rm -f *-combined.log
Hardik Windlassdad8e5c2021-11-11 05:19:47 +0000322 """
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400323
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000324 sh """
325 if [ ${withMonitoring} = true ] ; then
Joey Armstrong8c6f6482023-01-12 12:31:44 -0500326 cd "$WORKSPACE/voltha-system-tests"
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400327 make venv-activate-script
328 set +u && source .venv/bin/activate && set -u
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000329 # Collect memory consumption of voltha pods once all the tests are complete
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400330 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 +0000331 fi
332 """
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400333 } // stage
334} // execute_test()
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800335
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400336// -----------------------------------------------------------------------
337// -----------------------------------------------------------------------
338def collectArtifacts(exitStatus)
339{
Joey Armstrong97a8b882023-08-02 16:08:52 -0400340 echo '''
341
342** -----------------------------------------------------------------------
343** collectArtifacts
344** -----------------------------------------------------------------------
345'''
346
Hardik Windlassec9341b2021-06-07 11:58:29 +0000347 getPodsInfo("$WORKSPACE/${exitStatus}")
Joey Armstrong97a8b882023-08-02 16:08:52 -0400348
Hardik Windlassec9341b2021-06-07 11:58:29 +0000349 sh """
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400350 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log
Hardik Windlassec9341b2021-06-07 11:58:29 +0000351 """
Joey Armstrong97a8b882023-08-02 16:08:52 -0400352
Hardik Windlass8cd517c2022-03-22 04:01:40 +0000353 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 -0400354
Hardik Windlassec9341b2021-06-07 11:58:29 +0000355 sh '''
356 sync
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400357 [[ $(pgrep --count kail) -gt 0 ]] && pkill --echo kail
Hardik Windlassec9341b2021-06-07 11:58:29 +0000358 which voltctl
359 md5sum $(which voltctl)
360 '''
Joey Armstrong97a8b882023-08-02 16:08:52 -0400361
Hardik Windlassec9341b2021-06-07 11:58:29 +0000362 step([$class: 'RobotPublisher',
363 disableArchiveOutput: false,
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700364 logFileName: "**/*/log*.html",
Hardik Windlassec9341b2021-06-07 11:58:29 +0000365 otherFiles: '',
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700366 outputFileName: "**/*/output*.xml",
Hardik Windlassec9341b2021-06-07 11:58:29 +0000367 outputPath: '.',
368 passThreshold: 100,
Matteo Scandolo9c230bb2021-10-22 12:48:39 -0700369 reportFileName: "**/*/report*.html",
Andrea Campanellaabc09772021-06-16 12:08:57 +0200370 unstableThreshold: 0,
371 onlyCritical: true]);
Hardik Windlassec9341b2021-06-07 11:58:29 +0000372}
373
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800374pipeline {
375
376 /* no label, executor is determined by JJB */
377 agent {
378 label "${params.buildNode}"
379 }
380 options {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000381 timeout(time: "${timeout}", unit: 'MINUTES')
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800382 }
383 environment {
Hardik Windlassec9341b2021-06-07 11:58:29 +0000384 KUBECONFIG="$HOME/.kube/kind-${clusterName}"
385 VOLTCONFIG="$HOME/.volt/config"
386 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
Hardik Windlassec9341b2021-06-07 11:58:29 +0000387 DIAGS_PROFILE="VOLTHA_PROFILE"
Matteo Scandolo35ac7822021-10-28 18:08:54 -0700388 SSHPASS="karaf"
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800389 }
Hardik Windlassec9341b2021-06-07 11:58:29 +0000390 stages {
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800391 stage('Download Code') {
392 steps {
393 getVolthaCode([
394 branch: "${branch}",
395 gerritProject: "${gerritProject}",
396 gerritRefspec: "${gerritRefspec}",
397 volthaSystemTestsChange: "${volthaSystemTestsChange}",
398 volthaHelmChartsChange: "${volthaHelmChartsChange}",
399 ])
400 }
401 }
Joey Armstrong84adc542023-04-11 14:47:34 -0400402
403 stage('Build patch v1.1')
404 {
405 // build the patch only if gerritProject is specified
406 when
407 {
408 expression
409 {
410 return !gerritProject.isEmpty()
411 }
Hardik Windlassec9341b2021-06-07 11:58:29 +0000412 }
Joey Armstrong06a68372023-07-24 16:37:16 -0400413
Joey Armstrong97a8b882023-08-02 16:08:52 -0400414 steps
415 {
416 // NOTE that the correct patch has already been checked out
417 // during the getVolthaCode step
418 buildVolthaComponent("${gerritProject}")
Joey Armstrong06a68372023-07-24 16:37:16 -0400419 }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800420 }
Joey Armstronged161f72023-04-11 13:16:59 -0400421
Joey Armstrong97a8b882023-08-02 16:08:52 -0400422 // -----------------------------------------------------------------------
423 // Intent: Install early so stage('Create K8s Cluster') will not
424 // fail on bogus "script.sh: line 1: kind: command not found".
425 // -----------------------------------------------------------------------
426 stage ('Install Kind')
427 {
428 steps
429 {
430 script
431 {
432 String branch_name = getBranchName()
433 install_kind(branch_name)
434 } // script
435 } // steps
436 } // stage
437
438 // -----------------------------------------------------------------------
439 // -----------------------------------------------------------------------
Joey Armstronge5aae1c2023-07-24 14:11:20 -0400440 stage('Create K8s Cluster')
441 {
Joey Armstrongf076c312023-08-01 17:17:10 -0400442 steps
443 {
444 script
Joey Armstrong84adc542023-04-11 14:47:34 -0400445 {
Joey Armstrong97a8b882023-08-02 16:08:52 -0400446 def clusterExists = sh(
Joey Armstrongf076c312023-08-01 17:17:10 -0400447 returnStdout: true,
448 script: """kind get clusters | grep "${clusterName}" | wc -l""")
Joey Armstrongbf492922023-04-13 17:05:09 -0400449
Joey Armstrongf076c312023-08-01 17:17:10 -0400450 if (clusterExists.trim() == "0")
451 {
452 createKubernetesCluster([nodes: 3, name: clusterName])
453 }
454 } // script
455 } // steps
456 } // stage('Create K8s Cluster')
Joey Armstrong84adc542023-04-11 14:47:34 -0400457
Joey Armstrong97a8b882023-08-02 16:08:52 -0400458 // -----------------------------------------------------------------------
459 // -----------------------------------------------------------------------
460 stage('Replace voltctl')
461 {
462 // if the project is voltctl, override the downloaded one with the built one
463 when {
464 expression {
465 return gerritProject == "voltctl"
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400466 }
Matteo Scandolo29597f02021-02-12 10:53:57 -0800467 }
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400468
Joey Armstrong97a8b882023-08-02 16:08:52 -0400469 // Hmmmm(?) where did the voltctl download happen ?
470 // Likely Makefile but would be helpful to document here.
471 steps
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400472 {
Joey Armstrong97a8b882023-08-02 16:08:52 -0400473 println("${iam} Running: installVoltctl($branch)")
474 installVoltctl("$branch")
475 } // steps
476 } // stage
477
478 // -----------------------------------------------------------------------
479 // -----------------------------------------------------------------------
480 stage('Load image in kind nodes')
481 {
482 when {
483 expression {
484 return !gerritProject.isEmpty()
485 }
486 }
487 steps {
488 loadToKind()
489 } // steps
490 } // stage
491
492 // -----------------------------------------------------------------------
493 // -----------------------------------------------------------------------
494 stage('Parse and execute tests')
495 {
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400496 steps {
497 script {
498 def tests = readYaml text: testTargets
499
500 for(int i = 0;i<tests.size();i++) {
501 def test = tests[i]
502 def target = test["target"]
503 def workflow = test["workflow"]
504 def flags = test["flags"]
505 def teardown = test["teardown"].toBoolean()
506 def logging = test["logging"].toBoolean()
507 def testLogging = 'False'
508 if (logging) {
509 testLogging = 'True'
510 }
511 println "Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}"
512 execute_test(target, workflow, testLogging, teardown, flags)
513 }
514 }
515 }
516 } // stage
517 } // stages
Joey Armstrong84adc542023-04-11 14:47:34 -0400518
519 post
520 {
521 aborted { collectArtifacts('aborted') }
522 failure { collectArtifacts('failed') }
Joey Armstrongbf492922023-04-13 17:05:09 -0400523 always { collectArtifacts('always') }
Matteo Scandolo42f6e572021-01-25 15:11:34 -0800524 }
Joey Armstrong2d5a7c12023-04-13 09:37:42 -0400525} // pipeline
Joey Armstronged161f72023-04-11 13:16:59 -0400526
527// EOF