pods_all_edge
[ealt-edge.git] / ci / daily build / csit / verifyClusterMep.sh
1 #!/bin/bash -ex
2 ##############################################################################
3 # Copyright (c) 2020 Huawei Tech and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 KUBERNETES=~/testk8s-kubernetes.yaml
12
13 cat <<EOF > "${KUBERNETES}"
14 ---
15 apiVersion: apps/v1
16 kind: Deployment
17 metadata:
18   name: kubernets-deployment
19   labels:
20     app: nginx
21 spec:
22   replicas: 1
23   selector:
24     matchLabels:
25       app: nginx
26   template:
27     metadata:
28       labels:
29         app: nginx
30     spec:
31       containers:
32         - name: nginx
33           image: nginx:1.15.12
34           ports:
35             - containerPort: 80
36               hostPort: 80
37 EOF
38
39 CLUSTER_INFO=$(kubectl cluster-info)
40
41 count=0
42 total=2
43 result_nginx="failure"
44 result_pods="failure"
45
46 if [[ $CLUSTER_INFO != "" ]]; then
47    kubectl create -f ~/testk8s-kubernetes.yaml
48    count=$((count+1))
49 else
50    echo "No kubernetes cluster present"
51 fi
52
53 sleep 20
54
55 echo "Kubectl deployments........................................."
56 kubectl get deployments
57
58 echo "Test Case: Nginx-Deployment started"
59
60 DEPLOY_CONDIT=$(kubectl get pods \
61               --field-selector=status.phase==Running \
62               | grep kubernets-deployment \
63               | grep -c Running)
64
65 if [[ $DEPLOY_CONDIT == 1 ]]; then
66    result_nginx="success";
67    echo $result_nginx
68 fi
69
70 echo "Kubectl pods in all namespaces................................."
71 kubectl get pods -A
72
73 echo "-------------------------------------------------------------------"
74 echo "-------------------------------------------------------------------"
75
76 sleep 20
77
78 echo "Test Case: Pods status check started"
79
80 PODS_NOT_RUN_COUNT=$(kubectl get pods \
81                     --field-selector=status.phase!=Running \
82                     | grep -c STATUS)
83
84 if [[ $PODS_NOT_RUN_COUNT > 0 ]]; then > /dev/null 2>&1
85    result_pods="failure";
86    count=$((count+1))
87 else
88    count=$((count+1))
89    result_pods="success";
90    echo $result_pods
91 fi
92
93
94 echo "-------------------------------------------------------------------"
95 echo "|                        Total CSIT Tests: $count                      |"
96 echo "|-----------------------------------------------------------------|"
97 echo "|           TEST CASE NAME          |           RESULT            |"
98 echo "|-----------------------------------------------------------------|"
99 echo "|                                   |                             |"
100 echo "|          Nginx-Deployment         |           $result_nginx           |"
101 echo "|                                   |                             |"
102 echo "|          Pods status check        |           $result_pods           |"
103 echo "|                                   |                             |"
104 echo "|-----------------------------------------------------------------|"
105 echo "|              Executed Total CSIT Tests: $count                       |"
106 echo "-------------------------------------------------------------------"