Skip to content
Merged
Show file tree
Hide file tree
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
17 changes: 12 additions & 5 deletions tests/arp/arp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
from tests.common.helpers.assertions import pytest_assert
from tests.common.utilities import wait_until
from ipaddress import ip_interface
from ipaddress import ip_interface, ip_network, IPv4Network


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -95,14 +95,21 @@ def fdb_has_mac(duthost, mac):
return any(mac in line.lower() for line in duthost.command("show mac")["stdout_lines"])


def get_first_vlan_ipv4(config_facts):
def get_vlan_last_ipv4(config_facts):
"""
Get first VLAN interface and its IPv4 address
Return (vlan_intf_name, ipv4) for the first VLAN_INTERFACE with IPv4,
using the last IPv4 in that interface's address list.
"""
vlan_intfs = config_facts.get("VLAN_INTERFACE", {})
for intf, addrs in vlan_intfs.items():
intf_ipv4 = None
for addr in addrs:
if ":" in addr:
try:
if type(ip_network(addr, strict=False)) is IPv4Network:
iface = ip_interface(addr)
intf_ipv4 = (intf, iface.ip)
except ValueError:
continue
return intf, ip_interface(addr).ip
if intf_ipv4 is not None:
return intf_ipv4
return None, None
4 changes: 2 additions & 2 deletions tests/arp/test_arp_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest
import random

from tests.arp.arp_utils import clear_dut_arp_cache, fdb_cleanup, get_dut_mac, fdb_has_mac, get_first_vlan_ipv4
from tests.arp.arp_utils import clear_dut_arp_cache, fdb_cleanup, get_dut_mac, fdb_has_mac, get_vlan_last_ipv4
from tests.common.dualtor.mux_simulator_control import toggle_all_simulator_ports_to_rand_selected_tor # noqa: F401
from tests.common.fixtures.ptfhost_utils import setup_vlan_arp_responder, run_icmp_responder # noqa: F401
from tests.common.helpers.assertions import pytest_assert as pt_assert
Expand Down Expand Up @@ -61,7 +61,7 @@ def dut_interface_info(rand_selected_dut, config_facts, tbinfo):
"""
duthost = rand_selected_dut
dut_mac = get_dut_mac(duthost, config_facts, tbinfo)
vlan_name, dut_ipv4 = get_first_vlan_ipv4(config_facts)
vlan_name, dut_ipv4 = get_vlan_last_ipv4(config_facts)

return {
'host': duthost,
Expand Down
Loading