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