Skip to content

Commit 92d359d

Browse files
authored
[201811][dhcp_relay] Properly wait for routed interfaces to be ready before starting relay agent (#3442)
1 parent 9f28851 commit 92d359d

File tree

2 files changed

+26
-32
lines changed

2 files changed

+26
-32
lines changed

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +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
27+
# Wait for all interfaces with IPv4 addresses to be up and ready
3228
{% for (name, prefix) in INTERFACE %}
33-
wait_until_iface_ready ${PORT_TABLE_PREFIX} {{ name }}
29+
{% if prefix | ipv4 %}
30+
wait_until_iface_ready {{ name }} {{ prefix }}
31+
{% endif %}
3432
{% endfor %}
3533
{% for (name, prefix) in VLAN_INTERFACE %}
36-
wait_until_iface_ready ${VLAN_TABLE_PREFIX} {{ name }}
34+
{% if prefix | ipv4 %}
35+
wait_until_iface_ready {{ name }} {{ prefix }}
36+
{% endif %}
3737
{% endfor %}
3838
{% for (name, prefix) in PORTCHANNEL_INTERFACE %}
39-
wait_until_iface_ready ${LAG_TABLE_PREFIX} {{ name }}
39+
{% if prefix | ipv4 %}
40+
wait_until_iface_ready {{ name }} {{ prefix }}
41+
{% endif %}
4042
{% endfor %}

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

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +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} PortChannel01
35-
wait_until_iface_ready ${LAG_TABLE_PREFIX} PortChannel02
36-
wait_until_iface_ready ${LAG_TABLE_PREFIX} PortChannel02
37-
wait_until_iface_ready ${LAG_TABLE_PREFIX} PortChannel03
38-
wait_until_iface_ready ${LAG_TABLE_PREFIX} PortChannel03
39-
wait_until_iface_ready ${LAG_TABLE_PREFIX} PortChannel04
40-
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
4133

0 commit comments

Comments
 (0)