blob: 1a50e9e83ea4c2648ee98ac735899a48eca65288 [file] [log] [blame]
Scott Bakerff887712020-04-29 13:39:41 -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.withPatchset ) {
26 GERRIT_EVENT_COMMENT_TEXT = ""
27 GERRIT_PROJECT = ""
28 GERRIT_CHANGE_NUMBER = ""
29 GERRIT_PATCHSET_NUMBER = ""
30}
31
32pipeline {
33
34 /* no label, executor is determined by JJB */
35 agent {
36 label "${params.buildNode}"
37 }
38 options {
39 timeout(time: 90, unit: 'MINUTES')
40 }
41
42 environment {
43 KUBECONFIG="$HOME/.kube/kind-config-voltha-minimal"
44 VOLTCONFIG="$HOME/.volt/config-minimal"
45 PATH="$WORKSPACE/kind-voltha/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
46 TYPE="minimal"
47 FANCY=0
48 //VOL-2194 ONOS SSH and REST ports hardcoded to 30115/30120 in tests
49 ONOS_SSH_PORT=30115
50 ONOS_API_PORT=30120
51 }
52
53 stages {
54 stage ('Initialize') {
55 steps {
56 sh returnStdout: false, script: """
57 test -e $WORKSPACE/kind-voltha/voltha && cd $WORKSPACE/kind-voltha && ./voltha down
58 cd $WORKSPACE
59 rm -rf $WORKSPACE/*
60 """
61 script {
62 if (env.configRepo && ! env.localConfigDir) {
63 env.localConfigDir = "$WORKSPACE"
64 sh returnStdout: false, script: "git clone -b master ${cordRepoUrl}/${configRepo}"
65 }
66 localDeploymentConfigFile = "${env.localConfigDir}/${params.deploymentConfigFile}"
67 localKindVolthaValuesFile = "${env.localConfigDir}/${params.kindVolthaValuesFile}"
68 localSadisConfigFile = "${env.localConfigDir}/${params.sadisConfigFile}"
69 }
70 }
71 }
72
73 stage('Repo') {
74 steps {
75 checkout(changelog: true,
76 poll: false,
77 scm: [$class: 'RepoScm',
78 manifestRepositoryUrl: "${params.manifestUrl}",
79 manifestBranch: "${params.manifestBranch}",
80 currentBranch: true,
81 destinationDir: 'voltha',
82 forceSync: true,
83 resetFirst: true,
84 quiet: true,
85 jobs: 4,
86 showAllChanges: true]
87 )
88 }
89 }
90
91 stage('Get Patch') {
92 when {
93 expression { params.withPatchset }
94 }
95 steps {
96 sh returnStdout: false, script: """
97 cd voltha
98 repo download "${gerritProject}" "${gerritChangeNumber}/${gerritPatchsetNumber}"
99 """
100 }
101 }
102
103 stage('Check config files') {
104 steps {
105 script {
106 try {
107 deployment_config = readYaml file: "${localDeploymentConfigFile}"
108 } catch (err) {
109 echo "Error reading ${localDeploymentConfigFile}"
110 throw err
111 }
112 sh returnStdout: false, script: """
113 if [ ! -e ${localKindVolthaValuesFile} ]; then echo "${localKindVolthaValuesFile} not found"; exit 1; fi
114 if [ ! -e ${localSadisConfigFile} ]; then echo "${localSadisConfigFile} not found"; exit 1; fi
115 """
116 }
117 }
118 }
119
120 stage('Create KinD Cluster') {
121 steps {
122 sh returnStdout: false, script: """
123 git clone https://github.com/ciena/kind-voltha.git
124 cd kind-voltha/
125 JUST_K8S=y ./voltha up
126 """
127 }
128 }
129
130 stage('Build and Push Images') {
131 when {
132 expression { params.withPatchset }
133 }
134 steps {
135 sh returnStdout: false, script: """
136 make -C $WORKSPACE/voltha/\$1 DOCKER_REPOSITORY=voltha/ DOCKER_TAG=citest docker-build
137 docker images | grep citest
138 for image in \$(docker images -f "reference=*/*citest" --format "{{.Repository}}"); do echo "Pushing \$image to nodes"; kind load docker-image \$image:citest --name voltha-\$TYPE --nodes voltha-\$TYPE-worker,voltha-\$TYPE-worker2; done
139 """
140 }
141 }
142
143 stage('Deploy Voltha') {
144 environment {
145 WITH_SIM_ADAPTERS="n"
146 WITH_RADIUS="y"
147 DEPLOY_K8S="n"
148 VOLTHA_LOG_LEVEL="debug"
149 }
150 steps {
151 script {
152 sh returnStdout: false, script: """
153 export EXTRA_HELM_FLAGS='--set log_agent.enabled=False -f ${localKindVolthaValuesFile} '
154
155 cd $WORKSPACE/kind-voltha/
156 echo \$EXTRA_HELM_FLAGS
157 kail -n voltha -n default > $WORKSPACE/onos-voltha-combined.log &
158 ./voltha up
159 """
160 }
161 }
162 }
163
164 stage('Deploy Kafka Dump Chart') {
165 steps {
166 script {
167 sh returnStdout: false, script: """
168 helm repo add cord https://charts.opencord.org
169 helm repo update
170 helm install -n voltha-kafka-dump cord/voltha-kafka-dump
171 """
172 }
173 }
174 }
175
176 stage('Push Tech-Profile') {
177 when {
178 expression { params.profile != "Default" }
179 }
180 steps {
181 sh returnStdout: false, script: """
182 etcd_container=\$(kubectl get pods -n voltha | grep voltha-etcd-cluster | awk 'NR==1{print \$1}')
183 kubectl cp $WORKSPACE/voltha/voltha-system-tests/tests/data/TechProfile-${profile}.json voltha/\$etcd_container:/tmp/flexpod.json
184 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'
185 """
186 }
187 }
188
189 stage('Push Sadis-config') {
190 steps {
191 sh returnStdout: false, script: """
192 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}
193 """
194 }
195 }
196
197 stage('Reinstall OLT software') {
198 when {
199 expression { params.reinstallOlt }
200 }
201 steps {
202 script {
203 deployment_config.olts.each { olt ->
204 sh returnStdout: false, script: "sshpass -p ${olt.pass} ssh -l ${olt.user} ${olt.ip} 'service openolt stop' || true"
205 sh returnStdout: false, script: "sshpass -p ${olt.pass} ssh -l ${olt.user} ${olt.ip} 'killall dev_mgmt_daemon' || true"
206 sh returnStdout: false, script: "sshpass -p ${olt.pass} ssh -l ${olt.user} ${olt.ip} 'dpkg --remove asfvolt16 && dpkg --purge asfvolt16'"
207 waitUntil {
208 olt_sw_present = sh returnStdout: true, script: "sshpass -p ${olt.pass} ssh -l ${olt.user} ${olt.ip} 'dpkg --list | grep asfvolt16 | wc -l'"
209 return olt_sw_present.toInteger() == 0
210 }
211 sh returnStdout: false, script: "sshpass -p ${olt.pass} ssh -l ${olt.user} ${olt.ip} 'dpkg --install ${oltDebVersion}'"
212 waitUntil {
213 olt_sw_present = sh returnStdout: true, script: "sshpass -p ${olt.pass} ssh -l ${olt.user} ${olt.ip} 'dpkg --list | grep asfvolt16 | wc -l'"
214 return olt_sw_present.toInteger() == 1
215 }
216 if ( olt.fortygig ) {
217 // If the OLT is connected to a 40G switch interface, set the NNI port to be downgraded
218 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'"
219 }
220 }
221 }
222 }
223 }
224
225 stage('Restart OLT processes') {
226 steps {
227 script {
228 deployment_config.olts.each { olt ->
229 sh returnStdout: false, script: """
230 ssh-keyscan -H ${olt.ip} >> ~/.ssh/known_hosts
231 sshpass -p ${olt.pass} ssh -l ${olt.user} ${olt.ip} 'service openolt stop' || true
232 sshpass -p ${olt.pass} ssh -l ${olt.user} ${olt.ip} 'killall dev_mgmt_daemon' || true
233 sshpass -p ${olt.pass} ssh -l ${olt.user} ${olt.ip} 'rm -f /var/log/openolt.log'
234 sshpass -p ${olt.pass} ssh -l ${olt.user} ${olt.ip} 'rm -f /var/log/dev_mgmt_daemon.log'
235 sshpass -p ${olt.pass} ssh -l ${olt.user} ${olt.ip} 'service dev_mgmt_daemon start &'
236 sleep 5
237 sshpass -p ${olt.pass} ssh -l ${olt.user} ${olt.ip} 'service openolt start &'
238 """
239 waitUntil {
240 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'"
241 return onu_discovered.toInteger() > 0
242 }
243 }
244 }
245 }
246 }
247
248 stage('Run E2E Tests') {
249 environment {
250 ROBOT_CONFIG_FILE="${localDeploymentConfigFile}"
251 ROBOT_MISC_ARGS="${params.extraRobotArgs} --removekeywords wuks -d $WORKSPACE/RobotLogs -v container_log_dir:$WORKSPACE "
252 ROBOT_FILE="Voltha_PODTests.robot"
253 }
254 steps {
255 sh returnStdout: false, script: """
256 cd voltha
257 git clone -b ${branch} ${cordRepoUrl}/cord-tester
258 mkdir -p $WORKSPACE/RobotLogs
259
260 # tell the kubernetes script to use images tagged citest and pullPolicy:Never
261 sed -i 's/master/citest/g' $WORKSPACE/voltha/device-management/kubernetes/deploy-redfish-importer.yaml
262 sed -i 's/imagePullPolicy: Always/imagePullPolicy: Never/g' $WORKSPACE/voltha/device-management/kubernetes/deploy-redfish-importer.yaml
263 make -C $WORKSPACE/voltha/device-management functional-mock-test || true
264 """
265 }
266 }
267
268 stage('After-Test Delay') {
269 when {
270 expression { params.withPatchset }
271 }
272 steps {
273 sh returnStdout: false, script: """
274 # Note: Gerrit comment text will be prefixed by "Patch set n:" and a blank line
275 REGEX="hardware test with delay\$"
276 [[ "$GERRIT_EVENT_COMMENT_TEXT" =~ \$REGEX ]] && sleep 10m || true
277 """
278 }
279 }
280 }
281
282 post {
283 always {
284 sh returnStdout: false, script: '''
285 set +e
286 cp kind-voltha/install-minimal.log $WORKSPACE/
287 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.image}{'\\t'}{.imageID}{'\\n'}" | sort | uniq -c
288 kubectl get nodes -o wide
289 kubectl get pods -o wide
290 kubectl get pods -n voltha -o wide
291
292 sync
293 pkill kail || true
294
295 ## Pull out errors from log files
296 extract_errors_go() {
297 echo
298 echo "Error summary for $1:"
299 grep $1 $WORKSPACE/onos-voltha-combined.log | grep '"level":"error"' | cut -d ' ' -f 2- | jq -r '.msg'
300 echo
301 }
302
303 extract_errors_python() {
304 echo
305 echo "Error summary for $1:"
306 grep $1 $WORKSPACE/onos-voltha-combined.log | grep 'ERROR' | cut -d ' ' -f 2-
307 echo
308 }
309
310 extract_errors_go voltha-rw-core > $WORKSPACE/error-report.log
311 extract_errors_go adapter-open-olt >> $WORKSPACE/error-report.log
312 extract_errors_python adapter-open-onu >> $WORKSPACE/error-report.log
313 extract_errors_python voltha-ofagent >> $WORKSPACE/error-report.log
314
315 gzip $WORKSPACE/onos-voltha-combined.log
316
317 ## collect events, the chart should be running by now
318 kubectl get pods | grep -i voltha-kafka-dump | grep -i running
319 if [[ $? == 0 ]]; then
320 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
321 fi
322 '''
323 script {
324 deployment_config.olts.each { olt ->
325 sh returnStdout: false, script: """
326 sshpass -p ${olt.pass} scp ${olt.user}@${olt.ip}:/var/log/openolt.log $WORKSPACE/openolt-${olt.ip}.log || true
327 sed -i 's/\\x1b\\[[0-9;]*[a-zA-Z]//g' $WORKSPACE/openolt-${olt.ip}.log # Remove escape sequences
328 sshpass -p ${olt.pass} scp ${olt.user}@${olt.ip}:/var/log/dev_mgmt_daemon.log $WORKSPACE/dev_mgmt_daemon-${olt.ip}.log || true
329 sed -i 's/\\x1b\\[[0-9;]*[a-zA-Z]//g' $WORKSPACE/dev_mgmt_daemon-${olt.ip}.log # Remove escape sequences
330 """
331 }
332 }
333 step([$class: 'RobotPublisher',
334 disableArchiveOutput: false,
335 logFileName: 'RobotLogs/log*.html',
336 otherFiles: '',
337 outputFileName: 'RobotLogs/output*.xml',
338 outputPath: '.',
339 passThreshold: 100,
340 reportFileName: 'RobotLogs/report*.html',
341 unstableThreshold: 0]);
342 archiveArtifacts artifacts: '*.log,*.gz'
343 }
344 }
345}