1717 import copy_ptftests_directory # noqa: F401
1818from tests .ptf_runner import ptf_runner
1919from tests .vxlan .vxlan_ecmp_utils import Ecmp_Utils
20- from tests .common .config_reload import config_system_checks_passed
2120from tests .common .fixtures .duthost_utils import backup_and_restore_config_db_on_duts # noqa F401
2221from tests .common .config_reload import config_reload
2322Logger = logging .getLogger (__name__ )
@@ -204,6 +203,13 @@ def fixture_setUp(duthosts,
204203 outer_layer_version = ecmp_utils .get_outer_layer_version (encap_type )
205204 payload_version = ecmp_utils .get_payload_version (encap_type )
206205
206+ # In case any of the tests fail, this method will cleanup the VNET routes.
207+ ecmp_utils .set_routes_in_dut (
208+ data ['duthost' ],
209+ data [encap_type ]['dest_to_nh_map' ],
210+ payload_version ,
211+ "DEL" )
212+
207213 for intf in data [encap_type ]['selected_interfaces' ]:
208214 redis_string = "INTERFACE"
209215 if "PortChannel" in intf :
@@ -225,6 +231,7 @@ def fixture_setUp(duthosts,
225231 data ['duthost' ].shell (
226232 "redis-cli -n 4 del \" VXLAN_TUNNEL|{}\" " .format (tunnel ))
227233 time .sleep (1 )
234+ ecmp_utils .stop_bfd_responder (data ['ptfhost' ])
228235
229236
230237@pytest .fixture (scope = "module" , autouse = True )
@@ -235,6 +242,17 @@ def restore_config_by_config_reload(duthosts, rand_one_dut_hostname, localhost):
235242 config_reload (duthost , safe_reload = True )
236243
237244
245+ def is_vnet_route_configured_on_asic (duthost , dest ):
246+ '''
247+ Function to check if a VNET route to dest is configured on ASIC DB.
248+ A VNET route to dest must be configured on ASIC DB before running
249+ PTF tests.
250+ '''
251+ result = duthost .shell (f"sonic-db-cli ASIC_DB KEYS \
252+ 'ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY*{ dest } *'" )["stdout_lines" ]
253+ return bool (result )
254+
255+
238256class Test_VxLAN_BFD_TSA ():
239257 '''
240258 Class for all the Vxlan tunnel cases where primary and secondary next hops are configured.
@@ -523,13 +541,12 @@ def test_tsa_case4(self, setUp, encap_type):
523541
524542 self .dump_self_info_and_run_ptf ("test4" , encap_type , True , [])
525543
526- duthost .shell ("sudo config reload -y" ,
527- executable = "/bin/bash" , module_ignore_errors = True )
528- assert wait_until (300 , 20 , 0 , config_system_checks_passed , duthost , [])
544+ config_reload (duthost , safe_reload = True , check_intf_up_ports = True , wait_for_bgp = True )
529545
530546 # readd routes as they are removed by config reload
531547 ecmp_utils .configure_vxlan_switch (duthost , vxlan_port = 4789 , dutmac = self .vxlan_test_setup ['dut_mac' ])
532548 dest , ep_list = self .create_vnet_route (encap_type )
549+ wait_until (20 , 2 , 0 , is_vnet_route_configured_on_asic , duthost , dest )
533550
534551 self .dump_self_info_and_run_ptf ("test4b" , encap_type , True , [])
535552
@@ -565,13 +582,12 @@ def test_tsa_case5(self, setUp, encap_type):
565582 pytest_assert (self .in_maintainence ())
566583 self .verfiy_bfd_down (ep_list )
567584
568- duthost .shell ("sudo config reload -y" ,
569- executable = "/bin/bash" , module_ignore_errors = True )
570- assert wait_until (300 , 20 , 0 , config_system_checks_passed , duthost , [])
585+ config_reload (duthost , safe_reload = True , check_intf_up_ports = True , wait_for_bgp = True )
571586
572587 # readd routes as they are removed by config reload
573588 ecmp_utils .configure_vxlan_switch (duthost , vxlan_port = 4789 , dutmac = self .vxlan_test_setup ['dut_mac' ])
574589 dest , ep_list = self .create_vnet_route (encap_type )
590+ wait_until (20 , 2 , 0 , is_vnet_route_configured_on_asic , duthost , dest )
575591
576592 self .apply_tsb ()
577593 pytest_assert (not self .in_maintainence ())
@@ -611,13 +627,12 @@ def test_tsa_case6(self, setUp, encap_type):
611627
612628 self .verfiy_bfd_down (ep_list )
613629
614- duthost .shell ("sudo config reload -y" ,
615- executable = "/bin/bash" , module_ignore_errors = True )
616- assert wait_until (300 , 20 , 0 , config_system_checks_passed , duthost , [])
630+ config_reload (duthost , safe_reload = True , check_intf_up_ports = True , wait_for_bgp = True )
617631
618632 # readd routes as they are removed by config reload
619633 ecmp_utils .configure_vxlan_switch (duthost , vxlan_port = 4789 , dutmac = self .vxlan_test_setup ['dut_mac' ])
620634 dest , ep_list = self .create_vnet_route (encap_type )
635+ wait_until (20 , 2 , 0 , is_vnet_route_configured_on_asic , duthost , dest )
621636
622637 self .apply_tsb ()
623638 pytest_assert (not self .in_maintainence ())
0 commit comments