blob: 79f648a1352fb82bc0732dcc664a4f2834714cce [file] [log] [blame]
Joey Armstrong7adbfb02023-01-24 17:02:37 -05001// 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
18library identifier: 'cord-jenkins-libraries@master',
19 retriever: modernSCM([
20 $class: 'GitSCMSource',
21 remote: 'https://gerrit.opencord.org/ci-management.git'
22])
23
24def clusterName = "kind-ci"
25
Joey Armstrong6146f7e2023-08-28 09:05:38 -040026// -----------------------------------------------------------------------
27// Intent:
28// -----------------------------------------------------------------------
29String branchName() {
30 String name = 'voltha-2.11'
31
32 // [TODO] Sanity check the target branch
33 // if (name != jenkins.branch) { fatal }
34 return(name)
35}
36
37// -----------------------------------------------------------------------
38// Intent: Difficult at times to determine when pipeline jobs have
39// regenerated. Hardcode a version string that can be assigned
40// per-script to be sure latest repository changes are being used.
41// -----------------------------------------------------------------------
42String pipelineVer() {
43 String version = '5addce3fac89095d103ac5c6eedff2bb02e9ec63'
44 return(version)
45}
46
47// -----------------------------------------------------------------------
48// Intent: Due to lack of a reliable stack trace, construct a literal.
49// Jenkins will re-write the call stack for serialization.S
50// -----------------------------------------------------------------------
51// Note: Hardcoded version string used to visualize changes in jenkins UI
52// -----------------------------------------------------------------------
53String getIam(String func) {
54 String branchName = branchName()
55 String version = pipelineVer()
56 String src = [
57 'ci-management',
58 'jjb',
59 'pipeline',
60 'voltha',
61 branchName,
62 'bbsim-tests.groovy'
63 ].join('/')
64
65 String name = [src, version, func].join('::')
66 return(name)
67}
68
Joey Armstrong0eb8bd82023-07-10 13:26:25 -040069def execute_test(testTarget, workflow, testLogging, teardown, testSpecificHelmFlags = "")
70{
Joey Armstrong7adbfb02023-01-24 17:02:37 -050071 def infraNamespace = "default"
72 def volthaNamespace = "voltha"
73 def logsDir = "$WORKSPACE/${testTarget}"
74
75 stage('IAM')
76 {
77 script
78 {
79 String iam = [
80 'ci-management',
81 'jjb',
82 'pipeline',
83 'voltha',
Joey Armstrong6baeaae2023-02-07 01:35:55 -050084 'voltha-2.11', // release-delta
Joey Armstrong7adbfb02023-01-24 17:02:37 -050085 'bbsim-tests.groovy'
86 ].join('/')
87 println("** ${iam}: ENTER")
88
89 String cmd = "which pkill"
90 def stream = sh(
91 returnStatus:false,
92 returnStdout: true,
93 script: cmd)
94 println(" ** ${cmd}:\n${stream}")
Joey Armstrong0eb8bd82023-07-10 13:26:25 -040095
Joey Armstrong7adbfb02023-01-24 17:02:37 -050096 println("** ${iam}: LEAVE")
97 }
98 }
99
100 stage('Cleanup') {
101 if (teardown) {
102 timeout(15) {
103 script {
104 helmTeardown(["default", infraNamespace, volthaNamespace])
105 }
106 timeout(1) {
107 sh returnStdout: false, script: '''
108 # remove orphaned port-forward from different namespaces
109 ps aux | grep port-forw | grep -v grep | awk '{print $2}' | xargs --no-run-if-empty kill -9 || true
110 '''
111 }
112 }
113 }
114 }
115
116 stage ('Initialize')
117 {
Joey Armstrong6146f7e2023-08-28 09:05:38 -0400118 steps
119 {
120 script
121 {
122 String iam = getIam('Initialize')
123 println("${iam}: ENTER")
124
125 // VOL-4926 - Is voltha-system-tests available ?
126 String cmd = [
127 'make',
128 '-C', "$WORKSPACE/voltha-system-tests",
129 "KAIL_PATH=\"$WORKSPACE/bin\"",
130 'kail',
131 ].join(' ')
132 println(" ** Running: ${cmd}:\n")
133 sh("${cmd}")
134
135 println("${iam}: LEAVE")
136 } // script
137 } // steps
138 } // stage
Joey Armstrong7adbfb02023-01-24 17:02:37 -0500139
140 stage('Deploy common infrastructure') {
141 sh '''
142 helm repo add onf https://charts.opencord.org
143 helm repo update
144 if [ ${withMonitoring} = true ] ; then
145 helm install nem-monitoring onf/nem-monitoring \
146 --set prometheus.alertmanager.enabled=false,prometheus.pushgateway.enabled=false \
147 --set kpi_exporter.enabled=false,dashboards.xos=false,dashboards.onos=false,dashboards.aaa=false,dashboards.voltha=false
148 fi
149 '''
150 }
151
152 stage('Deploy Voltha') {
153 if (teardown) {
154 timeout(10) {
155 script {
156
157 sh """
158 mkdir -p ${logsDir}
159 _TAG=kail-startup kail -n ${infraNamespace} -n ${volthaNamespace} > ${logsDir}/onos-voltha-startup-combined.log &
160 """
161
162 // if we're downloading a voltha-helm-charts patch, then install from a local copy of the charts
163 def localCharts = false
164 if (volthaHelmChartsChange != ""
165 || gerritProject == "voltha-helm-charts"
166 || branch != 'master'
167 ) {
168 localCharts = true
169 }
170
171 // NOTE temporary workaround expose ONOS node ports
172 def localHelmFlags = extraHelmFlags.trim() + " --set global.log_level=${logLevel.toUpperCase()} " +
173 " --set onos-classic.onosSshPort=30115 " +
174 " --set onos-classic.onosApiPort=30120 " +
175 " --set onos-classic.onosOfPort=31653 " +
176 " --set onos-classic.individualOpenFlowNodePorts=true " + testSpecificHelmFlags
177
178 if (gerritProject != "") {
179 localHelmFlags = "${localHelmFlags} " + getVolthaImageFlags("${gerritProject}")
180 }
181
182 volthaDeploy([
183 infraNamespace: infraNamespace,
184 volthaNamespace: volthaNamespace,
185 workflow: workflow.toLowerCase(),
186 withMacLearning: enableMacLearning.toBoolean(),
187 extraHelmFlags: localHelmFlags,
188 localCharts: localCharts,
189 bbsimReplica: olts.toInteger(),
190 dockerRegistry: registry,
191 ])
192 }
193
194 // stop logging
195 sh """
196 P_IDS="\$(ps e -ww -A | grep "_TAG=kail-startup" | grep -v grep | awk '{print \$1}')"
197 if [ -n "\$P_IDS" ]; then
198 echo \$P_IDS
199 for P_ID in \$P_IDS; do
200 kill -9 \$P_ID
201 done
202 fi
203 cd ${logsDir}
204 gzip -k onos-voltha-startup-combined.log
205 rm onos-voltha-startup-combined.log
206 """
207 }
208 sh """
209 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"&
210 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"&
211 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"&
212 bbsimDmiPortFwd=50075
213 for i in {0..${olts.toInteger() - 1}}; do
214 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"&
215 ((bbsimDmiPortFwd++))
216 done
217 if [ ${withMonitoring} = true ] ; then
218 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"&
219 fi
220 ps aux | grep port-forward
221 """
222 // setting ONOS log level
223 script {
224 setOnosLogLevels([
225 onosNamespace: infraNamespace,
226 apps: [
227 'org.opencord.dhcpl2relay',
228 'org.opencord.olt',
229 'org.opencord.aaa',
230 'org.opencord.maclearner',
231 'org.onosproject.net.flowobjective.impl.FlowObjectiveManager',
232 'org.onosproject.net.flowobjective.impl.InOrderFlowObjectiveManager'
233 ],
234 logLevel: logLevel
235 ])
236 }
237 }
238 }
239
240 stage('Run test ' + testTarget + ' on ' + workflow + ' workFlow') {
241 sh """
242 if [ ${withMonitoring} = true ] ; then
243 mkdir -p "$WORKSPACE/voltha-pods-mem-consumption-${workflow}"
244 cd "$WORKSPACE/voltha-system-tests"
245 make vst_venv
246 source ./vst_venv/bin/activate || true
247 # Collect initial memory consumption
248 python scripts/mem_consumption.py -o $WORKSPACE/voltha-pods-mem-consumption-${workflow} -a 0.0.0.0:31301 -n ${volthaNamespace} || true
249 fi
250 """
251 sh """
252 mkdir -p ${logsDir}
253 export ROBOT_MISC_ARGS="-d ${logsDir} ${params.extraRobotArgs} "
254 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}"
255 export KVSTOREPREFIX=voltha/voltha_voltha
256
257 make -C "$WORKSPACE/voltha-system-tests" ${testTarget} || true
258 """
259 getPodsInfo("${logsDir}")
260 sh """
261 set +e
262 # collect logs collected in the Robot Framework StartLogging keyword
263 cd ${logsDir}
264 gzip *-combined.log || true
265 rm *-combined.log || true
266 """
267 sh """
268 if [ ${withMonitoring} = true ] ; then
269 cd "$WORKSPACE/voltha-system-tests"
270 source ./vst_venv/bin/activate || true
271 # Collect memory consumption of voltha pods once all the tests are complete
272 python scripts/mem_consumption.py -o $WORKSPACE/voltha-pods-mem-consumption-${workflow} -a 0.0.0.0:31301 -n ${volthaNamespace} || true
273 fi
274 """
275 }
276}
277
278def collectArtifacts(exitStatus) {
279 getPodsInfo("$WORKSPACE/${exitStatus}")
280 sh """
281 kubectl logs -n voltha -l app.kubernetes.io/part-of=voltha > $WORKSPACE/${exitStatus}/voltha.log || true
282 """
283 archiveArtifacts artifacts: '**/*.log,**/*.gz,**/*.txt,**/*.html,**/voltha-pods-mem-consumption-att/*,**/voltha-pods-mem-consumption-dt/*,**/voltha-pods-mem-consumption-tt/*'
284 sh '''
285 sync
286 pkill kail || true
287 which voltctl
288 md5sum $(which voltctl)
289 '''
290 step([$class: 'RobotPublisher',
291 disableArchiveOutput: false,
292 logFileName: "**/*/log*.html",
293 otherFiles: '',
294 outputFileName: "**/*/output*.xml",
295 outputPath: '.',
296 passThreshold: 100,
297 reportFileName: "**/*/report*.html",
298 unstableThreshold: 0,
299 onlyCritical: true]);
300}
301
302pipeline {
303
304 /* no label, executor is determined by JJB */
305 agent {
306 label "${params.buildNode}"
307 }
308 options {
309 timeout(time: "${timeout}", unit: 'MINUTES')
310 }
311 environment {
312 KUBECONFIG="$HOME/.kube/kind-${clusterName}"
313 VOLTCONFIG="$HOME/.volt/config"
314 PATH="$PATH:$WORKSPACE/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
315 DIAGS_PROFILE="VOLTHA_PROFILE"
316 SSHPASS="karaf"
317 }
318
319 stages {
320 stage('Download Code') {
321 steps {
322 getVolthaCode([
323 branch: "${branch}",
324 gerritProject: "${gerritProject}",
325 gerritRefspec: "${gerritRefspec}",
326 volthaSystemTestsChange: "${volthaSystemTestsChange}",
327 volthaHelmChartsChange: "${volthaHelmChartsChange}",
328 ])
329 }
330 }
331
332 stage('Build patch') {
333 // build the patch only if gerritProject is specified
334 when {
335 expression {
336 return !gerritProject.isEmpty()
337 }
338 }
339 steps {
340 // NOTE that the correct patch has already been checked out
341 // during the getVolthaCode step
342 buildVolthaComponent("${gerritProject}")
343 }
344 }
345 stage('Create K8s Cluster') {
346 steps {
347 script {
348 def clusterExists = sh returnStdout: true, script: """
349 kind get clusters | grep ${clusterName} | wc -l
350 """
351 if (clusterExists.trim() == "0") {
352 createKubernetesCluster([nodes: 3, name: clusterName])
353 }
354 }
355 }
356 }
357 stage('Replace voltctl') {
358 // if the project is voltctl override the downloaded one with the built one
359 when {
360 expression {
361 return gerritProject == "voltctl"
362 }
363 }
364 steps{
365 sh """
366 # [TODO] - why is this platform specific (?)
Joey Armstrong93c82732023-02-07 03:01:25 -0500367 # [TODO] - revisit, command alteration has masked an error (see: voltha-2.11).
368 # find will fail when no filsystem matches are found.
369 # mv(ls) succeded simply by accident/invoked at a different time.
Joey Armstrong7adbfb02023-01-24 17:02:37 -0500370 # find "$WORKSPACE/voltctl/release" -name 'voltctl-*-linux-amd*' \
Joey Armstrong93c82732023-02-07 03:01:25 -0500371 # -exec mv {} $WORKSPACE/bin/voltctl ;
Joey Armstrong7adbfb02023-01-24 17:02:37 -0500372 mv `ls $WORKSPACE/voltctl/release/voltctl-*-linux-amd*` $WORKSPACE/bin/voltctl
373 chmod +x $WORKSPACE/bin/voltctl
374 """
375 }
376 }
377 stage('Load image in kind nodes') {
378 when {
379 expression {
380 return !gerritProject.isEmpty()
381 }
382 }
383 steps {
384 loadToKind()
385 }
386 }
387 stage('Parse and execute tests') {
388 steps {
389 script {
390 def tests = readYaml text: testTargets
391
392 for(int i = 0;i<tests.size();i++) {
393 def test = tests[i]
394 def target = test["target"]
395 def workflow = test["workflow"]
396 def flags = test["flags"]
397 def teardown = test["teardown"].toBoolean()
398 def logging = test["logging"].toBoolean()
399 def testLogging = 'False'
400 if (logging) {
401 testLogging = 'True'
402 }
403 println "Executing test ${target} on workflow ${workflow} with logging ${testLogging} and extra flags ${flags}"
404 execute_test(target, workflow, testLogging, teardown, flags)
405 }
406 }
407 }
408 }
409 }
410 post {
411 aborted {
412 collectArtifacts("aborted")
413 }
414 failure {
415 collectArtifacts("failed")
416 }
417 always {
418 collectArtifacts("always")
419 }
420 }
421}