blob: 2ac34bf3f3993d50f01c6e3645295f2e4b5bc165 [file] [log] [blame]
Andy Bavierd83bf3a2020-08-13 14:55:07 -07001// Copyright 2019-present Open Networking Foundation
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// deploy VOLTHA built from patchset on a physical pod and run e2e test
16// uses kind-voltha to deploy voltha-2.X
17
18// Need this so that deployment_config has global scope when it's read later
19deployment_config = null
20localDeploymentConfigFile = null
21localKindVolthaValuesFile = null
22localSadisConfigFile = null
23
24// The pipeline assumes these variables are always defined
25if ( params.manualBranch != "" ) {
26 GERRIT_EVENT_COMMENT_TEXT = ""
27 GERRIT_PROJECT = ""
28 GERRIT_BRANCH = "${params.manualBranch}"
29 GERRIT_CHANGE_NUMBER = ""
30 GERRIT_PATCHSET_NUMBER = ""
31}
32
33pipeline {
34
35 /* no label, executor is determined by JJB */
36 agent {
37 label "${params.buildNode}"
38 }
39 options {
40 timeout(time: 120, unit: 'MINUTES')
41 }
42
43 environment {
44 KUBECONFIG="$HOME/.kube/kind-config-voltha-minimal"
45 VOLTCONFIG="$HOME/.volt/config-minimal"
46 PATH="$WORKSPACE/voltha/kind-voltha/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
Matteo Scandolo4d1a12f2020-12-07 16:17:12 -080047 NAME="minimal"
Andy Bavierd83bf3a2020-08-13 14:55:07 -070048 FANCY=0
49 //VOL-2194 ONOS SSH and REST ports hardcoded to 30115/30120 in tests
50 ONOS_SSH_PORT=30115
51 ONOS_API_PORT=30120
52 }
53
54 stages {
55 stage ('Initialize') {
56 steps {
57 sh returnStdout: false, script: """
Andrea Campanella57735a82021-05-18 13:22:49 +020058 if [ "${branch}" != "master" ]; then
59 echo "on branch: ${branch}, sourcing kind-voltha/releases/${branch}"
60 source "$WORKSPACE/kind-voltha/releases/${branch}"
61 else
62 echo "on master, using default settings for kind-voltha"
63 fi
Andy Bavierd83bf3a2020-08-13 14:55:07 -070064 test -e $WORKSPACE/voltha/kind-voltha/voltha && cd $WORKSPACE/voltha/kind-voltha && ./voltha down
65 cd $WORKSPACE
66 rm -rf $WORKSPACE/*
67 """
68 script {
69 if (env.configRepo && ! env.localConfigDir) {
70 env.localConfigDir = "$WORKSPACE"
71 sh returnStdout: false, script: "git clone -b master ${cordRepoUrl}/${configRepo}"
72 }
73 localDeploymentConfigFile = "${env.localConfigDir}/${params.deploymentConfigFile}"
74 localKindVolthaValuesFile = "${env.localConfigDir}/${params.kindVolthaValuesFile}"
75 localSadisConfigFile = "${env.localConfigDir}/${params.sadisConfigFile}"
76 }
77 }
78 }
79
80 stage('Repo') {
81 steps {
82 checkout(changelog: true,
83 poll: false,
84 scm: [$class: 'RepoScm',
85 manifestRepositoryUrl: "${params.manifestUrl}",
86 manifestBranch: "${params.branch}",
87 currentBranch: true,
88 destinationDir: 'voltha',
89 forceSync: true,
90 resetFirst: true,
91 quiet: true,
92 jobs: 4,
93 showAllChanges: true]
94 )
95 }
96 }
97
98 stage('Get Patch') {
99 when {
100 expression { params.manualBranch == "" }
101 }
102 steps {
103 sh returnStdout: false, script: """
104 cd voltha
105 repo download "${gerritProject}" "${gerritChangeNumber}/${gerritPatchsetNumber}"
106 """
107 }
108 }
109
110 stage('Check config files') {
111 steps {
112 script {
113 try {
114 deployment_config = readYaml file: "${localDeploymentConfigFile}"
115 } catch (err) {
116 echo "Error reading ${localDeploymentConfigFile}"
117 throw err
118 }
119 sh returnStdout: false, script: """
120 if [ ! -e ${localKindVolthaValuesFile} ]; then echo "${localKindVolthaValuesFile} not found"; exit 1; fi
121 if [ ! -e ${localSadisConfigFile} ]; then echo "${localSadisConfigFile} not found"; exit 1; fi
122 """
123 }
124 }
125 }
126
127 stage('Create KinD Cluster') {
128 steps {
129 sh returnStdout: false, script: """
130 if [ "${branch}" != "master" ]; then
131 echo "on branch: ${branch}, sourcing kind-voltha/releases/${branch}"
132 source "$WORKSPACE/voltha/kind-voltha/releases/${branch}"
133 else
134 echo "on master, using default settings for kind-voltha"
135 fi
136
137 cd $WORKSPACE/voltha/kind-voltha/
138 JUST_K8S=y ./voltha up
139 """
140 }
141 }
142
143 stage('Build and Push Images') {
144 when {
145 expression { params.manualBranch == "" }
146 }
147 steps {
148 sh returnStdout: false, script: """
149
150 if [ "${branch}" != "master" ]; then
151 echo "on branch: ${branch}, sourcing kind-voltha/releases/${branch}"
152 source "$WORKSPACE/voltha/kind-voltha/releases/${branch}"
153 else
154 echo "on master, using default settings for kind-voltha"
155 fi
156
157 if ! [[ "${gerritProject}" =~ ^(voltha-system-tests|kind-voltha|voltha-helm-charts)\$ ]]; then
158 make -C $WORKSPACE/voltha/${gerritProject} DOCKER_REPOSITORY=voltha/ DOCKER_TAG=citest docker-build
159 docker images | grep citest
160 for image in \$(docker images -f "reference=*/*citest" --format "{{.Repository}}")
161 do
162 echo "Pushing \$image to nodes"
Matteo Scandolo6fede0e2020-12-09 17:19:09 -0800163 kind load docker-image \$image:citest --name voltha-\$NAME --nodes voltha-\$NAME-worker,voltha-\$NAME-worker2
Andy Bavierd83bf3a2020-08-13 14:55:07 -0700164 docker rmi \$image:citest \$image:latest || true
165 done
166 fi
167 """
168 }
169 }
170
171 stage('Deploy Voltha') {
172 environment {
173 WITH_RADIUS="no"
174 WITH_EAPOL="no"
175 WITH_DHCP="no"
176 WITH_IGMP="no"
177 CONFIG_SADIS="no"
178 WITH_SIM_ADAPTERS="no"
179 DEPLOY_K8S="no"
180 VOLTHA_LOG_LEVEL="DEBUG"
181 }
182 steps {
183 script {
184 sh returnStdout: false, script: """
185 if [ "${branch}" != "master" ]; then
186 echo "on branch: ${branch}, sourcing kind-voltha/releases/${branch}"
187 source "$WORKSPACE/voltha/kind-voltha/releases/${branch}"
188 else
189 echo "on master, using default settings for kind-voltha"
190 fi
191
192 export EXTRA_HELM_FLAGS+='--set log_agent.enabled=False -f ${localKindVolthaValuesFile} '
193
194 IMAGES=""
195 if [ "${gerritProject}" = "voltha-go" ]; then
196 IMAGES="rw_core ro_core "
197 elif [ "${gerritProject}" = "ofagent-py" ]; then
198 IMAGES="ofagent "
199 elif [ "${gerritProject}" = "voltha-onos" ]; then
200 IMAGES="onos "
201 elif [ "${gerritProject}" = "voltha-openolt-adapter" ]; then
202 IMAGES="adapter_open_olt "
203 elif [ "${gerritProject}" = "voltha-openonu-adapter" ]; then
204 IMAGES="adapter_open_onu "
Girish Gowdra7beebea2021-01-31 18:56:45 -0800205 elif [ "${gerritProject}" = "voltha-openonu-adapter-go" ]; then
206 IMAGES="adapter_open_onu_go "
Andy Bavierd83bf3a2020-08-13 14:55:07 -0700207 elif [ "${gerritProject}" = "voltha-api-server" ]; then
208 IMAGES="afrouter afrouterd "
209 else
210 echo "No images to push"
211 fi
212
213 for I in \$IMAGES
214 do
215 EXTRA_HELM_FLAGS+="--set images.\$I.tag=citest,images.\$I.pullPolicy=Never "
216 done
217
218 if [ "${gerritProject}" = "voltha-helm-charts" ]; then
219 export CHART_PATH=$WORKSPACE/voltha/voltha-helm-charts
220 export VOLTHA_CHART=\$CHART_PATH/voltha
221 export VOLTHA_ADAPTER_OPEN_OLT_CHART=\$CHART_PATH/voltha-adapter-openolt
222 export VOLTHA_ADAPTER_OPEN_ONU_CHART=\$CHART_PATH/voltha-adapter-openonu
223 helm dep update \$VOLTHA_CHART
224 helm dep update \$VOLTHA_ADAPTER_OPEN_OLT_CHART
225 helm dep update \$VOLTHA_ADAPTER_OPEN_ONU_CHART
226 fi
227
228 cd $WORKSPACE/voltha/kind-voltha/
229 echo \$EXTRA_HELM_FLAGS
230 kail -n voltha -n default > $WORKSPACE/onos-voltha-combined.log &
231 ./voltha up
232
233 set +e
234
235 # Remove noise from voltha-core logs
236 voltctl log level set WARN read-write-core#github.com/opencord/voltha-go/db/model
237 voltctl log level set WARN read-write-core#github.com/opencord/voltha-lib-go/v3/pkg/kafka
238 # Remove noise from openolt logs
239 voltctl log level set WARN adapter-open-olt#github.com/opencord/voltha-lib-go/v3/pkg/db
240 voltctl log level set WARN adapter-open-olt#github.com/opencord/voltha-lib-go/v3/pkg/probe
241 voltctl log level set WARN adapter-open-olt#github.com/opencord/voltha-lib-go/v3/pkg/kafka
242 """
243 }
244 }
245 }
246
247 stage('Deploy Kafka Dump Chart') {
248 steps {
249 script {
250 sh returnStdout: false, script: """
251 helm repo add cord https://charts.opencord.org
252 helm repo update
253 if helm version -c --short|grep v2 -q; then
254 helm install -n voltha-kafka-dump cord/voltha-kafka-dump
255 else
256 helm install voltha-kafka-dump cord/voltha-kafka-dump
257 fi
258 """
259 }
260 }
261 }
262
263 stage('Push Tech-Profile') {
264 when {
265 expression { params.profile != "Default" }
266 }
267 steps {
268 sh returnStdout: false, script: """
269 etcd_container=\$(kubectl get pods -n voltha | grep voltha-etcd-cluster | awk 'NR==1{print \$1}')
270 kubectl cp $WORKSPACE/voltha/voltha-system-tests/tests/data/TechProfile-${profile}.json voltha/\$etcd_container:/tmp/flexpod.json
271 kubectl exec -it \$etcd_container -n voltha -- /bin/sh -c 'cat /tmp/flexpod.json | ETCDCTL_API=3 etcdctl put service/voltha/technology_profiles/XGS-PON/64'
272 """
273 }
274 }
275
276 stage('Push Sadis-config') {
277 steps {
278 sh returnStdout: false, script: """
279 curl -sSL --user karaf:karaf -X POST -H Content-Type:application/json http://${deployment_config.nodes[0].ip}:$ONOS_API_PORT/onos/v1/network/configuration --data @${localSadisConfigFile}
280 """
281 }
282 }
283
284 stage('Reinstall OLT software') {
285 when {
286 expression { params.reinstallOlt }
287 }
288 steps {
289 script {
290 deployment_config.olts.each { olt ->
291 sh returnStdout: false, script: "sshpass -p ${olt.pass} ssh -l ${olt.user} ${olt.ip} 'dpkg --remove asfvolt16 && dpkg --purge asfvolt16'"
292 waitUntil {
293 olt_sw_present = sh returnStdout: true, script: "sshpass -p ${olt.pass} ssh -l ${olt.user} ${olt.ip} 'dpkg --list | grep asfvolt16 | wc -l'"
294 return olt_sw_present.toInteger() == 0
295 }
296 if ( params.branch == 'voltha-2.3' ) {
297 oltDebVersion = oltDebVersionVoltha23
298 } else {
299 oltDebVersion = oltDebVersionMaster
300 }
301 sh returnStdout: false, script: "sshpass -p ${olt.pass} ssh -l ${olt.user} ${olt.ip} 'dpkg --install ${oltDebVersion}'"
302 waitUntil {
303 olt_sw_present = sh returnStdout: true, script: "sshpass -p ${olt.pass} ssh -l ${olt.user} ${olt.ip} 'dpkg --list | grep asfvolt16 | wc -l'"
304 return olt_sw_present.toInteger() == 1
305 }
306 if ( olt.fortygig ) {
307 // If the OLT is connected to a 40G switch interface, set the NNI port to be downgraded
308 sh returnStdout: false, script: "sshpass -p ${olt.pass} ssh -l ${olt.user} ${olt.ip} 'echo port ce128 sp=40000 >> /broadcom/qax.soc ; /opt/bcm68620/svk_init.sh'"
309 }
310 }
311 }
312 }
313 }
314
315 stage('Restart OLT processes') {
316 steps {
317 script {
318 deployment_config.olts.each { olt ->
319 sh returnStdout: false, script: """
320 ssh-keyscan -H ${olt.ip} >> ~/.ssh/known_hosts
321 sshpass -p ${olt.pass} ssh -l ${olt.user} ${olt.ip} 'rm -f /var/log/openolt.log; rm -f /var/log/dev_mgmt_daemon.log; reboot'
322 sleep 120
323 """
324 waitUntil {
325 onu_discovered = sh returnStdout: true, script: "sshpass -p ${olt.pass} ssh -l ${olt.user} ${olt.ip} 'grep \"onu discover indication\" /var/log/openolt.log | wc -l'"
326 return onu_discovered.toInteger() > 0
327 }
328 }
329 }
330 }
331 }
332
333 stage('Run E2E Tests') {
334 environment {
335 ROBOT_CONFIG_FILE="${localDeploymentConfigFile}"
336 ROBOT_MISC_ARGS="${params.extraRobotArgs} --removekeywords wuks -d $WORKSPACE/RobotLogs -v container_log_dir:$WORKSPACE "
337 ROBOT_FILE="Voltha_DT_PODTests.robot"
338 }
339 steps {
340 sh returnStdout: false, script: """
341 cd voltha
342 mkdir -p $WORKSPACE/RobotLogs
343
344 # If the Gerrit comment contains a line with "functional tests" then run the full
345 # functional test suite. This covers tests tagged either 'sanity' or 'functional'.
346 # Note: Gerrit comment text will be prefixed by "Patch set n:" and a blank line
347 REGEX="functional tests"
348 if [[ "$GERRIT_EVENT_COMMENT_TEXT" =~ \$REGEX ]]; then
349 ROBOT_MISC_ARGS+="-i functionalDt"
350 fi
Andy Bavierc8ee4322020-08-18 16:37:38 -0700351 # Likewise for dataplane tests
352 REGEX="dataplane tests"
353 if [[ "$GERRIT_EVENT_COMMENT_TEXT" =~ \$REGEX ]]; then
354 ROBOT_MISC_ARGS+="-i dataplaneDt"
355 fi
Andy Bavierd83bf3a2020-08-13 14:55:07 -0700356
357 make -C $WORKSPACE/voltha/voltha-system-tests voltha-dt-test || true
358 """
359 }
360 }
361
362 stage('After-Test Delay') {
363 when {
364 expression { params.manualBranch == "" }
365 }
366 steps {
367 sh returnStdout: false, script: """
368 # Note: Gerrit comment text will be prefixed by "Patch set n:" and a blank line
369 REGEX="hardware test with delay\$"
370 [[ "$GERRIT_EVENT_COMMENT_TEXT" =~ \$REGEX ]] && sleep 10m || true
371 """
372 }
373 }
374 }
375
376 post {
377 always {
378 sh returnStdout: false, script: '''
379 set +e
380 cp $WORKSPACE/voltha/kind-voltha/install-minimal.log $WORKSPACE/
381 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.image}{'\\n'}" | sort | uniq
382 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.imageID}{'\\n'}" | sort | uniq
383 kubectl get nodes -o wide
384 kubectl get pods -o wide
385 kubectl get pods -n voltha -o wide
386
387 sync
388 pkill kail || true
389
390 ## Pull out errors from log files
391 extract_errors_go() {
392 echo
393 echo "Error summary for $1:"
394 grep $1 $WORKSPACE/onos-voltha-combined.log | grep '"level":"error"' | cut -d ' ' -f 2- | jq -r '.msg'
395 echo
396 }
397
398 extract_errors_python() {
399 echo
400 echo "Error summary for $1:"
401 grep $1 $WORKSPACE/onos-voltha-combined.log | grep 'ERROR' | cut -d ' ' -f 2-
402 echo
403 }
404
405 extract_errors_go voltha-rw-core > $WORKSPACE/error-report.log
406 extract_errors_go adapter-open-olt >> $WORKSPACE/error-report.log
407 extract_errors_python adapter-open-onu >> $WORKSPACE/error-report.log
408 extract_errors_python voltha-ofagent >> $WORKSPACE/error-report.log
409
410 gzip $WORKSPACE/onos-voltha-combined.log
411
412 ## collect events, the chart should be running by now
413 kubectl get pods | grep -i voltha-kafka-dump | grep -i running
414 if [[ $? == 0 ]]; then
415 kubectl exec -it `kubectl get pods | grep -i voltha-kafka-dump | grep -i running | cut -f1 -d " "` ./voltha-dump-events.sh > $WORKSPACE/voltha-events.log
416 fi
417 '''
418 script {
419 deployment_config.olts.each { olt ->
420 sh returnStdout: false, script: """
421 until sshpass -p ${olt.pass} scp ${olt.user}@${olt.ip}:/var/log/openolt.log $WORKSPACE/openolt-${olt.ip}.log
422 do
423 echo "Fetching openolt.log log failed, retrying..."
424 sleep 10
425 done
426 sed -i 's/\\x1b\\[[0-9;]*[a-zA-Z]//g' $WORKSPACE/openolt-${olt.ip}.log # Remove escape sequences
427 until sshpass -p ${olt.pass} scp ${olt.user}@${olt.ip}:/var/log/dev_mgmt_daemon.log $WORKSPACE/dev_mgmt_daemon-${olt.ip}.log
428 do
429 echo "Fetching dev_mgmt_daemon.log failed, retrying..."
430 sleep 10
431 done
432 sed -i 's/\\x1b\\[[0-9;]*[a-zA-Z]//g' $WORKSPACE/dev_mgmt_daemon-${olt.ip}.log # Remove escape sequences
433 """
434 }
435 }
436 step([$class: 'RobotPublisher',
437 disableArchiveOutput: false,
438 logFileName: 'RobotLogs/log*.html',
439 otherFiles: '',
440 outputFileName: 'RobotLogs/output*.xml',
441 outputPath: '.',
442 passThreshold: 100,
443 reportFileName: 'RobotLogs/report*.html',
444 unstableThreshold: 0]);
445 archiveArtifacts artifacts: '*.log,*.gz'
446 }
447 }
448}