Merge "Fix password issue with mysql address for ceilometer"
[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
9   for REMOTE_IP in $(echo $REMOTE_IPS | sed -e "s| |\n|g" | sort -u); do
10
11     for LOCAL_NETWORK in $(ip r | grep -v default | cut -d " " -f 1); do
12        local LOCAL_CIDR=$(echo $LOCAL_NETWORK | cut -d "/" -f 2)
13        local LOCAL_NETMASK=$(ipcalc -m $LOCAL_NETWORK | grep NETMASK | cut -d "=" -f 2)
14        local REMOTE_NETWORK=$(ipcalc -np $REMOTE_IP $LOCAL_NETMASK | grep NETWORK | cut -d "=" -f 2)
15
16        if [ $REMOTE_NETWORK/$LOCAL_CIDR == $LOCAL_NETWORK ]; then
17          echo -n "Trying to ping $REMOTE_IP for local network $LOCAL_NETWORK..."
18          if ! ping -W 300 -c 1 $REMOTE_IP &> /dev/null; then
19            echo "FAILURE"
20            echo "$REMOTE_IP is not pingable. Local Network: $LOCAL_NETWORK" >&2
21            exit 1
22          fi
23          echo "SUCCESS"
24        fi
25     done
26   done
27 }
28
29 # Ping all default gateways. There should only be one
30 # if using upstream t-h-t network templates but we test
31 # all of them should some manual network config have
32 # multiple gateways.
33 function ping_default_gateways() {
34   DEFAULT_GW=$(ip r | grep ^default | cut -d " " -f 3)
35   for GW in $DEFAULT_GW; do
36     echo -n "Trying to ping default gateway ${GW}..."
37     if ! ping -c 1 $GW &> /dev/null; then
38       echo "FAILURE"
39       echo "$GW is not pingable."
40       exit 1
41     fi
42   done
43   echo "SUCCESS"
44 }
45
46 ping_controller_ips "$ping_test_ips"
47 ping_default_gateways