blob: 1c8a43dbd91eaf178aaffd234bc89ed6acf93590 [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 }
111 stage('candiate tag') {
112 steps {
113 sh """
114 XOS_MAJOR=\$(cut -b 1 cord/orchestration/xos/VERSION)
115 for df in cord/orchestration/xos_services/*/Dockerfile.synchronizer cord/orchestration/profiles/*/Dockerfile.synchronizer
116 do
117 sed -i "s/^FROM\\(.*\\):\${XOS_MAJOR}.*\$/FROM\\1:candidate/" "\$df"
118 done
119 """
120 }
121 }
122
123 stage('prep') {
124 parallel {
125
126 stage('images') {
127 steps {
128 sh '''
129 pushd cord/automation-tools/developer
130 mkdir ib_logs
131 ./imagebuilder.py -l ib_logs -a ib_actions.yml -g ib_graph.dot -f ../../helm-charts/examples/filter-images.yaml
132 popd
133 '''
134 archiveArtifacts artifacts: 'cord/automation-tools/developer/ib_actions.yml, cord/automation-tools/developer/ib_graph.dot, cord/automation-tools/developer/ib_logs/*', fingerprint: true
135 }
136 }
137
138 stage('minikube') {
139 steps {
140 /* see https://github.com/kubernetes/minikube/#linux-continuous-integration-without-vm-support */
141 sh '''
142 export MINIKUBE_WANTUPDATENOTIFICATION=false
143 export MINIKUBE_WANTREPORTERRORPROMPT=false
144 export CHANGE_MINIKUBE_NONE_USER=true
145 export MINIKUBE_HOME=$HOME
146 mkdir -p $HOME/.kube || true
147 touch $HOME/.kube/config
148 export KUBECONFIG=$HOME/.kube/config
149 sudo -E /usr/bin/minikube start --vm-driver=none
150 '''
151 script {
152 timeout(3) {
153 waitUntil {
154 sleep 5
155 def kc_ret = sh script: "kubectl get po", returnStatus: true
156 return (kc_ret == 0);
157 }
158 }
159 }
160 }
161 }
162 }
163 }
164
165 stage('helm') {
166 steps {
167 sh '''
168 helm init
169 sleep 60
170 helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/
171 '''
172 }
173 }
174
175 stage('build') {
176 steps {
177 sh """
178 #!/usr/bin/env bash
179 set -eu -o pipefail
180
181 helm_install_args='-f examples/image-tag-candidate.yaml -f examples/imagePullPolicy-IfNotPresent.yaml -f examples/api-test-values.yaml'
182 basesleep=300
183 extrasleep=60
184
185 pushd cord/helm-charts
186
187 helm dep up xos-core
188 helm install \${helm_install_args} xos-core -n xos-core
189
190 # Pick which chart(s) to load depending on the project being tested
191 # In regex, please list repos in same order as requirements.yaml in the chart(s) loaded!
192
193 if [[ "$GERRIT_PROJECT" =~ ^(rcord|onos-service|fabric|olt-service|vsg-hw|vrouter)\$ ]]; then
194 helm dep update xos-profiles/rcord-lite
195 helm install \${helm_install_args} xos-profiles/rcord-lite -n rcord-lite
196 extrasleep=300
197
198 elif [[ "$GERRIT_PROJECT" =~ ^(vMME|vspgwc|vspgwu|vHSS|hss_db|internetemulator|sdn-controller|epc-service|mcord|progran)\$ ]]; then
199 helm dep update xos-profiles/base-openstack
200 helm dep update xos-profiles/mcord
201 helm install \${helm_install_args} xos-profiles/base-openstack -n base-openstack
202 helm install \${helm_install_args} xos-profiles/mcord -n mcord
203 extrasleep=900
204
205 elif [[ "$GERRIT_PROJECT" =~ ^(openstack|vtn-service|exampleservice|addressmanager)\$ ]]; then
206 # NOTE: onos-service is included in base-openstack, but tested w/rcord-lite chart
207
208 helm dep update xos-profiles/base-openstack
209 helm dep update xos-profiles/demo-exampleservice
210 helm install \${helm_install_args} xos-profiles/base-openstack -n base-openstack
211 helm install \${helm_install_args} xos-profiles/demo-exampleservice -n demo-exampleservice
212
213 elif [[ "$GERRIT_PROJECT" =~ ^(kubernetes-service|simpleexampleservice)\$ ]]; then
214 helm dep update xos-profiles/base-kubernetes
215 helm dep update xos-profiles/demo-simpleexampleservice
216 helm install \${helm_install_args} xos-profiles/base-kubernetes -n base-kubernetes
217 helm install \${helm_install_args} xos-profiles/demo-simpleexampleservice -n demo-simpleexampleservice
218
219 elif [[ "$GERRIT_PROJECT" =~ ^(hippie-oss)\$ ]]; then
220 helm dep update xos-services/hippie-oss
221 helm install \${helm_install_args} xos-services/hippie-oss -n hippie-oss
222
223 elif [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester|helm-charts)\$ ]]; then
224 echo "No additional charts to install for testing $GERRIT_PROJECT"
225
226 else
227 echo "Couldn't find a chart to test project: $GERRIT_PROJECT!"
228 exit 1
229 fi
230
231 # sleep to wait for services to load
232 sleep "\$basesleep"
233 sleep "\$extrasleep"
234
235 echo "# Checking helm deployments"
236 kubectl get pods
237 helm list
238
239 for hchart in \$(helm list -q);
240 do
241 echo "## 'helm status' for chart: \${hchart} ##"
242 helm status "\${hchart}"
243 done
244
245 popd
246 """
247 }
248 }
249
250 stage('setup') {
251 steps {
252 sh """
253 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
254
255 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
256 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
257 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
258 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
259
260 # create additional testing files if services are loaded
261 if ! [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester|helm-charts)\$ ]]; then
262 export testname=_service_api.robot
263 export library=_library.robot
264
265 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
266 echo \$SERVICES
267
268 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
269
270 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
271 fi
272 """
273 }
274 }
275
276 stage('test') {
277 steps {
278 sh """
279 pushd cord/test/cord-tester/src/test/cord-api/Tests
280
281 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
282 CHAM_CONTAINER=\$(docker ps | grep k8s_xos-chameleon | awk '{print \$1}')
283 XOS_CHAMELEON=\$(docker exec \$CHAM_CONTAINER ip a | grep -oE "([0-9]{1,3}\\.){3}[0-9]{1,3}\\b" | grep 172)
284
285 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Properties/
286 sed -i \"s/^\\(SERVER_IP = \\).*/\\1\'\$XOS_CHAMELEON\'/\" RestApiProperties.py
287 sed -i \"s/^\\(SERVER_PORT = \\).*/\\1\'9101\'/\" RestApiProperties.py
288 sed -i \"s/^\\(XOS_USER = \\).*/\\1\'admin@opencord.org\'/\" RestApiProperties.py
289 sed -i \"s/^\\(XOS_PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
290 sed -i \"s/^\\(PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
291
292 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests
293 pybot -d Log -T -e TenantWithContainer -e Port -e ControllerImages -e ControllerNetwork -e ControllerSlice -e ControllerUser XOSCoreAPITests.robot || true
294
295 # do additional tests 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 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
300 echo \$SERVICES
301
302 for i in \$SERVICES; do bash -c "pybot -d Log -T -e AddressManagerServiceInstance -v TESTLIBRARY:\$i\$library \$i\$testname"; sleep 2; done || true
303 fi
304
305 popd
306 """
307 }
308 }
309
310 stage('Publish') {
311 steps {
312 sh """
313 if [ -d RobotLogs ]; then rm -r RobotLogs; fi; mkdir RobotLogs
314 cp -r $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/Log/*ml ./RobotLogs
315 """
316
317 step([$class: 'RobotPublisher',
318 disableArchiveOutput: false,
319 logFileName: 'RobotLogs/log*.html',
320 otherFiles: '',
321 outputFileName: 'RobotLogs/output*.xml',
322 outputPath: '.',
323 passThreshold: 95,
324 reportFileName: 'RobotLogs/report*.html',
325 unstableThreshold: 0]);
326 }
327 }
328
329 }
330
331 post {
332 always {
333 sh '''
334 kubectl get pods --all-namespaces
335
336 echo "# removing helm deployments"
337 kubectl get pods
338 helm list
339
340 for hchart in \$(helm list -q);
341 do
342 echo "## Purging chart: \${hchart} ##"
343 helm delete --purge "\${hchart}"
344 done
345
346 sudo minikube delete
347 '''
348 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "suchitra@opennetworking.org, you@opennetworking.org, kailash@opennetworking.org", sendToIndividuals: false])
349 }
350 }
351}