blob: 5a08c962708f77c6aa70fc3b2fb0756f1d82fe9d [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
266
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
282 stage('setup') {
283 steps {
284 sh """
285 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
286
287 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
288 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
289 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
290 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
291
292 # create additional testing files if services are loaded
293 if ! [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester|helm-charts)\$ ]]; then
294 export testname=_service_api.robot
295 export library=_library.robot
296
297 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
298 echo \$SERVICES
299
300 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
301
302 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
303 fi
304 """
305 }
306 }
307
308 stage('test') {
309 steps {
310 sh """
311 pushd cord/test/cord-tester/src/test/cord-api/Tests
312
313 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
314 CHAM_CONTAINER=\$(docker ps | grep k8s_xos-chameleon | awk '{print \$1}')
315 XOS_CHAMELEON=\$(docker exec \$CHAM_CONTAINER ip a | grep -oE "([0-9]{1,3}\\.){3}[0-9]{1,3}\\b" | grep 172)
316
317 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Properties/
318 sed -i \"s/^\\(SERVER_IP = \\).*/\\1\'\$XOS_CHAMELEON\'/\" RestApiProperties.py
319 sed -i \"s/^\\(SERVER_PORT = \\).*/\\1\'9101\'/\" RestApiProperties.py
320 sed -i \"s/^\\(XOS_USER = \\).*/\\1\'admin@opencord.org\'/\" RestApiProperties.py
321 sed -i \"s/^\\(XOS_PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
322 sed -i \"s/^\\(PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
323
324 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests
325 pybot -d Log -T -e TenantWithContainer -e Port -e ControllerImages -e ControllerNetwork -e ControllerSlice -e ControllerUser XOSCoreAPITests.robot || true
326
327 # do additional tests if services are loaded
328 if ! [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester|helm-charts)\$ ]]; then
329 export testname=_service_api.robot
330 export library=_library.robot
331 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
332 echo \$SERVICES
333
334 for i in \$SERVICES; do bash -c "pybot -d Log -T -e AddressManagerServiceInstance -v TESTLIBRARY:\$i\$library \$i\$testname"; sleep 2; done || true
335 fi
336
337 popd
338 """
339 }
340 }
341
342 stage('Publish') {
343 steps {
344 sh """
345 if [ -d RobotLogs ]; then rm -r RobotLogs; fi; mkdir RobotLogs
346 cp -r $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/Log/*ml ./RobotLogs
347 """
348
349 step([$class: 'RobotPublisher',
350 disableArchiveOutput: false,
351 logFileName: 'RobotLogs/log*.html',
352 otherFiles: '',
353 outputFileName: 'RobotLogs/output*.xml',
354 outputPath: '.',
Kailash Khalasiad6cfda2018-07-25 11:31:35 -0700355 passThreshold: 100,
Zack Williams15bc4a52018-07-23 15:31:58 -0700356 reportFileName: 'RobotLogs/report*.html',
357 unstableThreshold: 0]);
358 }
359 }
360
361 }
362
363 post {
364 always {
365 sh '''
366 kubectl get pods --all-namespaces
367
368 echo "# removing helm deployments"
369 kubectl get pods
370 helm list
371
372 for hchart in \$(helm list -q);
373 do
374 echo "## Purging chart: \${hchart} ##"
375 helm delete --purge "\${hchart}"
376 done
377
378 sudo minikube delete
379 '''
380 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "suchitra@opennetworking.org, you@opennetworking.org, kailash@opennetworking.org", sendToIndividuals: false])
381 }
382 }
383}