blob: eeb2fff5beab682a634a2906088fb40f8bba92b8 [file] [log] [blame]
Joey Armstrong7bcb5782023-06-07 12:25:57 -04001// Copyright 2021-2023 Open Networking Foundation (ONF) and the ONF Contributors
2//
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
15// voltha-2.x e2e tests for openonu-go
16// uses bbsim to simulate OLT/ONUs
17
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040018// [TODO] Update syntax below to the latest supported
Joey Armstrong7bcb5782023-06-07 12:25:57 -040019library identifier: 'cord-jenkins-libraries@master',
20 retriever: modernSCM([
21 $class: 'GitSCMSource',
22 remote: 'https://gerrit.opencord.org/ci-management.git'
23])
24
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040025//------------------//
26//---] GLOBAL [---//
27//------------------//
28def clusterName = 'kind-ci'
Joey Armstrong7bcb5782023-06-07 12:25:57 -040029
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040030// -----------------------------------------------------------------------
31// Intent:
32// -----------------------------------------------------------------------
33String getBranchName() {
34 String name = 'voltha-2.12'
35
36 // [TODO] Sanity check the target branch
37 // if (name != jenkins.branch) { fatal }
38 return(name)
39}
40
41// -----------------------------------------------------------------------
42// Intent: Due to lack of a reliable stack trace, construct a literal.
43// Jenkins will re-write the call stack for serialization.
44// -----------------------------------------------------------------------
45String getIam(String func) {
46 String branch_name = getBranchName()
47 String src = [
48 'ci-management',
49 'jjb',
50 'pipeline',
51 'voltha',
52 branch_name,
53 'bbsim-tests.groovy'
54 ].join('/')
55
56 String name = [src, func].join('::')
57 return(name)
58}
59
60// -----------------------------------------------------------------------
61// 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']
67 // if branch_name in modifiers
68 return(name != 'master') // OR branch_name.contains('-')
69}
70
71// -----------------------------------------------------------------------
72// Intent:
73// -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -040074def execute_test(testTarget, workflow, testLogging, teardown, testSpecificHelmFlags = "")
75{
76 def infraNamespace = "default"
77 def volthaNamespace = "voltha"
78 def logsDir = "$WORKSPACE/${testTarget}"
79
80 stage('IAM')
81 {
82 script
83 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040084 // Announce ourselves for log usability
85 String iam = getIam('execute_test')
86 println("${iam}: ENTER")
87 println("${iam}: LEAVE")
Joey Armstrong7bcb5782023-06-07 12:25:57 -040088 }
89 }
Joey Armstrong0e0a42b2023-08-02 21:04:21 -040090
91 // -----------------------------------------------------------------------
92 // -----------------------------------------------------------------------
93 stage('Cleanup')
94 {
Joey Armstrong7bcb5782023-06-07 12:25:57 -040095 if (teardown) {
96 timeout(15) {
97 script {
98 helmTeardown(["default", infraNamespace, volthaNamespace])
99 }
100 timeout(1) {
101 sh returnStdout: false, script: '''
102 # remove orphaned port-forward from different namespaces
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400103 ps aux | grep port-forw | grep -v grep | awk '{print $2}' | xargs --no-run-if-empty kill -9
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400104 '''
105 }
106 }
107 }
108 }
109
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400110 // -----------------------------------------------------------------------
111 // -----------------------------------------------------------------------
112 stage('Deploy common infrastructure')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400113 {
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400114 sh '''
115 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 '''
123 }
124
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400125 stage('Deploy Voltha')
126 {
127 if (teardown)
128 {
129 timeout(10)
130 {
131 script
132 {
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400133 sh """
134 mkdir -p ${logsDir}
135 _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} > ${logsDir}/onos-voltha-startup-combined.log &
136 """
137
138 // if we're downloading a voltha-helm-charts patch, then install from a local copy of the charts
139 def localCharts = false
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400140
141 if (volthaHelmChartsChange != ""
142 || gerritProject == "voltha-helm-charts"
143 || isReleaseBranch(branch) // branch != 'master'
144 ) {
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400145 localCharts = true
146 }
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400147 String branch_name = getBranchName()
148 Boolean is_release = isReleaseBranch(branch)
149 println([
150 " ** localCharts=${localCharts}",
151 "branch_name=${branch_name}",
152 "branch=${branch}",
153 "branch=isReleaseBranch=${is_release}",
154 ].join(', '))
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400155
156 // NOTE temporary workaround expose ONOS node ports
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400157 def localHelmFlags = extraHelmFlags.trim()
158 + " --set global.log_level=${logLevel.toUpperCase()} "
159 + " --set onos-classic.onosSshPort=30115 "
160 + " --set onos-classic.onosApiPort=30120 "
161 + " --set onos-classic.onosOfPort=31653 "
162 + " --set onos-classic.individualOpenFlowNodePorts=true "
163 + testSpecificHelmFlags
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400164
165 if (gerritProject != "") {
166 localHelmFlags = "${localHelmFlags} " + getVolthaImageFlags("${gerritProject}")
167 }
168
169 volthaDeploy([
170 infraNamespace: infraNamespace,
171 volthaNamespace: volthaNamespace,
172 workflow: workflow.toLowerCase(),
173 withMacLearning: enableMacLearning.toBoolean(),
174 extraHelmFlags: localHelmFlags,
175 localCharts: localCharts,
176 bbsimReplica: olts.toInteger(),
177 dockerRegistry: registry,
178 ])
179 }
180
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400181 // -----------------------------------------------------------------------
182 // Intent: Replacing P_IDS with pgrep/pkill is a step forward.
183 // Why not simply use a pid file, capture _TAG=kail-startup above
184 // Grep runs the risk of terminating stray commands (??-good <=> bad-??)
185 // -----------------------------------------------------------------------
186 echo 'Try out pgrep/pkill commands'
187 def stream = sh(
188 returnStatus:false,
189 returnStdout:true,
190 script: '''pgrep --list-full kail-startup || true'''
191 )
192 println("** pgrep output: ${stream}")
193
194 // -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400195 // stop logging
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400196 // -----------------------------------------------------------------------
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400197 sh """
198 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-startup" | grep -v grep | awk '{print \$1}')"
199 if [ -n "\$P_IDS" ]; then
200 echo \$P_IDS
201 for P_ID in \$P_IDS; do
202 kill -9 \$P_ID
203 done
204 fi
205 cd ${logsDir}
206 gzip -k onos-voltha-startup-combined.log
207 rm onos-voltha-startup-combined.log
208 """
209 }
210
211 sh """
212 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"&
213 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"&
214 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"&
215 bbsimDmiPortFwd=50075
216 for i in {0..${olts.toInteger() - 1}}; do
217 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"&
218 ((bbsimDmiPortFwd++))
219 done
220 if [ ${withMonitoring} = true ] ; then
221 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"&
222 fi
223 ps aux | grep port-forward
224 """
225
226 // setting ONOS log level
227 script
228 {
229 setOnosLogLevels([
230 onosNamespace: infraNamespace,
231 apps: [
232 'org.opencord.dhcpl2relay',
233 'org.opencord.olt',
234 'org.opencord.aaa',
235 'org.opencord.maclearner',
236 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
237 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
238 ],
239 logLevel: logLevel
240 ])
241 } // script
242 } // if (teardown)
243 } // stage('Deploy Voltha')
244
245 stage('Run test ' + testTarget + ' on ' + workflow + ' workFlow')
246 {
247 sh """
248 if [ ${withMonitoring} = true ] ; then
249 mkdir -p "$WORKSPACE/voltha-pods-mem-consumption-${workflow}"
250 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400251 make venv-activate-script
252 set +u && source .venv/bin/activate && set -u
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400253 # Collect initial memory consumption
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400254 python scripts/mem_consumption.py -o $WORKSPACE/voltha-pods-mem-consumption-${workflow} -a 0.0.0.0:31301 -n ${volthaNamespace}
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400255 fi
256 """
257
258 sh """
259 mkdir -p ${logsDir}
260 export ROBOT_MISC_ARGS="-d ${logsDir} ${params.extraRobotArgs} "
261 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}"
262 export KVSTOREPREFIX=voltha/voltha_voltha
263
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400264 make -C "$WORKSPACE/voltha-system-tests" ${testTarget}
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400265 """
266
267 getPodsInfo("${logsDir}")
268
269 sh """
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400270 # set +e
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400271 # collect logs collected in the Robot Framework StartLogging keyword
272 cd ${logsDir}
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400273 gzip *-combined.log
274 rm -f *-combined.log
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400275 """
276
277 sh """
278 if [ ${withMonitoring} = true ] ; then
279 cd "$WORKSPACE/voltha-system-tests"
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400280 make venv-activate-script
281 set +u && source .venv/bin/activate && set -u
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400282 # Collect memory consumption of voltha pods once all the tests are complete
Joey Armstrong0eb8bd82023-07-10 13:26:25 -0400283 python scripts/mem_consumption.py -o $WORKSPACE/voltha-pods-mem-consumption-${workflow} -a 0.0.0.0:31301 -n ${volthaNamespace}
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400284 fi
285 """
286 } // stage
287} // execute_test()
288
289// -----------------------------------------------------------------------
290// -----------------------------------------------------------------------
291def collectArtifacts(exitStatus)
292{
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400293 echo '''
294
295** -----------------------------------------------------------------------
296** collectArtifacts
297** -----------------------------------------------------------------------
298'''
299
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400300 getPodsInfo("$WORKSPACE/${exitStatus}")
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400301
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400302 sh """
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400303 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400304 """
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400305
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400306 archiveArtifacts artifacts: '**/*.log,**/*.gz,**/*.txt,**/*.html,**/voltha-pods-mem-consumption-att/*,**/voltha-pods-mem-consumption-dt/*,**/voltha-pods-mem-consumption-tt/*'
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400307
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400308 sh '''
309 sync
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400310 [[ $(pgrep --count kail) -gt 0 ]] && pkill --echo kail
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400311 which voltctl
312 md5sum $(which voltctl)
313 '''
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400314
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400315 step([$class: 'RobotPublisher',
316 disableArchiveOutput: false,
317 logFileName: "**/*/log*.html",
318 otherFiles: '',
319 outputFileName: "**/*/output*.xml",
320 outputPath: '.',
321 passThreshold: 100,
322 reportFileName: "**/*/report*.html",
323 unstableThreshold: 0,
324 onlyCritical: true]);
325}
326
327pipeline {
328
329 /* no label, executor is determined by JJB */
330 agent {
331 label "${params.buildNode}"
332 }
333 options {
334 timeout(time: "${timeout}", unit: 'MINUTES')
335 }
336 environment {
337 KUBECONFIG="$HOME/.kube/kind-${clusterName}"
338 VOLTCONFIG="$HOME/.volt/config"
339 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
340 DIAGS_PROFILE="VOLTHA_PROFILE"
341 SSHPASS="karaf"
342 }
343 stages {
344 stage('Download Code') {
345 steps {
346 getVolthaCode([
347 branch: "${branch}",
348 gerritProject: "${gerritProject}",
349 gerritRefspec: "${gerritRefspec}",
350 volthaSystemTestsChange: "${volthaSystemTestsChange}",
351 volthaHelmChartsChange: "${volthaHelmChartsChange}",
352 ])
353 }
354 }
355
356 stage('Build patch v1.1')
357 {
358 // build the patch only if gerritProject is specified
359 when
360 {
361 expression
362 {
363 return !gerritProject.isEmpty()
364 }
365 }
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400366
367 steps
368 {
369 // NOTE that the correct patch has already been checked out
370 // during the getVolthaCode step
371 buildVolthaComponent("${gerritProject}")
372 }
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400373 }
374
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400375 // -----------------------------------------------------------------------
376 // -----------------------------------------------------------------------
377 stage ('Install Kail')
378 {
379 String cmd = [
380 'make',
381 '-C', "$WORKSPACE/voltha-system-tests",
382 "KAIL_PATH=\"$WORKSPACE/bin\"",
383 'kail',
384 ].join(' ')
385
386 println(" ** Running: ${cmd}:\n")
387 sh("${cmd}")
388 }
389
390 // -----------------------------------------------------------------------
391 // -----------------------------------------------------------------------
392 stage ('Install Kind')
393 {
394 String cmd = [
395 'make',
396 '-C', "$WORKSPACE/voltha-system-tests",
397 "KIND_PATH=\"$WORKSPACE/bin\"",
398 'install-command-kind',
399 ].join(' ')
400
401 println(" ** Running: ${cmd}:\n")
402 sh("${cmd}")
403 }
404
405 // -----------------------------------------------------------------------
406 // -----------------------------------------------------------------------
407 stage('Create K8s Cluster')
408 {
409 steps
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400410 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400411 script
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400412 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400413 def clusterExists = sh(
414 returnStdout: true,
415 script: """kind get clusters | grep "${clusterName}" | wc -l""")
416
417 if (clusterExists.trim() == "0")
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400418 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400419 createKubernetesCluster([nodes: 3, name: clusterName])
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400420 }
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400421 } // script
422 } // steps
423 } // stage('Create K8s Cluster')
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400424
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400425 // -----------------------------------------------------------------------
426 // -----------------------------------------------------------------------
427 stage('Replace voltctl')
428 {
429 // if the project is voltctl, override the downloaded one with the built one
430 when {
431 expression {
432 return gerritProject == "voltctl"
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400433 }
434 }
435
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400436 // Hmmmm(?) where did the voltctl download happen ?
437 // Likely Makefile but would be helpful to document here.
438 steps
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400439 {
Joey Armstrong0e0a42b2023-08-02 21:04:21 -0400440 println("${iam} Running: installVoltctl($branch)")
441 installVoltctl("$branch")
442 } // steps
443 } // stage
444
445 // -----------------------------------------------------------------------
446 // -----------------------------------------------------------------------
447 stage('Load image in kind nodes')
448 {
449 when {
450 expression {
451 return !gerritProject.isEmpty()
452 }
453 }
454 steps {
455 loadToKind()
456 } // steps
457 } // stage
458
459 // -----------------------------------------------------------------------
460 // -----------------------------------------------------------------------
461 stage('Parse and execute tests')
462 {
Joey Armstrong7bcb5782023-06-07 12:25:57 -0400463 steps {
464 script {
465 def tests = readYaml text: testTargets
466
467 for(int i = 0;i<tests.size();i++) {
468 def test = tests[i]
469 def target = test["target"]
470 def workflow = test["workflow"]
471 def flags = test["flags"]
472 def teardown = test["teardown"].toBoolean()
473 def logging = test["logging"].toBoolean()
474 def testLogging = 'False'
475 if (logging) {
476 testLogging = 'True'
477 }
478 println "Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}"
479 execute_test(target, workflow, testLogging, teardown, flags)
480 }
481 }
482 }
483 } // stage
484 } // stages
485
486 post
487 {
488 aborted { collectArtifacts('aborted') }
489 failure { collectArtifacts('failed') }
490 always { collectArtifacts('always') }
491 }
492} // pipeline
493
494// EOF