blob: f04db9a5a728cb7470e55077736b30c9facadcf8 [file] [log] [blame]
Andy Bavier61c5b2a2019-11-12 12:08:19 -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
18node {
19 // Need this so that deployment_config has global scope when it's read later
20 deployment_config = null
21 localDeploymentConfigFile = null
22 localKindVolthaValuesFile = null
23 localSadisConfigFile = null
24}
25
26pipeline {
27
28 /* no label, executor is determined by JJB */
29 agent {
30 label "${params.buildNode}"
31 }
32 options {
33 timeout(time: 60, unit: 'MINUTES')
34 }
35
36 environment {
37 KUBECONFIG="$HOME/.kube/kind-config-voltha-minimal"
38 VOLTCONFIG="$HOME/.volt/config-minimal"
39 PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$WORKSPACE/kind-voltha/bin"
40 TYPE="minimal"
41 FANCY=0
42 //VOL-2194 ONOS SSH and REST ports hardcoded to 30115/30120 in tests
43 ONOS_SSH_PORT=30115
44 ONOS_API_PORT=30120
45 }
46
47 stages {
48 stage ('Initialize') {
49 steps {
50 sh returnStdout: true, script: """
51 test -e $WORKSPACE/kind-voltha/voltha && cd $WORKSPACE/kind-voltha && ./voltha down
52 cd $WORKSPACE
53 rm -rf $WORKSPACE/*
54 """
55 script {
56 if (env.configRepo && ! env.localConfigDir) {
57 env.localConfigDir = "$WORKSPACE"
58 sh returnStdout: true, script: "git clone -b master ${cordRepoUrl}/${configRepo}"
59 }
60 localDeploymentConfigFile = "${env.localConfigDir}/${params.deploymentConfigFile}"
61 localKindVolthaValuesFile = "${env.localConfigDir}/${params.kindVolthaValuesFile}"
62 localSadisConfigFile = "${env.localConfigDir}/${params.sadisConfigFile}"
63 if ( ! params.withPatchset ) {
64 sh returnStdout: false, script: """
65 mkdir -p voltha
66 cd voltha
67 git clone -b ${branch} ${cordRepoUrl}/voltha-system-tests
68 """
69 }
Andy Bavier61c5b2a2019-11-12 12:08:19 -070070 }
71 }
72 }
73
74 stage('Get Patch') {
75 when {
76 expression { params.withPatchset }
77 }
78 steps {
79 checkout(changelog: false, \
80 poll: false,
81 scm: [$class: 'RepoScm', \
82 manifestRepositoryUrl: "${params.manifestUrl}", \
83 manifestBranch: "${params.manifestBranch}", \
84 currentBranch: true, \
85 destinationDir: 'voltha', \
86 forceSync: true,
87 resetFirst: true, \
88 quiet: true, \
89 jobs: 4, \
90 showAllChanges: true] \
91 )
92 sh returnStdout: false, script: """
93 cd voltha
94 PROJECT_PATH=\$(xmllint --xpath "string(//project[@name=\\\"${gerritProject}\\\"]/@path)" .repo/manifest.xml)
95 repo download "\$PROJECT_PATH" "${gerritChangeNumber}/${gerritPatchsetNumber}"
96 """
97 }
98 }
99
Andy Bavier9a376602019-11-13 11:53:37 -0700100 stage('Check config files') {
101 steps {
102 try {
103 deployment_config = readYaml file: "${localDeploymentConfigFile}"
104 } catch (err) {
105 echo "Error reading ${localDeploymentConfigFile}"
106 throw err
107 }
108 sh returnStdout: false, script: """
109 if [ ! -e ${localKindVolthaValuesFile} ]; then echo "${localKindVolthaValuesFile} not found"; exit 1; fi
110 if [ ! -e ${localSadisConfigFile} ]; then echo "${localSadisConfigFile} not found"; exit 1; fi
111 """
112 }
113 }
114
Andy Bavier61c5b2a2019-11-12 12:08:19 -0700115 stage('Create KinD Cluster') {
116 steps {
117 sh returnStdout: false, script: """
118 git clone https://github.com/ciena/kind-voltha.git
119 cd kind-voltha/
120 JUST_K8S=y ./voltha up
121 """
122 }
123 }
124
125 stage('Build and Push Images') {
126 when {
127 expression { params.withPatchset }
128 }
129 steps {
130 sh returnStdout: false, script: """
131 if ! [[ "${gerritProject}" =~ ^(voltha-system-tests)\$ ]]; then
132 make -C $WORKSPACE/voltha/${gerritProject} DOCKER_REPOSITORY=voltha/ DOCKER_TAG=citest docker-build
133 docker images | grep citest
134 for image in \$(docker images -f "reference=*/*citest" --format "{{.Repository}}")
135 do
136 echo "Pushing \$image to nodes"
137 kind load docker-image \$image:citest --name voltha-\$TYPE --nodes voltha-\$TYPE-worker,voltha-\$TYPE-worker2
138 docker rmi \$image:citest \$image:latest || true
139 done
140 fi
141 """
142 }
143 }
144
145 stage('Deploy Voltha') {
146 environment {
147 WITH_SIM_ADAPTERS="n"
148 WITH_RADIUS="y"
149 DEPLOY_K8S="n"
150 VOLTHA_LOG_LEVEL="debug"
151 }
152 steps {
153 script {
154 if ( params.withPatchset ) {
155 sh returnStdout: false, script: """
156 export EXTRA_HELM_FLAGS='-f ${localKindVolthaValuesFile} '
157
158 IMAGES=""
159 if [ "${gerritProject}" = "voltha-go" ]; then
160 IMAGES="cli ofagent rw_core ro_core "
161 elif [ "${gerritProject}" = "voltha-openolt-adapter" ]; then
162 IMAGES="adapter_open_olt "
163 elif [ "${gerritProject}" = "voltha-openonu-adapter" ]; then
164 IMAGES="adapter_open_onu "
165 elif [ "${gerritProject}" = "voltha-api-server" ]; then
166 IMAGES="afrouter afrouterd "
167 else
168 echo "No images to push"
169 fi
170
171 for I in \$IMAGES
172 do
173 EXTRA_HELM_FLAGS+="--set images.\$I.tag=citest,images.\$I.pullPolicy=Never "
174 done
175
176 cd $WORKSPACE/kind-voltha/
177 echo \$EXTRA_HELM_FLAGS
178 ./voltha up
179 """
180 } else {
181 sh returnStdout: false, script: """
182 export EXTRA_HELM_FLAGS='-f ${localKindVolthaValuesFile} '
183 cd $WORKSPACE/kind-voltha/
184 echo \$EXTRA_HELM_FLAGS
185 ./voltha up
186 """
187 }
188 }
189 }
190 }
191
192 stage('Push Tech-Profile') {
193 when {
194 expression { params.profile != "Default" }
195 }
196 steps {
197 sh returnStdout: false, script: """
198 etcd_container=\$(kubectl get pods -n voltha | grep voltha-etcd-cluster | awk 'NR==1{print \$1}')
199 kubectl cp $WORKSPACE/voltha/voltha-system-tests/tests/data/TechProfile-${profile}.json voltha/\$etcd_container:/tmp/flexpod.json
200 kubectl exec -it \$etcd_container -n voltha -- /bin/sh -c 'cat /tmp/flexpod.json | ETCDCTL_API=3 etcdctl put service/voltha/technology_profiles/xgspon/64'
201 """
202 }
203 }
204
205 stage('Push Sadis-config') {
206 steps {
207 sh returnStdout: false, script: """
208 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}
209 """
210 }
211 }
212
213 stage('Reinstall OLT software') {
214 when {
215 expression { params.reinstallOlt }
216 }
217 steps {
218 script {
219 deployment_config.olts.each { olt ->
220 sh returnStdout: true, script: "sshpass -p ${olt.pass} ssh -l ${olt.user} ${olt.ip} 'service bal_core_dist stop' || true"
221 sh returnStdout: true, script: "sshpass -p ${olt.pass} ssh -l ${olt.user} ${olt.ip} 'service bal_core_dist stop' || true"
222 sh returnStdout: true, script: "sshpass -p ${olt.pass} ssh -l ${olt.user} ${olt.ip} 'dpkg --remove asfvolt16 && dpkg --purge asfvolt16'"
223 waitUntil {
224 olt_sw_present = sh returnStdout: true, script: "sshpass -p ${olt.pass} ssh -l ${olt.user} ${olt.ip} 'dpkg --list | grep asfvolt16 | wc -l'"
225 return olt_sw_present.toInteger() == 0
226 }
227 sh returnStdout: true, script: "sshpass -p ${olt.pass} ssh -l ${olt.user} ${olt.ip} 'dpkg --install ${oltDebVersion}'"
228 waitUntil {
229 olt_sw_present = sh returnStdout: true, script: "sshpass -p ${olt.pass} ssh -l ${olt.user} ${olt.ip} 'dpkg --list | grep asfvolt16 | wc -l'"
230 return olt_sw_present.toInteger() == 1
231 }
232 if ( olt.fortygig ) {
233 // If the OLT is connected to a 40G switch interface, set the NNI port to be downgraded
234 sh returnStdout: true, script: "sshpass -p ${olt.pass} ssh -l ${olt.user} ${olt.ip} 'echo port ce128 sp=40000 >> /broadcom/qax.soc ; /opt/bcm68620/svk_init.sh'"
235 }
236 }
237 }
238 }
239 }
240
241 stage('Restart OLT processes') {
242 steps {
243 script {
244 deployment_config.olts.each { olt ->
245 sh returnStdout: true, script: """
246 ssh-keyscan -H ${olt.ip} >> ~/.ssh/known_hosts
247 sshpass -p ${olt.pass} ssh -l ${olt.user} ${olt.ip} 'service bal_core_dist stop' || true
248 sshpass -p ${olt.pass} ssh -l ${olt.user} ${olt.ip} 'service openolt stop' || true
249 sshpass -p ${olt.pass} ssh -l ${olt.user} ${olt.ip} 'rm -f /var/log/bal_core_dist.log /var/log/openolt.log'
250 sshpass -p ${olt.pass} ssh -l ${olt.user} ${olt.ip} 'service bal_core_dist start &'
251 sleep 5
252 sshpass -p ${olt.pass} ssh -l ${olt.user} ${olt.ip} 'service openolt start &'
253 """
254 waitUntil {
255 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'"
256 return onu_discovered.toInteger() > 0
257 }
258 }
259 }
260 }
261 }
262
263 stage('Run E2E Tests') {
264 environment {
Andy Bavierbda4c6b2019-11-12 17:06:22 -0700265 ROBOT_CONFIG_FILE="${localDeploymentConfigFile}"
Andy Bavier61c5b2a2019-11-12 12:08:19 -0700266 ROBOT_MISC_ARGS="--removekeywords wuks -d $WORKSPACE/RobotLogs"
Andy Bavierbda4c6b2019-11-12 17:06:22 -0700267 ROBOT_FILE="Voltha_PODTests.robot"
Andy Bavier61c5b2a2019-11-12 12:08:19 -0700268 }
269 steps {
270 sh returnStdout: false, script: """
271 cd voltha
272 git clone -b ${branch} ${cordRepoUrl}/cord-tester
273 git clone -b ${branch} ${cordRepoUrl}/voltha # VOL-2104 recommends we get rid of this
274 mkdir -p $WORKSPACE/RobotLogs
Andy Bavierbda4c6b2019-11-12 17:06:22 -0700275 make -C $WORKSPACE/voltha/voltha-system-tests voltha-test || true
Andy Bavier61c5b2a2019-11-12 12:08:19 -0700276 """
277 }
278 }
279 }
280
281 post {
282 always {
283 sh returnStdout: true, script: """
284 set +e
285 cp kind-voltha/install-minimal.log $WORKSPACE/
286 kubectl get pods --all-namespaces -o jsonpath="{range .items[*].status.containerStatuses[*]}{.image}{'\\t'}{.imageID}{'\\n'}" | sort | uniq -c
287 kubectl get nodes -o wide
288 kubectl get pods -o wide
289 kubectl get pods -n voltha -o wide
290 ## get default pod logs
291 for pod in \$(kubectl get pods --no-headers | awk '{print \$1}');
292 do
293 if [[ \$pod == *"onos"* && \$pod != *"onos-service"* ]]; then
294 kubectl logs \$pod onos> $WORKSPACE/\$pod.log;
295 else
296 kubectl logs \$pod> $WORKSPACE/\$pod.log;
297 fi
298 done
299 ## get voltha pod logs
300 for pod in \$(kubectl get pods --no-headers -n voltha | awk '{print \$1}');
301 do
302 if [[ \$pod == *"-api-"* ]]; then
303 kubectl logs \$pod arouter -n voltha > $WORKSPACE/\$pod.log;
304 elif [[ \$pod == "bbsim-"* ]]; then
305 kubectl logs \$pod -n voltha -p > $WORKSPACE/\$pod.log;
306 else
307 kubectl logs \$pod -n voltha > $WORKSPACE/\$pod.log;
308 fi
309 done
310 """
311 step([$class: 'RobotPublisher',
312 disableArchiveOutput: false,
313 logFileName: 'RobotLogs/log*.html',
314 otherFiles: '',
315 outputFileName: 'RobotLogs/output*.xml',
316 outputPath: '.',
317 passThreshold: 80,
318 reportFileName: 'RobotLogs/report*.html',
319 unstableThreshold: 0]);
320 archiveArtifacts artifacts: '*.log'
321 }
322 }
323}