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