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
35 changes: 24 additions & 11 deletions tests/dualtor/test_orchagent_slb.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
from tests.common.fixtures.ptfhost_utils import change_mac_addresses # noqa F401
from tests.common.fixtures.ptfhost_utils import copy_ptftests_directory # noqa F401
from tests.common.helpers import bgp
from tests.common.helpers.assertions import pytest_assert
from tests.common.utilities import is_ipv4_address
from tests.common.utilities import wait_until


pytestmark = [
Expand Down Expand Up @@ -180,7 +182,8 @@ def bgp_neighbors(ptfhost, setup_interfaces):
def save_slb_exabgp_logfiles(ptfhost, pytestconfig, request):
"""Save slb exabgp log files to the log directory."""
# remove log files before test
log_files_before = ptfhost.shell("ls /tmp/exabgp-slb_*.log")["stdout"].split()
log_files_before = ptfhost.shell("ls /tmp/exabgp-slb_*.log*",
module_ignore_errors=True)["stdout"].split()
for log_file in log_files_before:
ptfhost.file(path=log_file, state="absent")

Expand All @@ -189,7 +192,8 @@ def save_slb_exabgp_logfiles(ptfhost, pytestconfig, request):
test_log_file = pytestconfig.getoption("log_file", None)
if test_log_file:
log_dir = os.path.dirname(os.path.abspath(test_log_file))
log_files = ptfhost.shell("ls /tmp/exabgp-slb_*.log")["stdout"].split()
log_files = ptfhost.shell("ls /tmp/exabgp-slb_*.log*",
module_ignore_errors=True)["stdout"].split()
for log_file in log_files:
logging.debug("Save slb exabgp log %s to %s", log_file, log_dir)
ptfhost.fetch(src=log_file, dest=log_dir + os.path.sep, fail_on_missing=False, flat=True)
Expand Down Expand Up @@ -256,9 +260,9 @@ def verify_route(duthost, route, existing=True):
prefix = ipaddress.ip_network(route["prefix"])
existing_route = duthost.get_ip_route_info(dstip=prefix)
if existing:
assert route["nexthop"] in [str(_[0]) for _ in existing_route["nexthops"]]
return route["nexthop"] in [str(_[0]) for _ in existing_route["nexthops"]]
else:
assert len(existing_route["nexthops"]) == 0
return len(existing_route["nexthops"]) == 0

def verify_traffic(duthost, connection, route, is_duthost_active=True, is_route_existed=True):

Expand Down Expand Up @@ -311,8 +315,10 @@ def verify_traffic(duthost, connection, route, is_duthost_active=True, is_route_

time.sleep(constants.bgp_update_sleep_interval)

verify_route(upper_tor_host, constants.route, existing=True)
verify_route(lower_tor_host, constants.route, existing=True)
pytest_assert(verify_route(upper_tor_host, constants.route, existing=True),
"route is not present on the upper ToR")
pytest_assert(verify_route(lower_tor_host, constants.route, existing=True),
"route is not present on the lower ToR")

# STEP 3: verify the route by sending some downstream traffic
verify_traffic(
Expand All @@ -330,8 +336,12 @@ def verify_traffic(duthost, connection, route, is_duthost_active=True, is_route_

time.sleep(constants.bgp_update_sleep_interval)

verify_route(upper_tor_host, constants.route, existing=False)
verify_route(lower_tor_host, constants.route, existing=False)
pytest_assert(wait_until(10, 5, 0, verify_route, upper_tor_host,
constants.route, existing=False),
"route is not withdrawed from the upper ToR")
pytest_assert(wait_until(10, 5, 0, verify_route, lower_tor_host,
constants.route, existing=False),
"route is not withdrawed from the lower ToR")

# STEP 5: verify the route is removed by verifying that downstream traffic is dropped
verify_traffic(
Expand All @@ -357,8 +367,10 @@ def verify_traffic(duthost, connection, route, is_duthost_active=True, is_route_

time.sleep(constants.bgp_update_sleep_interval)

verify_route(upper_tor_host, constants.route, existing=True)
verify_route(lower_tor_host, constants.route, existing=True)
pytest_assert(verify_route(upper_tor_host, constants.route, existing=True),
"route is not present on the upper ToR")
pytest_assert(verify_route(lower_tor_host, constants.route, existing=True),
"route is not present on the lower ToR")

# STEP 8: verify the route by sending some downstream traffic
verify_traffic(
Expand All @@ -374,7 +386,8 @@ def verify_traffic(duthost, connection, route, is_duthost_active=True, is_route_
upper_tor_bgp_neighbor.stop_session()

verify_bgp_session(lower_tor_host, lower_tor_bgp_neighbor)
verify_route(lower_tor_host, constants.route, existing=True)
pytest_assert(verify_route(lower_tor_host, constants.route, existing=True),
"route is not present on the lower ToR")

lower_tor_bgp_neighbor.stop_session()

Expand Down
Loading