Skip to content

Commit

Permalink
fix fdb test failed randomly
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Li committed Nov 5, 2019
1 parent c5cd406 commit 70c3222
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
14 changes: 14 additions & 0 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
20 changes: 14 additions & 6 deletions tests/test_fdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,18 +334,26 @@ def test_FdbAddedAfterMemberCreated(self, dvs, testlog):
]
)

# 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"), ("vlan", "2")], [])
assert ok == False, "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 form 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 @@ -361,7 +369,7 @@ def test_FdbAddedAfterMemberCreated(self, dvs, testlog):

# check that the FDB entry was 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"), ("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 form 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 70c3222

Please sign in to comment.