Skip to content

Commit 5604566

Browse files
Tyler Lilguohan
Tyler Li
authored andcommitted
[vs_test] fix fdb test failed randomly (sonic-net#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.
1 parent 038d994 commit 5604566

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

tests/conftest.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,20 @@ def get_map_iface_bridge_port_id(self, asic_db):
548548

549549
return iface_2_bridge_port_id
550550

551+
def get_vlan_oid(self, asic_db, vlan_id):
552+
tbl = swsscommon.Table(asic_db, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN")
553+
keys = tbl.getKeys()
554+
555+
for key in keys:
556+
status, fvs = tbl.get(key)
557+
assert status, "Error reading from table %s" % "ASIC_STATE:SAI_OBJECT_TYPE_VLAN"
558+
559+
for k, v in fvs:
560+
if k == "SAI_VLAN_ATTR_VLAN_ID" and v == vlan_id:
561+
return True, key
562+
563+
return False, "Not found vlan id %s" % vlan_id
564+
551565
def is_table_entry_exists(self, db, table, keyregex, attributes):
552566
tbl = swsscommon.Table(db, table)
553567
keys = tbl.getKeys()
@@ -637,11 +651,15 @@ def is_fdb_entry_exists(self, db, table, key_values, attributes):
637651
except ValueError:
638652
d_key = json.loads('{' + key + '}')
639653

654+
key_found = True
655+
640656
for k, v in key_values:
641657
if k not in d_key or v != d_key[k]:
642-
continue
658+
key_found = False
659+
break
643660

644-
key_found = True
661+
if not key_found:
662+
continue
645663

646664
status, fvs = tbl.get(key)
647665
assert status, "Error reading from table %s" % table

tests/test_fdb.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -334,16 +334,26 @@ def test_FdbAddedAfterMemberCreated(self, dvs, testlog):
334334
]
335335
)
336336

337-
# check that the FDB entry wasn't inserted into ASIC DB
338-
assert how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY") == 0, "The fdb entry leaked to ASIC"
339-
340337
vlan_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN")
341338
bp_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_BRIDGE_PORT")
342339
vm_before = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN_MEMBER")
343340

344341
# create vlan
345342
dvs.create_vlan("2")
343+
time.sleep(1)
344+
345+
# Get bvid from vlanid
346+
ok, bvid = dvs.get_vlan_oid(dvs.adb, "2")
347+
assert ok, bvid
348+
349+
# check that the FDB entry wasn't inserted into ASIC DB
350+
ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY",
351+
[("mac", "52:54:00:25:06:E9"), ("bvid", bvid)], [])
352+
assert ok == False, "The fdb entry leaked to ASIC"
353+
354+
# create vlan member
346355
dvs.create_vlan_member("2", "Ethernet0")
356+
time.sleep(1)
347357

348358
# check that the vlan information was propagated
349359
vlan_after = how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_VLAN")
@@ -358,10 +368,8 @@ def test_FdbAddedAfterMemberCreated(self, dvs, testlog):
358368
iface_2_bridge_port_id = dvs.get_map_iface_bridge_port_id(dvs.adb)
359369

360370
# check that the FDB entry was inserted into ASIC DB
361-
assert how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY") == 1, "The fdb entry wasn't inserted to ASIC"
362-
363371
ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY",
364-
[("mac", "52-54-00-25-06-E9"), ("vlan", "2")],
372+
[("mac", "52:54:00:25:06:E9"), ("bvid", bvid)],
365373
[("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"),
366374
("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet0"]),
367375
('SAI_FDB_ENTRY_ATTR_PACKET_ACTION', 'SAI_PACKET_ACTION_FORWARD')]

tests/test_fdb_update.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,18 @@ def test_FDBAddedAndUpdated(dvs, testlog):
102102
assert bp_after - bp_before == 1, "The bridge port wasn't created"
103103
assert vm_after - vm_before == 1, "The vlan member wasn't added"
104104

105+
# Get bvid from vlanid
106+
ok, bvid = dvs.get_vlan_oid(dvs.adb, "2")
107+
assert ok, bvid
108+
105109
# Get mapping between interface name and its bridge port_id
106110
iface_2_bridge_port_id = dvs.get_map_iface_bridge_port_id(dvs.adb)
107111

108112
# check that the FDB entry was inserted into ASIC DB
109113
assert how_many_entries_exist(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY") == 1, "The fdb entry wasn't inserted to ASIC"
110114

111115
ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY",
112-
[("mac", "52-54-00-25-06-E9"), ("vlan", "2")],
116+
[("mac", "52:54:00:25:06:E9"), ("bvid", bvid)],
113117
[("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"),
114118
("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet0"]),
115119
('SAI_FDB_ENTRY_ATTR_PACKET_ACTION', 'SAI_PACKET_ACTION_FORWARD')]
@@ -139,7 +143,7 @@ def test_FDBAddedAndUpdated(dvs, testlog):
139143
iface_2_bridge_port_id = dvs.get_map_iface_bridge_port_id(dvs.adb)
140144

141145
ok, extra = dvs.is_fdb_entry_exists(dvs.adb, "ASIC_STATE:SAI_OBJECT_TYPE_FDB_ENTRY",
142-
[("mac", "52-54-00-25-06-E9"), ("vlan", "2")],
146+
[("mac", "52:54:00:25:06:E9"), ("bvid", bvid)],
143147
[("SAI_FDB_ENTRY_ATTR_TYPE", "SAI_FDB_ENTRY_TYPE_DYNAMIC"),
144148
("SAI_FDB_ENTRY_ATTR_BRIDGE_PORT_ID", iface_2_bridge_port_id["Ethernet4"]),
145149
('SAI_FDB_ENTRY_ATTR_PACKET_ACTION', 'SAI_PACKET_ACTION_FORWARD')]

0 commit comments

Comments
 (0)