Skip to content

Commit

Permalink
[vs_test] fix fdb test failed randomly (sonic-net#1118)
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Tyler Li authored and lguohan committed Nov 5, 2019
1 parent 038d994 commit 5604566
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
22 changes: 20 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
20 changes: 14 additions & 6 deletions tests/test_fdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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')]
Expand Down
8 changes: 6 additions & 2 deletions tests/test_fdb_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,18 @@ 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)

# 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')]
Expand Down Expand Up @@ -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')]
Expand Down

0 comments on commit 5604566

Please sign in to comment.