Skip to content

Commit 0e62280

Browse files
authored
[dhcp_relay] Properly wait for routed interfaces to be ready before starting relay agent (#3441)
1 parent 2114b21 commit 0e62280

File tree

2 files changed

+26
-35
lines changed

2 files changed

+26
-35
lines changed

dockers/docker-dhcp-relay/wait_for_intf.sh.j2

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,41 @@
22

33
STATE_DB_IDX="6"
44

5-
PORT_TABLE_PREFIX="PORT_TABLE"
6-
VLAN_TABLE_PREFIX="VLAN_TABLE"
7-
LAG_TABLE_PREFIX="LAG_TABLE"
8-
95
function wait_until_iface_ready
106
{
11-
TABLE_PREFIX=$1
12-
IFACE=$2
7+
IFACE_NAME=$1
8+
IFACE_CIDR=$2
139

14-
echo "Waiting until interface $IFACE is ready..."
10+
echo "Waiting until interface ${IFACE_NAME} is ready..."
1511

1612
# Wait for the interface to come up
1713
# (i.e., interface is present in STATE_DB and state is "ok")
1814
while true; do
19-
RESULT=$(redis-cli -n ${STATE_DB_IDX} HGET "${TABLE_PREFIX}|${IFACE}" "state" 2> /dev/null)
15+
RESULT=$(redis-cli -n ${STATE_DB_IDX} HGET "INTERFACE_TABLE|${IFACE_NAME}|${IFACE_CIDR}" "state" 2> /dev/null)
2016
if [ x"$RESULT" == x"ok" ]; then
2117
break
2218
fi
2319

2420
sleep 1
2521
done
2622

27-
echo "Interface ${IFACE} is ready!"
23+
echo "Interface ${IFACE_NAME} is ready!"
2824
}
2925

3026

31-
# Wait for all interfaces to be up and ready
32-
{% for name in PORT %}
33-
{% if name in INTERFACE %}
34-
wait_until_iface_ready ${PORT_TABLE_PREFIX} {{ name }}
27+
# Wait for all interfaces with IPv4 addresses to be up and ready
28+
{% for (name, prefix) in INTERFACE|pfx_filter %}
29+
{% if prefix | ipv4 %}
30+
wait_until_iface_ready {{ name }} {{ prefix }}
3531
{% endif %}
3632
{% endfor %}
37-
{% for name in VLAN %}
38-
{% if name in VLAN_INTERFACE %}
39-
wait_until_iface_ready ${VLAN_TABLE_PREFIX} {{ name }}
33+
{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %}
34+
{% if prefix | ipv4 %}
35+
wait_until_iface_ready {{ name }} {{ prefix }}
4036
{% endif %}
4137
{% endfor %}
42-
{% for name in PORTCHANNEL %}
43-
{% if name in PORTCHANNEL_INTERFACE %}
44-
wait_until_iface_ready ${LAG_TABLE_PREFIX} {{ name }}
38+
{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %}
39+
{% if prefix | ipv4 %}
40+
wait_until_iface_ready {{ name }} {{ prefix }}
4541
{% endif %}
4642
{% endfor %}
47-

src/sonic-config-engine/tests/sample_output/wait_for_intf.sh

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,32 @@
22

33
STATE_DB_IDX="6"
44

5-
PORT_TABLE_PREFIX="PORT_TABLE"
6-
VLAN_TABLE_PREFIX="VLAN_TABLE"
7-
LAG_TABLE_PREFIX="LAG_TABLE"
8-
95
function wait_until_iface_ready
106
{
11-
TABLE_PREFIX=$1
12-
IFACE=$2
7+
IFACE_NAME=$1
8+
IFACE_CIDR=$2
139

14-
echo "Waiting until interface $IFACE is ready..."
10+
echo "Waiting until interface ${IFACE_NAME} is ready..."
1511

1612
# Wait for the interface to come up
1713
# (i.e., interface is present in STATE_DB and state is "ok")
1814
while true; do
19-
RESULT=$(redis-cli -n ${STATE_DB_IDX} HGET "${TABLE_PREFIX}|${IFACE}" "state" 2> /dev/null)
15+
RESULT=$(redis-cli -n ${STATE_DB_IDX} HGET "INTERFACE_TABLE|${IFACE_NAME}|${IFACE_CIDR}" "state" 2> /dev/null)
2016
if [ x"$RESULT" == x"ok" ]; then
2117
break
2218
fi
2319

2420
sleep 1
2521
done
2622

27-
echo "Interface ${IFACE} is ready!"
23+
echo "Interface ${IFACE_NAME} is ready!"
2824
}
2925

3026

31-
# Wait for all interfaces to be up and ready
32-
wait_until_iface_ready ${VLAN_TABLE_PREFIX} Vlan1000
33-
wait_until_iface_ready ${LAG_TABLE_PREFIX} PortChannel01
34-
wait_until_iface_ready ${LAG_TABLE_PREFIX} PortChannel02
35-
wait_until_iface_ready ${LAG_TABLE_PREFIX} PortChannel03
36-
wait_until_iface_ready ${LAG_TABLE_PREFIX} PortChannel04
27+
# Wait for all interfaces with IPv4 addresses to be up and ready
28+
wait_until_iface_ready Vlan1000 192.168.0.1/27
29+
wait_until_iface_ready PortChannel01 10.0.0.56/31
30+
wait_until_iface_ready PortChannel02 10.0.0.58/31
31+
wait_until_iface_ready PortChannel03 10.0.0.60/31
32+
wait_until_iface_ready PortChannel04 10.0.0.62/31
3733

0 commit comments

Comments
 (0)