Make BPA VM verifier aware of NUM_WORKERS
[icn.git] / cmd / bpa-operator / e2etest / bpa_vm_verifier.sh
1 #!/usr/bin/env bash
2 set -eu -o pipefail
3
4 CLUSTER_NAME=cluster-test
5 NUM_MASTERS=${NUM_MASTERS:-"1"}
6 NUM_WORKERS=${NUM_WORKERS:-"1"}
7
8 # Create Fake DHCP File
9 mkdir -p /opt/icn/dhcp
10 cat <<EOF > /opt/icn/dhcp/dhcpd.leases
11 # The format of this file is documented in the dhcpd.leases(5) manual page.
12 # This lease file was written by isc-dhcp-4.3.5
13
14 # authoring-byte-order entry is generated, DO NOT DELETE
15 authoring-byte-order little-endian;
16
17 EOF
18 for ((master=0;master<NUM_MASTERS;++master)); do
19     lease=$(virsh net-dhcp-leases baremetal |grep "master-${master}")
20     mac=$(echo $lease | cut -d " " -f 3)
21     ip=$(echo $lease | cut -d " " -f 5)
22     ip="${ip%%/*}"
23     cat <<EOF >> /opt/icn/dhcp/dhcpd.leases
24 lease ${ip} {
25   starts 4 2019/08/08 22:32:49;
26   ends 4 2019/08/08 23:52:49;
27   cltt 4 2019/08/08 22:32:49;
28   binding state active;
29   next binding state free;
30   rewind binding state free;
31   hardware ethernet ${mac};
32   client-hostname "master-${master}";
33 }
34 EOF
35 done
36 for ((worker=0;worker<NUM_WORKERS;++worker)); do
37     lease=$(virsh net-dhcp-leases baremetal |grep "worker-${worker}")
38     mac=$(echo $lease | cut -d " " -f 3)
39     ip=$(echo $lease | cut -d " " -f 5)
40     ip="${ip%%/*}"
41     cat <<EOF >> /opt/icn/dhcp/dhcpd.leases
42 lease ${ip} {
43   starts 4 2019/08/08 22:32:49;
44   ends 4 2019/08/08 23:52:49;
45   cltt 4 2019/08/08 22:32:49;
46   binding state active;
47   next binding state free;
48   rewind binding state free;
49   hardware ethernet ${mac};
50   client-hostname "worker-${worker}";
51 }
52 EOF
53 done
54
55 # Create provisioning CR file for testing
56 cat <<EOF > e2etest/e2e_test_provisioning_cr.yaml
57 apiVersion: bpa.akraino.org/v1alpha1
58 kind: Provisioning
59 metadata:
60   name: e2e-test-provisioning
61   labels:
62     cluster: ${CLUSTER_NAME}
63     owner: c1
64 spec:
65   masters:
66 EOF
67 for ((master=0;master<NUM_MASTERS;++master)); do
68     lease=$(virsh net-dhcp-leases baremetal |grep "master-${master}")
69     mac=$(echo $lease | cut -d " " -f 3)
70     cat <<EOF >> e2etest/e2e_test_provisioning_cr.yaml
71     - master-${master}:
72         mac-address: ${mac}
73 EOF
74 done
75 cat <<EOF >> e2etest/e2e_test_provisioning_cr.yaml
76   workers:
77 EOF
78 for ((worker=0;worker<NUM_WORKERS;++worker)); do
79     lease=$(virsh net-dhcp-leases baremetal |grep "worker-${worker}")
80     mac=$(echo $lease | cut -d " " -f 3)
81     cat <<EOF >> e2etest/e2e_test_provisioning_cr.yaml
82     - worker-${worker}:
83         mac-address: ${mac}
84 EOF
85 done
86 cat <<EOF >> e2etest/e2e_test_provisioning_cr.yaml
87   KUDPlugins:
88     - emco
89 EOF
90 kubectl apply -f e2etest/e2e_test_provisioning_cr.yaml
91 sleep 5
92
93 #Check Status of kud job pod
94 status="Running"
95
96 while [[ $status == "Running" ]]
97 do
98         echo "KUD install job still running"
99         sleep 2m
100         stats=$(kubectl get pods |grep -i kud-${CLUSTER_NAME})
101         status=$(echo $stats | cut -d " " -f 3)
102 done
103
104 if [[ $status == "Completed" ]];
105 then
106    printf "KUD Install Job completed\n"
107    printf "Checking cluster status\n"
108
109    source ../../env/lib/common.sh
110    KUBECONFIG=--kubeconfig=/opt/kud/multi-cluster/${CLUSTER_NAME}/artifacts/admin.conf
111    APISERVER=$(kubectl ${KUBECONFIG} config view --minify -o jsonpath='{.clusters[0].cluster.server}')
112    TOKEN=$(kubectl ${KUBECONFIG} get secret $(kubectl ${KUBECONFIG} get serviceaccount default -o jsonpath='{.secrets[0].name}') -o jsonpath='{.data.token}' | base64 --decode )
113    if ! call_api $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure;
114    then
115      printf "\nKubernetes Cluster Install did not complete successfully\n"
116    else
117      printf "\nKubernetes Cluster Install was successful\n"
118    fi
119
120 else
121    printf "KUD Install Job failed\n"
122 fi
123
124
125 #Print logs of Job Pod
126 jobPod=$(kubectl get pods|grep kud-${CLUSTER_NAME})
127 podName=$(echo $jobPod | cut -d " " -f 1)
128 printf "\nNow Printing Job pod logs\n"
129 kubectl logs $podName
130
131 #Teardown Setup
132 printf "\n\nBeginning E2E Test Teardown\n\n"
133 kubectl delete -f e2etest/e2e_test_provisioning_cr.yaml
134 kubectl delete job kud-${CLUSTER_NAME}
135 kubectl delete --ignore-not-found=true configmap ${CLUSTER_NAME}-configmap
136 rm e2etest/e2e_test_provisioning_cr.yaml
137 rm -rf /opt/kud/multi-cluster/${CLUSTER_NAME}
138 rm /opt/icn/dhcp/dhcpd.leases
139 make delete