blob: 3d6153176ca1ec490b12962fc99c648267c0bd32 [file] [log] [blame]
Kailash Khalasi54170812018-05-24 12:50:22 -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
Zack Williams9d68aa32018-07-12 11:50:37 -070015// Run XOS api tests on HEAD of a branch (usually master), loading the
16// corresponding charts
17
Kailash Khalasi54170812018-05-24 12:50:22 -070018CORE_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 """
Zack Williams0efdd262018-06-28 14:17:29 -070050 #!/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
Zack Williams2d0ac6b2018-06-29 09:17:41 -070055 releaseversion=0
Zack Williams0efdd262018-06-28 14:17:29 -070056
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
Kailash Khalasi54170812018-05-24 12:50:22 -070083 pushd cord
84 PROJECT_PATH=\$(xmllint --xpath "string(//project[@name=\\\"${gerritProject}\\\"]/@path)" .repo/manifest.xml)
85 repo download "\$PROJECT_PATH" "${gerritChangeNumber}/${gerritPatchsetNumber}"
Zack Williams0efdd262018-06-28 14:17:29 -070086
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
Kailash Khalasi54170812018-05-24 12:50:22 -0700106 popd
Zack Williams0efdd262018-06-28 14:17:29 -0700107 popd
108 """
Kailash Khalasi54170812018-05-24 12:50:22 -0700109 }
110 }
111
Zack Williams0efdd262018-06-28 14:17:29 -0700112
Kailash Khalasi54170812018-05-24 12:50:22 -0700113 stage('prep') {
114 parallel {
115
116 stage('images') {
117 steps {
118 sh '''
Kailash Khalasi934d39b2018-05-30 10:59:49 -0700119 pushd cord/automation-tools/developer
Zack Williamsa3185032018-07-03 17:38:33 -0700120 mkdir ib_logs
Zack Williams7fea5722018-07-03 21:17:47 -0700121 ./imagebuilder.py -l ib_logs -a ib_actions.yml -g ib_graph.dot -f ../../helm-charts/examples/filter-images.yaml
Kailash Khalasi54170812018-05-24 12:50:22 -0700122 popd
123 '''
Zack Williamsa3185032018-07-03 17:38:33 -0700124 archiveArtifacts artifacts: 'cord/automation-tools/developer/ib_actions.yml, cord/automation-tools/developer/ib_graph.dot, cord/automation-tools/developer/ib_logs/*', fingerprint: true
Kailash Khalasi54170812018-05-24 12:50:22 -0700125 }
126 }
127
128 stage('minikube') {
129 steps {
130 /* see https://github.com/kubernetes/minikube/#linux-continuous-integration-without-vm-support */
131 sh '''
132 export MINIKUBE_WANTUPDATENOTIFICATION=false
133 export MINIKUBE_WANTREPORTERRORPROMPT=false
134 export CHANGE_MINIKUBE_NONE_USER=true
135 export MINIKUBE_HOME=$HOME
136 mkdir -p $HOME/.kube || true
137 touch $HOME/.kube/config
138 export KUBECONFIG=$HOME/.kube/config
139 sudo -E /usr/bin/minikube start --vm-driver=none
140 '''
141 script {
142 timeout(3) {
143 waitUntil {
144 sleep 5
145 def kc_ret = sh script: "kubectl get po", returnStatus: true
146 return (kc_ret == 0);
147 }
148 }
149 }
150 }
151 }
152 }
153 }
Zack Williamsfd87d652018-07-12 14:21:12 -0700154
Kailash Khalasi54170812018-05-24 12:50:22 -0700155 stage('helm') {
156 steps {
157 sh '''
158 helm init
159 sleep 60
160 helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/
161 '''
162 }
163 }
Zack Williamsfd87d652018-07-12 14:21:12 -0700164
165 stage('build') {
Kailash Khalasi54170812018-05-24 12:50:22 -0700166 steps {
167 sh """
Zack Williamsc8cfb222018-07-05 13:29:28 -0700168 #!/usr/bin/env bash
169 set -eu -o pipefail
Kailash Khalasi12b2e222018-06-13 09:45:25 -0700170
Zack Williamsc8cfb222018-07-05 13:29:28 -0700171 helm_install_args='-f examples/image-tag-candidate.yaml -f examples/imagePullPolicy-IfNotPresent.yaml -f examples/api-test-values.yaml'
172 basesleep=300
173 extrasleep=60
174
175 pushd cord/helm-charts
176
177 helm dep up xos-core
178 helm install \${helm_install_args} xos-core -n xos-core
179
180 # Pick which chart(s) to load depending on the project being tested
181 # In regex, please list repos in same order as requirements.yaml in the chart(s) loaded!
182
183 if [[ "$GERRIT_PROJECT" =~ ^(rcord|onos-service|fabric|olt-service|vsg-hw|vrouter)\$ ]]; then
184 helm dep update xos-profiles/rcord-lite
185 helm install \${helm_install_args} xos-profiles/rcord-lite -n rcord-lite
186 extrasleep=300
187
188 elif [[ "$GERRIT_PROJECT" =~ ^(vMME|vspgwc|vspgwu|vHSS|hss_db|internetemulator|sdn-controller|epc-service|mcord|progran)\$ ]]; then
Zack Williamsee86e662018-07-06 10:18:28 -0700189 helm dep update xos-profiles/base-openstack
Zack Williamsc8cfb222018-07-05 13:29:28 -0700190 helm dep update xos-profiles/mcord
Zack Williamsee86e662018-07-06 10:18:28 -0700191 helm install \${helm_install_args} xos-profiles/base-openstack -n base-openstack
192 helm install \${helm_install_args} xos-profiles/mcord -n mcord
Zack Williamsc8cfb222018-07-05 13:29:28 -0700193 extrasleep=900
194
195 elif [[ "$GERRIT_PROJECT" =~ ^(openstack|vtn-service|exampleservice|addressmanager)\$ ]]; then
196 # NOTE: onos-service is included in base-openstack, but tested w/rcord-lite chart
197
198 helm dep update xos-profiles/base-openstack
199 helm dep update xos-profiles/demo-exampleservice
200 helm install \${helm_install_args} xos-profiles/base-openstack -n base-openstack
201 helm install \${helm_install_args} xos-profiles/demo-exampleservice -n demo-exampleservice
202
203 elif [[ "$GERRIT_PROJECT" =~ ^(kubernetes-service|simpleexampleservice)\$ ]]; then
204 helm dep update xos-profiles/base-kubernetes
205 helm dep update xos-profiles/demo-simpleexampleservice
206 helm install \${helm_install_args} xos-profiles/base-kubernetes -n base-kubernetes
207 helm install \${helm_install_args} xos-profiles/demo-simpleexampleservice -n demo-simpleexampleservice
208
209 elif [[ "$GERRIT_PROJECT" =~ ^(hippie-oss)\$ ]]; then
210 helm dep update xos-services/hippie-oss
211 helm install \${helm_install_args} xos-services/hippie-oss -n hippie-oss
212
Zack Williams9d68aa32018-07-12 11:50:37 -0700213 elif [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester|helm-charts)\$ ]]; then
Zack Williamsbafed362018-07-05 16:32:27 -0700214 echo "No additional charts to install for testing $GERRIT_PROJECT"
215
Zack Williamsc8cfb222018-07-05 13:29:28 -0700216 else
217 echo "Couldn't find a chart to test project: $GERRIT_PROJECT!"
218 exit 1
Kailash Khalasi54170812018-05-24 12:50:22 -0700219 fi
Zack Williamsc8cfb222018-07-05 13:29:28 -0700220
221 # sleep to wait for services to load
222 sleep "\$basesleep"
223 sleep "\$extrasleep"
224
225 echo "# Checking helm deployments"
Kailash Khalasi12b2e222018-06-13 09:45:25 -0700226 kubectl get pods
Zack Williamsc8cfb222018-07-05 13:29:28 -0700227 helm list
228
229 for hchart in \$(helm list -q);
230 do
231 echo "## 'helm status' for chart: \${hchart} ##"
232 helm status "\${hchart}"
233 done
234
Kailash Khalasi54170812018-05-24 12:50:22 -0700235 popd
Zack Williamsfd87d652018-07-12 14:21:12 -0700236 """
Kailash Khalasi54170812018-05-24 12:50:22 -0700237 }
238 }
Zack Williamsfd87d652018-07-12 14:21:12 -0700239
240 stage('setup') {
Kailash Khalasi54170812018-05-24 12:50:22 -0700241 steps {
242 sh """
Zack Williamsfd87d652018-07-12 14:21:12 -0700243 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
Zack Williamsc8cfb222018-07-05 13:29:28 -0700244
Zack Williamsfd87d652018-07-12 14:21:12 -0700245 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
246 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
247 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
248 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
Zack Williamsc8cfb222018-07-05 13:29:28 -0700249
Zack Williamsfd87d652018-07-12 14:21:12 -0700250 # create additional testing files if services are loaded
251 if ! [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester|helm-charts)\$ ]]; then
252 export testname=_service_api.robot
253 export library=_library.robot
Zack Williamsc8cfb222018-07-05 13:29:28 -0700254
Zack Williamsfd87d652018-07-12 14:21:12 -0700255 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
256 echo \$SERVICES
Zack Williamsc8cfb222018-07-05 13:29:28 -0700257
Zack Williamsfd87d652018-07-12 14:21:12 -0700258 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
259
260 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
261 fi
262 """
Kailash Khalasi54170812018-05-24 12:50:22 -0700263 }
Kailash Khalasi54170812018-05-24 12:50:22 -0700264 }
Zack Williamsfd87d652018-07-12 14:21:12 -0700265
266 stage('test') {
267 steps {
268 sh """
269 pushd cord/test/cord-tester/src/test/cord-api/Tests
270
271 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
272 CHAM_CONTAINER=\$(docker ps | grep k8s_xos-chameleon | awk '{print \$1}')
273 XOS_CHAMELEON=\$(docker exec \$CHAM_CONTAINER ip a | grep -oE "([0-9]{1,3}\\.){3}[0-9]{1,3}\\b" | grep 172)
274
275 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Properties/
276 sed -i \"s/^\\(SERVER_IP = \\).*/\\1\'\$XOS_CHAMELEON\'/\" RestApiProperties.py
277 sed -i \"s/^\\(SERVER_PORT = \\).*/\\1\'9101\'/\" RestApiProperties.py
278 sed -i \"s/^\\(XOS_USER = \\).*/\\1\'admin@opencord.org\'/\" RestApiProperties.py
279 sed -i \"s/^\\(XOS_PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
280 sed -i \"s/^\\(PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
281
282 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests
283 pybot -d Log -T -e TenantWithContainer -e Port -e ControllerImages -e ControllerNetwork -e ControllerSlice -e ControllerUser XOSCoreAPITests.robot || true
284
285 # do additional tests if services are loaded
286 if ! [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester|helm-charts)\$ ]]; then
287 export testname=_service_api.robot
288 export library=_library.robot
289 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
290 echo \$SERVICES
291
292 for i in \$SERVICES; do bash -c "pybot -d Log -T -e AddressManagerServiceInstance -v TESTLIBRARY:\$i\$library \$i\$testname"; sleep 2; done || true
293 fi
294
295 popd
296 """
297 }
298 }
299
Kailash Khalasi54170812018-05-24 12:50:22 -0700300 stage('Publish') {
Zack Williamsfd87d652018-07-12 14:21:12 -0700301 steps {
302 sh """
303 if [ -d RobotLogs ]; then rm -r RobotLogs; fi; mkdir RobotLogs
304 cp -r $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/Log/*ml ./RobotLogs
305 """
Zack Williamsc8cfb222018-07-05 13:29:28 -0700306
Zack Williamsfd87d652018-07-12 14:21:12 -0700307 step([$class: 'RobotPublisher',
308 disableArchiveOutput: false,
309 logFileName: 'RobotLogs/log*.html',
310 otherFiles: '',
311 outputFileName: 'RobotLogs/output*.xml',
312 outputPath: '.',
313 passThreshold: 95,
314 reportFileName: 'RobotLogs/report*.html',
315 unstableThreshold: 0]);
316 }
Kailash Khalasi54170812018-05-24 12:50:22 -0700317 }
Zack Williamsfd87d652018-07-12 14:21:12 -0700318
319 }
320
321 post {
322 always {
323 sh '''
324 kubectl get pods --all-namespaces
325
326 echo "# removing helm deployments"
327 kubectl get pods
328 helm list
329
330 for hchart in \$(helm list -q);
331 do
332 echo "## Purging chart: \${hchart} ##"
333 helm delete --purge "\${hchart}"
334 done
335
336 minikube delete
337 '''
338 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "suchitra@opennetworking.org, you@opennetworking.org, kailash@opennetworking.org", sendToIndividuals: false])
339 }
340 }
Kailash Khalasi54170812018-05-24 12:50:22 -0700341}