blob: 9f38652061748cd1835ff9b020a1f290f8e9912b [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"
Kailash Khalasi49097db2018-07-26 14:14:34 -0700256 # ADDING TEMP SLEEP UNIL SEBA-102 resolves
257 sleep 300
Zack Williams15bc4a52018-07-23 15:31:58 -0700258
259 else
260 echo "Couldn't find a chart to test project: $GERRIT_PROJECT!"
261 exit 1
262 fi
263
Kailash Khalasi2bc499b2018-07-25 16:10:11 -0700264 # wait for services to load
265 ./scripts/wait_for_jobs.sh
Kailash Khalasi512a7e52018-07-30 09:12:16 -0700266
Zack Williams15bc4a52018-07-23 15:31:58 -0700267 echo "# Checking helm deployments"
268 kubectl get pods
269 helm list
270
271 for hchart in \$(helm list -q);
272 do
273 echo "## 'helm status' for chart: \${hchart} ##"
274 helm status "\${hchart}"
275 done
276
277 popd
278 """
279 }
280 }
281
Kailash Khalasi512a7e52018-07-30 09:12:16 -0700282 stage('wait for core') {
283 steps {
284 timeout(time:5) {
285 waitUntil {
286 script {
287 try {
288 sh """
289 CORE_POD=\$(kubectl get pods | grep xos-core | awk '{print \$1}')
290 CHAM_POD=\$(kubectl get pods | grep chameleon | awk '{print \$1}')
291 CHAM_CONTAINER=\$(docker ps | grep k8s_xos-chameleon | awk '{print \$1}')
292 XOS_CHAMELEON=\$(docker exec \$CHAM_CONTAINER ip a | grep -oE "([0-9]{1,3}\\.){3}[0-9]{1,3}\\b" | grep 172)
293 kubectl logs \$CORE_POD | grep "XOS core entering wait loop"
294 kubectl logs \$CHAM_POD | grep reconnected | wc -l | grep 2
295 curl -I -u admin@opencord.org:letmein http://\$XOS_CHAMELEON:9101/xosapi/v1/core/users | grep "200 OK"
296 """
297 return true
298 } catch (exception) {
299 return false
300 }
301 }
302 }
303 }
304 }
305 }
306
Zack Williams15bc4a52018-07-23 15:31:58 -0700307 stage('setup') {
308 steps {
309 sh """
310 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
311
312 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
313 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
314 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
315 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
316
317 # create additional testing files if services are loaded
318 if ! [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester|helm-charts)\$ ]]; then
319 export testname=_service_api.robot
320 export library=_library.robot
321
322 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
323 echo \$SERVICES
324
325 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
326
327 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
328 fi
329 """
330 }
331 }
332
333 stage('test') {
334 steps {
335 sh """
336 pushd cord/test/cord-tester/src/test/cord-api/Tests
337
338 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
339 CHAM_CONTAINER=\$(docker ps | grep k8s_xos-chameleon | awk '{print \$1}')
340 XOS_CHAMELEON=\$(docker exec \$CHAM_CONTAINER ip a | grep -oE "([0-9]{1,3}\\.){3}[0-9]{1,3}\\b" | grep 172)
341
342 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Properties/
343 sed -i \"s/^\\(SERVER_IP = \\).*/\\1\'\$XOS_CHAMELEON\'/\" RestApiProperties.py
344 sed -i \"s/^\\(SERVER_PORT = \\).*/\\1\'9101\'/\" RestApiProperties.py
345 sed -i \"s/^\\(XOS_USER = \\).*/\\1\'admin@opencord.org\'/\" RestApiProperties.py
346 sed -i \"s/^\\(XOS_PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
347 sed -i \"s/^\\(PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
348
349 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests
350 pybot -d Log -T -e TenantWithContainer -e Port -e ControllerImages -e ControllerNetwork -e ControllerSlice -e ControllerUser XOSCoreAPITests.robot || true
351
352 # do additional tests if services are loaded
353 if ! [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester|helm-charts)\$ ]]; then
354 export testname=_service_api.robot
355 export library=_library.robot
356 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
357 echo \$SERVICES
358
359 for i in \$SERVICES; do bash -c "pybot -d Log -T -e AddressManagerServiceInstance -v TESTLIBRARY:\$i\$library \$i\$testname"; sleep 2; done || true
360 fi
361
362 popd
363 """
364 }
365 }
366
367 stage('Publish') {
368 steps {
369 sh """
370 if [ -d RobotLogs ]; then rm -r RobotLogs; fi; mkdir RobotLogs
371 cp -r $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/Log/*ml ./RobotLogs
372 """
373
374 step([$class: 'RobotPublisher',
375 disableArchiveOutput: false,
376 logFileName: 'RobotLogs/log*.html',
377 otherFiles: '',
378 outputFileName: 'RobotLogs/output*.xml',
379 outputPath: '.',
Kailash Khalasiad6cfda2018-07-25 11:31:35 -0700380 passThreshold: 100,
Zack Williams15bc4a52018-07-23 15:31:58 -0700381 reportFileName: 'RobotLogs/report*.html',
382 unstableThreshold: 0]);
383 }
384 }
385
386 }
387
388 post {
389 always {
390 sh '''
391 kubectl get pods --all-namespaces
392
393 echo "# removing helm deployments"
394 kubectl get pods
395 helm list
396
397 for hchart in \$(helm list -q);
398 do
399 echo "## Purging chart: \${hchart} ##"
400 helm delete --purge "\${hchart}"
401 done
402
403 sudo minikube delete
404 '''
405 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "suchitra@opennetworking.org, you@opennetworking.org, kailash@opennetworking.org", sendToIndividuals: false])
406 }
407 }
408}