blob: d7640071ebdca8b2ab1e70cf404995fe75ee32d0 [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
18pipeline {
19
20 /* no label, executor is determined by JJB */
21 agent {
22 label "${params.executorNode}"
23 }
24
25 stages {
26
27 stage('repo') {
28 steps {
29 checkout(changelog: false, \
30 poll: false,
31 scm: [$class: 'RepoScm', \
32 manifestRepositoryUrl: "${params.manifestUrl}", \
33 manifestBranch: "${params.manifestBranch}", \
34 currentBranch: true, \
35 destinationDir: 'cord', \
36 forceSync: true,
37 resetFirst: true, \
38 quiet: true, \
39 jobs: 4, \
40 showAllChanges: true] \
41 )
42 }
43 }
44
45 stage('patch') {
46 steps {
47 sh '''
48 pushd cord
49 PROJECT_PATH=\$(xmllint --xpath "string(//project[@name=\\\"${gerritProject}\\\"]/@path)" .repo/manifest.xml)
50 repo download "\$PROJECT_PATH" "${gerritChangeNumber}/${gerritPatchsetNumber}"
51 popd
52 '''
53 }
54 }
55
56 stage('minikube') {
57 steps {
58 /* see https://github.com/kubernetes/minikube/#linux-continuous-integration-without-vm-support */
59 sh '''
60 export MINIKUBE_WANTUPDATENOTIFICATION=false
61 export MINIKUBE_WANTREPORTERRORPROMPT=false
62 export CHANGE_MINIKUBE_NONE_USER=true
63 export MINIKUBE_HOME=$HOME
64 mkdir -p $HOME/.kube || true
65 touch $HOME/.kube/config
66 export KUBECONFIG=$HOME/.kube/config
67 sudo -E /usr/bin/minikube start --vm-driver=none
68 '''
69 script {
70 timeout(3) {
71 waitUntil {
72 sleep 5
73 def kc_ret = sh script: "kubectl get po", returnStatus: true
74 return (kc_ret == 0);
75 }
76 }
77 }
78 }
79 }
80
81 stage('helm') {
82 steps {
83 sh '''
84 helm init
85 sleep 60
86 helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/
87 '''
88 }
89 }
90
91 stage('Install XOS w/Service') {
92 steps {
93 sh """
94 #!/usr/bin/env bash
95 set -eu -o pipefail
96
97 pushd cord/helm-charts
98 helm dep update xos-core
99 helm install xos-core -n xos-core
100
101 git clone https://gerrit.opencord.org/helm-repo-tools
102 helm-repo-tools/wait_for_pods.sh
103
104 #install service
105 helm dep update xos-services/${gerritProject}
106 helm install xos-services/${gerritProject} -n ${gerritProject}
107 popd
108 """
109 }
110 }
111 stage('Verify') {
112 steps {
113 sh """
114 #!/usr/bin/env bash
115 set -ex -o pipefail
116 export DOCKER_TAG=\$(cat $WORKSPACE/cord/orchestration/xos/VERSION)
117
118 #wait for xos-core and models to be loaded
119 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"
120 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 Core to be loaded'; sleep 5; done"
121 http -a admin@opencord.org:letmein GET http://127.0.0.1:30001/xosapi/v1/dynamicload/load_status | jq ".services[] | select(.name==\\"core\\").version"| grep -q \$DOCKER_TAG
122
123 ## get pod logs
124 for pod in \$(kubectl get pods --no-headers | awk '{print \$1}');
125 do
126 kubectl logs \$pod> $WORKSPACE/\$pod.log;
127 done
128 """
129 }
130 }
Kailashf5c3f2b2019-04-30 08:58:49 -0700131 stage('Generate Model API Tests') {
132 steps {
133 sh """
134 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
135 cd $WORKSPACE/cord/test/cord-tester
Kailashf5c3f2b2019-04-30 08:58:49 -0700136 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
137 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
138
139 export testname=_service_api.robot
140 export library=_library.robot
141
142 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
143 echo \$SERVICES
144
145 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
146
147 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
148 ls -al $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/
149 """
150 }
151 }
152
153 stage('Test Pre-Upgrade') {
154 steps {
155 sh """
156 pushd cord/test/cord-tester/src/test/cord-api/Tests
157
158 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
159 CHAM_CONTAINER=\$(docker ps | grep k8s_xos-chameleon | awk '{print \$1}')
160 XOS_CHAMELEON=\$(docker exec \$CHAM_CONTAINER ip a | grep -oE "([0-9]{1,3}\\.){3}[0-9]{1,3}\\b" | grep 172)
161
162 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Properties/
163 sed -i \"s/^\\(SERVER_IP = \\).*/\\1\'\$XOS_CHAMELEON\'/\" RestApiProperties.py
164 sed -i \"s/^\\(SERVER_PORT = \\).*/\\1\'9101\'/\" RestApiProperties.py
165 sed -i \"s/^\\(XOS_USER = \\).*/\\1\'admin@opencord.org\'/\" RestApiProperties.py
166 sed -i \"s/^\\(XOS_PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
167 sed -i \"s/^\\(PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
168
169 export testname=_service_api.robot
170 export library=_library.robot
171 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
172 echo \$SERVICES
173
174 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests
175 for i in \$SERVICES; do bash -c "robot -v SETUP_FLAG:Setup -i create -d Log -T -v TESTLIBRARY:${gerritProject}_library.robot \$i\$testname"; sleep 2; done || true
176
177 popd
178 """
179 }
180 }
Kailash66c389c2019-04-24 14:56:11 -0700181
182 stage('Build/Install New Service') {
183 steps {
184 sh """
185 #!/usr/bin/env bash
186 set -eu -o pipefail
187 pushd $WORKSPACE/cord/orchestration/xos-services/${gerritProject}
188 export DOCKER_TAG=\$(cat VERSION)-test
189 export DOCKER_REPOSITORY=xosproject/
190 export DOCKER_BUILD_ARGS=--no-cache
191 cd $WORKSPACE/cord/orchestration/xos-services/${gerritProject}
192 echo "\$(cat VERSION)-test" > VERSION
193 make docker-build
194
195 #install newservice
196 cd $WORKSPACE/cord/helm-charts
197 helm upgrade --set image.tag=\$DOCKER_TAG \
198 --set image.pullPolicy=Never \
199 --recreate-pods ${gerritProject} xos-services/${gerritProject}
200 popd
201 """
202 }
203 }
Kailash44fd62c2019-04-30 10:26:31 -0700204
Kailash66c389c2019-04-24 14:56:11 -0700205 stage('Verify Service Upgrade') {
206 steps {
207 sh """
208 #!/usr/bin/env bash
209 set -ex -o pipefail
210 DOCKER_TAG=\$(cat $WORKSPACE/cord/orchestration/xos-services/${gerritProject}/VERSION)
211
212 #wait for xos-core and models to be loaded
213 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"
214 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 New Service to be loaded'; sleep 5; done"
215 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}\\").version'| grep -q \$DOCKER_TAG; do echo 'Waiting for New Service Version Check'; sleep 5; done"
Kailash44fd62c2019-04-30 10:26:31 -0700216 sleep 15
Kailash66c389c2019-04-24 14:56:11 -0700217 """
218 }
219 }
Kailash44fd62c2019-04-30 10:26:31 -0700220
Kailashf5c3f2b2019-04-30 08:58:49 -0700221 stage('Test Post-Upgrade') {
222 steps {
223 sh """
224 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
225
226 export testname=_service_api.robot
227 export library=_library.robot
228 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
229 echo \$SERVICES
230 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests
231 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
Kailash44fd62c2019-04-30 10:26:31 -0700232
233 ## get pod logs
234 for pod in \$(kubectl get pods --no-headers | awk '{print \$1}');
235 do
236 kubectl logs \$pod> $WORKSPACE/\$pod.log;
237 done || true
238 """
239 }
240 }
241
242 stage('Downgrade Service') {
243 steps {
244 sh """
245 #!/usr/bin/env bash
246 set -eu -o pipefail
247
248 pushd cord/helm-charts
249 #delete service
250 helm delete --purge ${gerritProject}
251
252 #re-install service with previous version
253 helm dep update xos-services/${gerritProject}
254 helm install xos-services/${gerritProject} -n ${gerritProject}
255
256 #wait for xos-core and models to be loaded
257 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"
258 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"
259 sleep 15
260 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests
261
262 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
263
264 export testname=_service_api.robot
265 export library=_library.robot
266 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
267 echo \$SERVICES
268 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
269
270 ## get pod logs
271 for pod in \$(kubectl get pods --no-headers | awk '{print \$1}');
272 do
273 kubectl logs \$pod> $WORKSPACE/\$pod.log;
274 done || true
275
276 popd
Kailashf5c3f2b2019-04-30 08:58:49 -0700277 """
278 }
279 }
280
Kailash66c389c2019-04-24 14:56:11 -0700281 }
Kailash44fd62c2019-04-30 10:26:31 -0700282
Kailash66c389c2019-04-24 14:56:11 -0700283 post {
284 always {
285 sh """
Kailashf5c3f2b2019-04-30 08:58:49 -0700286 # copy robot logs
287 if [ -d RobotLogs ]; then rm -r RobotLogs; fi; mkdir RobotLogs
288 cp -r $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/Log/*ml ./RobotLogs
Kailash66c389c2019-04-24 14:56:11 -0700289 kubectl get pods --all-namespaces
290 kubectl describe pods
291 http -a admin@opencord.org:letmein GET http://127.0.0.1:30001/xosapi/v1/dynamicload/load_status
292 echo "# removing helm deployments"
293 kubectl get pods
294 helm list
295
296 for hchart in \$(helm list -q);
297 do
298 echo "## Purging chart: \${hchart} ##"
299 helm delete --purge "\${hchart}"
300 done
301
302 sudo minikube delete
303 """
Kailashf5c3f2b2019-04-30 08:58:49 -0700304 step([$class: 'RobotPublisher',
305 disableArchiveOutput: false,
306 logFileName: 'RobotLogs/log*.html',
307 otherFiles: '',
308 outputFileName: 'RobotLogs/output*.xml',
309 outputPath: '.',
310 passThreshold: 100,
311 reportFileName: 'RobotLogs/report*.html',
312 unstableThreshold: 0]);
Kailash66c389c2019-04-24 14:56:11 -0700313 archiveArtifacts artifacts: '*.log'
314 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "kailash@opennetworking.org, scottb@opennetworking.org", sendToIndividuals: false])
Kailash66c389c2019-04-24 14:56:11 -0700315 }
316 }
317}