2222from tests .common .fixtures .ptfhost_utils import change_mac_addresses # noqa F401
2323from tests .common .fixtures .ptfhost_utils import copy_ptftests_directory # noqa F401
2424from tests .common .helpers import bgp
25+ from tests .common .helpers .assertions import pytest_assert
2526from tests .common .utilities import is_ipv4_address
27+ from tests .common .utilities import wait_until
2628
2729
2830pytestmark = [
@@ -180,7 +182,8 @@ def bgp_neighbors(ptfhost, setup_interfaces):
180182def save_slb_exabgp_logfiles (ptfhost , pytestconfig , request ):
181183 """Save slb exabgp log files to the log directory."""
182184 # remove log files before test
183- log_files_before = ptfhost .shell ("ls /tmp/exabgp-slb_*.log" )["stdout" ].split ()
185+ log_files_before = ptfhost .shell ("ls /tmp/exabgp-slb_*.log*" ,
186+ module_ignore_errors = True )["stdout" ].split ()
184187 for log_file in log_files_before :
185188 ptfhost .file (path = log_file , state = "absent" )
186189
@@ -189,7 +192,8 @@ def save_slb_exabgp_logfiles(ptfhost, pytestconfig, request):
189192 test_log_file = pytestconfig .getoption ("log_file" , None )
190193 if test_log_file :
191194 log_dir = os .path .dirname (os .path .abspath (test_log_file ))
192- log_files = ptfhost .shell ("ls /tmp/exabgp-slb_*.log" )["stdout" ].split ()
195+ log_files = ptfhost .shell ("ls /tmp/exabgp-slb_*.log*" ,
196+ module_ignore_errors = True )["stdout" ].split ()
193197 for log_file in log_files :
194198 logging .debug ("Save slb exabgp log %s to %s" , log_file , log_dir )
195199 ptfhost .fetch (src = log_file , dest = log_dir + os .path .sep , fail_on_missing = False , flat = True )
@@ -256,9 +260,9 @@ def verify_route(duthost, route, existing=True):
256260 prefix = ipaddress .ip_network (route ["prefix" ])
257261 existing_route = duthost .get_ip_route_info (dstip = prefix )
258262 if existing :
259- assert route ["nexthop" ] in [str (_ [0 ]) for _ in existing_route ["nexthops" ]]
263+ return route ["nexthop" ] in [str (_ [0 ]) for _ in existing_route ["nexthops" ]]
260264 else :
261- assert len (existing_route ["nexthops" ]) == 0
265+ return len (existing_route ["nexthops" ]) == 0
262266
263267 def verify_traffic (duthost , connection , route , is_duthost_active = True , is_route_existed = True ):
264268
@@ -311,8 +315,10 @@ def verify_traffic(duthost, connection, route, is_duthost_active=True, is_route_
311315
312316 time .sleep (constants .bgp_update_sleep_interval )
313317
314- verify_route (upper_tor_host , constants .route , existing = True )
315- verify_route (lower_tor_host , constants .route , existing = True )
318+ pytest_assert (verify_route (upper_tor_host , constants .route , existing = True ),
319+ "route is not present on the upper ToR" )
320+ pytest_assert (verify_route (lower_tor_host , constants .route , existing = True ),
321+ "route is not present on the lower ToR" )
316322
317323 # STEP 3: verify the route by sending some downstream traffic
318324 verify_traffic (
@@ -330,8 +336,12 @@ def verify_traffic(duthost, connection, route, is_duthost_active=True, is_route_
330336
331337 time .sleep (constants .bgp_update_sleep_interval )
332338
333- verify_route (upper_tor_host , constants .route , existing = False )
334- verify_route (lower_tor_host , constants .route , existing = False )
339+ pytest_assert (wait_until (10 , 5 , 0 , verify_route , upper_tor_host ,
340+ constants .route , existing = False ),
341+ "route is not withdrawed from the upper ToR" )
342+ pytest_assert (wait_until (10 , 5 , 0 , verify_route , lower_tor_host ,
343+ constants .route , existing = False ),
344+ "route is not withdrawed from the lower ToR" )
335345
336346 # STEP 5: verify the route is removed by verifying that downstream traffic is dropped
337347 verify_traffic (
@@ -357,8 +367,10 @@ def verify_traffic(duthost, connection, route, is_duthost_active=True, is_route_
357367
358368 time .sleep (constants .bgp_update_sleep_interval )
359369
360- verify_route (upper_tor_host , constants .route , existing = True )
361- verify_route (lower_tor_host , constants .route , existing = True )
370+ pytest_assert (verify_route (upper_tor_host , constants .route , existing = True ),
371+ "route is not present on the upper ToR" )
372+ pytest_assert (verify_route (lower_tor_host , constants .route , existing = True ),
373+ "route is not present on the lower ToR" )
362374
363375 # STEP 8: verify the route by sending some downstream traffic
364376 verify_traffic (
@@ -374,7 +386,8 @@ def verify_traffic(duthost, connection, route, is_duthost_active=True, is_route_
374386 upper_tor_bgp_neighbor .stop_session ()
375387
376388 verify_bgp_session (lower_tor_host , lower_tor_bgp_neighbor )
377- verify_route (lower_tor_host , constants .route , existing = True )
389+ pytest_assert (verify_route (lower_tor_host , constants .route , existing = True ),
390+ "route is not present on the lower ToR" )
378391
379392 lower_tor_bgp_neighbor .stop_session ()
380393
0 commit comments