blob: 4b2cf969253c05520dab873aca2b954e6aa07623 [file] [log] [blame]
Zack Williams15bc4a52018-07-23 15:31:58 -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
Zack Williams66500002018-09-06 15:29:05 -070015// Run XOS api tests after changing the containers to use the current XOS
16// container versions as parent, which may include synchronizer framework
17// changes
Zack Williams15bc4a52018-07-23 15:31:58 -070018
19CORE_CONTAINER="null"
20
21pipeline {
22
23 /* no label, executor is determined by JJB */
24 agent {
25 label "${params.executorNode}"
26 }
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
48 stage('patch') {
49 steps {
50 sh """
51 #!/usr/bin/env bash
52 set -eu -o pipefail
53
54 VERSIONFILE="" # file path to file containing version number
55 NEW_VERSION="" # version number found in VERSIONFILE
56 releaseversion=0
57
58 function read_version {
59 if [ -f "VERSION" ]
60 then
61 NEW_VERSION=\$(head -n1 "VERSION")
62 VERSIONFILE="VERSION"
63 elif [ -f "package.json" ]
64 then
65 NEW_VERSION=\$(python -c 'import json,sys;obj=json.load(sys.stdin); print obj["version"]' < package.json)
66 VERSIONFILE="package.json"
67 else
68 echo "ERROR: No versioning file found!"
69 exit 1
70 fi
71 }
72
73 # check if the version is a released version
74 function check_if_releaseversion {
75 if [[ "\$NEW_VERSION" =~ ^([0-9]+)\\.([0-9]+)\\.([0-9]+)\$ ]]
76 then
77 echo "Version string '\$NEW_VERSION' in '\$VERSIONFILE' is a SemVer released version!"
78 releaseversion=1
79 else
80 echo "Version string '\$NEW_VERSION' in '\$VERSIONFILE' is not a SemVer released version, skipping."
81 fi
82 }
83
84 pushd cord
85 PROJECT_PATH=\$(xmllint --xpath "string(//project[@name=\\\"${gerritProject}\\\"]/@path)" .repo/manifest.xml)
86 repo download "\$PROJECT_PATH" "${gerritChangeNumber}/${gerritPatchsetNumber}"
87
88 pushd \$PROJECT_PATH
89 echo "Existing git tags:"
90 git tag -n
91
92 read_version
93 check_if_releaseversion
94
95 # perform checks if a released version
96 if [ "\$releaseversion" -eq "1" ]
97 then
98 git config --global user.email "apitest@opencord.org"
99 git config --global user.name "API Test"
100
101 git tag -a "\$NEW_VERSION" -m "Tagged for api test on Gerrit patchset: ${gerritChangeNumber}"
102
103 echo "Tags including new tag:"
104 git tag -n
105
106 fi
107 popd
108 popd
109 """
110 }
111 }
Zack Williams1f672932018-07-24 11:24:10 -0700112
Zack Williams66500002018-09-06 15:29:05 -0700113 stage('tag update') {
Zack Williams15bc4a52018-07-23 15:31:58 -0700114 steps {
115 sh """
Zack Williams66500002018-09-06 15:29:05 -0700116 #!/usr/bin/env bash
117 set -eu -o pipefail
118
Kailash Khalasif57dcdd2018-09-16 09:22:27 -0700119 echo "" > $WORKSPACE/xos_tags.yaml
120 echo "" > $WORKSPACE/updated_dockerfiles
Zack Williams15bc4a52018-07-23 15:31:58 -0700121 XOS_MAJOR=\$(cut -b 1 cord/orchestration/xos/VERSION)
Zack Williams66500002018-09-06 15:29:05 -0700122 XOS_VERSION=\$(cat cord/orchestration/xos/VERSION)
Zack Williams1f672932018-07-24 11:24:10 -0700123
Zack Williams66500002018-09-06 15:29:05 -0700124 # update services
Zack Williams15bc4a52018-07-23 15:31:58 -0700125 for df in cord/orchestration/xos_services/*/Dockerfile.synchronizer cord/orchestration/profiles/*/Dockerfile.synchronizer
126 do
Kailash Khalasi70b626e2018-08-21 11:12:02 -0700127 df_contents=\$(cat "\$df")
Kailash Khalasif57dcdd2018-09-16 09:22:27 -0700128 if [[ "\$df_contents" =~ "FROM xosproject/xos-synchronizer-base:\$XOS_MAJOR" ||
Zack Williams42acdd12018-08-17 13:58:07 -0700129 "\$df_contents" =~ "FROM xosproject/xos-synchronizer-base:master" ]]
130 then
Zack Williams66500002018-09-06 15:29:05 -0700131 sed -i "s/^FROM\\(.*\\):.*\$/FROM\\1:\$XOS_VERSION/" "\$df"
Kailash Khalasif57dcdd2018-09-16 09:22:27 -0700132 echo "$WORKSPACE/\$df" >> $WORKSPACE/updated_dockerfiles
Zack Williams42acdd12018-08-17 13:58:07 -0700133 fi
Zack Williams15bc4a52018-07-23 15:31:58 -0700134 done
Zack Williams66500002018-09-06 15:29:05 -0700135
136 # create values file with core version tags
Zack Williams9b6b5eb2018-09-14 13:45:18 -0700137 # not indented because heredoc requires it
Kailash Khalasif57dcdd2018-09-16 09:22:27 -0700138 cat << EOF > $WORKSPACE/xos_tags.yaml
Zack Williams9b6b5eb2018-09-14 13:45:18 -0700139---
Zack Williamseffda9e2018-10-10 10:49:49 -0700140images:
141 xos_core:
142 tag: '\$XOS_VERSION'
143 xos_chameleon:
144 tag: '\$XOS_VERSION'
Zack Williams9b6b5eb2018-09-14 13:45:18 -0700145EOF
Zack Williams15bc4a52018-07-23 15:31:58 -0700146 """
147 }
148 }
149
Zack Williams1f672932018-07-24 11:24:10 -0700150 stage('unittest') {
151 steps {
152 sh """
153 #!/usr/bin/env bash
154 set -e -o pipefail
155
156 cd "\${WORKSPACE}"
157
158 export XOS_DIR=\${WORKSPACE}/cord/orchestration/xos
159 \$XOS_DIR/scripts/setup_venv.sh
160 source "\${WORKSPACE}/venv-xos/bin/activate"
161
162 for df in \$(cat "\${WORKSPACE}/updated_dockerfiles")
163 do
164 projectdir=\$(dirname "\${df}")
165 if [ -e "\${projectdir}/xos/unittest.cfg" ]
166 then
167 pushd \${projectdir}/xos
168 echo "Performing nose2 tests"
169 nose2 --verbose --coverage-report xml --coverage-report term --junit-xml
170 popd
171 else
172 echo "No unit tests found for project \$(basename \${projectdir})"
173 fi
174 done
175 """
176 junit '**/nose2-junit.xml'
177 cobertura coberturaReportFile: '**/coverage.xml', fileCoverageTargets: '80, 0, 0', methodCoverageTargets: '50, 0, 0'
178 }
179 }
180
Zack Williams15bc4a52018-07-23 15:31:58 -0700181 stage('prep') {
182 parallel {
183
184 stage('images') {
185 steps {
186 sh '''
187 pushd cord/automation-tools/developer
188 mkdir ib_logs
189 ./imagebuilder.py -l ib_logs -a ib_actions.yml -g ib_graph.dot -f ../../helm-charts/examples/filter-images.yaml
190 popd
191 '''
192 archiveArtifacts artifacts: 'cord/automation-tools/developer/ib_actions.yml, cord/automation-tools/developer/ib_graph.dot, cord/automation-tools/developer/ib_logs/*', fingerprint: true
193 }
194 }
195
196 stage('minikube') {
197 steps {
198 /* see https://github.com/kubernetes/minikube/#linux-continuous-integration-without-vm-support */
199 sh '''
200 export MINIKUBE_WANTUPDATENOTIFICATION=false
201 export MINIKUBE_WANTREPORTERRORPROMPT=false
202 export CHANGE_MINIKUBE_NONE_USER=true
203 export MINIKUBE_HOME=$HOME
204 mkdir -p $HOME/.kube || true
205 touch $HOME/.kube/config
206 export KUBECONFIG=$HOME/.kube/config
207 sudo -E /usr/bin/minikube start --vm-driver=none
208 '''
209 script {
210 timeout(3) {
211 waitUntil {
212 sleep 5
213 def kc_ret = sh script: "kubectl get po", returnStatus: true
214 return (kc_ret == 0);
215 }
216 }
217 }
218 }
219 }
220 }
221 }
222
223 stage('helm') {
224 steps {
225 sh '''
226 helm init
227 sleep 60
228 helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/
229 '''
230 }
231 }
232
233 stage('build') {
234 steps {
235 sh """
236 #!/usr/bin/env bash
237 set -eu -o pipefail
238
Zack Williams66500002018-09-06 15:29:05 -0700239 helm_install_args='-f examples/image-tag-candidate.yaml -f examples/imagePullPolicy-IfNotPresent.yaml -f examples/api-test-values.yaml -f $WORKSPACE/xos_tags.yaml'
Zack Williams15bc4a52018-07-23 15:31:58 -0700240
241 pushd cord/helm-charts
242
Zack Williamsa26fc9d2018-09-18 16:49:01 -0700243 helm install -f examples/kafka-single.yaml --version 0.8.8 -n cord-kafka incubator/kafka
244 scripts/wait_for_pods.sh
245
Zack Williams15bc4a52018-07-23 15:31:58 -0700246 helm dep up xos-core
247 helm install \${helm_install_args} xos-core -n xos-core
248
249 # Pick which chart(s) to load depending on the project being tested
250 # In regex, please list repos in same order as requirements.yaml in the chart(s) loaded!
251
252 if [[ "$GERRIT_PROJECT" =~ ^(rcord|onos-service|fabric|olt-service|vsg-hw|vrouter)\$ ]]; then
253 helm dep update xos-profiles/rcord-lite
254 helm install \${helm_install_args} xos-profiles/rcord-lite -n rcord-lite
Zack Williams15bc4a52018-07-23 15:31:58 -0700255
256 elif [[ "$GERRIT_PROJECT" =~ ^(vMME|vspgwc|vspgwu|vHSS|hss_db|internetemulator|sdn-controller|epc-service|mcord|progran)\$ ]]; then
257 helm dep update xos-profiles/base-openstack
258 helm dep update xos-profiles/mcord
259 helm install \${helm_install_args} xos-profiles/base-openstack -n base-openstack
260 helm install \${helm_install_args} xos-profiles/mcord -n mcord
Zack Williams15bc4a52018-07-23 15:31:58 -0700261
262 elif [[ "$GERRIT_PROJECT" =~ ^(openstack|vtn-service|exampleservice|addressmanager)\$ ]]; then
263 # NOTE: onos-service is included in base-openstack, but tested w/rcord-lite chart
264
265 helm dep update xos-profiles/base-openstack
266 helm dep update xos-profiles/demo-exampleservice
267 helm install \${helm_install_args} xos-profiles/base-openstack -n base-openstack
268 helm install \${helm_install_args} xos-profiles/demo-exampleservice -n demo-exampleservice
269
270 elif [[ "$GERRIT_PROJECT" =~ ^(kubernetes-service|simpleexampleservice)\$ ]]; then
271 helm dep update xos-profiles/base-kubernetes
272 helm dep update xos-profiles/demo-simpleexampleservice
273 helm install \${helm_install_args} xos-profiles/base-kubernetes -n base-kubernetes
274 helm install \${helm_install_args} xos-profiles/demo-simpleexampleservice -n demo-simpleexampleservice
275
276 elif [[ "$GERRIT_PROJECT" =~ ^(hippie-oss)\$ ]]; then
277 helm dep update xos-services/hippie-oss
278 helm install \${helm_install_args} xos-services/hippie-oss -n hippie-oss
279
280 elif [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester|helm-charts)\$ ]]; then
281 echo "No additional charts to install for testing $GERRIT_PROJECT"
282
283 else
284 echo "Couldn't find a chart to test project: $GERRIT_PROJECT!"
285 exit 1
286 fi
287
Kailash Khalasi2bc499b2018-07-25 16:10:11 -0700288 # wait for services to load
Kailash Khalasiedb48b12018-07-31 13:01:01 -0700289 JOBS_TIMEOUT=900 ./scripts/wait_for_jobs.sh
Kailash Khalasi512a7e52018-07-30 09:12:16 -0700290
Zack Williams15bc4a52018-07-23 15:31:58 -0700291 echo "# Checking helm deployments"
292 kubectl get pods
293 helm list
294
295 for hchart in \$(helm list -q);
296 do
297 echo "## 'helm status' for chart: \${hchart} ##"
298 helm status "\${hchart}"
299 done
300
301 popd
302 """
303 }
304 }
305
Kailash Khalasi512a7e52018-07-30 09:12:16 -0700306 stage('wait for core') {
307 steps {
308 timeout(time:5) {
309 waitUntil {
310 script {
311 try {
312 sh """
313 CORE_POD=\$(kubectl get pods | grep xos-core | awk '{print \$1}')
314 CHAM_POD=\$(kubectl get pods | grep chameleon | awk '{print \$1}')
315 CHAM_CONTAINER=\$(docker ps | grep k8s_xos-chameleon | awk '{print \$1}')
316 XOS_CHAMELEON=\$(docker exec \$CHAM_CONTAINER ip a | grep -oE "([0-9]{1,3}\\.){3}[0-9]{1,3}\\b" | grep 172)
317 kubectl logs \$CORE_POD | grep "XOS core entering wait loop"
Kailash Khalasi512a7e52018-07-30 09:12:16 -0700318 curl -I -u admin@opencord.org:letmein http://\$XOS_CHAMELEON:9101/xosapi/v1/core/users | grep "200 OK"
Kailash Khalasi309872a2018-07-31 12:39:02 -0700319 sleep 30
Kailash Khalasi25ee0722018-07-30 14:26:41 -0700320 curl -I -u admin@opencord.org:letmein http://\$XOS_CHAMELEON:9101/xosapi/v1/core/sites | grep "200 OK"
321 """
Kailash Khalasi512a7e52018-07-30 09:12:16 -0700322 return true
323 } catch (exception) {
324 return false
325 }
326 }
327 }
328 }
329 }
330 }
331
Zack Williams15bc4a52018-07-23 15:31:58 -0700332 stage('setup') {
333 steps {
334 sh """
335 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
336
337 docker cp $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/targets/xosapitests.xtarget \$CORE_CONTAINER:/opt/xos/lib/xos-genx/xosgenx/targets/xosapitests.xtarget
338 docker cp $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/targets/xosserviceapitests.xtarget \$CORE_CONTAINER:/opt/xos/lib/xos-genx/xosgenx/targets/xosserviceapitests.xtarget
339 docker cp $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/targets/xoslibrary.xtarget \$CORE_CONTAINER:/opt/xos/lib/xos-genx/xosgenx/targets/xoslibrary.xtarget
340 docker exec -i \$CORE_CONTAINER /bin/bash -c "xosgenx --target /opt/xos/lib/xos-genx/xosgenx/targets/./xosapitests.xtarget /opt/xos/core/models/core.xproto" > $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/XOSCoreAPITests.robot
341
342 # create additional testing files if services are loaded
343 if ! [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester|helm-charts)\$ ]]; then
344 export testname=_service_api.robot
345 export library=_library.robot
346
347 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
348 echo \$SERVICES
349
350 for i in \$SERVICES; do bash -c "docker exec -i \$CORE_CONTAINER /bin/bash -c 'xosgenx --target /opt/xos/lib/xos-genx/xosgenx/targets/./xosserviceapitests.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
351
352 for i in \$SERVICES; do bash -c "docker exec -i \$CORE_CONTAINER /bin/bash -c 'xosgenx --target /opt/xos/lib/xos-genx/xosgenx/targets/./xoslibrary.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
353 fi
354 """
355 }
356 }
357
358 stage('test') {
359 steps {
360 sh """
361 pushd cord/test/cord-tester/src/test/cord-api/Tests
362
363 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
364 CHAM_CONTAINER=\$(docker ps | grep k8s_xos-chameleon | awk '{print \$1}')
365 XOS_CHAMELEON=\$(docker exec \$CHAM_CONTAINER ip a | grep -oE "([0-9]{1,3}\\.){3}[0-9]{1,3}\\b" | grep 172)
366
367 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Properties/
368 sed -i \"s/^\\(SERVER_IP = \\).*/\\1\'\$XOS_CHAMELEON\'/\" RestApiProperties.py
369 sed -i \"s/^\\(SERVER_PORT = \\).*/\\1\'9101\'/\" RestApiProperties.py
370 sed -i \"s/^\\(XOS_USER = \\).*/\\1\'admin@opencord.org\'/\" RestApiProperties.py
371 sed -i \"s/^\\(XOS_PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
372 sed -i \"s/^\\(PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
373
374 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests
Kailashf14606e2018-12-06 14:11:11 -0800375 robot -d Log -T XOSCoreAPITests.robot || true
Zack Williams15bc4a52018-07-23 15:31:58 -0700376
377 # do additional tests if services are loaded
378 if ! [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester|helm-charts)\$ ]]; then
379 export testname=_service_api.robot
380 export library=_library.robot
381 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
382 echo \$SERVICES
383
Kailashf14606e2018-12-06 14:11:11 -0800384 for i in \$SERVICES; do bash -c "robot -d Log -T -v TESTLIBRARY:\$i\$library \$i\$testname"; sleep 2; done || true
Zack Williams15bc4a52018-07-23 15:31:58 -0700385 fi
386
387 popd
388 """
389 }
390 }
391
392 stage('Publish') {
393 steps {
394 sh """
395 if [ -d RobotLogs ]; then rm -r RobotLogs; fi; mkdir RobotLogs
396 cp -r $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/Log/*ml ./RobotLogs
397 """
398
399 step([$class: 'RobotPublisher',
400 disableArchiveOutput: false,
401 logFileName: 'RobotLogs/log*.html',
402 otherFiles: '',
403 outputFileName: 'RobotLogs/output*.xml',
404 outputPath: '.',
Kailash Khalasiad6cfda2018-07-25 11:31:35 -0700405 passThreshold: 100,
Zack Williams15bc4a52018-07-23 15:31:58 -0700406 reportFileName: 'RobotLogs/report*.html',
407 unstableThreshold: 0]);
408 }
409 }
410
411 }
412
413 post {
414 always {
415 sh '''
Kailash Khalasiecb4eb62018-07-31 15:20:19 -0700416 for pod in \$(kubectl get pods --no-headers | awk '{print \$1}');
417 do
418 kubectl logs \$pod > $WORKSPACE/\$pod.log;
419 done
420
Zack Williams15bc4a52018-07-23 15:31:58 -0700421 kubectl get pods --all-namespaces
422
423 echo "# removing helm deployments"
424 kubectl get pods
425 helm list
426
427 for hchart in \$(helm list -q);
428 do
429 echo "## Purging chart: \${hchart} ##"
430 helm delete --purge "\${hchart}"
431 done
432
433 sudo minikube delete
434 '''
Kailash Khalasiecb4eb62018-07-31 15:20:19 -0700435 archiveArtifacts artifacts: '*.log'
Zack Williams15bc4a52018-07-23 15:31:58 -0700436 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "suchitra@opennetworking.org, you@opennetworking.org, kailash@opennetworking.org", sendToIndividuals: false])
437 }
438 }
439}