Skip to content
Merged
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
33 changes: 23 additions & 10 deletions tests/dhcp_relay/test_dhcp_relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pytest
import random
import time
import logging

from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # lgtm[py/unused-import]
from tests.common.fixtures.ptfhost_utils import change_mac_addresses # lgtm[py/unused-import]
Expand All @@ -22,6 +23,7 @@
SINGLE_TOR_MODE = 'single'
DUAL_TOR_MODE = 'dual'

logger = logging.getLogger(__name__)

@pytest.fixture(autouse=True)
def ignore_expected_loganalyzer_exceptions(rand_one_dut_hostname, loganalyzer):
Expand Down Expand Up @@ -114,18 +116,27 @@ def dut_dhcp_relay_data(duthosts, rand_one_dut_hostname, ptfhost, tbinfo):
return dhcp_relay_data_list


@pytest.fixture(scope="module")
def validate_dut_routes_exist(duthosts, rand_one_dut_hostname, dut_dhcp_relay_data):
"""Fixture to valid a route to each DHCP server exist
def check_routes_to_dhcp_server(duthost, dut_dhcp_relay_data):
"""Validate there is route on DUT to each DHCP server
"""
duthost = duthosts[rand_one_dut_hostname]
dhcp_servers = set()
for dhcp_relay in dut_dhcp_relay_data:
dhcp_servers |= set(dhcp_relay['downlink_vlan_iface']['dhcp_server_addrs'])

for dhcp_server in dhcp_servers:
rtInfo = duthost.get_ip_route_info(ipaddress.ip_address(dhcp_server))
assert len(rtInfo["nexthops"]) > 0, "Failed to find route to DHCP server '{0}'".format(dhcp_server)
if len(rtInfo["nexthops"]) == 0:
logger.info("Failed to find route to DHCP server '{0}'".format(dhcp_server))
return False
return True


@pytest.fixture(scope="module")
def validate_dut_routes_exist(duthosts, rand_one_dut_hostname, dut_dhcp_relay_data):
"""Fixture to valid a route to each DHCP server exist
"""
pytest_assert(check_routes_to_dhcp_server(duthosts[rand_one_dut_hostname], dut_dhcp_relay_data),
"Failed to find route for DHCP server")


def restart_dhcp_service(duthost):
Expand Down Expand Up @@ -239,9 +250,10 @@ def test_dhcp_relay_after_link_flap(ptfhost, dut_dhcp_relay_data, validate_dut_r
# Bring all uplink interfaces back up
for iface in dhcp_relay['uplink_interfaces']:
duthost.shell('ifconfig {} up'.format(iface))

pytest_assert(wait_until(50, 5, check_link_status, duthost, dhcp_relay['uplink_interfaces'], "up"),
"Not all uplinks are up")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the issue happening if the portchannel consists of one interface and doesn't happen otherwise?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I don't think so. There are two members in each portchannel on this testbed

  No.  Team Dev         Protocol     Ports
-----  ---------------  -----------  ---------------------------
 0001  PortChannel0001  LACP(A)(Up)  Ethernet0(S) Ethernet4(S)
 0002  PortChannel0002  LACP(A)(Up)  Ethernet20(S) Ethernet16(S)
 0003  PortChannel0003  LACP(A)(Up)  Ethernet68(S) Ethernet64(S)
 0004  PortChannel0004  LACP(A)(Up)  Ethernet84(S) Ethernet80(S)

# Wait until uplinks are up and routes are recovered
pytest_assert(wait_until(50, 5, check_routes_to_dhcp_server, duthost, dut_dhcp_relay_data),
"Not all DHCP servers are routed")

# Run the DHCP relay test on the PTF host
ptf_runner(ptfhost,
Expand Down Expand Up @@ -297,8 +309,9 @@ def test_dhcp_relay_start_with_uplinks_down(ptfhost, dut_dhcp_relay_data, valida
for iface in dhcp_relay['uplink_interfaces']:
duthost.shell('ifconfig {} up'.format(iface))

pytest_assert(wait_until(50, 5, check_link_status, duthost, dhcp_relay['uplink_interfaces'], "up"),
"Not all uplinks are up")
# Wait until uplinks are up and routes are recovered
pytest_assert(wait_until(50, 5, check_routes_to_dhcp_server, duthost, dut_dhcp_relay_data),
"Not all DHCP servers are routed")

# Run the DHCP relay test on the PTF host
ptf_runner(ptfhost,
Expand Down