blob: 863baec1e06322c9dde62a57b1152c8eeb804004 [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
Zack Williamsee86e662018-07-06 10:18:28 -0700185 helm dep update xos-profiles/base-openstack
Zack Williamsc8cfb222018-07-05 13:29:28 -0700186 helm dep update xos-profiles/mcord
Zack Williamsee86e662018-07-06 10:18:28 -0700187 helm install \${helm_install_args} xos-profiles/base-openstack -n base-openstack
188 helm install \${helm_install_args} xos-profiles/mcord -n mcord
Zack Williamsc8cfb222018-07-05 13:29:28 -0700189 extrasleep=900
190
191 elif [[ "$GERRIT_PROJECT" =~ ^(openstack|vtn-service|exampleservice|addressmanager)\$ ]]; then
192 # NOTE: onos-service is included in base-openstack, but tested w/rcord-lite chart
193
194 helm dep update xos-profiles/base-openstack
195 helm dep update xos-profiles/demo-exampleservice
196 helm install \${helm_install_args} xos-profiles/base-openstack -n base-openstack
197 helm install \${helm_install_args} xos-profiles/demo-exampleservice -n demo-exampleservice
198
199 elif [[ "$GERRIT_PROJECT" =~ ^(kubernetes-service|simpleexampleservice)\$ ]]; then
200 helm dep update xos-profiles/base-kubernetes
201 helm dep update xos-profiles/demo-simpleexampleservice
202 helm install \${helm_install_args} xos-profiles/base-kubernetes -n base-kubernetes
203 helm install \${helm_install_args} xos-profiles/demo-simpleexampleservice -n demo-simpleexampleservice
204
205 elif [[ "$GERRIT_PROJECT" =~ ^(hippie-oss)\$ ]]; then
206 helm dep update xos-services/hippie-oss
207 helm install \${helm_install_args} xos-services/hippie-oss -n hippie-oss
208
Zack Williamsbafed362018-07-05 16:32:27 -0700209 elif [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester)\$ ]]; then
210 echo "No additional charts to install for testing $GERRIT_PROJECT"
211
Zack Williamsc8cfb222018-07-05 13:29:28 -0700212 else
213 echo "Couldn't find a chart to test project: $GERRIT_PROJECT!"
214 exit 1
Kailash Khalasi54170812018-05-24 12:50:22 -0700215 fi
Zack Williamsc8cfb222018-07-05 13:29:28 -0700216
217 # sleep to wait for services to load
218 sleep "\$basesleep"
219 sleep "\$extrasleep"
220
221 echo "# Checking helm deployments"
Kailash Khalasi12b2e222018-06-13 09:45:25 -0700222 kubectl get pods
Zack Williamsc8cfb222018-07-05 13:29:28 -0700223 helm list
224
225 for hchart in \$(helm list -q);
226 do
227 echo "## 'helm status' for chart: \${hchart} ##"
228 helm status "\${hchart}"
229 done
230
Kailash Khalasi54170812018-05-24 12:50:22 -0700231 popd
232 """
233 }
234 }
235 stage('Setup') {
236 steps {
237 sh """
238 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
Zack Williamsc8cfb222018-07-05 13:29:28 -0700239
Kailash Khalasi54170812018-05-24 12:50:22 -0700240 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
241 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
242 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
243 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 -0700244
Kailash Khalasi934d39b2018-05-30 10:59:49 -0700245 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 -0700246
Kailash Khalasi54170812018-05-24 12:50:22 -0700247 export testname=_service_api.robot
248 export library=_library.robot
Zack Williamsc8cfb222018-07-05 13:29:28 -0700249
250 # do addtional tests if additional services are loaded
Zack Williamsbafed362018-07-05 16:32:27 -0700251 if ! [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester)\$ ]]; then
Zack Williamsc8cfb222018-07-05 13:29:28 -0700252 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
253 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 -0700254 fi
Kailash Khalasi54170812018-05-24 12:50:22 -0700255 """
256 }
257 }
258 stage('Test') {
259 steps {
260 sh """
261 pushd cord/test/cord-tester/src/test/cord-api/Tests
262 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
Kailash Khalasi934d39b2018-05-30 10:59:49 -0700263 CHAM_CONTAINER=\$(docker ps | grep k8s_xos-chameleon | awk '{print \$1}')
264 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 -0700265 export testname=_service_api.robot
266 export library=_library.robot
267 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
268 echo \$SERVICES
Kailash Khalasi54170812018-05-24 12:50:22 -0700269 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Properties/
Kailash Khalasi934d39b2018-05-30 10:59:49 -0700270 sed -i \"s/^\\(SERVER_IP = \\).*/\\1\'\$XOS_CHAMELEON\'/\" RestApiProperties.py
Kailash Khalasi54170812018-05-24 12:50:22 -0700271 sed -i \"s/^\\(SERVER_PORT = \\).*/\\1\'9101\'/\" RestApiProperties.py
Kailash Khalasi934d39b2018-05-30 10:59:49 -0700272 sed -i \"s/^\\(XOS_USER = \\).*/\\1\'admin@opencord.org\'/\" RestApiProperties.py
273 sed -i \"s/^\\(XOS_PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
274 sed -i \"s/^\\(PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
Kailash Khalasi54170812018-05-24 12:50:22 -0700275 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests
276 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 -0700277 if ! [[ "$GERRIT_PROJECT" =~ ^(cord|platform-install|xos|xos-tosca|cord-tester)\$ ]]; then
Kailash Khalasi934d39b2018-05-30 10:59:49 -0700278 for i in \$SERVICES; do bash -c "pybot -d Log -T -e AddressManagerServiceInstance -v TESTLIBRARY:\$i\$library \$i\$testname"; sleep 2; done || true
279 fi
Kailash Khalasi54170812018-05-24 12:50:22 -0700280 popd
281 """
282 }
283 }
284 stage('Publish') {
285 steps {
286 sh """
287 if [ -d RobotLogs ]; then rm -r RobotLogs; fi; mkdir RobotLogs
288 cp -r $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/Log/*ml ./RobotLogs
289 """
290 step([$class: 'RobotPublisher',
291 disableArchiveOutput: false,
292 logFileName: 'RobotLogs/log*.html',
293 otherFiles: '',
294 outputFileName: 'RobotLogs/output*.xml',
295 outputPath: '.',
Kailash Khalasia4cad352018-07-02 10:58:07 -0700296 passThreshold: 95,
Kailash Khalasi54170812018-05-24 12:50:22 -0700297 reportFileName: 'RobotLogs/report*.html',
298 unstableThreshold: 0]);
299 }
300 }
301 }
302 post {
303 always {
304 sh '''
Zack Williamsa834c342018-05-31 11:30:15 -0700305 kubectl get pods --all-namespaces
Zack Williamsc8cfb222018-07-05 13:29:28 -0700306
307 echo "# removing helm deployments"
308 kubectl get pods
Zack Williamsa834c342018-05-31 11:30:15 -0700309 helm list
Zack Williamsc8cfb222018-07-05 13:29:28 -0700310
311 for hchart in \$(helm list -q);
312 do
313 echo "## Purging chart: \${hchart} ##"
314 helm delete --purge "\${hchart}"
315 done
316
Zack Williamsa834c342018-05-31 11:30:15 -0700317 minikube delete
Kailash Khalasi54170812018-05-24 12:50:22 -0700318 '''
Kailash Khalasi934d39b2018-05-30 10:59:49 -0700319 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "suchitra@opennetworking.org, you@opennetworking.org, kailash@opennetworking.org", sendToIndividuals: false])
Kailash Khalasi54170812018-05-24 12:50:22 -0700320 }
321 }
322}