blob: d2cdfdaf111e1232d370202d23d5230e75a56d62 [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
15// Run XOS api tests after changing the containers to use the `candidate`
16// parent, which may include synchronizer changes
17
18CORE_CONTAINER="null"
19
20pipeline {
21
22 /* no label, executor is determined by JJB */
23 agent {
24 label "${params.executorNode}"
25 }
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 #!/usr/bin/env bash
51 set -eu -o pipefail
52
53 VERSIONFILE="" # file path to file containing version number
54 NEW_VERSION="" # version number found in VERSIONFILE
55 releaseversion=0
56
57 function read_version {
58 if [ -f "VERSION" ]
59 then
60 NEW_VERSION=\$(head -n1 "VERSION")
61 VERSIONFILE="VERSION"
62 elif [ -f "package.json" ]
63 then
64 NEW_VERSION=\$(python -c 'import json,sys;obj=json.load(sys.stdin); print obj["version"]' < package.json)
65 VERSIONFILE="package.json"
66 else
67 echo "ERROR: No versioning file found!"
68 exit 1
69 fi
70 }
71
72 # check if the version is a released version
73 function check_if_releaseversion {
74 if [[ "\$NEW_VERSION" =~ ^([0-9]+)\\.([0-9]+)\\.([0-9]+)\$ ]]
75 then
76 echo "Version string '\$NEW_VERSION' in '\$VERSIONFILE' is a SemVer released version!"
77 releaseversion=1
78 else
79 echo "Version string '\$NEW_VERSION' in '\$VERSIONFILE' is not a SemVer released version, skipping."
80 fi
81 }
82
83 pushd cord
84 PROJECT_PATH=\$(xmllint --xpath "string(//project[@name=\\\"${gerritProject}\\\"]/@path)" .repo/manifest.xml)
85 repo download "\$PROJECT_PATH" "${gerritChangeNumber}/${gerritPatchsetNumber}"
86
87 pushd \$PROJECT_PATH
88 echo "Existing git tags:"
89 git tag -n
90
91 read_version
92 check_if_releaseversion
93
94 # perform checks if a released version
95 if [ "\$releaseversion" -eq "1" ]
96 then
97 git config --global user.email "apitest@opencord.org"
98 git config --global user.name "API Test"
99
100 git tag -a "\$NEW_VERSION" -m "Tagged for api test on Gerrit patchset: ${gerritChangeNumber}"
101
102 echo "Tags including new tag:"
103 git tag -n
104
105 fi
106 popd
107 popd
108 """
109 }
110 }
Zack Williams1f672932018-07-24 11:24:10 -0700111
Zack Williams15bc4a52018-07-23 15:31:58 -0700112 stage('candiate tag') {
113 steps {
114 sh """
Zack Williams1f672932018-07-24 11:24:10 -0700115 echo "" > \${WORKSPACE}/updated_dockerfiles
Zack Williams15bc4a52018-07-23 15:31:58 -0700116 XOS_MAJOR=\$(cut -b 1 cord/orchestration/xos/VERSION)
Zack Williams1f672932018-07-24 11:24:10 -0700117
Zack Williams15bc4a52018-07-23 15:31:58 -0700118 for df in cord/orchestration/xos_services/*/Dockerfile.synchronizer cord/orchestration/profiles/*/Dockerfile.synchronizer
119 do
Kailash Khalasi70b626e2018-08-21 11:12:02 -0700120 df_contents=\$(cat "\$df")
Zack Williams42acdd12018-08-17 13:58:07 -0700121 if [[ "\$df_contents" =~ "FROM xosproject/xos-synchronizer-base:\${XOS_MAJOR}" ||
122 "\$df_contents" =~ "FROM xosproject/xos-synchronizer-base:master" ]]
123 then
124 sed -i "s/^FROM\\(.*\\):.*\$/FROM\\1:candidate/" "\$df"
125 echo "\${WORKSPACE}/\$df" >> \${WORKSPACE}/updated_dockerfiles
126 fi
Zack Williams15bc4a52018-07-23 15:31:58 -0700127 done
128 """
129 }
130 }
131
Zack Williams1f672932018-07-24 11:24:10 -0700132 stage('unittest') {
133 steps {
134 sh """
135 #!/usr/bin/env bash
136 set -e -o pipefail
137
138 cd "\${WORKSPACE}"
139
140 export XOS_DIR=\${WORKSPACE}/cord/orchestration/xos
141 \$XOS_DIR/scripts/setup_venv.sh
142 source "\${WORKSPACE}/venv-xos/bin/activate"
143
144 for df in \$(cat "\${WORKSPACE}/updated_dockerfiles")
145 do
146 projectdir=\$(dirname "\${df}")
147 if [ -e "\${projectdir}/xos/unittest.cfg" ]
148 then
149 pushd \${projectdir}/xos
150 echo "Performing nose2 tests"
151 nose2 --verbose --coverage-report xml --coverage-report term --junit-xml
152 popd
153 else
154 echo "No unit tests found for project \$(basename \${projectdir})"
155 fi
156 done
157 """
158 junit '**/nose2-junit.xml'
159 cobertura coberturaReportFile: '**/coverage.xml', fileCoverageTargets: '80, 0, 0', methodCoverageTargets: '50, 0, 0'
160 }
161 }
162
Zack Williams15bc4a52018-07-23 15:31:58 -0700163 stage('prep') {
164 parallel {
165
166 stage('images') {
167 steps {
168 sh '''
169 pushd cord/automation-tools/developer
170 mkdir ib_logs
171 ./imagebuilder.py -l ib_logs -a ib_actions.yml -g ib_graph.dot -f ../../helm-charts/examples/filter-images.yaml
172 popd
173 '''
174 archiveArtifacts artifacts: 'cord/automation-tools/developer/ib_actions.yml, cord/automation-tools/developer/ib_graph.dot, cord/automation-tools/developer/ib_logs/*', fingerprint: true
175 }
176 }
177
178 stage('minikube') {
179 steps {
180 /* see https://github.com/kubernetes/minikube/#linux-continuous-integration-without-vm-support */
181 sh '''
182 export MINIKUBE_WANTUPDATENOTIFICATION=false
183 export MINIKUBE_WANTREPORTERRORPROMPT=false
184 export CHANGE_MINIKUBE_NONE_USER=true
185 export MINIKUBE_HOME=$HOME
186 mkdir -p $HOME/.kube || true
187 touch $HOME/.kube/config
188 export KUBECONFIG=$HOME/.kube/config
189 sudo -E /usr/bin/minikube start --vm-driver=none
190 '''
191 script {
192 timeout(3) {
193 waitUntil {
194 sleep 5
195 def kc_ret = sh script: "kubectl get po", returnStatus: true
196 return (kc_ret == 0);
197 }
198 }
199 }
200 }
201 }
202 }
203 }
204
205 stage('helm') {
206 steps {
207 sh '''
208 helm init
209 sleep 60
210 helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/
211 '''
212 }
213 }
214
215 stage('build') {
216 steps {
217 sh """
218 #!/usr/bin/env bash
219 set -eu -o pipefail
220
221 helm_install_args='-f examples/image-tag-candidate.yaml -f examples/imagePullPolicy-IfNotPresent.yaml -f examples/api-test-values.yaml'
Zack Williams15bc4a52018-07-23 15:31:58 -0700222
223 pushd cord/helm-charts
224
225 helm dep up xos-core
226 helm install \${helm_install_args} xos-core -n xos-core
227
228 # Pick which chart(s) to load depending on the project being tested
229 # In regex, please list repos in same order as requirements.yaml in the chart(s) loaded!
230
231 if [[ "$GERRIT_PROJECT" =~ ^(rcord|onos-service|fabric|olt-service|vsg-hw|vrouter)\$ ]]; then
232 helm dep update xos-profiles/rcord-lite
233 helm install \${helm_install_args} xos-profiles/rcord-lite -n rcord-lite
Zack Williams15bc4a52018-07-23 15:31:58 -0700234
235 elif [[ "$GERRIT_PROJECT" =~ ^(vMME|vspgwc|vspgwu|vHSS|hss_db|internetemulator|sdn-controller|epc-service|mcord|progran)\$ ]]; then
236 helm dep update xos-profiles/base-openstack
237 helm dep update xos-profiles/mcord
238 helm install \${helm_install_args} xos-profiles/base-openstack -n base-openstack
239 helm install \${helm_install_args} xos-profiles/mcord -n mcord
Zack Williams15bc4a52018-07-23 15:31:58 -0700240
241 elif [[ "$GERRIT_PROJECT" =~ ^(openstack|vtn-service|exampleservice|addressmanager)\$ ]]; then
242 # NOTE: onos-service is included in base-openstack, but tested w/rcord-lite chart
243
244 helm dep update xos-profiles/base-openstack
245 helm dep update xos-profiles/demo-exampleservice
246 helm install \${helm_install_args} xos-profiles/base-openstack -n base-openstack
247 helm install \${helm_install_args} xos-profiles/demo-exampleservice -n demo-exampleservice
248
249 elif [[ "$GERRIT_PROJECT" =~ ^(kubernetes-service|simpleexampleservice)\$ ]]; then
250 helm dep update xos-profiles/base-kubernetes
251 helm dep update xos-profiles/demo-simpleexampleservice
252 helm install \${helm_install_args} xos-profiles/base-kubernetes -n base-kubernetes
253 helm install \${helm_install_args} xos-profiles/demo-simpleexampleservice -n demo-simpleexampleservice
254
255 elif [[ "$GERRIT_PROJECT" =~ ^(hippie-oss)\$ ]]; then
256 helm dep update xos-services/hippie-oss
257 helm install \${helm_install_args} xos-services/hippie-oss -n hippie-oss
258
259 elif [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester|helm-charts)\$ ]]; then
260 echo "No additional charts to install for testing $GERRIT_PROJECT"
261
262 else
263 echo "Couldn't find a chart to test project: $GERRIT_PROJECT!"
264 exit 1
265 fi
266
Kailash Khalasi2bc499b2018-07-25 16:10:11 -0700267 # wait for services to load
Kailash Khalasiedb48b12018-07-31 13:01:01 -0700268 JOBS_TIMEOUT=900 ./scripts/wait_for_jobs.sh
Kailash Khalasi512a7e52018-07-30 09:12:16 -0700269
Zack Williams15bc4a52018-07-23 15:31:58 -0700270 echo "# Checking helm deployments"
271 kubectl get pods
272 helm list
273
274 for hchart in \$(helm list -q);
275 do
276 echo "## 'helm status' for chart: \${hchart} ##"
277 helm status "\${hchart}"
278 done
279
280 popd
281 """
282 }
283 }
284
Kailash Khalasi512a7e52018-07-30 09:12:16 -0700285 stage('wait for core') {
286 steps {
287 timeout(time:5) {
288 waitUntil {
289 script {
290 try {
291 sh """
292 CORE_POD=\$(kubectl get pods | grep xos-core | awk '{print \$1}')
293 CHAM_POD=\$(kubectl get pods | grep chameleon | awk '{print \$1}')
294 CHAM_CONTAINER=\$(docker ps | grep k8s_xos-chameleon | awk '{print \$1}')
295 XOS_CHAMELEON=\$(docker exec \$CHAM_CONTAINER ip a | grep -oE "([0-9]{1,3}\\.){3}[0-9]{1,3}\\b" | grep 172)
296 kubectl logs \$CORE_POD | grep "XOS core entering wait loop"
Kailash Khalasi512a7e52018-07-30 09:12:16 -0700297 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 -0700298 sleep 30
Kailash Khalasi25ee0722018-07-30 14:26:41 -0700299 curl -I -u admin@opencord.org:letmein http://\$XOS_CHAMELEON:9101/xosapi/v1/core/sites | grep "200 OK"
300 """
Kailash Khalasi512a7e52018-07-30 09:12:16 -0700301 return true
302 } catch (exception) {
303 return false
304 }
305 }
306 }
307 }
308 }
309 }
310
Zack Williams15bc4a52018-07-23 15:31:58 -0700311 stage('setup') {
312 steps {
313 sh """
314 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
315
316 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
317 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
318 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
319 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
320
321 # create additional testing files if services are loaded
322 if ! [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester|helm-charts)\$ ]]; then
323 export testname=_service_api.robot
324 export library=_library.robot
325
326 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
327 echo \$SERVICES
328
329 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
330
331 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
332 fi
333 """
334 }
335 }
336
337 stage('test') {
338 steps {
339 sh """
340 pushd cord/test/cord-tester/src/test/cord-api/Tests
341
342 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
343 CHAM_CONTAINER=\$(docker ps | grep k8s_xos-chameleon | awk '{print \$1}')
344 XOS_CHAMELEON=\$(docker exec \$CHAM_CONTAINER ip a | grep -oE "([0-9]{1,3}\\.){3}[0-9]{1,3}\\b" | grep 172)
345
346 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Properties/
347 sed -i \"s/^\\(SERVER_IP = \\).*/\\1\'\$XOS_CHAMELEON\'/\" RestApiProperties.py
348 sed -i \"s/^\\(SERVER_PORT = \\).*/\\1\'9101\'/\" RestApiProperties.py
349 sed -i \"s/^\\(XOS_USER = \\).*/\\1\'admin@opencord.org\'/\" RestApiProperties.py
350 sed -i \"s/^\\(XOS_PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
351 sed -i \"s/^\\(PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
352
353 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests
Kailash Khalasi07c97a42018-08-06 12:15:43 -0700354 pybot -d Log -T XOSCoreAPITests.robot || true
Zack Williams15bc4a52018-07-23 15:31:58 -0700355
356 # do additional tests if services are loaded
357 if ! [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester|helm-charts)\$ ]]; then
358 export testname=_service_api.robot
359 export library=_library.robot
360 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
361 echo \$SERVICES
362
Kailash Khalasi07c97a42018-08-06 12:15:43 -0700363 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 -0700364 fi
365
366 popd
367 """
368 }
369 }
370
371 stage('Publish') {
372 steps {
373 sh """
374 if [ -d RobotLogs ]; then rm -r RobotLogs; fi; mkdir RobotLogs
375 cp -r $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/Log/*ml ./RobotLogs
376 """
377
378 step([$class: 'RobotPublisher',
379 disableArchiveOutput: false,
380 logFileName: 'RobotLogs/log*.html',
381 otherFiles: '',
382 outputFileName: 'RobotLogs/output*.xml',
383 outputPath: '.',
Kailash Khalasiad6cfda2018-07-25 11:31:35 -0700384 passThreshold: 100,
Zack Williams15bc4a52018-07-23 15:31:58 -0700385 reportFileName: 'RobotLogs/report*.html',
386 unstableThreshold: 0]);
387 }
388 }
389
390 }
391
392 post {
393 always {
394 sh '''
Kailash Khalasiecb4eb62018-07-31 15:20:19 -0700395 for pod in \$(kubectl get pods --no-headers | awk '{print \$1}');
396 do
397 kubectl logs \$pod > $WORKSPACE/\$pod.log;
398 done
399
Zack Williams15bc4a52018-07-23 15:31:58 -0700400 kubectl get pods --all-namespaces
401
402 echo "# removing helm deployments"
403 kubectl get pods
404 helm list
405
406 for hchart in \$(helm list -q);
407 do
408 echo "## Purging chart: \${hchart} ##"
409 helm delete --purge "\${hchart}"
410 done
411
412 sudo minikube delete
413 '''
Kailash Khalasiecb4eb62018-07-31 15:20:19 -0700414 archiveArtifacts artifacts: '*.log'
Zack Williams15bc4a52018-07-23 15:31:58 -0700415 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "suchitra@opennetworking.org, you@opennetworking.org, kailash@opennetworking.org", sendToIndividuals: false])
416 }
417 }
418}