blob: a682c1fdafe201c8ec0161254da90015728d9d84 [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'
217 basesleep=300
218 extrasleep=60
219
220 pushd cord/helm-charts
221
222 helm dep up xos-core
223 helm install \${helm_install_args} xos-core -n xos-core
224
225 # Pick which chart(s) to load depending on the project being tested
226 # In regex, please list repos in same order as requirements.yaml in the chart(s) loaded!
227
228 if [[ "$GERRIT_PROJECT" =~ ^(rcord|onos-service|fabric|olt-service|vsg-hw|vrouter)\$ ]]; then
229 helm dep update xos-profiles/rcord-lite
230 helm install \${helm_install_args} xos-profiles/rcord-lite -n rcord-lite
231 extrasleep=300
232
233 elif [[ "$GERRIT_PROJECT" =~ ^(vMME|vspgwc|vspgwu|vHSS|hss_db|internetemulator|sdn-controller|epc-service|mcord|progran)\$ ]]; then
234 helm dep update xos-profiles/base-openstack
235 helm dep update xos-profiles/mcord
236 helm install \${helm_install_args} xos-profiles/base-openstack -n base-openstack
237 helm install \${helm_install_args} xos-profiles/mcord -n mcord
238 extrasleep=900
239
240 elif [[ "$GERRIT_PROJECT" =~ ^(openstack|vtn-service|exampleservice|addressmanager)\$ ]]; then
241 # NOTE: onos-service is included in base-openstack, but tested w/rcord-lite chart
242
243 helm dep update xos-profiles/base-openstack
244 helm dep update xos-profiles/demo-exampleservice
245 helm install \${helm_install_args} xos-profiles/base-openstack -n base-openstack
246 helm install \${helm_install_args} xos-profiles/demo-exampleservice -n demo-exampleservice
247
248 elif [[ "$GERRIT_PROJECT" =~ ^(kubernetes-service|simpleexampleservice)\$ ]]; then
249 helm dep update xos-profiles/base-kubernetes
250 helm dep update xos-profiles/demo-simpleexampleservice
251 helm install \${helm_install_args} xos-profiles/base-kubernetes -n base-kubernetes
252 helm install \${helm_install_args} xos-profiles/demo-simpleexampleservice -n demo-simpleexampleservice
253
254 elif [[ "$GERRIT_PROJECT" =~ ^(hippie-oss)\$ ]]; then
255 helm dep update xos-services/hippie-oss
256 helm install \${helm_install_args} xos-services/hippie-oss -n hippie-oss
257
258 elif [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester|helm-charts)\$ ]]; then
259 echo "No additional charts to install for testing $GERRIT_PROJECT"
260
261 else
262 echo "Couldn't find a chart to test project: $GERRIT_PROJECT!"
263 exit 1
264 fi
265
266 # sleep to wait for services to load
267 sleep "\$basesleep"
268 sleep "\$extrasleep"
269
270 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
285 stage('setup') {
286 steps {
287 sh """
288 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
289
290 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
291 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
292 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
293 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
294
295 # create additional testing files if services are loaded
296 if ! [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester|helm-charts)\$ ]]; then
297 export testname=_service_api.robot
298 export library=_library.robot
299
300 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
301 echo \$SERVICES
302
303 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
304
305 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
306 fi
307 """
308 }
309 }
310
311 stage('test') {
312 steps {
313 sh """
314 pushd cord/test/cord-tester/src/test/cord-api/Tests
315
316 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
317 CHAM_CONTAINER=\$(docker ps | grep k8s_xos-chameleon | awk '{print \$1}')
318 XOS_CHAMELEON=\$(docker exec \$CHAM_CONTAINER ip a | grep -oE "([0-9]{1,3}\\.){3}[0-9]{1,3}\\b" | grep 172)
319
320 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Properties/
321 sed -i \"s/^\\(SERVER_IP = \\).*/\\1\'\$XOS_CHAMELEON\'/\" RestApiProperties.py
322 sed -i \"s/^\\(SERVER_PORT = \\).*/\\1\'9101\'/\" RestApiProperties.py
323 sed -i \"s/^\\(XOS_USER = \\).*/\\1\'admin@opencord.org\'/\" RestApiProperties.py
324 sed -i \"s/^\\(XOS_PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
325 sed -i \"s/^\\(PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
326
327 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests
328 pybot -d Log -T -e TenantWithContainer -e Port -e ControllerImages -e ControllerNetwork -e ControllerSlice -e ControllerUser XOSCoreAPITests.robot || true
329
330 # do additional tests if services are loaded
331 if ! [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester|helm-charts)\$ ]]; then
332 export testname=_service_api.robot
333 export library=_library.robot
334 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
335 echo \$SERVICES
336
337 for i in \$SERVICES; do bash -c "pybot -d Log -T -e AddressManagerServiceInstance -v TESTLIBRARY:\$i\$library \$i\$testname"; sleep 2; done || true
338 fi
339
340 popd
341 """
342 }
343 }
344
345 stage('Publish') {
346 steps {
347 sh """
348 if [ -d RobotLogs ]; then rm -r RobotLogs; fi; mkdir RobotLogs
349 cp -r $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/Log/*ml ./RobotLogs
350 """
351
352 step([$class: 'RobotPublisher',
353 disableArchiveOutput: false,
354 logFileName: 'RobotLogs/log*.html',
355 otherFiles: '',
356 outputFileName: 'RobotLogs/output*.xml',
357 outputPath: '.',
358 passThreshold: 95,
359 reportFileName: 'RobotLogs/report*.html',
360 unstableThreshold: 0]);
361 }
362 }
363
364 }
365
366 post {
367 always {
368 sh '''
369 kubectl get pods --all-namespaces
370
371 echo "# removing helm deployments"
372 kubectl get pods
373 helm list
374
375 for hchart in \$(helm list -q);
376 do
377 echo "## Purging chart: \${hchart} ##"
378 helm delete --purge "\${hchart}"
379 done
380
381 sudo minikube delete
382 '''
383 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "suchitra@opennetworking.org, you@opennetworking.org, kailash@opennetworking.org", sendToIndividuals: false])
384 }
385 }
386}