blob: 57889b37b7c6b77560b0bca7615d7f290498e379 [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
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 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
165 """
166 }
167 }
168 stage('setup') {
169 steps {
170 sh """
171 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
172
173 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
174 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
175 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
176 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
177
178 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
179
180 export testname=_service_api.robot
181 export library=_library.robot
182
183 # do addtional tests if additional services are loaded
184 if ! [[ "$GERRIT_PROJECT" =~ ^(xos|xos-tosca|cord-tester)\$ ]]; then
185 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
186 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
187 fi
188 """
189 }
190 }
191 stage('test') {
192 steps {
193 sh """
194 pushd cord/test/cord-tester/src/test/cord-api/Tests
195 CORE_CONTAINER=\$(docker ps | grep k8s_xos-core | awk '{print \$1}')
196 CHAM_CONTAINER=\$(docker ps | grep k8s_xos-chameleon | awk '{print \$1}')
197 XOS_CHAMELEON=\$(docker exec \$CHAM_CONTAINER ip a | grep -oE "([0-9]{1,3}\\.){3}[0-9]{1,3}\\b" | grep 172)
198 export testname=_service_api.robot
199 export library=_library.robot
200 SERVICES=\$(docker exec -i \$CORE_CONTAINER /bin/bash -c "cd /opt/xos/dynamic_services/;find -name '*.xproto'" | awk -F[//] '{print \$2}')
201 echo \$SERVICES
202 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Properties/
203 sed -i \"s/^\\(SERVER_IP = \\).*/\\1\'\$XOS_CHAMELEON\'/\" RestApiProperties.py
204 sed -i \"s/^\\(SERVER_PORT = \\).*/\\1\'9101\'/\" RestApiProperties.py
205 sed -i \"s/^\\(XOS_USER = \\).*/\\1\'admin@opencord.org\'/\" RestApiProperties.py
206 sed -i \"s/^\\(XOS_PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
207 sed -i \"s/^\\(PASSWD = \\).*/\\1\'letmein\'/\" RestApiProperties.py
208 cd $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests
209 pybot -d Log -T -e TenantWithContainer -e Port -e ControllerImages -e ControllerNetwork -e ControllerSlice -e ControllerUser XOSCoreAPITests.robot || true
210 if ! [[ "$GERRIT_PROJECT" =~ ^(cord|platform-install|xos|xos-tosca|cord-tester)\$ ]]; then
211 for i in \$SERVICES; do bash -c "pybot -d Log -T -e AddressManagerServiceInstance -v TESTLIBRARY:\$i\$library \$i\$testname"; sleep 2; done || true
212 fi
213 popd
214 """
215 }
216 }
217 stage('Publish') {
218 steps {
219 sh """
220 if [ -d RobotLogs ]; then rm -r RobotLogs; fi; mkdir RobotLogs
221 cp -r $WORKSPACE/cord/test/cord-tester/src/test/cord-api/Tests/Log/*ml ./RobotLogs
222 """
223 step([$class: 'RobotPublisher',
224 disableArchiveOutput: false,
225 logFileName: 'RobotLogs/log*.html',
226 otherFiles: '',
227 outputFileName: 'RobotLogs/output*.xml',
228 outputPath: '.',
229 passThreshold: 95,
230 reportFileName: 'RobotLogs/report*.html',
231 unstableThreshold: 0]);
232 }
233 }
234 }
235 post {
236 always {
237 sh '''
238 kubectl get pods --all-namespaces
239
240 echo "# removing helm deployments"
241 kubectl get pods
242 helm list
243
244 for hchart in \$(helm list -q);
245 do
246 echo "## Purging chart: \${hchart} ##"
247 helm delete --purge "\${hchart}"
248 done
249
250 minikube delete
251 '''
252 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "suchitra@opennetworking.org, you@opennetworking.org, kailash@opennetworking.org", sendToIndividuals: false])
253 }
254 }
255}