blob: a4c715e409cb1c39a9fc04422dd0158dcd92ada3 [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
Zack Williams1f672932018-07-24 11:24:10 -0700119 echo "" > \${WORKSPACE}/updated_dockerfiles
Zack Williams15bc4a52018-07-23 15:31:58 -0700120 XOS_MAJOR=\$(cut -b 1 cord/orchestration/xos/VERSION)
Zack Williams66500002018-09-06 15:29:05 -0700121 XOS_VERSION=\$(cat cord/orchestration/xos/VERSION)
Zack Williams1f672932018-07-24 11:24:10 -0700122
Zack Williams66500002018-09-06 15:29:05 -0700123 # update services
Zack Williams15bc4a52018-07-23 15:31:58 -0700124 for df in cord/orchestration/xos_services/*/Dockerfile.synchronizer cord/orchestration/profiles/*/Dockerfile.synchronizer
125 do
Kailash Khalasi70b626e2018-08-21 11:12:02 -0700126 df_contents=\$(cat "\$df")
Zack Williams42acdd12018-08-17 13:58:07 -0700127 if [[ "\$df_contents" =~ "FROM xosproject/xos-synchronizer-base:\${XOS_MAJOR}" ||
128 "\$df_contents" =~ "FROM xosproject/xos-synchronizer-base:master" ]]
129 then
Zack Williams66500002018-09-06 15:29:05 -0700130 sed -i "s/^FROM\\(.*\\):.*\$/FROM\\1:\$XOS_VERSION/" "\$df"
Zack Williams42acdd12018-08-17 13:58:07 -0700131 echo "\${WORKSPACE}/\$df" >> \${WORKSPACE}/updated_dockerfiles
132 fi
Zack Williams15bc4a52018-07-23 15:31:58 -0700133 done
Zack Williams66500002018-09-06 15:29:05 -0700134
135 # create values file with core version tags
Zack Williams9b6b5eb2018-09-14 13:45:18 -0700136 # not indented because heredoc requires it
Zack Williams66500002018-09-06 15:29:05 -0700137 cat << EOF > \${WORKSPACE}/xos_tags.yaml
Zack Williams9b6b5eb2018-09-14 13:45:18 -0700138---
139xos_coreImage: 'xosproject/xos-core:\${XOS_VERSION}'
140xos_chameleonImage: 'xosproject/chameleon:\${XOS_VERSION}'
141xos_toscaImage: 'xosproject/xos-tosca:\${XOS_VERSION}'
142EOF
Zack Williams15bc4a52018-07-23 15:31:58 -0700143 """
144 }
145 }
146
Zack Williams1f672932018-07-24 11:24:10 -0700147 stage('unittest') {
148 steps {
149 sh """
150 #!/usr/bin/env bash
151 set -e -o pipefail
152
153 cd "\${WORKSPACE}"
154
155 export XOS_DIR=\${WORKSPACE}/cord/orchestration/xos
156 \$XOS_DIR/scripts/setup_venv.sh
157 source "\${WORKSPACE}/venv-xos/bin/activate"
158
159 for df in \$(cat "\${WORKSPACE}/updated_dockerfiles")
160 do
161 projectdir=\$(dirname "\${df}")
162 if [ -e "\${projectdir}/xos/unittest.cfg" ]
163 then
164 pushd \${projectdir}/xos
165 echo "Performing nose2 tests"
166 nose2 --verbose --coverage-report xml --coverage-report term --junit-xml
167 popd
168 else
169 echo "No unit tests found for project \$(basename \${projectdir})"
170 fi
171 done
172 """
173 junit '**/nose2-junit.xml'
174 cobertura coberturaReportFile: '**/coverage.xml', fileCoverageTargets: '80, 0, 0', methodCoverageTargets: '50, 0, 0'
175 }
176 }
177
Zack Williams15bc4a52018-07-23 15:31:58 -0700178 stage('prep') {
179 parallel {
180
181 stage('images') {
182 steps {
183 sh '''
184 pushd cord/automation-tools/developer
185 mkdir ib_logs
186 ./imagebuilder.py -l ib_logs -a ib_actions.yml -g ib_graph.dot -f ../../helm-charts/examples/filter-images.yaml
187 popd
188 '''
189 archiveArtifacts artifacts: 'cord/automation-tools/developer/ib_actions.yml, cord/automation-tools/developer/ib_graph.dot, cord/automation-tools/developer/ib_logs/*', fingerprint: true
190 }
191 }
192
193 stage('minikube') {
194 steps {
195 /* see https://github.com/kubernetes/minikube/#linux-continuous-integration-without-vm-support */
196 sh '''
197 export MINIKUBE_WANTUPDATENOTIFICATION=false
198 export MINIKUBE_WANTREPORTERRORPROMPT=false
199 export CHANGE_MINIKUBE_NONE_USER=true
200 export MINIKUBE_HOME=$HOME
201 mkdir -p $HOME/.kube || true
202 touch $HOME/.kube/config
203 export KUBECONFIG=$HOME/.kube/config
204 sudo -E /usr/bin/minikube start --vm-driver=none
205 '''
206 script {
207 timeout(3) {
208 waitUntil {
209 sleep 5
210 def kc_ret = sh script: "kubectl get po", returnStatus: true
211 return (kc_ret == 0);
212 }
213 }
214 }
215 }
216 }
217 }
218 }
219
220 stage('helm') {
221 steps {
222 sh '''
223 helm init
224 sleep 60
225 helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/
226 '''
227 }
228 }
229
230 stage('build') {
231 steps {
232 sh """
233 #!/usr/bin/env bash
234 set -eu -o pipefail
235
Zack Williams66500002018-09-06 15:29:05 -0700236 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 -0700237
238 pushd cord/helm-charts
239
240 helm dep up xos-core
241 helm install \${helm_install_args} xos-core -n xos-core
242
243 # Pick which chart(s) to load depending on the project being tested
244 # In regex, please list repos in same order as requirements.yaml in the chart(s) loaded!
245
246 if [[ "$GERRIT_PROJECT" =~ ^(rcord|onos-service|fabric|olt-service|vsg-hw|vrouter)\$ ]]; then
247 helm dep update xos-profiles/rcord-lite
248 helm install \${helm_install_args} xos-profiles/rcord-lite -n rcord-lite
Zack Williams15bc4a52018-07-23 15:31:58 -0700249
250 elif [[ "$GERRIT_PROJECT" =~ ^(vMME|vspgwc|vspgwu|vHSS|hss_db|internetemulator|sdn-controller|epc-service|mcord|progran)\$ ]]; then
251 helm dep update xos-profiles/base-openstack
252 helm dep update xos-profiles/mcord
253 helm install \${helm_install_args} xos-profiles/base-openstack -n base-openstack
254 helm install \${helm_install_args} xos-profiles/mcord -n mcord
Zack Williams15bc4a52018-07-23 15:31:58 -0700255
256 elif [[ "$GERRIT_PROJECT" =~ ^(openstack|vtn-service|exampleservice|addressmanager)\$ ]]; then
257 # NOTE: onos-service is included in base-openstack, but tested w/rcord-lite chart
258
259 helm dep update xos-profiles/base-openstack
260 helm dep update xos-profiles/demo-exampleservice
261 helm install \${helm_install_args} xos-profiles/base-openstack -n base-openstack
262 helm install \${helm_install_args} xos-profiles/demo-exampleservice -n demo-exampleservice
263
264 elif [[ "$GERRIT_PROJECT" =~ ^(kubernetes-service|simpleexampleservice)\$ ]]; then
265 helm dep update xos-profiles/base-kubernetes
266 helm dep update xos-profiles/demo-simpleexampleservice
267 helm install \${helm_install_args} xos-profiles/base-kubernetes -n base-kubernetes
268 helm install \${helm_install_args} xos-profiles/demo-simpleexampleservice -n demo-simpleexampleservice
269
270 elif [[ "$GERRIT_PROJECT" =~ ^(hippie-oss)\$ ]]; then
271 helm dep update xos-services/hippie-oss
272 helm install \${helm_install_args} xos-services/hippie-oss -n hippie-oss
273
274 elif [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester|helm-charts)\$ ]]; then
275 echo "No additional charts to install for testing $GERRIT_PROJECT"
276
277 else
278 echo "Couldn't find a chart to test project: $GERRIT_PROJECT!"
279 exit 1
280 fi
281
Kailash Khalasi2bc499b2018-07-25 16:10:11 -0700282 # wait for services to load
Kailash Khalasiedb48b12018-07-31 13:01:01 -0700283 JOBS_TIMEOUT=900 ./scripts/wait_for_jobs.sh
Kailash Khalasi512a7e52018-07-30 09:12:16 -0700284
Zack Williams15bc4a52018-07-23 15:31:58 -0700285 echo "# Checking helm deployments"
286 kubectl get pods
287 helm list
288
289 for hchart in \$(helm list -q);
290 do
291 echo "## 'helm status' for chart: \${hchart} ##"
292 helm status "\${hchart}"
293 done
294
295 popd
296 """
297 }
298 }
299
Kailash Khalasi512a7e52018-07-30 09:12:16 -0700300 stage('wait for core') {
301 steps {
302 timeout(time:5) {
303 waitUntil {
304 script {
305 try {
306 sh """
307 CORE_POD=\$(kubectl get pods | grep xos-core | awk '{print \$1}')
308 CHAM_POD=\$(kubectl get pods | grep chameleon | awk '{print \$1}')
309 CHAM_CONTAINER=\$(docker ps | grep k8s_xos-chameleon | awk '{print \$1}')
310 XOS_CHAMELEON=\$(docker exec \$CHAM_CONTAINER ip a | grep -oE "([0-9]{1,3}\\.){3}[0-9]{1,3}\\b" | grep 172)
311 kubectl logs \$CORE_POD | grep "XOS core entering wait loop"
Kailash Khalasi512a7e52018-07-30 09:12:16 -0700312 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 -0700313 sleep 30
Kailash Khalasi25ee0722018-07-30 14:26:41 -0700314 curl -I -u admin@opencord.org:letmein http://\$XOS_CHAMELEON:9101/xosapi/v1/core/sites | grep "200 OK"
315 """
Kailash Khalasi512a7e52018-07-30 09:12:16 -0700316 return true
317 } catch (exception) {
318 return false
319 }
320 }
321 }
322 }
323 }
324 }
325
Zack Williams15bc4a52018-07-23 15:31:58 -0700326 stage('setup') {
327 steps {
328 sh """
329 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
330
331 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
332 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
333 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
334 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
335
336 # create additional testing files if services are loaded
337 if ! [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester|helm-charts)\$ ]]; then
338 export testname=_service_api.robot
339 export library=_library.robot
340
341 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
342 echo \$SERVICES
343
344 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
345
346 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
347 fi
348 """
349 }
350 }
351
352 stage('test') {
353 steps {
354 sh """
355 pushd cord/test/cord-tester/src/test/cord-api/Tests
356
357 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
358 CHAM_CONTAINER=\$(docker ps | grep k8s_xos-chameleon | awk '{print \$1}')
359 XOS_CHAMELEON=\$(docker exec \$CHAM_CONTAINER ip a | grep -oE "([0-9]{1,3}\\.){3}[0-9]{1,3}\\b" | grep 172)
360
361 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Properties/
362 sed -i \"s/^\\(SERVER_IP = \\).*/\\1\'\$XOS_CHAMELEON\'/\" RestApiProperties.py
363 sed -i \"s/^\\(SERVER_PORT = \\).*/\\1\'9101\'/\" RestApiProperties.py
364 sed -i \"s/^\\(XOS_USER = \\).*/\\1\'admin@opencord.org\'/\" RestApiProperties.py
365 sed -i \"s/^\\(XOS_PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
366 sed -i \"s/^\\(PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
367
368 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests
Kailash Khalasi07c97a42018-08-06 12:15:43 -0700369 pybot -d Log -T XOSCoreAPITests.robot || true
Zack Williams15bc4a52018-07-23 15:31:58 -0700370
371 # do additional tests if services are loaded
372 if ! [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester|helm-charts)\$ ]]; then
373 export testname=_service_api.robot
374 export library=_library.robot
375 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
376 echo \$SERVICES
377
Kailash Khalasi07c97a42018-08-06 12:15:43 -0700378 for i in \$SERVICES; do bash -c "pybot -d Log -T -v TESTLIBRARY:\$i\$library \$i\$testname"; sleep 2; done || true
Zack Williams15bc4a52018-07-23 15:31:58 -0700379 fi
380
381 popd
382 """
383 }
384 }
385
386 stage('Publish') {
387 steps {
388 sh """
389 if [ -d RobotLogs ]; then rm -r RobotLogs; fi; mkdir RobotLogs
390 cp -r $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/Log/*ml ./RobotLogs
391 """
392
393 step([$class: 'RobotPublisher',
394 disableArchiveOutput: false,
395 logFileName: 'RobotLogs/log*.html',
396 otherFiles: '',
397 outputFileName: 'RobotLogs/output*.xml',
398 outputPath: '.',
Kailash Khalasiad6cfda2018-07-25 11:31:35 -0700399 passThreshold: 100,
Zack Williams15bc4a52018-07-23 15:31:58 -0700400 reportFileName: 'RobotLogs/report*.html',
401 unstableThreshold: 0]);
402 }
403 }
404
405 }
406
407 post {
408 always {
409 sh '''
Kailash Khalasiecb4eb62018-07-31 15:20:19 -0700410 for pod in \$(kubectl get pods --no-headers | awk '{print \$1}');
411 do
412 kubectl logs \$pod > $WORKSPACE/\$pod.log;
413 done
414
Zack Williams15bc4a52018-07-23 15:31:58 -0700415 kubectl get pods --all-namespaces
416
417 echo "# removing helm deployments"
418 kubectl get pods
419 helm list
420
421 for hchart in \$(helm list -q);
422 do
423 echo "## Purging chart: \${hchart} ##"
424 helm delete --purge "\${hchart}"
425 done
426
427 sudo minikube delete
428 '''
Kailash Khalasiecb4eb62018-07-31 15:20:19 -0700429 archiveArtifacts artifacts: '*.log'
Zack Williams15bc4a52018-07-23 15:31:58 -0700430 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "suchitra@opennetworking.org, you@opennetworking.org, kailash@opennetworking.org", sendToIndividuals: false])
431 }
432 }
433}