Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / mirroring / test-mirrors.sh
1 #!/bin/bash
2 #
3 # Simple script which performs a HTTP and rsync check on
4 # all Ceph mirrors over IPv4 and IPv6 to see if they are online
5 #
6 # Requires IPv4, IPv6, rsync and curl
7 #
8 # Example usage:
9 # - ./test-mirrors.sh eu.ceph.com,de.ceph.com,hk.ceph.com
10 # - cat MIRRORS |cut -d ':' -f 1|xargs -n 1 ./test-mirrors.sh
11 #
12
13 function print_usage {
14     echo "Usage: $0 mirror1,mirror2,mirror3,mirror4,etc"
15 }
16
17 function test_http {
18     HOST=$1
19
20     echo -n "$HOST HTTP IPv4: "
21     curl -s -I -4 -o /dev/null http://$HOST
22     if [ "$?" -ne 0 ]; then
23         echo "FAIL"
24     else
25         echo "OK"
26     fi
27
28     echo -n "$HOST HTTP IPv6: "
29     curl -s -I -6 -o /dev/null http://$HOST
30     if [ "$?" -ne 0 ]; then
31         echo "FAIL"
32     else
33         echo "OK"
34     fi
35 }
36
37 function test_rsync {
38     HOST=$1
39
40     echo -n "$HOST RSYNC IPv4: "
41     rsync -4 -avrqn ${HOST}::ceph /tmp 2>/dev/null
42     if [ "$?" -ne 0 ]; then
43         echo "FAIL"
44     else
45         echo "OK"
46     fi
47
48     echo -n "$HOST RSYNC IPv6: "
49     rsync -6 -avrqn ${HOST}::ceph /tmp 2>/dev/null
50     if [ "$?" -ne 0 ]; then
51         echo "FAIL"
52     else
53         echo "OK"
54     fi
55 }
56
57 MIRRORS=$1
58
59 if [ -z "$MIRRORS" ]; then
60     print_usage
61     exit 1
62 fi
63
64 IFS=', ' read -r -a array <<< "$MIRRORS"
65
66 for MIRROR in "${array[@]}"; do
67     test_http $MIRROR
68     test_rsync $MIRROR
69 done