blob: 6c92d88dd5c22759281c9c343131165255276810 [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
15PROFILE="null"
16CORE_CONTAINER="null"
17
18pipeline {
19
20 /* no label, executor is determined by JJB */
21 agent {
22 label "${params.executorNode}"
23 }
24
25 stages {
26
27 stage('repo') {
28 steps {
29 checkout(changelog: false, \
30 poll: false,
31 scm: [$class: 'RepoScm', \
32 manifestRepositoryUrl: "${params.manifestUrl}", \
33 manifestBranch: "${params.manifestBranch}", \
34 currentBranch: true, \
35 destinationDir: 'cord', \
36 forceSync: true,
37 resetFirst: true, \
38 quiet: true, \
39 jobs: 4, \
40 showAllChanges: true] \
41 )
42 }
43 }
44
45 stage('patch') {
46 steps {
47 sh """
Zack Williams0efdd262018-06-28 14:17:29 -070048 #!/usr/bin/env bash
49 set -eu -o pipefail
50
51 VERSIONFILE="" # file path to file containing version number
52 NEW_VERSION="" # version number found in VERSIONFILE
Zack Williams2d0ac6b2018-06-29 09:17:41 -070053 releaseversion=0
Zack Williams0efdd262018-06-28 14:17:29 -070054
55 function read_version {
56 if [ -f "VERSION" ]
57 then
58 NEW_VERSION=\$(head -n1 "VERSION")
59 VERSIONFILE="VERSION"
60 elif [ -f "package.json" ]
61 then
62 NEW_VERSION=\$(python -c 'import json,sys;obj=json.load(sys.stdin); print obj["version"]' < package.json)
63 VERSIONFILE="package.json"
64 else
65 echo "ERROR: No versioning file found!"
66 exit 1
67 fi
68 }
69
70 # check if the version is a released version
71 function check_if_releaseversion {
72 if [[ "\$NEW_VERSION" =~ ^([0-9]+)\\.([0-9]+)\\.([0-9]+)\$ ]]
73 then
74 echo "Version string '\$NEW_VERSION' in '\$VERSIONFILE' is a SemVer released version!"
75 releaseversion=1
76 else
77 echo "Version string '\$NEW_VERSION' in '\$VERSIONFILE' is not a SemVer released version, skipping."
78 fi
79 }
80
Kailash Khalasi54170812018-05-24 12:50:22 -070081 pushd cord
82 PROJECT_PATH=\$(xmllint --xpath "string(//project[@name=\\\"${gerritProject}\\\"]/@path)" .repo/manifest.xml)
83 repo download "\$PROJECT_PATH" "${gerritChangeNumber}/${gerritPatchsetNumber}"
Zack Williams0efdd262018-06-28 14:17:29 -070084
85 pushd \$PROJECT_PATH
86 echo "Existing git tags:"
87 git tag -n
88
89 read_version
90 check_if_releaseversion
91
92 # perform checks if a released version
93 if [ "\$releaseversion" -eq "1" ]
94 then
95 git config --global user.email "apitest@opencord.org"
96 git config --global user.name "API Test"
97
98 git tag -a "\$NEW_VERSION" -m "Tagged for api test on Gerrit patchset: ${gerritChangeNumber}"
99
100 echo "Tags including new tag:"
101 git tag -n
102
103 fi
Kailash Khalasi54170812018-05-24 12:50:22 -0700104 popd
Zack Williams0efdd262018-06-28 14:17:29 -0700105 popd
106 """
Kailash Khalasi54170812018-05-24 12:50:22 -0700107 }
108 }
109
Zack Williams0efdd262018-06-28 14:17:29 -0700110
Kailash Khalasi54170812018-05-24 12:50:22 -0700111 stage('prep') {
112 parallel {
113
114 stage('images') {
115 steps {
116 sh '''
Kailash Khalasi934d39b2018-05-30 10:59:49 -0700117 pushd cord/automation-tools/developer
Zack Williamsa3185032018-07-03 17:38:33 -0700118 mkdir ib_logs
Zack Williams7fea5722018-07-03 21:17:47 -0700119 ./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 -0700120 popd
121 '''
Zack Williamsa3185032018-07-03 17:38:33 -0700122 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 -0700123 }
124 }
125
126 stage('minikube') {
127 steps {
128 /* see https://github.com/kubernetes/minikube/#linux-continuous-integration-without-vm-support */
129 sh '''
130 export MINIKUBE_WANTUPDATENOTIFICATION=false
131 export MINIKUBE_WANTREPORTERRORPROMPT=false
132 export CHANGE_MINIKUBE_NONE_USER=true
133 export MINIKUBE_HOME=$HOME
134 mkdir -p $HOME/.kube || true
135 touch $HOME/.kube/config
136 export KUBECONFIG=$HOME/.kube/config
137 sudo -E /usr/bin/minikube start --vm-driver=none
138 '''
139 script {
140 timeout(3) {
141 waitUntil {
142 sleep 5
143 def kc_ret = sh script: "kubectl get po", returnStatus: true
144 return (kc_ret == 0);
145 }
146 }
147 }
148 }
149 }
150 }
151 }
152 stage('helm') {
153 steps {
154 sh '''
155 helm init
156 sleep 60
157 helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/
158 '''
159 }
160 }
161 stage('Build') {
162 steps {
163 sh """
Zack Williamsc8cfb222018-07-05 13:29:28 -0700164 #!/usr/bin/env bash
165 set -eu -o pipefail
Kailash Khalasi12b2e222018-06-13 09:45:25 -0700166
Zack Williamsc8cfb222018-07-05 13:29:28 -0700167 helm_install_args='-f examples/image-tag-candidate.yaml -f examples/imagePullPolicy-IfNotPresent.yaml -f examples/api-test-values.yaml'
168 basesleep=300
169 extrasleep=60
170
171 pushd cord/helm-charts
172
173 helm dep up xos-core
174 helm install \${helm_install_args} xos-core -n xos-core
175
176 # Pick which chart(s) to load depending on the project being tested
177 # In regex, please list repos in same order as requirements.yaml in the chart(s) loaded!
178
179 if [[ "$GERRIT_PROJECT" =~ ^(rcord|onos-service|fabric|olt-service|vsg-hw|vrouter)\$ ]]; then
180 helm dep update xos-profiles/rcord-lite
181 helm install \${helm_install_args} xos-profiles/rcord-lite -n rcord-lite
182 extrasleep=300
183
184 elif [[ "$GERRIT_PROJECT" =~ ^(vMME|vspgwc|vspgwu|vHSS|hss_db|internetemulator|sdn-controller|epc-service|mcord|progran)\$ ]]; then
185 helm dep update xos-profiles/mcord
186 helm install \${helm_install_args} xos-profiles/mcord -n mcord
187 extrasleep=900
188
189 elif [[ "$GERRIT_PROJECT" =~ ^(openstack|vtn-service|exampleservice|addressmanager)\$ ]]; then
190 # NOTE: onos-service is included in base-openstack, but tested w/rcord-lite chart
191
192 helm dep update xos-profiles/base-openstack
193 helm dep update xos-profiles/demo-exampleservice
194 helm install \${helm_install_args} xos-profiles/base-openstack -n base-openstack
195 helm install \${helm_install_args} xos-profiles/demo-exampleservice -n demo-exampleservice
196
197 elif [[ "$GERRIT_PROJECT" =~ ^(kubernetes-service|simpleexampleservice)\$ ]]; then
198 helm dep update xos-profiles/base-kubernetes
199 helm dep update xos-profiles/demo-simpleexampleservice
200 helm install \${helm_install_args} xos-profiles/base-kubernetes -n base-kubernetes
201 helm install \${helm_install_args} xos-profiles/demo-simpleexampleservice -n demo-simpleexampleservice
202
203 elif [[ "$GERRIT_PROJECT" =~ ^(hippie-oss)\$ ]]; then
204 helm dep update xos-services/hippie-oss
205 helm install \${helm_install_args} xos-services/hippie-oss -n hippie-oss
206
Zack Williamsbafed362018-07-05 16:32:27 -0700207 elif [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester)\$ ]]; then
208 echo "No additional charts to install for testing $GERRIT_PROJECT"
209
Zack Williamsc8cfb222018-07-05 13:29:28 -0700210 else
211 echo "Couldn't find a chart to test project: $GERRIT_PROJECT!"
212 exit 1
Kailash Khalasi54170812018-05-24 12:50:22 -0700213 fi
Zack Williamsc8cfb222018-07-05 13:29:28 -0700214
215 # sleep to wait for services to load
216 sleep "\$basesleep"
217 sleep "\$extrasleep"
218
219 echo "# Checking helm deployments"
Kailash Khalasi12b2e222018-06-13 09:45:25 -0700220 kubectl get pods
Zack Williamsc8cfb222018-07-05 13:29:28 -0700221 helm list
222
223 for hchart in \$(helm list -q);
224 do
225 echo "## 'helm status' for chart: \${hchart} ##"
226 helm status "\${hchart}"
227 done
228
Kailash Khalasi54170812018-05-24 12:50:22 -0700229 popd
230 """
231 }
232 }
233 stage('Setup') {
234 steps {
235 sh """
236 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
Zack Williamsc8cfb222018-07-05 13:29:28 -0700237
Kailash Khalasi54170812018-05-24 12:50:22 -0700238 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
239 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
240 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
241 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 -0700242
Kailash Khalasi934d39b2018-05-30 10:59:49 -0700243 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
Zack Williamsc8cfb222018-07-05 13:29:28 -0700244
Kailash Khalasi54170812018-05-24 12:50:22 -0700245 export testname=_service_api.robot
246 export library=_library.robot
Zack Williamsc8cfb222018-07-05 13:29:28 -0700247
248 # do addtional tests if additional services are loaded
Zack Williamsbafed362018-07-05 16:32:27 -0700249 if ! [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester)\$ ]]; then
Zack Williamsc8cfb222018-07-05 13:29:28 -0700250 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
251 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
Kailash Khalasia1f3a8d2018-05-30 12:36:29 -0700252 fi
Kailash Khalasi54170812018-05-24 12:50:22 -0700253 """
254 }
255 }
256 stage('Test') {
257 steps {
258 sh """
259 pushd cord/test/cord-tester/src/test/cord-api/Tests
260 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
Kailash Khalasi934d39b2018-05-30 10:59:49 -0700261 CHAM_CONTAINER=\$(docker ps | grep k8s_xos-chameleon | awk '{print \$1}')
262 XOS_CHAMELEON=\$(docker exec \$CHAM_CONTAINER ip a | grep -oE "([0-9]{1,3}\\.){3}[0-9]{1,3}\\b" | grep 172)
Kailash Khalasi54170812018-05-24 12:50:22 -0700263 export testname=_service_api.robot
264 export library=_library.robot
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
Kailash Khalasi54170812018-05-24 12:50:22 -0700267 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Properties/
Kailash Khalasi934d39b2018-05-30 10:59:49 -0700268 sed -i \"s/^\\(SERVER_IP = \\).*/\\1\'\$XOS_CHAMELEON\'/\" RestApiProperties.py
Kailash Khalasi54170812018-05-24 12:50:22 -0700269 sed -i \"s/^\\(SERVER_PORT = \\).*/\\1\'9101\'/\" RestApiProperties.py
Kailash Khalasi934d39b2018-05-30 10:59:49 -0700270 sed -i \"s/^\\(XOS_USER = \\).*/\\1\'admin@opencord.org\'/\" RestApiProperties.py
271 sed -i \"s/^\\(XOS_PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
272 sed -i \"s/^\\(PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
Kailash Khalasi54170812018-05-24 12:50:22 -0700273 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests
274 pybot -d Log -T -e TenantWithContainer -e Port -e ControllerImages -e ControllerNetwork -e ControllerSlice -e ControllerUser XOSCoreAPITests.robot || true
Kailash Khalasieaea6052018-06-15 17:51:19 -0700275 if ! [[ "$GERRIT_PROJECT" =~ ^(cord|platform-install|xos|xos-tosca|cord-tester)\$ ]]; then
Kailash Khalasi934d39b2018-05-30 10:59:49 -0700276 for i in \$SERVICES; do bash -c "pybot -d Log -T -e AddressManagerServiceInstance -v TESTLIBRARY:\$i\$library \$i\$testname"; sleep 2; done || true
277 fi
Kailash Khalasi54170812018-05-24 12:50:22 -0700278 popd
279 """
280 }
281 }
282 stage('Publish') {
283 steps {
284 sh """
285 if [ -d RobotLogs ]; then rm -r RobotLogs; fi; mkdir RobotLogs
286 cp -r $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/Log/*ml ./RobotLogs
287 """
288 step([$class: 'RobotPublisher',
289 disableArchiveOutput: false,
290 logFileName: 'RobotLogs/log*.html',
291 otherFiles: '',
292 outputFileName: 'RobotLogs/output*.xml',
293 outputPath: '.',
Kailash Khalasia4cad352018-07-02 10:58:07 -0700294 passThreshold: 95,
Kailash Khalasi54170812018-05-24 12:50:22 -0700295 reportFileName: 'RobotLogs/report*.html',
296 unstableThreshold: 0]);
297 }
298 }
299 }
300 post {
301 always {
302 sh '''
Zack Williamsa834c342018-05-31 11:30:15 -0700303 kubectl get pods --all-namespaces
Zack Williamsc8cfb222018-07-05 13:29:28 -0700304
305 echo "# removing helm deployments"
306 kubectl get pods
Zack Williamsa834c342018-05-31 11:30:15 -0700307 helm list
Zack Williamsc8cfb222018-07-05 13:29:28 -0700308
309 for hchart in \$(helm list -q);
310 do
311 echo "## Purging chart: \${hchart} ##"
312 helm delete --purge "\${hchart}"
313 done
314
Zack Williamsa834c342018-05-31 11:30:15 -0700315 minikube delete
Kailash Khalasi54170812018-05-24 12:50:22 -0700316 '''
Kailash Khalasi934d39b2018-05-30 10:59:49 -0700317 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "suchitra@opennetworking.org, you@opennetworking.org, kailash@opennetworking.org", sendToIndividuals: false])
Kailash Khalasi54170812018-05-24 12:50:22 -0700318 }
319 }
320}