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