[DHCP_RELAY] Updated wait_for_intf.sh to wait for ipv6 global and link local addr (#12273)

- Why I did it
Fixes #11431

- How I did it
dhcp6relay binds to ipv6 addresses configured on these vlan interfaces
Thus check if they are ready before launching dhcp6relay

- How to verify it
Unit Tests
Tested on a live device

Signed-off-by: Vivek Reddy Karri <vkarri@nvidia.com>
This commit is contained in:
Vivek 2022-10-12 01:46:20 -07:00 committed by GitHub
parent 257cc96d7c
commit 34f9a642dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 77 additions and 1 deletions

View File

@ -21,8 +21,28 @@ function wait_until_iface_ready
echo "Interface ${IFACE_NAME} is ready!"
}
function check_for_ipv6_link_local
{
IFACE_NAME=$1
echo "Waiting until interface ${IFACE_NAME} has a link-local ipv6 address configured...."
# Status of link local address is not populated in STATE_DB
while true; do
HAS_LL=$(ip -6 addr show ${IFACE_NAME} scope link 2> /dev/null)
RC=$?
if [[ ${RC} == "0" ]] && [[ ! -z ${HAS_LL} ]]; then
break
fi
sleep 1
done
echo "Link-Local address is configured on ${IFACE_NAME}"
}
# Wait for all interfaces with IPv4 addresses to be up and ready
# dhcp6relay binds to ipv6 addresses configured on these vlan ifaces
# Thus check if they are ready before launching dhcp6relay
{% for (name, prefix) in INTERFACE|pfx_filter %}
{% if prefix | ipv4 %}
wait_until_iface_ready {{ name }} {{ prefix }}
@ -32,6 +52,12 @@ wait_until_iface_ready {{ name }} {{ prefix }}
{% if prefix | ipv4 %}
wait_until_iface_ready {{ name }} {{ prefix }}
{% endif %}
{% if prefix | ipv6 %}
{% if DHCP_RELAY and name in DHCP_RELAY %}
wait_until_iface_ready {{ name }} {{ prefix }}
check_for_ipv6_link_local {{ name }}
{% endif %}
{% endif %}
{% endfor %}
{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %}
{% if prefix | ipv4 %}

View File

@ -0,0 +1,5 @@
{
"VLAN_INTERFACE": {
"Vlan1000|fc02:2000::2/24": {}
}
}

View File

@ -21,10 +21,32 @@ function wait_until_iface_ready
echo "Interface ${IFACE_NAME} is ready!"
}
function check_for_ipv6_link_local
{
IFACE_NAME=$1
echo "Waiting until interface ${IFACE_NAME} has a link-local ipv6 address configured...."
# Status of link local address is not populated in STATE_DB
while true; do
HAS_LL=$(ip -6 addr show ${IFACE_NAME} scope link 2> /dev/null)
RC=$?
if [[ ${RC} == "0" ]] && [[ ! -z ${HAS_LL} ]]; then
break
fi
sleep 1
done
echo "Link-Local address is configured on ${IFACE_NAME}"
}
# Wait for all interfaces with IPv4 addresses to be up and ready
# dhcp6relay binds to ipv6 addresses configured on these vlan ifaces
# Thus check if they are ready before launching dhcp6relay
wait_until_iface_ready Vlan2000 192.168.200.1/27
wait_until_iface_ready Vlan1000 192.168.0.1/27
wait_until_iface_ready Vlan1000 fc02:2000::2/24
check_for_ipv6_link_local Vlan1000
wait_until_iface_ready PortChannel02 10.0.0.58/31
wait_until_iface_ready PortChannel03 10.0.0.60/31
wait_until_iface_ready PortChannel04 10.0.0.62/31

View File

@ -21,8 +21,30 @@ function wait_until_iface_ready
echo "Interface ${IFACE_NAME} is ready!"
}
function check_for_ipv6_link_local
{
IFACE_NAME=$1
echo "Waiting until interface ${IFACE_NAME} has a link-local ipv6 address configured...."
# Status of link local address is not populated in STATE_DB
while true; do
HAS_LL=$(ip -6 addr show ${IFACE_NAME} scope link 2> /dev/null)
RC=$?
if [[ ${RC} == "0" ]] && [[ ! -z ${HAS_LL} ]]; then
break
fi
sleep 1
done
echo "Link-Local address is configured on ${IFACE_NAME}"
}
# Wait for all interfaces with IPv4 addresses to be up and ready
# dhcp6relay binds to ipv6 addresses configured on these vlan ifaces
# Thus check if they are ready before launching dhcp6relay
wait_until_iface_ready Vlan1000 fc02:2000::2/24
check_for_ipv6_link_local Vlan1000
wait_until_iface_ready Vlan1000 192.168.0.1/27
wait_until_iface_ready Vlan2000 192.168.200.1/27
wait_until_iface_ready PortChannel01 10.0.0.56/31

View File

@ -142,8 +142,9 @@ class TestJ2Files(TestCase):
def test_dhcp_relay(self):
# Test generation of wait_for_intf.sh
dhc_sample_data = os.path.join(self.test_dir, "dhcp-relay-sample.json")
template_path = os.path.join(self.test_dir, '..', '..', '..', 'dockers', 'docker-dhcp-relay', 'wait_for_intf.sh.j2')
argument = '-m ' + self.t0_minigraph + ' -p ' + self.t0_port_config + ' -t ' + template_path + ' > ' + self.output_file
argument = '-m ' + self.t0_minigraph + ' -j ' + dhc_sample_data + ' -p ' + self.t0_port_config + ' -t ' + template_path + ' > ' + self.output_file
self.run_script(argument)
self.assertTrue(utils.cmp(os.path.join(self.test_dir, 'sample_output', utils.PYvX_DIR, 'wait_for_intf.sh'), self.output_file))