Skip to content

Commit 7fa7cd6

Browse files
authored
[vstest]: stablize fgnhg test (#1491)
use standard wait API to wait for asic db and state db updates Signed-off-by: Guohan Lu <[email protected]>
1 parent 9b0696e commit 7fa7cd6

File tree

1 file changed

+28
-31
lines changed

1 file changed

+28
-31
lines changed

tests/test_fgnhg.py

+28-31
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def _access_function():
111111
elif key == "SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID":
112112
if nhgid != val:
113113
return false_ret
114-
if (index == -1 or
114+
if (index == -1 or
115115
nh_oid == "0" or
116116
nh_oid_map.get(nh_oid,"NULL") == "NULL" or
117117
nh_oid_map.get(nh_oid) not in nh_memb_exp_count):
@@ -149,18 +149,18 @@ def verify_programmed_fg_state_db_entry(state_db,nh_memb_exp_count):
149149
memb_dict = nh_memb_exp_count
150150
keys = state_db.get_keys("FG_ROUTE_TABLE")
151151
assert len(keys) != 0
152-
for key in keys:
152+
for key in keys:
153153
fvs = state_db.get_entry("FG_ROUTE_TABLE", key)
154154
assert fvs != {}
155155
for key, value in fvs.items():
156156
assert value in nh_memb_exp_count
157-
memb_dict[value] = memb_dict[value] - 1
157+
memb_dict[value] = memb_dict[value] - 1
158158

159159
for idx,memb in memb_dict.items():
160-
assert memb == 0
160+
assert memb == 0
161161

162162

163-
def validate_fine_grained_asic_n_state_db_entries(asic_db, state_db, ip_to_if_map,
163+
def validate_fine_grained_asic_n_state_db_entries(asic_db, state_db, ip_to_if_map,
164164
nh_memb_exp_count, nh_oid_map, nhgid, bucket_size):
165165
state_db_entry_memb_exp_count = {}
166166

@@ -227,11 +227,11 @@ def test_route_fgnhg(self, dvs, testlog):
227227

228228
asic_routes_count = len(asic_db.get_keys(ASIC_ROUTE_TB))
229229
ps = swsscommon.ProducerStateTable(app_db.db_connection, ROUTE_TB)
230-
fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.7,10.0.0.9,10.0.0.11"),
230+
fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.7,10.0.0.9,10.0.0.11"),
231231
("ifname", "Ethernet12,Ethernet16,Ethernet20")])
232232

233233
ps.set(fg_nhg_prefix, fvs)
234-
# No ASIC_DB entry we can wait for since ARP is not resolved yet,
234+
# No ASIC_DB entry we can wait for since ARP is not resolved yet,
235235
# We just use sleep so that the sw receives this entry
236236
time.sleep(1)
237237

@@ -261,7 +261,7 @@ def test_route_fgnhg(self, dvs, testlog):
261261

262262
validate_asic_nhg(asic_db, nhgid, bucket_size)
263263

264-
nh_oid_map = get_nh_oid_map(asic_db)
264+
nh_oid_map = get_nh_oid_map(asic_db)
265265

266266
### Test scenarios with bank 0 having 0 members up
267267
# ARP is not resolved for 10.0.0.7, so fg nhg should be created without 10.0.0.7
@@ -272,7 +272,7 @@ def test_route_fgnhg(self, dvs, testlog):
272272
# Resolve ARP for 10.0.0.7
273273
asic_nh_count = len(asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_NEXT_HOP"))
274274
dvs.runcmd("arp -s 10.0.0.7 00:00:00:00:00:04")
275-
asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_NEXT_HOP", asic_nh_count + 1)
275+
asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_NEXT_HOP", asic_nh_count + 1)
276276
nh_oid_map = get_nh_oid_map(asic_db)
277277
# Now that ARP was resolved, 10.0.0.7 should be added as a valid fg nhg member
278278
nh_memb_exp_count = {"10.0.0.7":20,"10.0.0.9":20,"10.0.0.11":20}
@@ -359,13 +359,13 @@ def test_route_fgnhg(self, dvs, testlog):
359359
nh_memb_exp_count = {"10.0.0.11":60}
360360
validate_fine_grained_asic_n_state_db_entries(asic_db, state_db, ip_to_if_map,
361361
nh_memb_exp_count, nh_oid_map, nhgid, bucket_size)
362-
362+
363363
# Bring down last link, there shouldn't be a crash or other bad orchagent state because of this
364364
shutdown_link(dvs, app_db, 5)
365365
# Nothing to check for in this case, sleep 1s for the shutdown to reach sw
366366
time.sleep(1)
367367

368-
# bring all links up one by one
368+
# bring all links up one by one
369369
startup_link(dvs, app_db, 3)
370370
startup_link(dvs, app_db, 4)
371371
startup_link(dvs, app_db, 5)
@@ -399,14 +399,12 @@ def test_route_fgnhg(self, dvs, testlog):
399399
# Remove route
400400
asic_rt_key = get_asic_route_key(asic_db, fg_nhg_prefix)
401401
ps._del(fg_nhg_prefix)
402-
asic_db.wait_for_deleted_entry(ASIC_ROUTE_TB, asic_rt_key)
403402

404-
keys = asic_db.get_keys(ASIC_NHG_MEMB)
405-
assert len(keys) == 0
403+
# validate routes and nhg member in asic db, route entry in state db are removed
404+
asic_db.wait_for_deleted_entry(ASIC_ROUTE_TB, asic_rt_key)
405+
asic_db.wait_for_n_keys(ASIC_NHG_MEMB, 0)
406+
state_db.wait_for_n_keys("FG_ROUTE_TABLE", 0)
406407

407-
keys = state_db.get_keys("FG_ROUTE_TABLE")
408-
assert len(keys) == 0
409-
410408
remove_entry(config_db, "FG_NHG_PREFIX", fg_nhg_prefix)
411409
# Nothing we can wait for in terms of db entries, we sleep here
412410
# to give the sw enough time to delete the entry
@@ -415,17 +413,16 @@ def test_route_fgnhg(self, dvs, testlog):
415413
# Add an ECMP route, since we deleted the FG_NHG_PREFIX it should see
416414
# standard(non-Fine grained) ECMP behavior
417415
asic_routes_count = len(asic_db.get_keys(ASIC_ROUTE_TB))
418-
fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.7,10.0.0.9,10.0.0.11"),
416+
fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.7,10.0.0.9,10.0.0.11"),
419417
("ifname", "Ethernet12,Ethernet16,Ethernet20")])
420418
ps.set(fg_nhg_prefix, fvs)
421419

