blob: f6aa928a30920998397b021254810d4498ab06da [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
Woojoong Kimad782d62019-07-16 16:04:38 -0700156 // verification: sriov pods will be deployed for each machine
157 timeout (1) {
158 waitUntil {
159 num_sriov_pods = sh returnStdout: true, script: """
160 kubectl get pods -n kube-system | grep sriov | wc -l
161 """
162 return num_sriov_pods.toInteger() == deployment_config.nodes.size()
163 }
164 }
165
166 // redeployment procedure for sriov pod
167 // Sometimes a SR-IOV pod encounters "MountVolume.Setup failed". To resolve it, the SR-IOV pod need to be removed and redployed.
168 max_retry_index = 100;
169 for (int i = 0; i<max_retry_index; i++) {
Woojoong Kim44578202019-07-22 10:55:34 -0700170 sh returnStdout: true, script: "sleep 30"
Woojoong Kimad782d62019-07-16 16:04:38 -0700171
172 sh script: """
173 init_num_sriov=\$(kubectl get pods -n kube-system | grep sriov | grep Init | wc -l);
174 for pod in \$(kubectl get pods -n kube-system | grep sriov | grep Init | awk '{print \$1}');
175 do
176 echo \$pod is initializing
Woojoong Kim58e78fa2019-07-30 10:30:09 -0700177 num_err_msgs=\$(kubectl describe pods \$pod -n kube-system | tail -4 | grep -E 'MountVolume.SetUp failed' | wc -l)
Woojoong Kimad782d62019-07-16 16:04:38 -0700178 if [ \$num_err_msgs > 0 ]; then
179 kubectl delete pod \$pod -n kube-system --force --grace-period=0
180 fi
181 done
182 """
183 sriov_all_ready = sh returnStdout: true, script: """
Woojoong Kim44578202019-07-22 10:55:34 -0700184 kubectl get pods -n kube-system | grep sriov | grep Running | wc -l
Woojoong Kimad782d62019-07-16 16:04:38 -0700185 """
Woojoong Kim44578202019-07-22 10:55:34 -0700186 if (sriov_all_ready.toInteger() == deployment_config.nodes.size()) {
Woojoong Kimad782d62019-07-16 16:04:38 -0700187 break;
188 }
189 }
190
Wei-Yu Chend8de5d52019-04-18 15:55:57 -0700191 // Sometimes tillerpod is up, but it's not ready to accept deployment yet
192 // use helm ls to make sure it's ready.
193 timeout(1) {
194 waitUntil {
195 helm_client_working = sh returnStatus: true, script: "helm ls"
196 return helm_client_working == 0
197 }
198 }
199
Woojoong Kim06955d92019-06-17 17:48:03 -0700200 // Before Start to deploy services, we need to take 10 seconds wait
201 sh returnStdout: true, script: "sleep 10"
Wei-Yu Chend8de5d52019-04-18 15:55:57 -0700202 }
203 }
204
205 stage("Deploy M-CORD Services") {
206 mcord_services_deployed = sh returnStatus: true, script: """
207 helm install -f $HELMCONFIG -n mcord-services cord/mcord-services
208 """
209 return mcord_services_deployed == 0
210
211 timeout (3) {
212 waitUntil {
213 // We should have 5 statefulsets: hss, hssdb, mme, spgwc, spgwu
214 mcord_services_running = sh returnStdout: true, script: """
215 kubectl get statefulset.apps -o json | jq '.items | length'
216 """
217 return mcord_services_running.toInteger() == 5
218 }
219 }
220 }
221
Woojoong Kim06955d92019-06-17 17:48:03 -0700222 stage("Deploy CDN-Remote Services") {
223 cdn_remote_service_deployed = sh returnStatus: true, script: """
224 helm install -f $HELMCONFIG -n cdn-remote --set remote_streaming.antmedia_ip=${deployment_config.nodes[0].ip} \
225 --set stream_name=360 --set remote_streaming.video_quality=360 cord/cdn-remote
226 """
227 return cdn_remote_service_deployed == 0
228
229 timeout (3) {
230 waitUntil {
231 // Are AntMedia server and ffMPEG containers ready?
232 cdn_remote_service_running = sh returnStdout: true, script: """
233 kubectl get statefulset.apps -o json | jq '.items[].metadata.name' | grep -E 'antmedia|remote-streaming' | wc -l
234 """
235 return cdn_remote_service_running.toInteger() == 2
236 }
237 }
238 }
239
240 stage("Deploy CDN-Local Services") {
241 //Is SPGW-U ready?
242 timeout(3) {
243 waitUntil {
244 spgwu_running = sh returnStdout: true, script: """
245 kubectl get pods | grep spgwu | grep Running | grep 1/1 | wc -l
246 """
247 return spgwu_running.toInteger() == 1
248 }
249 }
250
251 cdn_local_service_deployed = sh returnStatus: true, script: """
252 spgwu_ip=\$(kubectl exec -it spgwu-0 -- ip -4 addr show dev sgi-net | grep inet | awk '{print \$2}' | awk -F '/' '{print \$1}');
253 helm install -f $HELMCONFIG -n cdn-local --set remote_ip=${deployment_config.nodes[0].ip} --set stream_name=360 \
254 --set spgwu_sgiip=\$spgwu_ip cord/cdn-local
255 """
256 return cdn_local_service_deployed == 0
257
258 timeout(3) {
259 waitUntil {
260 // Is NGINX ready?
261 cdn_local_service_running = sh returnStdout: true, script: """
262 kubectl get statefulset.apps -o json | jq '.items[].metadata.name' | grep -E 'nginx-rtmp' | wc -l
263 """
264 return cdn_local_service_running.toInteger() == 1
265 }
266 }
267 }
268
Wei-Yu Chend8de5d52019-04-18 15:55:57 -0700269 stage('Install CORD Kafka') {
270 sh returnStdout: true, script: """
271 helm install --version 0.8.8 --set configurationOverrides."offsets\\.topic\\.replication\\.factor"=1 \
272 --set configurationOverrides."log\\.retention\\.hours"=4 \
273 --set configurationOverrides."log\\.message\\.timestamp\\.type"="LogAppendTime" \
274 --set replicas=1 --set persistence.enabled=false --set zookeeper.replicaCount=1 \
275 --set zookeeper.persistence.enabled=false -n cord-kafka incubator/kafka
276 """
277
278 timeout(3) {
279 waitUntil {
280 kafka_instances_running = sh returnStdout: true, script: """
281 kubectl get pods | grep cord-kafka | grep -i running | grep 1/1 | wc -l
282 """
283 return kafka_instances_running.toInteger() == 2
284 }
285 }
286 }
287
288 stage('Install Monitoring Infrastructure') {
289 timeout(3) {
290 sh returnStdout: true, script: """
291 helm install -f $HELMCONFIG -n nem-monitoring cord/nem-monitoring --version 1.0.1
292 helm-repo-tools/wait_for_pods.sh
293 """
294 }
295 }
296
297 stage('Install ONOS') {
298 sh returnStdout: true, script: """
299 helm install -n onos -f $HELMCONFIG cord/onos --version 1.1.0
300 """
301
302 timeout(3) {
303 waitUntil {
304 onos_completed = sh returnStdout: true, script: """
305 kubectl get pods | grep -i onos | grep -i running | grep 1/1 | wc -l
306 """
307 return onos_completed.toInteger() == 1
308 }
309 }
310 }
311
312 stage('Install xos-core') {
313 sh returnStdout: true, script: """
Woojoong Kim7805e9a2019-06-21 14:30:54 -0700314 helm install -f $HELMCONFIG -n xos-core cord/xos-core
Wei-Yu Chend8de5d52019-04-18 15:55:57 -0700315 """
316
317 timeout(3) {
318 waitUntil {
319 xos_core_running = sh returnStdout: true, script: """
320 kubectl get pods | grep -i xos | grep -i running | grep 1/1 | wc -l
321 """
322 return xos_core_running.toInteger() == 6
323 }
324 }
325 }
326 stage('Install M-CORD Profile') {
327 sh returnStdout: true, script: """
Woojoong Kim7805e9a2019-06-21 14:30:54 -0700328 helm install -f $HELMCONFIG -n mcord cord/mcord
Wei-Yu Chend8de5d52019-04-18 15:55:57 -0700329 """
330
331 timeout(5) {
332 waitUntil {
333 mcord_tosca_completed = sh returnStdout: true, script: """
334 kubectl get pods | grep -i mcord-tosca-loader | grep -i completed | wc -l
335 """
336 return mcord_tosca_completed.toInteger() == 1
337 }
338 }
339 }
Woojoong Kimdb678c92019-07-09 16:16:52 -0700340/*
Wei-Yu Chend8de5d52019-04-18 15:55:57 -0700341 stage('Install base-kubernetes') {
342 sh returnStdout: true, script: """
Woojoong Kim7805e9a2019-06-21 14:30:54 -0700343 helm install -f $HELMCONFIG -n base-kubernetes cord/base-kubernetes
Wei-Yu Chend8de5d52019-04-18 15:55:57 -0700344 """
345
346 timeout(5) {
347 waitUntil {
348 base_kubernetes_tosca_completed = sh returnStdout: true, script: """
349 kubectl get pods | grep -i base-kubernetes-tosca-loader | grep -i completed | wc -l
350 """
351 return base_kubernetes_tosca_completed.toInteger() == 1
352 }
353 }
354 }
Woojoong Kimdb678c92019-07-09 16:16:52 -0700355*/
Wei-Yu Chend8de5d52019-04-18 15:55:57 -0700356 if ( params.configurePod ) {
357 dir ("${configBaseDir}/${configToscaDir}/mcord") {
358 stage('Configure MCORD - Fabric') {
359 timeout(1) {
360 waitUntil {
361 out_fabric = sh returnStdout: true, script: """
362 curl -s -H "xos-username:admin@opencord.org" -H "xos-password:letmein" -X POST \
Woojoong Kimc45b6492019-07-24 11:49:34 -0700363 --data-binary @${configFileName}-fabric-cavium.yaml http://${deployment_config.nodes[0].ip}:30007/run |\
Wei-Yu Chend8de5d52019-04-18 15:55:57 -0700364 grep -i "created models" | wc -l
365 """
366 return out_fabric.toInteger() == 1
367 }
368 }
369 }
370 }
371 }
372 currentBuild.result = 'SUCCESS'
373 } catch (err) {
374 println err.meesage
375 currentBuild.result = 'FAILURE'
376 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "${notificationEmail}", sendToIndividuals: false])
377 }
378 echo "RESULT: ${currentBuild.result}"
379 }
380}
Woojoong Kim7805e9a2019-06-21 14:30:54 -0700381