bfc9478fe26a34837a185405f5ad403b0dbd5bfc
[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         break
49
50     fi
51     if [[ $cur_status == "Err"* ]]; then
52         exit 1
53     fi
54     sleep 10
55 done
56
57
58 #Get CLusterIP
59 IP=$(kubectl get services | grep bpa-api-service | awk '{print $3}')
60
61 call_api -i -F "metadata=</tmp/sample.json;type=application/json" -F \
62 file=@/tmp/sample.json -X POST \
63 http://$IP:9015/v1/baremetalcluster/alpha/beta/container_images
64
65 call_api -i -X GET \
66 http://$IP:9015/v1/baremetalcluster/alpha/beta/container_images/qwerty123
67
68 call_api --request PATCH --data-binary "@/tmp/sample_image" \
69 http://$IP:9015/v1/baremetalcluster/alpha/beta/container_images/qwerty123 \
70 --header "Upload-Offset: 0" --header "Expect:" -i
71
72 MINIO_IP=$(kubectl get services | grep minio-service | awk '{print $3}')
73 setup_mc $MINIO_IP
74 obj_size=$(get_object_size container qwerty123)
75 echo "Got obj size: $obj_size"
76 if [[ $obj_size != $IMAGE_SIZE ]]; then
77     exit 1
78 fi
79
80 call_api -i -X DELETE \
81 http://$IP:9015/v1/baremetalcluster/alpha/beta/container_images/qwerty123