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