blob: 55a797435311b54f03752bacff023cc7071a878b [file] [log] [blame]
Wei-Yu Chend8de5d52019-04-18 15:55:57 -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
15node ("${TestNodeName}") {
16 timeout (100) {
17 try {
18 stage ("Parse deployment configuration files") {
19 sh returnStdout: true, script: "rm -rf helm-charts helm-repo-tools ${configBaseDir}"
20 sh returnStdout: true, script: "git clone -b ${branch} ${cordRepoUrl}/helm-repo-tools"
21 sh returnStdout: true, script: "git clone -b ${branch} ${cordRepoUrl}/helm-charts"
22 sh returnStdout: true, script: "git clone -b ${branch} ${cordRepoUrl}/${configBaseDir}"
23 deployment_config = readYaml file: "${configBaseDir}/${configDeploymentDir}/${configFileName}.yaml"
24 }
25
26 // Define KUBECONFIG & HELMCONFIG environment variable to use in steps
27 env.KUBECONFIG="$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.conf"
28 env.HELMCONFIG="$WORKSPACE/${configBaseDir}/${configKubernetesDir}/${configFileName}.yml"
29
30 stage('Clean up') {
31 timeout(10) {
32 // Force helm client to reload server pod, otherwise it'll possible fail on version compatible issue.
33 sh returnStdout: true, script: "helm init --upgrade --force-upgrade"
34
35 timeout(1) {
36 waitUntil {
37 tillerpod_running = sh returnStdout: true, script: """
38 kubectl -n kube-system get pods | grep tiller-deploy | grep Running | wc -l
39 """
40 return tillerpod_running.toInteger() == 1
41 }
42 }
43
44 // Deleted all of charts
45 sh returnStdout: true, script: """
46 for hchart in \$(helm list -q | grep -E -v 'docker-registry|mavenrepo|ponnet');
47 do
48 echo "Purging chart: \${hchart}"
49 helm delete --purge "\${hchart}"
50 done
51 """
52
53 timeout(3) {
54 waitUntil {
55 charts_deleted = sh returnStdout: true, script: """
56 helm ls -q | grep -E -v 'docker-registry|mavenrepo|ponnet' | wc -l
57 """
58 return charts_deleted.toInteger() == 0
59 }
60 }
61
62 timeout(3) {
63 waitUntil {
64 allpods_deleted = sh returnStdout: true, script: """
65 kubectl get pods --all-namespaces --no-headers |\
66 grep -E -v 'kube-system|docker-registry|mavenrepo|ponnet|test' | wc -l
67 """
68 return allpods_deleted.toInteger() == 0
69 }
70 }
71 }
72 }
73
74
75 stage('Add Helm repositories') {
76 sh returnStdout: true, script: """
77 helm repo add cord https://charts.opencord.org
78 helm repo add incubator http://storage.googleapis.com/kubernetes-charts-incubator
79 helm repo update
80 """
81
82 timeout(1) {
83 waitUntil {
84 tillerpod_running = sh returnStdout: true, script: """
85 kubectl -n kube-system get pods | grep tiller-deploy | grep Running | wc -l
86 """
87 return tillerpod_running.toInteger() == 1
88 }
89 }
90
91 timeout(1) {
92 waitUntil {
93 cord_repo_present = sh returnStdout: true, script: """
94 helm repo list | grep cord | wc -l
95 """
96 return cord_repo_present.toInteger() == 1
97 }
98 }
99 }
100
101 stage('Install etcd-cluster') {
102 sh returnStdout: true, script: """
103 helm install -f $HELMCONFIG --version 0.8.3 -n etcd-operator stable/etcd-operator
104 """
105
106 timeout(1) {
107 waitUntil {
108 etcd_operator_running = sh returnStdout: true, script: """
109 kubectl get pods | grep etcd-operator | grep -i running | grep 1/1 | wc -l
110 """
111 return etcd_operator_running.toInteger() == 3
112 }
113 }
114
115 timeout(1) {
116 waitUntil {
117 etcd_operator_crd_present = sh returnStdout: true, script: """
118 kubectl get crd -o json | jq -r '.items[].spec | select(.group=="etcd.database.coreos.com").names.kind' |\
119 grep -E 'EtcdBackup|EtcdCluster|EtcdRestore' | wc -l
120 """
121 return etcd_operator_crd_present.toInteger() == 3
122 }
123 }
124
125 sh returnStdout: true, script: """
126 helm install -f $HELMCONFIG --set etcdNodePort=32379 --set clusterSize=1 -n etcd cord/etcd-cluster
127 """
128
129 timeout(3) {
130 waitUntil {
131 etcd_cluster_running = sh returnStdout: true, script: """
132 kubectl get pods | grep etcd-cluster | grep -i running | grep 1/1 | wc -l
133 """
134 return etcd_cluster_running.toInteger() == 1
135 }
136 }
137 }
138
139 dir ("helm-charts") {
140 stage('Install SR-IOV CNI and SR-IOV Network Device Plugin') {
141 sh returnStdout: true, script: """
142 kubectl delete crd network-attachment-definitions.k8s.cni.cncf.io || true
143 helm install -f $HELMCONFIG -n mcord-setup cord/mcord-setup
144 """
145
146 timeout(1) {
147 waitUntil {
148 network_definition_crd_exist = sh returnStdout: true, script: """
149 kubectl get crd -o json | jq -r '.items[].spec | select(.group=="k8s.cni.cncf.io").names.kind' |\
150 grep -E 'NetworkAttachmentDefinition' | wc -l
151 """
152 return network_definition_crd_exist.toInteger() == 1
153 }
154 }
155
156 // Sometimes tillerpod is up, but it's not ready to accept deployment yet
157 // use helm ls to make sure it's ready.
158 timeout(1) {
159 waitUntil {
160 helm_client_working = sh returnStatus: true, script: "helm ls"
161 return helm_client_working == 0
162 }
163 }
164
Woojoong Kim06955d92019-06-17 17:48:03 -0700165 // Before Start to deploy services, we need to take 10 seconds wait
166 sh returnStdout: true, script: "sleep 10"
Wei-Yu Chend8de5d52019-04-18 15:55:57 -0700167 }
168 }
169
170 stage("Deploy M-CORD Services") {
171 mcord_services_deployed = sh returnStatus: true, script: """
172 helm install -f $HELMCONFIG -n mcord-services cord/mcord-services
173 """
174 return mcord_services_deployed == 0
175
176 timeout (3) {
177 waitUntil {
178 // We should have 5 statefulsets: hss, hssdb, mme, spgwc, spgwu
179 mcord_services_running = sh returnStdout: true, script: """
180 kubectl get statefulset.apps -o json | jq '.items | length'
181 """
182 return mcord_services_running.toInteger() == 5
183 }
184 }
185 }
186
Woojoong Kim06955d92019-06-17 17:48:03 -0700187 stage("Deploy CDN-Remote Services") {
188 cdn_remote_service_deployed = sh returnStatus: true, script: """
189 helm install -f $HELMCONFIG -n cdn-remote --set remote_streaming.antmedia_ip=${deployment_config.nodes[0].ip} \
190 --set stream_name=360 --set remote_streaming.video_quality=360 cord/cdn-remote
191 """
192 return cdn_remote_service_deployed == 0
193
194 timeout (3) {
195 waitUntil {
196 // Are AntMedia server and ffMPEG containers ready?
197 cdn_remote_service_running = sh returnStdout: true, script: """
198 kubectl get statefulset.apps -o json | jq '.items[].metadata.name' | grep -E 'antmedia|remote-streaming' | wc -l
199 """
200 return cdn_remote_service_running.toInteger() == 2
201 }
202 }
203 }
204
205 stage("Deploy CDN-Local Services") {
206 //Is SPGW-U ready?
207 timeout(3) {
208 waitUntil {
209 spgwu_running = sh returnStdout: true, script: """
210 kubectl get pods | grep spgwu | grep Running | grep 1/1 | wc -l
211 """
212 return spgwu_running.toInteger() == 1
213 }
214 }
215
216 cdn_local_service_deployed = sh returnStatus: true, script: """
217 spgwu_ip=\$(kubectl exec -it spgwu-0 -- ip -4 addr show dev sgi-net | grep inet | awk '{print \$2}' | awk -F '/' '{print \$1}');
218 helm install -f $HELMCONFIG -n cdn-local --set remote_ip=${deployment_config.nodes[0].ip} --set stream_name=360 \
219 --set spgwu_sgiip=\$spgwu_ip cord/cdn-local
220 """
221 return cdn_local_service_deployed == 0
222
223 timeout(3) {
224 waitUntil {
225 // Is NGINX ready?
226 cdn_local_service_running = sh returnStdout: true, script: """
227 kubectl get statefulset.apps -o json | jq '.items[].metadata.name' | grep -E 'nginx-rtmp' | wc -l
228 """
229 return cdn_local_service_running.toInteger() == 1
230 }
231 }
232 }
233
Wei-Yu Chend8de5d52019-04-18 15:55:57 -0700234 stage('Install CORD Kafka') {
235 sh returnStdout: true, script: """
236 helm install --version 0.8.8 --set configurationOverrides."offsets\\.topic\\.replication\\.factor"=1 \
237 --set configurationOverrides."log\\.retention\\.hours"=4 \
238 --set configurationOverrides."log\\.message\\.timestamp\\.type"="LogAppendTime" \
239 --set replicas=1 --set persistence.enabled=false --set zookeeper.replicaCount=1 \
240 --set zookeeper.persistence.enabled=false -n cord-kafka incubator/kafka
241 """
242
243 timeout(3) {
244 waitUntil {
245 kafka_instances_running = sh returnStdout: true, script: """
246 kubectl get pods | grep cord-kafka | grep -i running | grep 1/1 | wc -l
247 """
248 return kafka_instances_running.toInteger() == 2
249 }
250 }
251 }
252
253 stage('Install Monitoring Infrastructure') {
254 timeout(3) {
255 sh returnStdout: true, script: """
256 helm install -f $HELMCONFIG -n nem-monitoring cord/nem-monitoring --version 1.0.1
257 helm-repo-tools/wait_for_pods.sh
258 """
259 }
260 }
261
262 stage('Install ONOS') {
263 sh returnStdout: true, script: """
264 helm install -n onos -f $HELMCONFIG cord/onos --version 1.1.0
265 """
266
267 timeout(3) {
268 waitUntil {
269 onos_completed = sh returnStdout: true, script: """
270 kubectl get pods | grep -i onos | grep -i running | grep 1/1 | wc -l
271 """
272 return onos_completed.toInteger() == 1
273 }
274 }
275 }
276
277 stage('Install xos-core') {
278 sh returnStdout: true, script: """
Woojoong Kim7805e9a2019-06-21 14:30:54 -0700279 helm install -f $HELMCONFIG -n xos-core cord/xos-core
Wei-Yu Chend8de5d52019-04-18 15:55:57 -0700280 """
281
282 timeout(3) {
283 waitUntil {
284 xos_core_running = sh returnStdout: true, script: """
285 kubectl get pods | grep -i xos | grep -i running | grep 1/1 | wc -l
286 """
287 return xos_core_running.toInteger() == 6
288 }
289 }
290 }
291 stage('Install M-CORD Profile') {
292 sh returnStdout: true, script: """
Woojoong Kim7805e9a2019-06-21 14:30:54 -0700293 helm install -f $HELMCONFIG -n mcord cord/mcord
Wei-Yu Chend8de5d52019-04-18 15:55:57 -0700294 """
295
296 timeout(5) {
297 waitUntil {
298 mcord_tosca_completed = sh returnStdout: true, script: """
299 kubectl get pods | grep -i mcord-tosca-loader | grep -i completed | wc -l
300 """
301 return mcord_tosca_completed.toInteger() == 1
302 }
303 }
304 }
305
306 stage('Install base-kubernetes') {
307 sh returnStdout: true, script: """
Woojoong Kim7805e9a2019-06-21 14:30:54 -0700308 helm install -f $HELMCONFIG -n base-kubernetes cord/base-kubernetes
Wei-Yu Chend8de5d52019-04-18 15:55:57 -0700309 """
310
311 timeout(5) {
312 waitUntil {
313 base_kubernetes_tosca_completed = sh returnStdout: true, script: """
314 kubectl get pods | grep -i base-kubernetes-tosca-loader | grep -i completed | wc -l
315 """
316 return base_kubernetes_tosca_completed.toInteger() == 1
317 }
318 }
319 }
320
321 if ( params.configurePod ) {
322 dir ("${configBaseDir}/${configToscaDir}/mcord") {
323 stage('Configure MCORD - Fabric') {
324 timeout(1) {
325 waitUntil {
326 out_fabric = sh returnStdout: true, script: """
327 curl -s -H "xos-username:admin@opencord.org" -H "xos-password:letmein" -X POST \
328 --data-binary @${configFileName}-fabric.yaml http://${deployment_config.nodes[0].ip}:30007/run |\
329 grep -i "created models" | wc -l
330 """
331 return out_fabric.toInteger() == 1
332 }
333 }
334 }
335 }
336 }
337 currentBuild.result = 'SUCCESS'
338 } catch (err) {
339 println err.meesage
340 currentBuild.result = 'FAILURE'
341 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${notificationEmail}", sendToIndividuals: false])
342 }
343 echo "RESULT: ${currentBuild.result}"
344 }
345}
Woojoong Kim7805e9a2019-06-21 14:30:54 -0700346