Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[action] [PR:16494] [dhcp_relay] Add test case to verify dhcp6relay LLA waiting logic #16554

Open
wants to merge 1 commit into
base: 202405
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 55 additions & 8 deletions tests/dhcp_relay/test_dhcpv6_relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def dut_dhcp_relay_data(duthosts, rand_one_dut_hostname, tbinfo):
duthost = duthosts[rand_one_dut_hostname]
dhcp_relay_data_list = []
down_interface_link_local = ""
down_interface_link_local_with_prefix_len = ""

mg_facts = duthost.get_extended_minigraph_facts(tbinfo)

Expand Down Expand Up @@ -179,18 +180,20 @@ def dut_dhcp_relay_data(duthosts, rand_one_dut_hostname, tbinfo):
uplink_interfaces.append(iface_name)
uplink_port_indices.append(mg_facts['minigraph_ptf_indices'][iface_name])
if down_interface_link_local == "":
command = "ip addr show {} | grep inet6 | grep 'scope link' | awk '{{print $2}}' | cut -d '/' -f1"\
command = "ip addr show {} | grep inet6 | grep 'scope link' | awk '{{print $2}}'"\
.format(downlink_vlan_iface['name'])
res = duthost.shell(command)
if res['stdout'] != "":
down_interface_link_local = res['stdout']
down_interface_link_local_with_prefix_len = res['stdout']
down_interface_link_local = down_interface_link_local_with_prefix_len.split("/")[0]

dhcp_relay_data = {}
dhcp_relay_data['downlink_vlan_iface'] = downlink_vlan_iface
dhcp_relay_data['client_iface'] = client_iface
dhcp_relay_data['uplink_interfaces'] = uplink_interfaces
dhcp_relay_data['uplink_port_indices'] = uplink_port_indices
dhcp_relay_data['down_interface_link_local'] = down_interface_link_local
dhcp_relay_data['down_interface_link_local_with_prefix_len'] = down_interface_link_local_with_prefix_len
dhcp_relay_data['loopback_iface'] = mg_facts['minigraph_lo_interfaces']
dhcp_relay_data['loopback_ipv6'] = mg_facts['minigraph_lo_interfaces'][1]['addr']
if 'dualtor' in tbinfo['topo']['name']:
Expand Down Expand Up @@ -259,12 +262,56 @@ def test_interface_binding(duthosts, rand_one_dut_hostname, dut_dhcp_relay_data,
config_reload(duthost)
wait_critical_processes(duthost)
pytest_assert(wait_until(120, 5, 0, check_interface_status, duthost))
output = duthost.shell("docker exec -t dhcp_relay ss -nlp | grep dhcp6relay")["stdout"]
logger.info(output)
for dhcp_relay in dut_dhcp_relay_data:
assert ("*:{}".format(dhcp_relay['downlink_vlan_iface']['name']) or "*:*" in output,
"{} is not found in {}".format("*:{}".format(dhcp_relay['downlink_vlan_iface']['name']), output)) or \
("*:*" in output, "dhcp6relay socket is not properly binded")

# Cmds to delete LLA for all Vlans
delete_cmds = ["ip -6 address del {} dev {}"
.format(data["down_interface_link_local_with_prefix_len"],
data["downlink_vlan_iface"]["name"]) for data in dut_dhcp_relay_data]

# Cmds to add LLA for all Vlans
add_cmds = ["ip -6 address add {} dev {}"
.format(data["down_interface_link_local_with_prefix_len"],
data["downlink_vlan_iface"]["name"]) for data in dut_dhcp_relay_data]

def _check_dhcp6relay_lla_socket(expect_exist):
res = {}
output = duthost.shell("docker exec -t dhcp_relay ss -nlp | grep dhcp6relay")["stdout"]
for dhcp_relay in dut_dhcp_relay_data:
key = dhcp_relay['downlink_vlan_iface']['name']
res[key] = "{}:547".format(key) in output

logger.info("_check_dhcp6relay_lla_socket res: {}".format(res))

# If expect socket exist, then sockets for all vlan should appear
if expect_exist:
return all(list(res.values()))
# If not expect socket exist, then sockets for all vlan shouldn't appear
else:
return not any(list(res.values()))

try:
duthost.shell_cmds(cmds=delete_cmds)
restart_dhcp_service(duthost)
time.sleep(10)

output = duthost.shell("docker exec -t dhcp_relay ss -nlp | grep dhcp6relay")["stdout"]
logger.info(output)

# Raw socket listen all port would startup
pytest_assert("*:*" in output, "Raw socket for dhcp6relay is not found")

# LLA is not ready, hence there should not be sockets listen on LLA
pytest_assert(_check_dhcp6relay_lla_socket(False), "LLA sockets are found, which is unexpected")

duthost.shell_cmds(cmds=add_cmds)

# Interval for checking lla in dhcp6relay is set as 60s, hence here we expect in worst scenario LLA sould
# be ready in 70s
# LLAs are ready, hence there should be sockets listen on LLA
pytest_assert(wait_until(70, 5, 0, _check_dhcp6relay_lla_socket, True), "Expected LLA sockets are not found")
finally:
for cmd in add_cmds:
duthost.shell(cmd, module_ignore_errors=True)

pytest_assert("Vlan{}".format(new_vlan_id) not in output,
"dhcp6relay bind to Vlan{} without dhcpv6_servers configured, which is unexpected"
Expand Down
Loading