Refactored BPA controller code for better testing
[icn.git] / cmd / bpa-operator / bpa_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 # Build KUD image
46 echo "Building KUD image"
47 git clone https://github.com/onap/multicloud-k8s.git
48 pushd multicloud-k8s
49 docker build  --rm \
50          --build-arg http_proxy=${http_proxy} \
51          --build-arg HTTP_PROXY=${HTTP_PROXY} \
52          --build-arg https_proxy=${https_proxy} \
53          --build-arg HTTPS_PROXY=${HTTPS_PROXY} \
54          --build-arg no_proxy=${no_proxy} \
55          --build-arg NO_PROXY=${NO_PROXY} \
56          -t github.com/onap/multicloud-k8s:latest . -f kud/build/Dockerfile
57
58 popd
59 # Create ssh-key-secret required for job
60 kubectl create secret generic ssh-key-secret --from-file=id_rsa=/root/.ssh/id_rsa --from-file=id_rsa.pub=/root/.ssh/id_rsa.pub
61
62 # Create provisioning CR file for testing
63 cat <<EOF > e2e_test_provisioning_cr.yaml
64 apiVersion: bpa.akraino.org/v1alpha1
65 kind: Provisioning
66 metadata:
67   name: e2e-test-provisioning
68   labels:
69     cluster: cluster-test
70     owner: c1
71 spec:
72   masters:
73     - master-0:
74         mac-address: ${masterMAC}
75   workers:
76     - worker-0:
77         mac-address: ${workerMAC}
78 EOF
79 kubectl apply -f e2e_test_provisioning_cr.yaml
80 sleep 5
81
82 #Check Status of kud job pod
83 status="Running"
84
85 while [[ $status == "Running" ]]
86 do
87         echo "KUD install job still running"
88         sleep 2m
89         stats=$(kubectl get pods |grep -i kud-cluster-test)
90         status=$(echo $stats | cut -d " " -f 3)
91 done
92
93 if [[ $status == "Completed" ]];
94 then
95    printf "KUD Install Job completed\n"
96 else
97    printf "KUD Install Job failed\n"
98 fi
99
100 printf "Checking cluster status\n"
101
102 source ../../env/lib/common.sh
103 CLUSTER_NAME=cluster-test
104 KUBECONFIG=--kubeconfig=/opt/kud/multi-cluster/${CLUSTER_NAME}/artifacts/admin.conf
105 APISERVER=$(kubectl ${KUBECONFIG} config view --minify -o jsonpath='{.clusters[0].cluster.server}')
106 TOKEN=$(kubectl ${KUBECONFIG} get secret $(kubectl ${KUBECONFIG} get serviceaccount default -o jsonpath='{.secrets[0].name}') -o jsonpath='{.data.token}' | base64 --decode )
107 call_api $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure
108 ret=$?
109 if [[ $ret != 0 ]];
110 then
111    printf "\nKubernetes Cluster Install did not complete successfully\n"
112 else
113   printf "\nKubernetes Cluster Install was successful\n"
114 fi
115
116
117 printf "\n\nBeginning E2E Test Teardown\n\n"
118 kubectl delete -f e2e_test_provisioning_cr.yaml
119 kubectl delete job kud-cluster-test
120 kubectl delete secret ssh-key-secret
121 rm e2e_test_provisioning_cr.yaml
122 rm -rf /multi-cluster/cluster-test
123 rm /opt/icn/dhcp/dhcpd.leases
124 rm -rf multicloud-k8s
125 make delete