SPEC-4816: Fix upload in agl-extend-test.sh
[src/qa-testdefinitions.git] / common / scripts / artiproxy-upload.sh
1 #!/bin/sh
2
3 if [ -z "$PYARTIPROXY_IP" ];then
4
5         echo "DEBUG: No PYARTIPROXY_IP variable, using fallbacks"
6         BAYLIBRE_IP=10.1.1.47
7         AGLCORELAB_IP=192.168.111.1
8
9         if ping -q -W 2 -4 -c 1 $BAYLIBRE_IP ; then 
10                 PYARTIPROXY_IP=$BAYLIBRE_IP
11         fi
12         if ping -q -W 2 -4 -c 1 $AGLCORELAB_IP ; then
13                 PYARTIPROXY_IP=$AGLCORELAB_IP
14         fi
15         if [ -z $PYARTIPROXY_IP ] ; then
16             echo "ERROR: no PYARTIPROXY_IP"
17             exit 1
18         fi
19 fi
20
21 if [ -z "$1" ];then
22         echo "ERROR: missing path argument"
23         exit 1
24 fi
25
26 if [ -z "$2" ];then
27         echo "ERROR: missing filename argument"
28         exit 1
29 fi
30
31 if [ -d "$1" ];then
32         echo "ERROR: $1 is a directory"
33         exit 1
34 fi
35
36 echo "DEBUG: filename=$2 data=$1"
37 if [ -e "$1" ];then
38         ls -l "$1"
39         if [ -s "$1" ];then
40                 echo "DEBUG: $1 exists and not empty"
41         else
42                 echo "WARNING: $1 is empty"
43         fi
44 else
45         echo "ERROR: data does not exists"
46 fi
47
48 curl --silent --show-error -F "filename=$2" -F "data=@$1" http://$PYARTIPROXY_IP:9090/cgi-bin/pyartiproxy.py --output curl.out
49 if [ $? -ne 0 ];then
50         echo "ERROR: with curl"
51         # retry without silent
52         curl --show-error -F "filename=$2" -F "data=@$1" http://$PYARTIPROXY_IP:9090/cgi-bin/pyartiproxy.py --output curl.out
53 fi
54 ARTI_URL=$(grep -E '^http://.*|https://.*' curl.out)
55 echo "==========================="
56 cat curl.out
57 echo "==========================="
58 if [ -z "$ARTI_URL" ];then
59         # No URL something is wrong
60         lava-test-reference artifactory-$2 --result fail
61         exit 1
62 else
63         lava-test-reference artifactory-$2 --result pass --reference $ARTI_URL
64 fi