Merge "Adds v6 capability to the deploy validation test (pings)"
[apex-tripleo-heat-templates.git] / validation-scripts / all-nodes.sh
1 #!/bin/bash
2
3 # For each unique remote IP (specified via Heat) we check to
4 # see if one of the locally configured networks matches and if so we
5 # attempt a ping test the remote network IP.
6 function ping_controller_ips() {
7   local REMOTE_IPS=$1
8   for REMOTE_IP in $(echo $REMOTE_IPS | sed -e "s| |\n|g" | sort -u); do
9     if [[ $REMOTE_IP =~ ":" ]]; then
10       networks=$(ip -6 r | grep -v default | cut -d " " -f 1 | grep -v "unreachable")
11       ping=ping6
12     else
13       networks=$(ip r | grep -v default | cut -d " " -f 1)
14       ping=ping
15     fi
16     for LOCAL_NETWORK in $networks; do
17       in_network=$(python -c "import ipaddr; net=ipaddr.IPNetwork('$LOCAL_NETWORK'); addr=ipaddr.IPAddress('$REMOTE_IP'); print(addr in net)")
18       if [[ $in_network == "True" ]]; then
19         echo -n "Trying to ping $REMOTE_IP for local network $LOCAL_NETWORK..."
20         if ! $ping -W 300 -c 1 $REMOTE_IP &> /dev/null; then
21           echo "FAILURE"
22           echo "$REMOTE_IP is not pingable. Local Network: $LOCAL_NETWORK" >&2
23           exit 1
24         fi
25         echo "SUCCESS"
26       fi
27     done
28   done
29 }
30
31 # Ping all default gateways. There should only be one
32 # if using upstream t-h-t network templates but we test
33 # all of them should some manual network config have
34 # multiple gateways.
35 function ping_default_gateways() {
36   DEFAULT_GW=$(ip r | grep ^default | cut -d " " -f 3)
37   for GW in $DEFAULT_GW; do
38     echo -n "Trying to ping default gateway ${GW}..."
39     if ! ping -c 1 $GW &> /dev/null; then
40       echo "FAILURE"
41       echo "$GW is not pingable."
42       exit 1
43     fi
44   done
45   echo "SUCCESS"
46 }
47
48 ping_controller_ips "$ping_test_ips"
49 ping_default_gateways