blob: 9ae73a4d6fde31b8968bb8487afc58cb40f218a2 [file] [log] [blame]
Zack Williams9d68aa32018-07-12 11:50:37 -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// chart-api-test-helm.groovy
16// Checks functionality of the helm-chart, without overriding the version/tag used
17
18CORE_CONTAINER="null"
19
20pipeline {
21
Zack Williamsfd87d652018-07-12 14:21:12 -070022 /* no label, executor is determined by JJB */
23 agent {
24 label "${params.executorNode}"
25 }
Zack Williams9d68aa32018-07-12 11:50:37 -070026
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 pushd cord
51 PROJECT_PATH=\$(xmllint --xpath "string(//project[@name=\\\"${gerritProject}\\\"]/@path)" .repo/manifest.xml)
52 repo download "\$PROJECT_PATH" "${gerritChangeNumber}/${gerritPatchsetNumber}"
53 popd
54 """
55 }
56 }
57
58
59 stage('minikube') {
60 steps {
61 /* see https://github.com/kubernetes/minikube/#linux-continuous-integration-without-vm-support */
62 sh '''
63 export MINIKUBE_WANTUPDATENOTIFICATION=false
64 export MINIKUBE_WANTREPORTERRORPROMPT=false
65 export CHANGE_MINIKUBE_NONE_USER=true
66 export MINIKUBE_HOME=$HOME
67 mkdir -p $HOME/.kube || true
68 touch $HOME/.kube/config
69 export KUBECONFIG=$HOME/.kube/config
70 sudo -E /usr/bin/minikube start --vm-driver=none
71 '''
72 script {
73 timeout(3) {
74 waitUntil {
75 sleep 5
76 def kc_ret = sh script: "kubectl get po", returnStatus: true
77 return (kc_ret == 0);
78 }
79 }
80 }
81 }
82 }
83
84 stage('helm') {
85 steps {
86 sh '''
87 helm init
88 sleep 60
89 helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/
90 '''
91 }
92 }
93
94 stage('build') {
95 steps {
96 sh """
97 #!/usr/bin/env bash
98 set -eu -o pipefail
99
100 helm_install_args='-f examples/api-test-values.yaml'
101 basesleep=300
102 extrasleep=60
103
104 pushd cord/helm-charts
105
106 helm dep up xos-core
107 helm install \${helm_install_args} xos-core -n xos-core
108
109 # Pick which chart(s) to load depending on the project being tested
110 # In regex, please list repos in same order as requirements.yaml in the chart(s) loaded!
111
112 if [[ "$GERRIT_PROJECT" =~ ^(rcord|onos-service|fabric|olt-service|vsg-hw|vrouter)\$ ]]; then
113 helm dep update xos-profiles/rcord-lite
114 helm install \${helm_install_args} xos-profiles/rcord-lite -n rcord-lite
115 extrasleep=300
116
117 elif [[ "$GERRIT_PROJECT" =~ ^(vMME|vspgwc|vspgwu|vHSS|hss_db|internetemulator|sdn-controller|epc-service|mcord|progran)\$ ]]; then
118 helm dep update xos-profiles/base-openstack
119 helm dep update xos-profiles/mcord
120 helm install \${helm_install_args} xos-profiles/base-openstack -n base-openstack
121 helm install \${helm_install_args} xos-profiles/mcord -n mcord
122 extrasleep=900
123
124 elif [[ "$GERRIT_PROJECT" =~ ^(openstack|vtn-service|exampleservice|addressmanager)\$ ]]; then
125 # NOTE: onos-service is included in base-openstack, but tested w/rcord-lite chart
126
127 helm dep update xos-profiles/base-openstack
128 helm dep update xos-profiles/demo-exampleservice
129 helm install \${helm_install_args} xos-profiles/base-openstack -n base-openstack
130 helm install \${helm_install_args} xos-profiles/demo-exampleservice -n demo-exampleservice
131
132 elif [[ "$GERRIT_PROJECT" =~ ^(kubernetes-service|simpleexampleservice)\$ ]]; then
133 helm dep update xos-profiles/base-kubernetes
134 helm dep update xos-profiles/demo-simpleexampleservice
135 helm install \${helm_install_args} xos-profiles/base-kubernetes -n base-kubernetes
136 helm install \${helm_install_args} xos-profiles/demo-simpleexampleservice -n demo-simpleexampleservice
137
138 elif [[ "$GERRIT_PROJECT" =~ ^(hippie-oss)\$ ]]; then
139 helm dep update xos-services/hippie-oss
140 helm install \${helm_install_args} xos-services/hippie-oss -n hippie-oss
141
142 elif [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester|helm-charts)\$ ]]; then
143 echo "No additional charts to install for testing $GERRIT_PROJECT"
144
145 else
146 echo "Couldn't find a chart to test project: $GERRIT_PROJECT!"
147 exit 1
148 fi
149
150 # sleep to wait for services to load
151 sleep "\$basesleep"
152 sleep "\$extrasleep"
153
154 echo "# Checking helm deployments"
155 kubectl get pods
156 helm list
157
158 for hchart in \$(helm list -q);
159 do
160 echo "## 'helm status' for chart: \${hchart} ##"
161 helm status "\${hchart}"
162 done
163
164 popd
Zack Williamsfd87d652018-07-12 14:21:12 -0700165 """
Zack Williams9d68aa32018-07-12 11:50:37 -0700166 }
167 }
Zack Williamsfd87d652018-07-12 14:21:12 -0700168
Zack Williams9d68aa32018-07-12 11:50:37 -0700169 stage('setup') {
170 steps {
171 sh """
Zack Williamsfd87d652018-07-12 14:21:12 -0700172 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
Zack Williams9d68aa32018-07-12 11:50:37 -0700173
Zack Williamsfd87d652018-07-12 14:21:12 -0700174 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
175 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
176 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
177 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 Williams9d68aa32018-07-12 11:50:37 -0700178
Zack Williamsfd87d652018-07-12 14:21:12 -0700179 # create additional testing files if services are loaded
180 if ! [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester|helm-charts)\$ ]]; then
181 export testname=_service_api.robot
182 export library=_library.robot
Zack Williams9d68aa32018-07-12 11:50:37 -0700183
Zack Williamsfd87d652018-07-12 14:21:12 -0700184 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
185 echo \$SERVICES
Zack Williams9d68aa32018-07-12 11:50:37 -0700186
Zack Williamsfd87d652018-07-12 14:21:12 -0700187 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
188
189 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
190 fi
191 """
Zack Williams9d68aa32018-07-12 11:50:37 -0700192 }
Zack Williamsfd87d652018-07-12 14:21:12 -0700193 }
194
Zack Williams9d68aa32018-07-12 11:50:37 -0700195 stage('test') {
Zack Williamsfd87d652018-07-12 14:21:12 -0700196 steps {
197 sh """
198 pushd cord/test/cord-tester/src/test/cord-api/Tests
Zack Williams9d68aa32018-07-12 11:50:37 -0700199
Zack Williamsfd87d652018-07-12 14:21:12 -0700200 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
201 CHAM_CONTAINER=\$(docker ps | grep k8s_xos-chameleon | awk '{print \$1}')
202 XOS_CHAMELEON=\$(docker exec \$CHAM_CONTAINER ip a | grep -oE "([0-9]{1,3}\\.){3}[0-9]{1,3}\\b" | grep 172)
Zack Williams9d68aa32018-07-12 11:50:37 -0700203
Zack Williamsfd87d652018-07-12 14:21:12 -0700204 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Properties/
205 sed -i \"s/^\\(SERVER_IP = \\).*/\\1\'\$XOS_CHAMELEON\'/\" RestApiProperties.py
206 sed -i \"s/^\\(SERVER_PORT = \\).*/\\1\'9101\'/\" RestApiProperties.py
207 sed -i \"s/^\\(XOS_USER = \\).*/\\1\'admin@opencord.org\'/\" RestApiProperties.py
208 sed -i \"s/^\\(XOS_PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
209 sed -i \"s/^\\(PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
Zack Williams9d68aa32018-07-12 11:50:37 -0700210
Zack Williamsfd87d652018-07-12 14:21:12 -0700211 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests
212 pybot -d Log -T -e TenantWithContainer -e Port -e ControllerImages -e ControllerNetwork -e ControllerSlice -e ControllerUser XOSCoreAPITests.robot || true
213
214 # do additional tests if services are loaded
215 if ! [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester|helm-charts)\$ ]]; then
216 export testname=_service_api.robot
217 export library=_library.robot
218 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
219 echo \$SERVICES
220
221 for i in \$SERVICES; do bash -c "pybot -d Log -T -e AddressManagerServiceInstance -v TESTLIBRARY:\$i\$library \$i\$testname"; sleep 2; done || true
222 fi
223
224 popd
225 """
226 }
Zack Williams9d68aa32018-07-12 11:50:37 -0700227 }
Zack Williamsfd87d652018-07-12 14:21:12 -0700228
229 stage('publish') {
230 steps {
231 sh """
232 if [ -d RobotLogs ]; then rm -r RobotLogs; fi; mkdir RobotLogs
233 cp -r $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/Log/*ml ./RobotLogs
234 """
235
236 step([$class: 'RobotPublisher',
237 disableArchiveOutput: false,
238 logFileName: 'RobotLogs/log*.html',
239 otherFiles: '',
240 outputFileName: 'RobotLogs/output*.xml',
241 outputPath: '.',
Kailash Khalasiad6cfda2018-07-25 11:31:35 -0700242 passThreshold: 100,
Zack Williamsfd87d652018-07-12 14:21:12 -0700243 reportFileName: 'RobotLogs/report*.html',
244 unstableThreshold: 0]);
245 }
246 }
247
248 }
249 post {
250 always {
251 sh '''
252 kubectl get pods --all-namespaces
253
254 echo "# removing helm deployments"
255 kubectl get pods
256 helm list
257
258 for hchart in \$(helm list -q);
259 do
260 echo "## Purging chart: \${hchart} ##"
261 helm delete --purge "\${hchart}"
262 done
263
Zack Williamsf8b356c2018-07-17 17:01:27 -0700264 sudo minikube delete
Zack Williamsfd87d652018-07-12 14:21:12 -0700265 '''
266 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "suchitra@opennetworking.org, you@opennetworking.org, kailash@opennetworking.org", sendToIndividuals: false])
267 }
268 }
Zack Williams9d68aa32018-07-12 11:50:37 -0700269}