diff --git a/test/sai_test/config/fdb_configer.py b/test/sai_test/config/fdb_configer.py index d8491dc7a..3dbaec8c5 100644 --- a/test/sai_test/config/fdb_configer.py +++ b/test/sai_test/config/fdb_configer.py @@ -63,6 +63,12 @@ def t0_fdb_config_helper(test_obj, is_create_fdb=True): # Todo dynamic use the vlan_member_port_map to add data to fdb test_obj.local_server_mac_list = local_server_mac_list +def t0_fdb_tear_down_helper(test_obj): + ''' + Args: + test_obj: test object + ''' + sai_thrift_flush_fdb_entries(test_obj.client, entry_type=SAI_FDB_FLUSH_ENTRY_TYPE_ALL) class FdbConfiger(object): """ diff --git a/test/sai_test/config/port_configer.py b/test/sai_test/config/port_configer.py index fa73929d3..2f10070f3 100644 --- a/test/sai_test/config/port_configer.py +++ b/test/sai_test/config/port_configer.py @@ -42,7 +42,6 @@ def t0_port_config_helper(test_obj, is_recreate_bridge=True, is_create_hostIf=Tr """ configer = PortConfiger(test_obj) - dev_port_list = configer.get_local_mapped_ports() portConfigs = configer.parse_port_config( test_obj.test_params['port_config_ini']) @@ -79,6 +78,15 @@ def t0_port_config_helper(test_obj, is_recreate_bridge=True, is_create_hostIf=Tr test_obj.default_1q_bridge_id = default_1q_bridge_id test_obj.bridge_port_list = bridge_port_list +def t0_port_tear_down_helper(test_obj): + ''' + Args: + test_obj: test object + ''' + configer = PortConfiger(test_obj) + default_1q_bridge_id = configer.get_default_1q_bridge() + configer.remove_bridge_port(default_1q_bridge_id) + configer.remove_host_inf(test_obj.host_intf_table_id,test_obj.hostif_list) class PortConfiger(object): """ @@ -348,6 +356,22 @@ def remove_bridge_port(self, bridge_id): sai_thrift_remove_bridge_port(self.client, port) self.test_obj.assertEqual(self.test_obj.status(), SAI_STATUS_SUCCESS) + + def remove_host_inf(self,host_intf_table_id,hostif_list): + """ + Remove host interface. + Steps: + 2. remove host interface + 1. remove host table entry + Args: + host_intf_table_id + hostif_list + """ + + for _, hostif in enumerate(hostif_list): + sai_thrift_remove_hostif(self.client,hostif) + sai_thrift_remove_hostif_table_entry(self.client,host_intf_table_id) + def turn_on_port_admin_state(self, port_list): """ Turn on port admin state @@ -356,7 +380,7 @@ def turn_on_port_admin_state(self, port_list): post_list: post list """ print("Set port...") - for i, port in enumerate(port_list): + for _, port in enumerate(port_list): sai_thrift_set_port_attribute( self.client, port_oid=port, mtu=self.get_mtu(), admin_state=True, fec_mode=self.get_fec_mode()) diff --git a/test/sai_test/config/vlan_configer.py b/test/sai_test/config/vlan_configer.py index 3a51dd8fe..a2ab46b39 100644 --- a/test/sai_test/config/vlan_configer.py +++ b/test/sai_test/config/vlan_configer.py @@ -56,6 +56,26 @@ def t0_vlan_config_helper(test_obj, is_reset_default_vlan=True, is_create_vlan=T test_obj.vlans.update({key: vlans[key]}) test_obj.default_vlan_id = default_vlan_id +def t0_vlan_tear_down_helper(test_obj): + ''' + Args: + test_obj: test object + remove vlan + ''' + configer = VlanConfiger(test_obj) + #remove default vlan + default_vlan_id = configer.get_default_vlan() + members = configer.get_vlan_member(default_vlan_id) + configer.remove_vlan_members(members) + # configer.remove_vlan(default_vlan_id) + + for _, vlan in test_obj.vlans.items(): + members = configer.get_vlan_member(vlan.vlan_oid) + configer.remove_vlan_members(members) + configer.remove_vlan(vlan.vlan_oid) + test_obj.vlans.clear() + + class VlanConfiger(object): """ diff --git a/test/sai_test/sai_test_base.py b/test/sai_test/sai_test_base.py index 44398568c..a9e74980a 100644 --- a/test/sai_test/sai_test_base.py +++ b/test/sai_test/sai_test_base.py @@ -34,12 +34,15 @@ from sai_thrift.sai_adapter import * from sai_utils import * from config.port_configer import t0_port_config_helper +from config.port_configer import t0_port_tear_down_helper from config.port_configer import PortConfiger from config.switch_configer import t0_switch_config_helper from config.switch_configer import SwitchConfiger from config.vlan_configer import t0_vlan_config_helper +from config.vlan_configer import t0_vlan_tear_down_helper from config.vlan_configer import VlanConfiger from config.fdb_configer import t0_fdb_config_helper +from config.fdb_configer import t0_fdb_tear_down_helper from config.fdb_configer import FdbConfiger THRIFT_PORT = 9092 @@ -233,3 +236,12 @@ def status(): int: sai call result """ return adapter.status + + def tearDown(self): + ''' + tear down + ''' + t0_fdb_tear_down_helper(self) + t0_vlan_tear_down_helper(self) + t0_port_tear_down_helper(self) + super().tearDown() diff --git a/test/sai_test/sai_vlan_test.py b/test/sai_test/sai_vlan_test.py index 4c8f5c89e..d95795f2d 100644 --- a/test/sai_test/sai_vlan_test.py +++ b/test/sai_test/sai_vlan_test.py @@ -78,7 +78,7 @@ def runTest(self): pass def tearDown(self): - pass + super().tearDown() class UntagAccessToAccessTest(T0TestBase): @@ -116,12 +116,11 @@ def runTest(self): send_packet(self, self.dev_port_list[9], pkt) verify_packet(self, pkt, self.dev_port_list[index]) verify_no_other_packets(self, timeout=2) - finally: pass def tearDown(self): - pass + super().tearDown() class MismatchDropTest(T0TestBase): @@ -163,7 +162,7 @@ def runTest(self): pass def tearDown(self): - pass + super().tearDown() class TaggedFrameFilteringTest(T0TestBase): @@ -196,7 +195,7 @@ def runTest(self): pass def tearDown(self): - pass + super().tearDown() class UnTaggedFrameFilteringTest(T0TestBase): @@ -229,7 +228,7 @@ def runTest(self): pass def tearDown(self): - pass + super().tearDown() class TaggedVlanFloodingTest(T0TestBase): @@ -257,7 +256,7 @@ def runTest(self): pass def tearDown(self): - pass + super().tearDown() class UnTaggedVlanFloodingTest(T0TestBase): @@ -285,7 +284,7 @@ def runTest(self): pass def tearDown(self): - pass + super().tearDown() class BroadcastTest(T0TestBase): @@ -321,7 +320,7 @@ def runTest(self): pass def tearDown(self): - pass + super().tearDown() class UntaggedMacLearningTest(T0TestBase): @@ -357,7 +356,7 @@ def runTest(self): pass def tearDown(self): - pass + super().tearDown() class TaggedMacLearningTest(T0TestBase): @@ -393,7 +392,7 @@ def runTest(self): pass def tearDown(self): - pass + super().tearDown() class VlanMemberListTest(T0TestBase): @@ -448,7 +447,7 @@ def runTest(self): self.assertEqual(self.vlans[20].vlan_mport_oids[i - 8], mbr_list[i]) def tearDown(self): - pass + super().tearDown() class VlanMemberInvalidTest(T0TestBase): @@ -469,7 +468,7 @@ def runTest(self): self.assertEqual(incorrect_member, 0) def tearDown(self): - pass + super().tearDown() class DisableMacLearningTaggedTest(T0TestBase): @@ -501,7 +500,7 @@ def runTest(self): def tearDown(self): - pass + super().tearDown() class DisableMacLearningUntaggedTest(T0TestBase): @@ -531,7 +530,7 @@ def runTest(self): self.assertEqual(attr["available_fdb_entry"] - current_fdb_entry, 0) def tearDown(self): - pass + super().tearDown() class ArpRequestFloodingTest(T0TestBase): @@ -554,7 +553,7 @@ def runTest(self): self, [self.arp_request], [self.dev_port_list[2:9]]) def tearDown(self): - pass + super().tearDown() class ArpRequestLearningTest(T0TestBase): @@ -582,7 +581,7 @@ def runTest(self): verify_no_other_packets(self) def tearDown(self): - pass + super().tearDown() class TaggedVlanStatusTest(T0TestBase): @@ -667,7 +666,7 @@ def runTest(self): # self.assertEqual(out_bytes, 0, 'vlan OUT bytes counter is not 0') def tearDown(self): - pass + super().tearDown() class UntaggedVlanStatusTest(T0TestBase): @@ -752,4 +751,4 @@ def runTest(self): # self.assertEqual(out_bytes, 0, 'vlan OUT bytes counter is not 0') def tearDown(self): - pass + super().tearDown()