blob: 12fb69b8e0fb49246336b2efe5a982dd1f088b7d [file] [log] [blame]
Kailash66c389c2019-04-24 14:56:11 -07001// Copyright 2017-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// chart-api-test-helm.groovy
16// Checks functionality of the helm-chart, without overriding the version/tag used
17
Matteo Scandolo5c6a4802019-05-14 10:44:21 -070018def serviceName = "${gerritProject}"
Carmelo Cascone43086e12020-03-23 19:29:04 -070019def xosCoreVersionMismatch = false
Matteo Scandolo5c6a4802019-05-14 10:44:21 -070020
Kailash66c389c2019-04-24 14:56:11 -070021pipeline {
22
23 /* no label, executor is determined by JJB */
24 agent {
Zack Williamsb3292082019-10-11 17:15:18 -070025 label "${params.buildNode}"
Kailash66c389c2019-04-24 14:56:11 -070026 }
27
28 stages {
29
30 stage('repo') {
31 steps {
32 checkout(changelog: false, \
33 poll: false,
34 scm: [$class: 'RepoScm', \
35 manifestRepositoryUrl: "${params.manifestUrl}", \
36 manifestBranch: "${params.manifestBranch}", \
37 currentBranch: true, \
38 destinationDir: 'cord', \
39 forceSync: true,
40 resetFirst: true, \
41 quiet: true, \
42 jobs: 4, \
43 showAllChanges: true] \
44 )
45 }
46 }
47
Kailash66c389c2019-04-24 14:56:11 -070048 stage('minikube') {
49 steps {
50 /* see https://github.com/kubernetes/minikube/#linux-continuous-integration-without-vm-support */
51 sh '''
52 export MINIKUBE_WANTUPDATENOTIFICATION=false
53 export MINIKUBE_WANTREPORTERRORPROMPT=false
54 export CHANGE_MINIKUBE_NONE_USER=true
55 export MINIKUBE_HOME=$HOME
56 mkdir -p $HOME/.kube || true
57 touch $HOME/.kube/config
58 export KUBECONFIG=$HOME/.kube/config
59 sudo -E /usr/bin/minikube start --vm-driver=none
60 '''
61 script {
62 timeout(3) {
63 waitUntil {
64 sleep 5
Zack Williamsd7af2072020-03-06 13:11:26 -070065 def kc_ret = sh script: "kubectl get pods", returnStatus: true
Kailash66c389c2019-04-24 14:56:11 -070066 return (kc_ret == 0);
67 }
68 }
69 }
70 }
71 }
72
73 stage('helm') {
74 steps {
75 sh '''
76 helm init
77 sleep 60
78 helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/
Carmelo Cascone319b34c2020-01-14 16:48:07 -080079 helm repo add cord https://charts.opencord.org
Kailash66c389c2019-04-24 14:56:11 -070080 '''
81 }
82 }
83
Carmelo Cascone43086e12020-03-23 19:29:04 -070084 stage('Verify xos-core version requirements') {
85 steps {
86 script {
87 if (serviceName == "olt-service") {
88 serviceName = "volt"
89 }
90 else if (serviceName == "onos-service") {
91 serviceName = "onos"
92 }
93 else if (serviceName == "kubernetes-service") {
94 serviceName = "kubernetes"
95 }
96 }
97 result = sh returnStdout: true, script: """
98 #!/usr/bin/env bash
99 set -eu -o pipefail
100
101 # Obtain git tag of the service corresponding to the the docker image
102 # used in the latest released version of the helm chart (i.e., HEAD
103 # of cord/helm-charts master branch, which should be already checked
104 # out by repo).
105 pushd cord/helm-charts
106 export RELEASED_GIT_TAG=\$(echo -e "import yaml\\nwith open('xos-services/${serviceName}/Chart.yaml', 'r') as f: print yaml.safe_load(f)['appVersion']" | python)
107 popd
108
109 # Obtain the xos-core version requirement from the config.yaml of the
110 # released service.
111 pushd cord
112 PROJECT_PATH=\$(xmllint --xpath "string(//project[@name=\\\"${gerritProject}\\\"]/@path)" .repo/manifest.xml)
113 pushd \${PROJECT_PATH}
114 git fetch --all --tags
115 git checkout tags/\${RELEASED_GIT_TAG} -b foobar
116 export RELEASED_CORE_VER_REQ=\$(echo -e "import yaml\\nwith open('xos/synchronizer/config.yaml', 'r') as f: yaml.safe_load(f)['core_version']" | python)
117 popd
118 popd
119
120 # Do the same for the patchset we want to verify.
121 pushd cord
122 repo download "\$PROJECT_PATH" "${gerritChangeNumber}/${gerritPatchsetNumber}"
123 pushd \${PROJECT_PATH}
124 export PATCHSET_CORE_VER_REQ=\$(echo -e "import yaml\\nwith open('xos/synchronizer/config.yaml', 'r') as f: yaml.safe_load(f)['core_version']" | python)
125 popd
126 popd
127
128 echo "RELEASED_CORE_VER_REQ: \${RELEASED_CORE_VER_REQ}"
129 echo "PATCHSET_CORE_VER_REQ: \${PATCHSET_CORE_VER_REQ}"
130
131 if [ "\${PATCHSET_CORE_VER_REQ}" == "\${RELEASED_CORE_VER_REQ}" ]; then
132 echo 0
133 else
134 # xosCoreVersionMismatch is true
135 echo 1
136 fi
137 """
138 xosCoreVersionMismatch = result.toBoolean()
139 }
140 }
141
142 if( xosCoreVersionMismatch ) {
143 echo "Detected xos-core version requirements mismatch. Will skip the rest of the pipeline and return SUCCESS"
144 currentBuild.result = 'SUCCESS'
145 return
146 }
147
148 // The patchset should be already checked out, but for consistency with
149 // other pipeline jobs, we re-do the same here.
150 stage('patch') {
151 steps {
152 sh '''
153 pushd cord
154 PROJECT_PATH=\$(xmllint --xpath "string(//project[@name=\\\"${gerritProject}\\\"]/@path)" .repo/manifest.xml)
155 repo download "\$PROJECT_PATH" "${gerritChangeNumber}/${gerritPatchsetNumber}"
156 popd
157 '''
158 }
159 }
160
Kailash66c389c2019-04-24 14:56:11 -0700161 stage('Install XOS w/Service') {
162 steps {
Carmelo Cascone43086e12020-03-23 19:29:04 -0700163 script {
Kailash5f300b92019-05-21 14:04:19 -0700164 if (serviceName == "olt-service") {
165 serviceName = "volt"
166 }
167 else if (serviceName == "onos-service") {
168 serviceName = "onos"
169 }
170 else if (serviceName == "kubernetes-service") {
171 serviceName = "kubernetes"
172 }
173 }
Kailash66c389c2019-04-24 14:56:11 -0700174 sh """
175 #!/usr/bin/env bash
176 set -eu -o pipefail
177
178 pushd cord/helm-charts
179 helm dep update xos-core
180 helm install xos-core -n xos-core
181
Kailash66c389c2019-04-24 14:56:11 -0700182 helm-repo-tools/wait_for_pods.sh
183
184 #install service
Kailash5f300b92019-05-21 14:04:19 -0700185 helm dep update xos-services/${serviceName}
186 helm install xos-services/${serviceName} -n ${serviceName}
Kailash66c389c2019-04-24 14:56:11 -0700187 popd
188 """
189 }
190 }
191 stage('Verify') {
192 steps {
Matteo Scandolo5c6a4802019-05-14 10:44:21 -0700193 echo "serviceName: ${serviceName}"
Kailash66c389c2019-04-24 14:56:11 -0700194 sh """
195 #!/usr/bin/env bash
196 set -ex -o pipefail
197 export DOCKER_TAG=\$(cat $WORKSPACE/cord/orchestration/xos/VERSION)
198
199 #wait for xos-core and models to be loaded
200 timeout 300 bash -c "until http -a admin@opencord.org:letmein GET http://127.0.0.1:30001/xosapi/v1/dynamicload/load_status | jq '.services[] | select(.name==\\"core\\").state'| grep -q present; do echo 'Waiting for Core to be loaded'; sleep 5; done"
Matteo Scandolo5c6a4802019-05-14 10:44:21 -0700201 timeout 300 bash -c "until http -a admin@opencord.org:letmein GET http://127.0.0.1:30001/xosapi/v1/dynamicload/load_status | jq '.services[] | select(.name==\\"${serviceName}\\").state'| grep -q present; do echo 'Waiting for Core to be loaded'; sleep 5; done"
Kailash66c389c2019-04-24 14:56:11 -0700202
203 ## get pod logs
204 for pod in \$(kubectl get pods --no-headers | awk '{print \$1}');
205 do
Daniele Moroa5f00782020-02-24 11:23:46 -0800206 kubectl logs \${pod} > $WORKSPACE/\${pod}_pre.log;
Kailash66c389c2019-04-24 14:56:11 -0700207 done
208 """
209 }
210 }
Kailashf5c3f2b2019-04-30 08:58:49 -0700211 stage('Generate Model API Tests') {
212 steps {
213 sh """
214 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
215 cd $WORKSPACE/cord/test/cord-tester
Kailashf5c3f2b2019-04-30 08:58:49 -0700216 docker cp $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/targets/xosserviceupgradetest.xtarget \$CORE_CONTAINER:/opt/xos/lib/xos-genx/xosgenx/targets/xosserviceupgradetest.xtarget
217 docker cp $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/targets/xosstaticlibrary.xtarget \$CORE_CONTAINER:/opt/xos/lib/xos-genx/xosgenx/targets/xosstaticlibrary.xtarget
218
219 export testname=_service_api.robot
220 export library=_library.robot
221
222 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
223 echo \$SERVICES
224
225 for i in \$SERVICES; do bash -c "docker exec -i \$CORE_CONTAINER /bin/bash -c 'xosgenx --target /opt/xos/lib/xos-genx/xosgenx/targets/./xosserviceupgradetest.xtarget /opt/xos/dynamic_services/\$i/\$i.xproto /opt/xos/core/models/core.xproto'" > $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/\$i\$testname; done
226
227 for i in \$SERVICES; do bash -c "docker exec -i \$CORE_CONTAINER /bin/bash -c 'xosgenx --target /opt/xos/lib/xos-genx/xosgenx/targets/./xosstaticlibrary.xtarget /opt/xos/dynamic_services/\$i/\$i.xproto /opt/xos/core/models/core.xproto'" > $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/\$i\$library; done
228 ls -al $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/
229 """
230 }
231 }
232
233 stage('Test Pre-Upgrade') {
234 steps {
235 sh """
Zack Williamsd7af2072020-03-06 13:11:26 -0700236 #!/usr/bin/env bash
237 set -ex -o pipefail
238
239 pushd cord/test/cord-tester
240 make venv_cord
241 source venv_cord/bin/activate
242 cd src/test/cord-api/Tests
Kailashf5c3f2b2019-04-30 08:58:49 -0700243
244 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
245 CHAM_CONTAINER=\$(docker ps | grep k8s_xos-chameleon | awk '{print \$1}')
246 XOS_CHAMELEON=\$(docker exec \$CHAM_CONTAINER ip a | grep -oE "([0-9]{1,3}\\.){3}[0-9]{1,3}\\b" | grep 172)
247
248 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Properties/
249 sed -i \"s/^\\(SERVER_IP = \\).*/\\1\'\$XOS_CHAMELEON\'/\" RestApiProperties.py
250 sed -i \"s/^\\(SERVER_PORT = \\).*/\\1\'9101\'/\" RestApiProperties.py
251 sed -i \"s/^\\(XOS_USER = \\).*/\\1\'admin@opencord.org\'/\" RestApiProperties.py
252 sed -i \"s/^\\(XOS_PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
253 sed -i \"s/^\\(PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
254
255 export testname=_service_api.robot
256 export library=_library.robot
257 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
258 echo \$SERVICES
259
260 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests
Matteo Scandolo5c6a4802019-05-14 10:44:21 -0700261 for i in \$SERVICES; do bash -c "robot -v SETUP_FLAG:Setup -i create -d Log -T -v TESTLIBRARY:${serviceName}_library.robot \$i\$testname"; sleep 2; done || true
Kailashf5c3f2b2019-04-30 08:58:49 -0700262
263 popd
264 """
265 }
266 }
Kailash66c389c2019-04-24 14:56:11 -0700267
268 stage('Build/Install New Service') {
269 steps {
270 sh """
271 #!/usr/bin/env bash
272 set -eu -o pipefail
Zack Williamsd7af2072020-03-06 13:11:26 -0700273
Kailash66c389c2019-04-24 14:56:11 -0700274 pushd $WORKSPACE/cord/orchestration/xos-services/${gerritProject}
275 export DOCKER_TAG=\$(cat VERSION)-test
276 export DOCKER_REPOSITORY=xosproject/
277 export DOCKER_BUILD_ARGS=--no-cache
Kailash66c389c2019-04-24 14:56:11 -0700278 echo "\$(cat VERSION)-test" > VERSION
279 make docker-build
280
281 #install newservice
282 cd $WORKSPACE/cord/helm-charts
283 helm upgrade --set image.tag=\$DOCKER_TAG \
284 --set image.pullPolicy=Never \
Kailash5f300b92019-05-21 14:04:19 -0700285 --recreate-pods ${serviceName} xos-services/${serviceName}
Kailash66c389c2019-04-24 14:56:11 -0700286 popd
287 """
288 }
289 }
Kailash44fd62c2019-04-30 10:26:31 -0700290
Kailash66c389c2019-04-24 14:56:11 -0700291 stage('Verify Service Upgrade') {
292 steps {
293 sh """
294 #!/usr/bin/env bash
295 set -ex -o pipefail
296 DOCKER_TAG=\$(cat $WORKSPACE/cord/orchestration/xos-services/${gerritProject}/VERSION)
297
298 #wait for xos-core and models to be loaded
299 timeout 300 bash -c "until http -a admin@opencord.org:letmein GET http://127.0.0.1:30001/xosapi/v1/dynamicload/load_status | jq '.services[] | select(.name==\\"core\\").state'| grep -q present; do echo 'Waiting for Core to be loaded'; sleep 5; done"
Matteo Scandolo5c6a4802019-05-14 10:44:21 -0700300 timeout 300 bash -c "until http -a admin@opencord.org:letmein GET http://127.0.0.1:30001/xosapi/v1/dynamicload/load_status | jq '.services[] | select(.name==\\"${serviceName}\\").state'| grep -q present; do echo 'Waiting for New Service to be loaded'; sleep 5; done"
301 timeout 300 bash -c "until http -a admin@opencord.org:letmein GET http://127.0.0.1:30001/xosapi/v1/dynamicload/load_status | jq '.services[] | select(.name==\\"${serviceName}\\").version'| grep -q \$DOCKER_TAG; do echo 'Waiting for New Service Version Check'; sleep 5; done"
Kailash4590ca12019-04-30 14:49:22 -0700302 sleep 120
Kailash66c389c2019-04-24 14:56:11 -0700303 """
304 }
305 }
Kailash44fd62c2019-04-30 10:26:31 -0700306
Kailashf5c3f2b2019-04-30 08:58:49 -0700307 stage('Test Post-Upgrade') {
308 steps {
309 sh """
Zack Williamsd7af2072020-03-06 13:11:26 -0700310 #!/usr/bin/env bash
311 set -ex -o pipefail
312
313 cd cord/test/cord-tester
314 make venv_cord
315 source venv_cord/bin/activate
316 cd src/test/cord-api/Tests
317
Kailashf5c3f2b2019-04-30 08:58:49 -0700318 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
319
320 export testname=_service_api.robot
321 export library=_library.robot
322 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
323 echo \$SERVICES
Matteo Scandolo5c6a4802019-05-14 10:44:21 -0700324 for i in \$SERVICES; do bash -c "robot -v SETUP_FLAG:Setup -i get -d Log -T -v TESTLIBRARY:${serviceName}_library.robot \$i\$testname"; sleep 2; done || true
Kailash44fd62c2019-04-30 10:26:31 -0700325 """
326 }
327 }
328
Andy Baviere053ad32019-05-09 13:58:34 -0700329 /* Disable the downgrade step because the core doesn't support reverse migrations
Kailash44fd62c2019-04-30 10:26:31 -0700330 stage('Downgrade Service') {
331 steps {
332 sh """
333 #!/usr/bin/env bash
334 set -eu -o pipefail
335
336 pushd cord/helm-charts
337 #delete service
338 helm delete --purge ${gerritProject}
339
340 #re-install service with previous version
341 helm dep update xos-services/${gerritProject}
342 helm install xos-services/${gerritProject} -n ${gerritProject}
343
344 #wait for xos-core and models to be loaded
345 timeout 300 bash -c "until http -a admin@opencord.org:letmein GET http://127.0.0.1:30001/xosapi/v1/dynamicload/load_status | jq '.services[] | select(.name==\\"core\\").state'| grep -q present; do echo 'Waiting for Core to be loaded'; sleep 5; done"
346 timeout 300 bash -c "until http -a admin@opencord.org:letmein GET http://127.0.0.1:30001/xosapi/v1/dynamicload/load_status | jq '.services[] | select(.name==\\"${gerritProject}\\").state'| grep -q present; do echo 'Waiting for Service to be loaded'; sleep 5; done"
Kailash4590ca12019-04-30 14:49:22 -0700347 sleep 120
Zack Williamsd7af2072020-03-06 13:11:26 -0700348
349 cd $WORKSPACE/cord/test/cord-tester
350 make venv_cord
351 source venv_cord/bin/activate
352 cd src/test/cord-api/Tests
Kailash44fd62c2019-04-30 10:26:31 -0700353
354 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
355
356 export testname=_service_api.robot
357 export library=_library.robot
358 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
Zack Williamsd7af2072020-03-06 13:11:26 -0700359
Kailash44fd62c2019-04-30 10:26:31 -0700360 echo \$SERVICES
361 for i in \$SERVICES; do bash -c "robot -v SETUP_FLAG:Setup -i get -d Log -T -v TESTLIBRARY:${gerritProject}_library.robot \$i\$testname"; sleep 2; done || true
362
363 ## get pod logs
364 for pod in \$(kubectl get pods --no-headers | awk '{print \$1}');
365 do
366 kubectl logs \$pod> $WORKSPACE/\$pod.log;
367 done || true
368
369 popd
Kailashf5c3f2b2019-04-30 08:58:49 -0700370 """
371 }
372 }
Andy Baviere053ad32019-05-09 13:58:34 -0700373 */
Kailashf5c3f2b2019-04-30 08:58:49 -0700374
Kailash66c389c2019-04-24 14:56:11 -0700375 }
Kailash44fd62c2019-04-30 10:26:31 -0700376
Kailash66c389c2019-04-24 14:56:11 -0700377 post {
378 always {
379 sh """
Daniele Moroa5f00782020-02-24 11:23:46 -0800380 ## get pod logs
381 for pod in \$(kubectl get pods --no-headers | awk '{print \$1}');
382 do
383 kubectl logs \${pod} > $WORKSPACE/\${pod}_post.log;
384 done
385
Kailashf5c3f2b2019-04-30 08:58:49 -0700386 # copy robot logs
387 if [ -d RobotLogs ]; then rm -r RobotLogs; fi; mkdir RobotLogs
388 cp -r $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/Log/*ml ./RobotLogs
Kailash66c389c2019-04-24 14:56:11 -0700389 kubectl get pods --all-namespaces
390 kubectl describe pods
391 http -a admin@opencord.org:letmein GET http://127.0.0.1:30001/xosapi/v1/dynamicload/load_status
392 echo "# removing helm deployments"
393 kubectl get pods
394 helm list
395
396 for hchart in \$(helm list -q);
397 do
398 echo "## Purging chart: \${hchart} ##"
399 helm delete --purge "\${hchart}"
400 done
401
402 sudo minikube delete
403 """
Kailashf5c3f2b2019-04-30 08:58:49 -0700404 step([$class: 'RobotPublisher',
405 disableArchiveOutput: false,
406 logFileName: 'RobotLogs/log*.html',
407 otherFiles: '',
408 outputFileName: 'RobotLogs/output*.xml',
409 outputPath: '.',
410 passThreshold: 100,
411 reportFileName: 'RobotLogs/report*.html',
412 unstableThreshold: 0]);
Kailash66c389c2019-04-24 14:56:11 -0700413 archiveArtifacts artifacts: '*.log'
Zack Williamsd7af2072020-03-06 13:11:26 -0700414 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "scottb@opennetworking.org", sendToIndividuals: false])
Kailash66c389c2019-04-24 14:56:11 -0700415 }
416 }
417}