blob: 783df49fa92462945b1924582cb363c4a0a545c2 [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
120 sed -i "s/^FROM\\(.*\\):\${XOS_MAJOR}.*\$/FROM\\1:candidate/" "\$df"
Zack Williams1f672932018-07-24 11:24:10 -0700121 echo "\${WORKSPACE}/\$df" >> \${WORKSPACE}/updated_dockerfiles
Zack Williams15bc4a52018-07-23 15:31:58 -0700122 done
123 """
124 }
125 }
126
Zack Williams1f672932018-07-24 11:24:10 -0700127 stage('unittest') {
128 steps {
129 sh """
130 #!/usr/bin/env bash
131 set -e -o pipefail
132
133 cd "\${WORKSPACE}"
134
135 export XOS_DIR=\${WORKSPACE}/cord/orchestration/xos
136 \$XOS_DIR/scripts/setup_venv.sh
137 source "\${WORKSPACE}/venv-xos/bin/activate"
138
139 for df in \$(cat "\${WORKSPACE}/updated_dockerfiles")
140 do
141 projectdir=\$(dirname "\${df}")
142 if [ -e "\${projectdir}/xos/unittest.cfg" ]
143 then
144 pushd \${projectdir}/xos
145 echo "Performing nose2 tests"
146 nose2 --verbose --coverage-report xml --coverage-report term --junit-xml
147 popd
148 else
149 echo "No unit tests found for project \$(basename \${projectdir})"
150 fi
151 done
152 """
153 junit '**/nose2-junit.xml'
154 cobertura coberturaReportFile: '**/coverage.xml', fileCoverageTargets: '80, 0, 0', methodCoverageTargets: '50, 0, 0'
155 }
156 }
157
Zack Williams15bc4a52018-07-23 15:31:58 -0700158 stage('prep') {
159 parallel {
160
161 stage('images') {
162 steps {
163 sh '''
164 pushd cord/automation-tools/developer
165 mkdir ib_logs
166 ./imagebuilder.py -l ib_logs -a ib_actions.yml -g ib_graph.dot -f ../../helm-charts/examples/filter-images.yaml
167 popd
168 '''
169 archiveArtifacts artifacts: 'cord/automation-tools/developer/ib_actions.yml, cord/automation-tools/developer/ib_graph.dot, cord/automation-tools/developer/ib_logs/*', fingerprint: true
170 }
171 }
172
173 stage('minikube') {
174 steps {
175 /* see https://github.com/kubernetes/minikube/#linux-continuous-integration-without-vm-support */
176 sh '''
177 export MINIKUBE_WANTUPDATENOTIFICATION=false
178 export MINIKUBE_WANTREPORTERRORPROMPT=false
179 export CHANGE_MINIKUBE_NONE_USER=true
180 export MINIKUBE_HOME=$HOME
181 mkdir -p $HOME/.kube || true
182 touch $HOME/.kube/config
183 export KUBECONFIG=$HOME/.kube/config
184 sudo -E /usr/bin/minikube start --vm-driver=none
185 '''
186 script {
187 timeout(3) {
188 waitUntil {
189 sleep 5
190 def kc_ret = sh script: "kubectl get po", returnStatus: true
191 return (kc_ret == 0);
192 }
193 }
194 }
195 }
196 }
197 }
198 }
199
200 stage('helm') {
201 steps {
202 sh '''
203 helm init
204 sleep 60
205 helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/
206 '''
207 }
208 }
209
210 stage('build') {
211 steps {
212 sh """
213 #!/usr/bin/env bash
214 set -eu -o pipefail
215
216 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 -0700217
218 pushd cord/helm-charts
219
220 helm dep up xos-core
221 helm install \${helm_install_args} xos-core -n xos-core
222
223 # Pick which chart(s) to load depending on the project being tested
224 # In regex, please list repos in same order as requirements.yaml in the chart(s) loaded!
225
226 if [[ "$GERRIT_PROJECT" =~ ^(rcord|onos-service|fabric|olt-service|vsg-hw|vrouter)\$ ]]; then
227 helm dep update xos-profiles/rcord-lite
228 helm install \${helm_install_args} xos-profiles/rcord-lite -n rcord-lite
Zack Williams15bc4a52018-07-23 15:31:58 -0700229
230 elif [[ "$GERRIT_PROJECT" =~ ^(vMME|vspgwc|vspgwu|vHSS|hss_db|internetemulator|sdn-controller|epc-service|mcord|progran)\$ ]]; then
231 helm dep update xos-profiles/base-openstack
232 helm dep update xos-profiles/mcord
233 helm install \${helm_install_args} xos-profiles/base-openstack -n base-openstack
234 helm install \${helm_install_args} xos-profiles/mcord -n mcord
Zack Williams15bc4a52018-07-23 15:31:58 -0700235
236 elif [[ "$GERRIT_PROJECT" =~ ^(openstack|vtn-service|exampleservice|addressmanager)\$ ]]; then
237 # NOTE: onos-service is included in base-openstack, but tested w/rcord-lite chart
238
239 helm dep update xos-profiles/base-openstack
240 helm dep update xos-profiles/demo-exampleservice
241 helm install \${helm_install_args} xos-profiles/base-openstack -n base-openstack
242 helm install \${helm_install_args} xos-profiles/demo-exampleservice -n demo-exampleservice
243
244 elif [[ "$GERRIT_PROJECT" =~ ^(kubernetes-service|simpleexampleservice)\$ ]]; then
245 helm dep update xos-profiles/base-kubernetes
246 helm dep update xos-profiles/demo-simpleexampleservice
247 helm install \${helm_install_args} xos-profiles/base-kubernetes -n base-kubernetes
248 helm install \${helm_install_args} xos-profiles/demo-simpleexampleservice -n demo-simpleexampleservice
249
250 elif [[ "$GERRIT_PROJECT" =~ ^(hippie-oss)\$ ]]; then
251 helm dep update xos-services/hippie-oss
252 helm install \${helm_install_args} xos-services/hippie-oss -n hippie-oss
253
254 elif [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester|helm-charts)\$ ]]; then
255 echo "No additional charts to install for testing $GERRIT_PROJECT"
256
257 else
258 echo "Couldn't find a chart to test project: $GERRIT_PROJECT!"
259 exit 1
260 fi
261
Kailash Khalasi2bc499b2018-07-25 16:10:11 -0700262 # wait for services to load
Kailash Khalasiedb48b12018-07-31 13:01:01 -0700263 JOBS_TIMEOUT=900 ./scripts/wait_for_jobs.sh
Kailash Khalasi512a7e52018-07-30 09:12:16 -0700264
Zack Williams15bc4a52018-07-23 15:31:58 -0700265 echo "# Checking helm deployments"
266 kubectl get pods
267 helm list
268
269 for hchart in \$(helm list -q);
270 do
271 echo "## 'helm status' for chart: \${hchart} ##"
272 helm status "\${hchart}"
273 done
274
275 popd
276 """
277 }
278 }
279
Kailash Khalasi512a7e52018-07-30 09:12:16 -0700280 stage('wait for core') {
281 steps {
282 timeout(time:5) {
283 waitUntil {
284 script {
285 try {
286 sh """
287 CORE_POD=\$(kubectl get pods | grep xos-core | awk '{print \$1}')
288 CHAM_POD=\$(kubectl get pods | grep chameleon | awk '{print \$1}')
289 CHAM_CONTAINER=\$(docker ps | grep k8s_xos-chameleon | awk '{print \$1}')
290 XOS_CHAMELEON=\$(docker exec \$CHAM_CONTAINER ip a | grep -oE "([0-9]{1,3}\\.){3}[0-9]{1,3}\\b" | grep 172)
291 kubectl logs \$CORE_POD | grep "XOS core entering wait loop"
Kailash Khalasi512a7e52018-07-30 09:12:16 -0700292 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 -0700293 sleep 30
Kailash Khalasi25ee0722018-07-30 14:26:41 -0700294 curl -I -u admin@opencord.org:letmein http://\$XOS_CHAMELEON:9101/xosapi/v1/core/sites | grep "200 OK"
295 """
Kailash Khalasi512a7e52018-07-30 09:12:16 -0700296 return true
297 } catch (exception) {
298 return false
299 }
300 }
301 }
302 }
303 }
304 }
305
Zack Williams15bc4a52018-07-23 15:31:58 -0700306 stage('setup') {
307 steps {
308 sh """
309 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
310
311 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
312 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
313 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
314 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
315
316 # create additional testing files if services are loaded
317 if ! [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester|helm-charts)\$ ]]; then
318 export testname=_service_api.robot
319 export library=_library.robot
320
321 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
322 echo \$SERVICES
323
324 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
325
326 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
327 fi
328 """
329 }
330 }
331
332 stage('test') {
333 steps {
334 sh """
335 pushd cord/test/cord-tester/src/test/cord-api/Tests
336
337 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
338 CHAM_CONTAINER=\$(docker ps | grep k8s_xos-chameleon | awk '{print \$1}')
339 XOS_CHAMELEON=\$(docker exec \$CHAM_CONTAINER ip a | grep -oE "([0-9]{1,3}\\.){3}[0-9]{1,3}\\b" | grep 172)
340
341 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Properties/
342 sed -i \"s/^\\(SERVER_IP = \\).*/\\1\'\$XOS_CHAMELEON\'/\" RestApiProperties.py
343 sed -i \"s/^\\(SERVER_PORT = \\).*/\\1\'9101\'/\" RestApiProperties.py
344 sed -i \"s/^\\(XOS_USER = \\).*/\\1\'admin@opencord.org\'/\" RestApiProperties.py
345 sed -i \"s/^\\(XOS_PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
346 sed -i \"s/^\\(PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
347
348 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests
Kailash Khalasi07c97a42018-08-06 12:15:43 -0700349 pybot -d Log -T XOSCoreAPITests.robot || true
Zack Williams15bc4a52018-07-23 15:31:58 -0700350
351 # do additional tests if services are loaded
352 if ! [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester|helm-charts)\$ ]]; then
353 export testname=_service_api.robot
354 export library=_library.robot
355 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
356 echo \$SERVICES
357
Kailash Khalasi07c97a42018-08-06 12:15:43 -0700358 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 -0700359 fi
360
361 popd
362 """
363 }
364 }
365
366 stage('Publish') {
367 steps {
368 sh """
369 if [ -d RobotLogs ]; then rm -r RobotLogs; fi; mkdir RobotLogs
370 cp -r $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/Log/*ml ./RobotLogs
371 """
372
373 step([$class: 'RobotPublisher',
374 disableArchiveOutput: false,
375 logFileName: 'RobotLogs/log*.html',
376 otherFiles: '',
377 outputFileName: 'RobotLogs/output*.xml',
378 outputPath: '.',
Kailash Khalasiad6cfda2018-07-25 11:31:35 -0700379 passThreshold: 100,
Zack Williams15bc4a52018-07-23 15:31:58 -0700380 reportFileName: 'RobotLogs/report*.html',
381 unstableThreshold: 0]);
382 }
383 }
384
385 }
386
387 post {
388 always {
389 sh '''
Kailash Khalasiecb4eb62018-07-31 15:20:19 -0700390 for pod in \$(kubectl get pods --no-headers | awk '{print \$1}');
391 do
392 kubectl logs \$pod > $WORKSPACE/\$pod.log;
393 done
394
Zack Williams15bc4a52018-07-23 15:31:58 -0700395 kubectl get pods --all-namespaces
396
397 echo "# removing helm deployments"
398 kubectl get pods
399 helm list
400
401 for hchart in \$(helm list -q);
402 do
403 echo "## Purging chart: \${hchart} ##"
404 helm delete --purge "\${hchart}"
405 done
406
407 sudo minikube delete
408 '''
Kailash Khalasiecb4eb62018-07-31 15:20:19 -0700409 archiveArtifacts artifacts: '*.log'
Zack Williams15bc4a52018-07-23 15:31:58 -0700410 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "suchitra@opennetworking.org, you@opennetworking.org, kailash@opennetworking.org", sendToIndividuals: false])
411 }
412 }
413}