sonic-buildimage/dockers/docker-dhcp-relay/wait_for_intf.sh.j2
wangshengjun 7b0389d8a3 [dhcp_relay] Only call 'wait_until_iface_ready' once for each interface (#3317)
Signed-off-by: wangshengjun <wangshengjun@asterfusion.com>
2019-08-09 11:28:15 -07:00

48 lines
1.1 KiB
Django/Jinja

#!/usr/bin/env bash
STATE_DB_IDX="6"
PORT_TABLE_PREFIX="PORT_TABLE"
VLAN_TABLE_PREFIX="VLAN_TABLE"
LAG_TABLE_PREFIX="LAG_TABLE"
function wait_until_iface_ready
{
TABLE_PREFIX=$1
IFACE=$2
echo "Waiting until interface $IFACE is ready..."
# Wait for the interface to come up
# (i.e., interface is present in STATE_DB and state is "ok")
while true; do
RESULT=$(redis-cli -n ${STATE_DB_IDX} HGET "${TABLE_PREFIX}|${IFACE}" "state" 2> /dev/null)
if [ x"$RESULT" == x"ok" ]; then
break
fi
sleep 1
done
echo "Interface ${IFACE} is ready!"
}
# Wait for all interfaces to be up and ready
{% for name in PORT %}
{% if name in INTERFACE %}
wait_until_iface_ready ${PORT_TABLE_PREFIX} {{ name }}
{% endif %}
{% endfor %}
{% for name in VLAN %}
{% if name in VLAN_INTERFACE %}
wait_until_iface_ready ${VLAN_TABLE_PREFIX} {{ name }}
{% endif %}
{% endfor %}
{% for name in PORTCHANNEL %}
{% if name in PORTCHANNEL_INTERFACE %}
wait_until_iface_ready ${LAG_TABLE_PREFIX} {{ name }}
{% endif %}
{% endfor %}