422420
keys = asic_db.wait_for_n_keys(ASIC_ROUTE_TB, asic_routes_count + 1)
423421
nhgid = asic_route_exists_and_is_nhg(asic_db, keys, fg_nhg_prefix)
424422
assert nhgid is not None
425423

426-
keys = asic_db.get_keys(ASIC_NHG_MEMB)
427-
assert len(keys) == 3
428-
424+
asic_db.wait_for_n_keys(ASIC_NHG_MEMB, 3)
425+
429426
# add fgnhg prefix: The regular route should transition to fine grained ECMP
430427
fvs = {"FG_NHG": fg_nhg_name}
431428
create_entry(config_db, FG_NHG_PREFIX, fg_nhg_prefix, fvs)
@@ -435,10 +432,10 @@ def test_route_fgnhg(self, dvs, testlog):
435432
keys = asic_db.get_keys(ASIC_ROUTE_TB)
436433
nhgid = asic_route_exists_and_is_nhg(asic_db, keys, fg_nhg_prefix)
437434
validate_asic_nhg(asic_db, nhgid, bucket_size)
438-
435+
439436
nh_oid_map = {}
440-
nh_oid_map = get_nh_oid_map(asic_db)
441-
437+
nh_oid_map = get_nh_oid_map(asic_db)
438+
442439
nh_memb_exp_count = {"10.0.0.7":20,"10.0.0.9":20,"10.0.0.11":20}
443440
validate_fine_grained_asic_n_state_db_entries(asic_db, state_db, ip_to_if_map,
444441
nh_memb_exp_count, nh_oid_map, nhgid, bucket_size)
@@ -449,7 +446,7 @@ def test_route_fgnhg(self, dvs, testlog):
449446
# Validate regular ECMP
450447
asic_db.wait_for_n_keys(ASIC_NHG_MEMB, 3)
451448
asic_route_exists_and_is_nhg(asic_db, keys, fg_nhg_prefix)
452-
449+
453450
# remove prefix entry
454451
asic_rt_key = get_asic_route_key(asic_db, fg_nhg_prefix)
455452
ps._del(fg_nhg_prefix)
@@ -458,7 +455,7 @@ def test_route_fgnhg(self, dvs, testlog):
458455

459456
# Cleanup all FG, arp and interface
460457
remove_entry(config_db, "FG_NHG", fg_nhg_name)
461-
458+
462459
for i in range(0,NUM_NHs):
463460
if_name_key = "Ethernet" + str(i*4)
464461
ip_pref_key = "Ethernet" + str(i*4) + "|10.0.0." + str(i*2) + "/31"
@@ -469,8 +466,8 @@ def test_route_fgnhg(self, dvs, testlog):
469466
remove_entry(config_db, "FG_NHG_MEMBER", "10.0.0." + str(1 + i*2))
470467

471468

472-
### Create new set of entries with a greater number of FG members and
473-
### bigger bucket size such that the # of nhs are not divisible by
469+
### Create new set of entries with a greater number of FG members and
470+
### bigger bucket size such that the # of nhs are not divisible by
474471
### bucket size.
475472
fg_nhg_name = "new_fgnhg_v4"
476473
fg_nhg_prefix = "3.3.3.0/24"
@@ -503,10 +500,10 @@ def test_route_fgnhg(self, dvs, testlog):
503500
create_entry(config_db, FG_NHG_MEMBER, "10.0.0." + str(1 + i*2), fvs)
504501
ip_to_if_map["10.0.0." + str(1 + i*2)] = if_name_key
505502
dvs.runcmd("arp -s 10.0.0." + str(1 + i*2) + " 00:00:00:00:00:" + str(1 + i*2))
506-
503+
507504
# Program the route
508505
asic_routes_count = len(asic_db.get_keys(ASIC_ROUTE_TB))
509-
fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.1,10.0.0.11"),
506+
fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.1,10.0.0.11"),
510507
("ifname", "Ethernet0,Ethernet20")])
511508
ps.set(fg_nhg_prefix, fvs)
512509

@@ -517,7 +514,7 @@ def test_route_fgnhg(self, dvs, testlog):
517514

518515
validate_asic_nhg(asic_db, nhgid, bucket_size)
519516

520-
nh_oid_map = get_nh_oid_map(asic_db)
517+
nh_oid_map = get_nh_oid_map(asic_db)
521518

522519
# Test addition of route with 0 members in bank
523520
nh_memb_exp_count = {"10.0.0.1":64,"10.0.0.11":64}

0 commit comments

Comments
 (0)