From 560456606b2c898d15c9cb2e588d65077fb03084 Mon Sep 17 00:00:00 2001 From: Tyler Li Date: Wed, 6 Nov 2019 02:44:31 +0800 Subject: [PATCH] [vs_test] fix fdb test failed randomly (#1118) - Change test_FdbAddedAfterMemberCreated not to assert the count of entries but to check the existance of entry added by itself, because other entry may be learned after flush. The former test case does't clean the config, that makes more chance to learn fdb entry. - Fix the bug is_fdb_entry_exists didn't match key. Add a function get_vlan_oid to change vlanid to bvid. Change mac format to match in asic_db. --- tests/conftest.py | 22 ++++++++++++++++++++-- tests/test_fdb.py | 20 ++++++++++++++------ tests/test_fdb_update.py | 8 ++++++-- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index c510e441cdc0..7ae579222971 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -548,6 +548,20 @@ def get_map_iface_bridge_port_id(self, asic_db): return iface_2_bridge_port_id + def get_vlan_oid(self, asic_db, vlan_id): + tbl = swsscommon.Table(asic_db, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") + keys = tbl.getKeys() + + for key in keys: + status, fvs = tbl.get(key) + assert status, "Error reading from table %s" % "ASIC_STATE:SAI_OBJECT_TYPE_VLAN" + + for k, v in fvs: + if k == "SAI_VLAN_ATTR_VLAN_ID" and v == vlan_id: + return True, key + + return False, "Not found vlan id %s" % vlan_id + def is_table_entry_exists(self, db, table, keyregex, attributes): tbl = swsscommon.Table(db, table) keys = tbl.getKeys() @@ -637,11 +651,15 @@ def is_fdb_entry_exists(self, db, table, key_values, attributes): except ValueError: d_key = json.loads('{' + key + '}') + key_found = True + for k, v in key_values: if k not in d_key or v != d_key[k]: - continue + key_found = False + break - key_found = True + if not key_found: + continue status, fvs = tbl.get(key) assert status, "Error reading from table %s" % table diff --git a/tests/test_fdb.py b/tests/test_fdb.py index 4e714d2021b9..37c210c492c7 100644 --- a/tests/test_fdb.py +++ b/tests/test_fdb.py @@ -334,16 +334,26 @@ def test_FdbAddedAfterMemberCreated(self, dvs, testlog): ] ) - # check that the FDB entry wasn't inserted into ASIC DB - assert how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY") == 0, "The fdb entry leaked to ASIC" - vlan_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") bp_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT") vm_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER") # create vlan dvs.create_vlan("2") + time.sleep(1) + + # Get bvid from vlanid + ok, bvid = dvs.get_vlan_oid(dvs.adb, "2") + assert ok, bvid + + # check that the FDB entry wasn't inserted into ASIC DB + ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", + [("mac", "52:54:00:25:06:E9"), ("bvid", bvid)], []) + assert ok == False, "The fdb entry leaked to ASIC" + + # create vlan member dvs.create_vlan_member("2", "Ethernet0") + time.sleep(1) # check that the vlan information was propagated vlan_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN") @@ -358,10 +368,8 @@ def test_FdbAddedAfterMemberCreated(self, dvs, testlog): iface_2_bridge_port_id = dvs.get_map_iface_bridge_port_id(dvs.adb) # check that the FDB entry was inserted into ASIC DB - assert how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY") == 1, "The fdb entry wasn't inserted to ASIC" - ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", - [("mac", "52-54-00-25-06-E9"), ("vlan", "2")], + [("mac", "52:54:00:25:06:E9"), ("bvid", bvid)], [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet0"]), ('SAI_FDB_ENTRY_ATTR_PACKET_ACTION', 'SAI_PACKET_ACTION_FORWARD')] diff --git a/tests/test_fdb_update.py b/tests/test_fdb_update.py index b3fd1a9670db..d74c3f0c0fb2 100644 --- a/tests/test_fdb_update.py +++ b/tests/test_fdb_update.py @@ -102,6 +102,10 @@ def test_FDBAddedAndUpdated(dvs, testlog): assert bp_after - bp_before == 1, "The bridge port wasn't created" assert vm_after - vm_before == 1, "The vlan member wasn't added" + # Get bvid from vlanid + ok, bvid = dvs.get_vlan_oid(dvs.adb, "2") + assert ok, bvid + # Get mapping between interface name and its bridge port_id iface_2_bridge_port_id = dvs.get_map_iface_bridge_port_id(dvs.adb) @@ -109,7 +113,7 @@ def test_FDBAddedAndUpdated(dvs, testlog): assert how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY") == 1, "The fdb entry wasn't inserted to ASIC" ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", - [("mac", "52-54-00-25-06-E9"), ("vlan", "2")], + [("mac", "52:54:00:25:06:E9"), ("bvid", bvid)], [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet0"]), ('SAI_FDB_ENTRY_ATTR_PACKET_ACTION', 'SAI_PACKET_ACTION_FORWARD')] @@ -139,7 +143,7 @@ def test_FDBAddedAndUpdated(dvs, testlog): iface_2_bridge_port_id = dvs.get_map_iface_bridge_port_id(dvs.adb) ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY", - [("mac", "52-54-00-25-06-E9"), ("vlan", "2")], + [("mac", "52:54:00:25:06:E9"), ("bvid", bvid)], [("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"), ("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet4"]), ('SAI_FDB_ENTRY_ATTR_PACKET_ACTION', 'SAI_PACKET_ACTION_FORWARD')]