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