Skip to content

Commit

Permalink
[dhcp_relay][telemetry] Fix incorrect client mac in dhcp_relay relate…
Browse files Browse the repository at this point in the history
…d telemetry test (#16112)

What is the motivation for this PR?
Client mac of DHCP packets should be ptf interface mac rather than DUT interface mac

How did you do it?
Modify test case to use ptf interface mac

How did you verify/test it?
Run tests in m0/t0 topo
  • Loading branch information
yaqiangz authored and mssonicbld committed Jan 1, 2025
1 parent 14ccfaa commit a6f05cf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions tests/telemetry/events/dhcp-relay_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from tests.common.helpers.assertions import pytest_assert as py_assert
from tests.common.utilities import wait_until
from run_events_test import run_test
from event_utils import find_test_vlan, find_test_port_and_mac, create_dhcp_discover_packet
from event_utils import find_test_vlan, find_test_client_port_and_mac, create_dhcp_discover_packet

logger = logging.getLogger(__name__)
tag = "sonic-events-dhcp-relay"
Expand Down Expand Up @@ -96,7 +96,7 @@ def send_dhcp_discover_packets(duthost, ptfadapter, packets_to_send=5, interval=
# Send packets

# results contains up to 5 tuples of member interfaces from vlan (port, mac address)
results = find_test_port_and_mac(duthost, member_interfaces, 5)
results = find_test_client_port_and_mac(ptfadapter, duthost, member_interfaces, 5)

for i in range(packets_to_send):
result = results[i % len(results)]
Expand Down
9 changes: 4 additions & 5 deletions tests/telemetry/events/event_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,18 @@ def find_test_vlan(duthost):
return {}


def find_test_port_and_mac(duthost, members, count):
# Will return up to count many up ports with their port index and mac address
def find_test_client_port_and_mac(ptfadapter, duthost, members, count):
# Will return up to count many up ports with their port index and mac address of ptf
results = []
interf_status = duthost.show_interface(command="status")['ansible_facts']['int_status']
for member_interface in members:
if len(results) == count:
return results
if interf_status[member_interface]['admin_state'] == "up":
mac = duthost.get_dut_iface_mac(member_interface)
minigraph_info = duthost.minigraph_facts(host=duthost.hostname)['ansible_facts']
port_index = minigraph_info['minigraph_port_indices'][member_interface]
if mac != "" and port_index != "":
results.append([int(port_index), mac])
if port_index != "":
results.append([int(port_index), ptfadapter.dataplane.get_mac(0, port_index).decode()])
return results


Expand Down

0 comments on commit a6f05cf

Please sign in to comment.