blob: 02edeebf11a1e3cd701ab83a83d1edf3d99f2466 [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"
Kailash66c389c2019-04-24 14:56:11 -0700121
122 ## get pod logs
123 for pod in \$(kubectl get pods --no-headers | awk '{print \$1}');
124 do
125 kubectl logs \$pod> $WORKSPACE/\$pod.log;
126 done
127 """
128 }
129 }
Kailashf5c3f2b2019-04-30 08:58:49 -0700130 stage('Generate Model API Tests') {
131 steps {
132 sh """
133 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
134 cd $WORKSPACE/cord/test/cord-tester
Kailashf5c3f2b2019-04-30 08:58:49 -0700135 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
136 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
137
138 export testname=_service_api.robot
139 export library=_library.robot
140
141 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
142 echo \$SERVICES
143
144 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
145
146 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
147 ls -al $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/
148 """
149 }
150 }
151
152 stage('Test Pre-Upgrade') {
153 steps {
154 sh """
155 pushd cord/test/cord-tester/src/test/cord-api/Tests
156
157 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
158 CHAM_CONTAINER=\$(docker ps | grep k8s_xos-chameleon | awk '{print \$1}')
159 XOS_CHAMELEON=\$(docker exec \$CHAM_CONTAINER ip a | grep -oE "([0-9]{1,3}\\.){3}[0-9]{1,3}\\b" | grep 172)
160
161 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Properties/
162 sed -i \"s/^\\(SERVER_IP = \\).*/\\1\'\$XOS_CHAMELEON\'/\" RestApiProperties.py
163 sed -i \"s/^\\(SERVER_PORT = \\).*/\\1\'9101\'/\" RestApiProperties.py
164 sed -i \"s/^\\(XOS_USER = \\).*/\\1\'admin@opencord.org\'/\" RestApiProperties.py
165 sed -i \"s/^\\(XOS_PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
166 sed -i \"s/^\\(PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
167
168 export testname=_service_api.robot
169 export library=_library.robot
170 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
171 echo \$SERVICES
172
173 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests
174 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
175
176 popd
177 """
178 }
179 }
Kailash66c389c2019-04-24 14:56:11 -0700180
181 stage('Build/Install New Service') {
182 steps {
183 sh """
184 #!/usr/bin/env bash
185 set -eu -o pipefail
186 pushd $WORKSPACE/cord/orchestration/xos-services/${gerritProject}
187 export DOCKER_TAG=\$(cat VERSION)-test
188 export DOCKER_REPOSITORY=xosproject/
189 export DOCKER_BUILD_ARGS=--no-cache
190 cd $WORKSPACE/cord/orchestration/xos-services/${gerritProject}
191 echo "\$(cat VERSION)-test" > VERSION
192 make docker-build
193
194 #install newservice
195 cd $WORKSPACE/cord/helm-charts
196 helm upgrade --set image.tag=\$DOCKER_TAG \
197 --set image.pullPolicy=Never \
198 --recreate-pods ${gerritProject} xos-services/${gerritProject}
199 popd
200 """
201 }
202 }
Kailash44fd62c2019-04-30 10:26:31 -0700203
Kailash66c389c2019-04-24 14:56:11 -0700204 stage('Verify Service Upgrade') {
205 steps {
206 sh """
207 #!/usr/bin/env bash
208 set -ex -o pipefail
209 DOCKER_TAG=\$(cat $WORKSPACE/cord/orchestration/xos-services/${gerritProject}/VERSION)
210
211 #wait for xos-core and models to be loaded
212 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"
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==\\"${gerritProject}\\").state'| grep -q present; do echo 'Waiting for New Service 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}\\").version'| grep -q \$DOCKER_TAG; do echo 'Waiting for New Service Version Check'; sleep 5; done"
Kailash4590ca12019-04-30 14:49:22 -0700215 sleep 120
Kailash66c389c2019-04-24 14:56:11 -0700216 """
217 }
218 }
Kailash44fd62c2019-04-30 10:26:31 -0700219
Kailashf5c3f2b2019-04-30 08:58:49 -0700220 stage('Test Post-Upgrade') {
221 steps {
222 sh """
223 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
224
225 export testname=_service_api.robot
226 export library=_library.robot
227 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
228 echo \$SERVICES
229 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests
230 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 -0700231
232 ## get pod logs
233 for pod in \$(kubectl get pods --no-headers | awk '{print \$1}');
234 do
235 kubectl logs \$pod> $WORKSPACE/\$pod.log;
236 done || true
237 """
238 }
239 }
240
Andy Baviere053ad32019-05-09 13:58:34 -0700241 /* Disable the downgrade step because the core doesn't support reverse migrations
Kailash44fd62c2019-04-30 10:26:31 -0700242 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"
Kailash4590ca12019-04-30 14:49:22 -0700259 sleep 120
Kailash44fd62c2019-04-30 10:26:31 -0700260 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 }
Andy Baviere053ad32019-05-09 13:58:34 -0700280 */
Kailashf5c3f2b2019-04-30 08:58:49 -0700281
Kailash66c389c2019-04-24 14:56:11 -0700282 }
Kailash44fd62c2019-04-30 10:26:31 -0700283
Kailash66c389c2019-04-24 14:56:11 -0700284 post {
285 always {
286 sh """
Kailashf5c3f2b2019-04-30 08:58:49 -0700287 # copy robot logs
288 if [ -d RobotLogs ]; then rm -r RobotLogs; fi; mkdir RobotLogs
289 cp -r $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/Log/*ml ./RobotLogs
Kailash66c389c2019-04-24 14:56:11 -0700290 kubectl get pods --all-namespaces
291 kubectl describe pods
292 http -a admin@opencord.org:letmein GET http://127.0.0.1:30001/xosapi/v1/dynamicload/load_status
293 echo "# removing helm deployments"
294 kubectl get pods
295 helm list
296
297 for hchart in \$(helm list -q);
298 do
299 echo "## Purging chart: \${hchart} ##"
300 helm delete --purge "\${hchart}"
301 done
302
303 sudo minikube delete
304 """
Kailashf5c3f2b2019-04-30 08:58:49 -0700305 step([$class: 'RobotPublisher',
306 disableArchiveOutput: false,
307 logFileName: 'RobotLogs/log*.html',
308 otherFiles: '',
309 outputFileName: 'RobotLogs/output*.xml',
310 outputPath: '.',
311 passThreshold: 100,
312 reportFileName: 'RobotLogs/report*.html',
313 unstableThreshold: 0]);
Kailash66c389c2019-04-24 14:56:11 -0700314 archiveArtifacts artifacts: '*.log'
315 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "kailash@opennetworking.org, scottb@opennetworking.org", sendToIndividuals: false])
Kailash66c389c2019-04-24 14:56:11 -0700316 }
317 }
318}