blob: 35075b0322aed91420e899356ce72bdb0f56fa3f [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}"
19
Kailash66c389c2019-04-24 14:56:11 -070020pipeline {
21
22 /* no label, executor is determined by JJB */
23 agent {
Zack Williamsb3292082019-10-11 17:15:18 -070024 label "${params.buildNode}"
Kailash66c389c2019-04-24 14:56:11 -070025 }
26
27 stages {
28
29 stage('repo') {
30 steps {
31 checkout(changelog: false, \
32 poll: false,
33 scm: [$class: 'RepoScm', \
34 manifestRepositoryUrl: "${params.manifestUrl}", \
35 manifestBranch: "${params.manifestBranch}", \
36 currentBranch: true, \
37 destinationDir: 'cord', \
38 forceSync: true,
39 resetFirst: true, \
40 quiet: true, \
41 jobs: 4, \
42 showAllChanges: true] \
43 )
44 }
45 }
46
47 stage('patch') {
48 steps {
49 sh '''
50 pushd cord
Zack Williamsde1c6212020-02-24 17:00:17 -070051 PROJECT_PATH=\$(xmllint --xpath "string(//project[@name=\\\"${gerritProject}\\\"]/@path)" .repo/manifests/default.xml)
Kailash66c389c2019-04-24 14:56:11 -070052 repo download "\$PROJECT_PATH" "${gerritChangeNumber}/${gerritPatchsetNumber}"
53 popd
54 '''
55 }
56 }
57
58 stage('minikube') {
59 steps {
60 /* see https://github.com/kubernetes/minikube/#linux-continuous-integration-without-vm-support */
61 sh '''
62 export MINIKUBE_WANTUPDATENOTIFICATION=false
63 export MINIKUBE_WANTREPORTERRORPROMPT=false
64 export CHANGE_MINIKUBE_NONE_USER=true
65 export MINIKUBE_HOME=$HOME
66 mkdir -p $HOME/.kube || true
67 touch $HOME/.kube/config
68 export KUBECONFIG=$HOME/.kube/config
69 sudo -E /usr/bin/minikube start --vm-driver=none
70 '''
71 script {
72 timeout(3) {
73 waitUntil {
74 sleep 5
Zack Williamsd7af2072020-03-06 13:11:26 -070075 def kc_ret = sh script: "kubectl get pods", returnStatus: true
Kailash66c389c2019-04-24 14:56:11 -070076 return (kc_ret == 0);
77 }
78 }
79 }
80 }
81 }
82
83 stage('helm') {
84 steps {
85 sh '''
86 helm init
87 sleep 60
88 helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/
Carmelo Cascone319b34c2020-01-14 16:48:07 -080089 helm repo add cord https://charts.opencord.org
Kailash66c389c2019-04-24 14:56:11 -070090 '''
91 }
92 }
93
94 stage('Install XOS w/Service') {
95 steps {
Kailash5f300b92019-05-21 14:04:19 -070096 script {
97 if (serviceName == "olt-service") {
98 serviceName = "volt"
99 }
100 else if (serviceName == "onos-service") {
101 serviceName = "onos"
102 }
103 else if (serviceName == "kubernetes-service") {
104 serviceName = "kubernetes"
105 }
106 }
Kailash66c389c2019-04-24 14:56:11 -0700107 sh """
108 #!/usr/bin/env bash
109 set -eu -o pipefail
110
111 pushd cord/helm-charts
112 helm dep update xos-core
113 helm install xos-core -n xos-core
114
Kailash66c389c2019-04-24 14:56:11 -0700115 helm-repo-tools/wait_for_pods.sh
116
117 #install service
Kailash5f300b92019-05-21 14:04:19 -0700118 helm dep update xos-services/${serviceName}
119 helm install xos-services/${serviceName} -n ${serviceName}
Kailash66c389c2019-04-24 14:56:11 -0700120 popd
121 """
122 }
123 }
124 stage('Verify') {
125 steps {
Matteo Scandolo5c6a4802019-05-14 10:44:21 -0700126 echo "serviceName: ${serviceName}"
Kailash66c389c2019-04-24 14:56:11 -0700127 sh """
128 #!/usr/bin/env bash
129 set -ex -o pipefail
130 export DOCKER_TAG=\$(cat $WORKSPACE/cord/orchestration/xos/VERSION)
131
132 #wait for xos-core and models to be loaded
133 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 -0700134 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 -0700135
136 ## get pod logs
137 for pod in \$(kubectl get pods --no-headers | awk '{print \$1}');
138 do
Daniele Moroa5f00782020-02-24 11:23:46 -0800139 kubectl logs \${pod} > $WORKSPACE/\${pod}_pre.log;
Kailash66c389c2019-04-24 14:56:11 -0700140 done
141 """
142 }
143 }
Kailashf5c3f2b2019-04-30 08:58:49 -0700144 stage('Generate Model API Tests') {
145 steps {
146 sh """
147 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
148 cd $WORKSPACE/cord/test/cord-tester
Kailashf5c3f2b2019-04-30 08:58:49 -0700149 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
150 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
151
152 export testname=_service_api.robot
153 export library=_library.robot
154
155 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
156 echo \$SERVICES
157
158 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
159
160 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
161 ls -al $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/
162 """
163 }
164 }
165
166 stage('Test Pre-Upgrade') {
167 steps {
168 sh """
Zack Williamsd7af2072020-03-06 13:11:26 -0700169 #!/usr/bin/env bash
170 set -ex -o pipefail
171
172 pushd cord/test/cord-tester
173 make venv_cord
174 source venv_cord/bin/activate
175 cd src/test/cord-api/Tests
Kailashf5c3f2b2019-04-30 08:58:49 -0700176
177 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
178 CHAM_CONTAINER=\$(docker ps | grep k8s_xos-chameleon | awk '{print \$1}')
179 XOS_CHAMELEON=\$(docker exec \$CHAM_CONTAINER ip a | grep -oE "([0-9]{1,3}\\.){3}[0-9]{1,3}\\b" | grep 172)
180
181 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Properties/
182 sed -i \"s/^\\(SERVER_IP = \\).*/\\1\'\$XOS_CHAMELEON\'/\" RestApiProperties.py
183 sed -i \"s/^\\(SERVER_PORT = \\).*/\\1\'9101\'/\" RestApiProperties.py
184 sed -i \"s/^\\(XOS_USER = \\).*/\\1\'admin@opencord.org\'/\" RestApiProperties.py
185 sed -i \"s/^\\(XOS_PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
186 sed -i \"s/^\\(PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
187
188 export testname=_service_api.robot
189 export library=_library.robot
190 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
191 echo \$SERVICES
192
193 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests
Matteo Scandolo5c6a4802019-05-14 10:44:21 -0700194 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 -0700195
196 popd
197 """
198 }
199 }
Kailash66c389c2019-04-24 14:56:11 -0700200
201 stage('Build/Install New Service') {
202 steps {
203 sh """
204 #!/usr/bin/env bash
205 set -eu -o pipefail
Zack Williamsd7af2072020-03-06 13:11:26 -0700206
Kailash66c389c2019-04-24 14:56:11 -0700207 pushd $WORKSPACE/cord/orchestration/xos-services/${gerritProject}
208 export DOCKER_TAG=\$(cat VERSION)-test
209 export DOCKER_REPOSITORY=xosproject/
210 export DOCKER_BUILD_ARGS=--no-cache
Kailash66c389c2019-04-24 14:56:11 -0700211 echo "\$(cat VERSION)-test" > VERSION
212 make docker-build
213
214 #install newservice
215 cd $WORKSPACE/cord/helm-charts
216 helm upgrade --set image.tag=\$DOCKER_TAG \
217 --set image.pullPolicy=Never \
Kailash5f300b92019-05-21 14:04:19 -0700218 --recreate-pods ${serviceName} xos-services/${serviceName}
Kailash66c389c2019-04-24 14:56:11 -0700219 popd
220 """
221 }
222 }
Kailash44fd62c2019-04-30 10:26:31 -0700223
Kailash66c389c2019-04-24 14:56:11 -0700224 stage('Verify Service Upgrade') {
225 steps {
226 sh """
227 #!/usr/bin/env bash
228 set -ex -o pipefail
229 DOCKER_TAG=\$(cat $WORKSPACE/cord/orchestration/xos-services/${gerritProject}/VERSION)
230
231 #wait for xos-core and models to be loaded
232 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 -0700233 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"
234 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 -0700235 sleep 120
Kailash66c389c2019-04-24 14:56:11 -0700236 """
237 }
238 }
Kailash44fd62c2019-04-30 10:26:31 -0700239
Kailashf5c3f2b2019-04-30 08:58:49 -0700240 stage('Test Post-Upgrade') {
241 steps {
242 sh """
Zack Williamsd7af2072020-03-06 13:11:26 -0700243 #!/usr/bin/env bash
244 set -ex -o pipefail
245
246 cd cord/test/cord-tester
247 make venv_cord
248 source venv_cord/bin/activate
249 cd src/test/cord-api/Tests
250
Kailashf5c3f2b2019-04-30 08:58:49 -0700251 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
252
253 export testname=_service_api.robot
254 export library=_library.robot
255 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
256 echo \$SERVICES
Matteo Scandolo5c6a4802019-05-14 10:44:21 -0700257 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 -0700258 """
259 }
260 }
261
Andy Baviere053ad32019-05-09 13:58:34 -0700262 /* Disable the downgrade step because the core doesn't support reverse migrations
Kailash44fd62c2019-04-30 10:26:31 -0700263 stage('Downgrade Service') {
264 steps {
265 sh """
266 #!/usr/bin/env bash
267 set -eu -o pipefail
268
269 pushd cord/helm-charts
270 #delete service
271 helm delete --purge ${gerritProject}
272
273 #re-install service with previous version
274 helm dep update xos-services/${gerritProject}
275 helm install xos-services/${gerritProject} -n ${gerritProject}
276
277 #wait for xos-core and models to be loaded
278 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"
279 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 -0700280 sleep 120
Zack Williamsd7af2072020-03-06 13:11:26 -0700281
282 cd $WORKSPACE/cord/test/cord-tester
283 make venv_cord
284 source venv_cord/bin/activate
285 cd src/test/cord-api/Tests
Kailash44fd62c2019-04-30 10:26:31 -0700286
287 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
288
289 export testname=_service_api.robot
290 export library=_library.robot
291 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 -0700292
Kailash44fd62c2019-04-30 10:26:31 -0700293 echo \$SERVICES
294 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
295
296 ## get pod logs
297 for pod in \$(kubectl get pods --no-headers | awk '{print \$1}');
298 do
299 kubectl logs \$pod> $WORKSPACE/\$pod.log;
300 done || true
301
302 popd
Kailashf5c3f2b2019-04-30 08:58:49 -0700303 """
304 }
305 }
Andy Baviere053ad32019-05-09 13:58:34 -0700306 */
Kailashf5c3f2b2019-04-30 08:58:49 -0700307
Kailash66c389c2019-04-24 14:56:11 -0700308 }
Kailash44fd62c2019-04-30 10:26:31 -0700309
Kailash66c389c2019-04-24 14:56:11 -0700310 post {
311 always {
312 sh """
Daniele Moroa5f00782020-02-24 11:23:46 -0800313 ## get pod logs
314 for pod in \$(kubectl get pods --no-headers | awk '{print \$1}');
315 do
316 kubectl logs \${pod} > $WORKSPACE/\${pod}_post.log;
317 done
318
Kailashf5c3f2b2019-04-30 08:58:49 -0700319 # copy robot logs
320 if [ -d RobotLogs ]; then rm -r RobotLogs; fi; mkdir RobotLogs
321 cp -r $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/Log/*ml ./RobotLogs
Kailash66c389c2019-04-24 14:56:11 -0700322 kubectl get pods --all-namespaces
323 kubectl describe pods
324 http -a admin@opencord.org:letmein GET http://127.0.0.1:30001/xosapi/v1/dynamicload/load_status
325 echo "# removing helm deployments"
326 kubectl get pods
327 helm list
328
329 for hchart in \$(helm list -q);
330 do
331 echo "## Purging chart: \${hchart} ##"
332 helm delete --purge "\${hchart}"
333 done
334
335 sudo minikube delete
336 """
Kailashf5c3f2b2019-04-30 08:58:49 -0700337 step([$class: 'RobotPublisher',
338 disableArchiveOutput: false,
339 logFileName: 'RobotLogs/log*.html',
340 otherFiles: '',
341 outputFileName: 'RobotLogs/output*.xml',
342 outputPath: '.',
343 passThreshold: 100,
344 reportFileName: 'RobotLogs/report*.html',
345 unstableThreshold: 0]);
Kailash66c389c2019-04-24 14:56:11 -0700346 archiveArtifacts artifacts: '*.log'
Zack Williamsd7af2072020-03-06 13:11:26 -0700347 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "scottb@opennetworking.org", sendToIndividuals: false])
Kailash66c389c2019-04-24 14:56:11 -0700348 }
349 }
350}