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