Skip to content

Commit b4d4209

Browse files
ysmanmanmssonicbld
authored andcommitted
Make test_neighbor_mac_noptf more robust (sonic-net#9422)
* test_neighbor_mac_noptf is flaky because sometimes it may take longer than usual to update intf address, add neighbor, and also change neighbor MAC. Make the test more robust by retrying the validation of neighbor in redis DB.
1 parent 8bc5226 commit b4d4209

File tree

1 file changed

+37
-13
lines changed

1 file changed

+37
-13
lines changed

tests/arp/test_neighbor_mac_noptf.py

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -264,19 +264,43 @@ def redisNeighborMac(self, duthosts, enum_rand_one_per_hwsku_frontend_hostname,
264264
duthost = duthosts[enum_rand_one_per_hwsku_frontend_hostname]
265265
asichost = duthost.asic_instance(enum_frontend_asic_index)
266266
redis_cmd = "{} ASIC_DB KEYS \"ASIC_STATE:SAI_OBJECT_TYPE_NEIGHBOR_ENTRY*\"".format(asichost.sonic_db_cli)
267-
result = duthost.shell(redis_cmd)
268-
neighborKey = None
269-
for key in result["stdout_lines"]:
270-
if self.TEST_INTF[ipVersion]["NeighborIp"] in key:
271-
neighborKey = key
272-
break
273-
pytest_assert(neighborKey, "Neighbor key NOT found in Redis DB, Redis db Output '{0}'".format(result["stdout"]))
274-
neighborKey = " '{}' {} ".format(
275-
neighborKey,
276-
REDIS_NEIGH_ENTRY_MAC_ATTR)
277-
result = duthost.shell("{} ASIC_DB HGET {}".format(asichost.sonic_db_cli, neighborKey))
278-
279-
yield (result['stdout_lines'][0])
267+
268+
# Sometimes it may take longer than usual to update interface address, add neighbor, and also change
269+
# neighbor MAC. Retry the validation of neighbor MAC to make test more robust.
270+
retry = 0
271+
maxRetry = 30
272+
result = None
273+
neighborMac = None
274+
expectedMac = self.TEST_MAC[ipVersion][1]
275+
while retry < maxRetry and neighborMac != expectedMac:
276+
neighborKey = None
277+
result = duthost.shell(redis_cmd)
278+
for key in result["stdout_lines"]:
279+
if self.TEST_INTF[ipVersion]["NeighborIp"] in key:
280+
neighborKey = key
281+
break
282+
283+
if neighborKey:
284+
neighborKey = " '{}' {} ".format(
285+
neighborKey,
286+
REDIS_NEIGH_ENTRY_MAC_ATTR)
287+
result = duthost.shell("{} ASIC_DB HGET {}".format(asichost.sonic_db_cli, neighborKey))
288+
neighborMac = result['stdout_lines'][0].lower()
289+
290+
# Since neighbor MAC is also changed/updated, check if all the updates have been processed already.
291+
# Stop retry if the neighbor MAC in ASIC_DB is what we expect.
292+
if neighborMac == expectedMac:
293+
logger.info("Verified MAC of neighbor {} after {} retries".format(
294+
self.TEST_INTF[ipVersion]["NeighborIp"], retry))
295+
break
296+
297+
logger.info("Failed to verify MAC of neighbor {}. Retry cnt: {}".format(
298+
self.TEST_INTF[ipVersion]["NeighborIp"], retry))
299+
retry += 1
300+
time.sleep(2)
301+
302+
pytest_assert(neighborMac, "Neighbor key NOT found in Redis DB, Redis db Output '{0}'".format(result["stdout"]))
303+
yield neighborMac
280304

281305
def testNeighborMacNoPtf(self, ipVersion, arpTableMac, redisNeighborMac):
282306
"""

0 commit comments

Comments
 (0)