adding make option for unit testing
[icn.git] / cmd / bpa-restapi-agent / e2e_test.sh
1 #!/bin/bash
2
3 ICN_DIR=$(dirname "$(dirname "$PWD")")
4
5 source "$ICN_DIR/env/lib/common.sh"
6 source "$ICN_DIR/deploy/kud-plugin-addons/minio/lib/minio.sh"
7
8 #create sample image
9 if true ; then
10     cat <<- EOF > /tmp/sample_image
11     This is a dummy file for testing.
12 EOF
13 fi
14
15 IMAGE_SIZE=$(ls -al /tmp/sample_image | awk '{print $5}')
16
17 if true ; then
18     cat <<- EOF > /tmp/sample.json
19     {
20         "owner":  "alpha",
21         "cluster_name": "beta",
22         "type": "container",
23         "image_name": "qwerty123",
24         "image_length": $IMAGE_SIZE,
25         "image_offset": 0,
26         "upload_complete":  false,
27         "description": {
28         "image_records":  [
29             {
30                 "image_record_name": "iuysdi1234",
31                 "repo": "icn",
32                 "tag":  "2"
33             }
34             ]
35         }
36     }
37 EOF
38 fi
39
40 cur_status=""
41
42 while [[ $cur_status != "Running" ]]; do
43
44     cur_status=$(kubectl get pods | grep bpa-api-deployment | awk '{print $3}')
45     if [[ $cur_status != "Running" ]]; then
46         echo "$(date +%H:%M:%S) - BPA-RESTful-API Pod status: $cur_status"
47     else
48         echo "$(date +%H:%M:%S) - BPA-RESTful-API Pod status: $cur_status"
49         break
50
51     fi
52     if [[ $cur_status == "Err"* ]]; then
53         exit 1
54     fi
55     sleep 10
56 done
57
58
59 #Get CLusterIP
60 IP=$(kubectl get services | grep bpa-api-service | awk '{print $3}')
61
62 call_api -i -F "metadata=</tmp/sample.json;type=application/json" -F \
63 file=@/tmp/sample.json -X POST \
64 http://$IP:9015/v1/baremetalcluster/alpha/beta/container_images
65
66 call_api -i -X GET \
67 http://$IP:9015/v1/baremetalcluster/alpha/beta/container_images/qwerty123
68
69 call_api --request PATCH --data-binary "@/tmp/sample_image" \
70 http://$IP:9015/v1/baremetalcluster/alpha/beta/container_images/qwerty123 \
71 --header "Upload-Offset: 0" --header "Expect:" -i
72
73 MINIO_IP=$(kubectl get services | grep minio-service | awk '{print $3}')
74 setup_mc $MINIO_IP
75 obj_size=$(get_object_size container qwerty123)
76 echo "Got obj size: $obj_size"
77 if [[ $obj_size != $IMAGE_SIZE ]]; then
78     exit 1
79 fi
80
81 call_api -i -X DELETE \
82 http://$IP:9015/v1/baremetalcluster/alpha/beta/container_images/qwerty123