Skip to content

Commit 9313750

Browse files
authored
[GCU] [MA] Adding support in existing tests - mmu dynamic threshold (sonic-net#15237)
Signed-off-by: opcoder0 <[email protected]>
1 parent f5e0ae0 commit 9313750

File tree

1 file changed

+40
-21
lines changed

1 file changed

+40
-21
lines changed

tests/generic_config_updater/test_mmu_dynamic_threshold_config_update.py

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,39 +41,46 @@ def ensure_dut_readiness(duthost):
4141
delete_checkpoint(duthost)
4242

4343

44-
def ensure_application_of_updated_config(duthost, value, pg_lossless_profiles):
44+
def ensure_application_of_updated_config(duthost, value, pg_lossless_profiles,
45+
ip_netns_namespace_prefix,
46+
cli_namespace_prefix):
4547
"""
4648
Ensures application of the JSON patch config update by verifying dynamic threshold value presence in DB
4749
4850
Args:
4951
duthost: DUT host object
5052
value: expected value of dynamic threshold
5153
pg_lossless_profiles: all pg_lossless buffer profiles stored on the device
54+
ip_netns_namespace_prefix: fixture for the formatted ip netns namespace
55+
cli_namespace_prefix: fixture for the formatted cli namespace
5256
"""
5357
def _confirm_value_in_appl_db_and_asic_db():
54-
5558
for pg_lossless_profile in pg_lossless_profiles:
5659
# Retrieve dynamic_th from APPL_DB
57-
dynamic_th_in_appl_db = duthost.shell("sonic-db-cli APPL_DB hget BUFFER_PROFILE_"
58-
"TABLE:{} dynamic_th".format(pg_lossless_profile))["stdout"]
60+
dynamic_th_in_appl_db = duthost.shell("sonic-db-cli {} APPL_DB hget BUFFER_PROFILE_"
61+
"TABLE:{} dynamic_th"
62+
.format(cli_namespace_prefix,
63+
pg_lossless_profile))["stdout"]
5964
if dynamic_th_in_appl_db != value:
6065
return False
6166

6267
# Retrieve dynamic_th from ASIC_DB
63-
ingress_lossless_pool_oid = duthost.shell("sonic-db-cli COUNTERS_DB hget COUNTERS_BUFFER_POOL_NAME_MAP "
64-
"ingress_lossless_pool")["stdout"]
65-
buffer_pool_keys = duthost.shell("redis-cli -n 1 KEYS ASIC_STATE:SAI_OBJECT_TYPE_BUFFER_PROFILE:"
66-
"oid*")["stdout_lines"]
68+
ingress_lossless_pool_oid = duthost.shell("sonic-db-cli {} COUNTERS_DB hget COUNTERS_BUFFER_POOL_NAME_MAP "
69+
"ingress_lossless_pool"
70+
.format(cli_namespace_prefix))["stdout"]
71+
buffer_pool_keys = duthost.shell("{} redis-cli -n 1 KEYS ASIC_STATE:SAI_OBJECT_TYPE_BUFFER_PROFILE:"
72+
"oid*".format(ip_netns_namespace_prefix))["stdout_lines"]
6773

6874
for buffer_pool in buffer_pool_keys:
69-
pool_oid = duthost.shell("sonic-db-cli ASIC_DB hget {} SAI_BUFFER_PROFILE_ATTR_"
70-
"POOL_ID".format(buffer_pool))["stdout"]
75+
pool_oid = duthost.shell("sonic-db-cli {} ASIC_DB hget {} SAI_BUFFER_PROFILE_ATTR_"
76+
"POOL_ID".format(cli_namespace_prefix, buffer_pool))["stdout"]
7177

7278
if pool_oid == ingress_lossless_pool_oid:
73-
xoff_val = duthost.shell("sonic-db-cli ASIC_DB hget {} SAI_BUFFER_PROFILE_ATTR_"
74-
"XOFF_TH".format(buffer_pool))["stdout"]
75-
dynamic_th_in_asic_db = duthost.shell("sonic-db-cli ASIC_DB hget {} SAI_BUFFER_PROFILE_"
76-
"ATTR_SHARED_DYNAMIC_TH".format(buffer_pool))["stdout"]
79+
xoff_val = duthost.shell("sonic-db-cli {} ASIC_DB hget {} SAI_BUFFER_PROFILE_ATTR_"
80+
"XOFF_TH".format(cli_namespace_prefix, buffer_pool))["stdout"]
81+
dynamic_th_in_asic_db = duthost.shell("sonic-db-cli {} ASIC_DB hget {} SAI_BUFFER_PROFILE_"
82+
"ATTR_SHARED_DYNAMIC_TH"
83+
.format(cli_namespace_prefix, buffer_pool))["stdout"]
7784
# Dynamic threshold values are a mismatch for pg_lossless profiles
7885
if dynamic_th_in_asic_db != value and len(xoff_val) > 0:
7986
return False
@@ -82,18 +89,21 @@ def _confirm_value_in_appl_db_and_asic_db():
8289

8390
pytest_assert(
8491
wait_until(READ_APPL_DB_TIMEOUT, READ_APPL_DB_INTERVAL, 0, _confirm_value_in_appl_db_and_asic_db),
85-
"ASIC_DB or APPL_DB does not properly reflect new dynamic threshold expected value: {}".format(value)
92+
"ASIC_DB or APPL_DB for namespace prefix {} does not properly reflect new dynamic threshold expected value: {}"
93+
.format(cli_namespace_prefix, value)
8694
)
8795

8896

89-
def get_pg_lossless_profiles(duthost):
97+
def get_pg_lossless_profiles(duthost, cli_namespace_prefix):
9098
"""
9199
Retrieves all pg_lossless buffer profiles that are present on the device. Ex. pg_lossless_100000_40m_profile
92100
93101
Args:
94102
duthost: DUT host object
103+
cli_namespace_prefix: fixture for the formatted cli namespace
95104
"""
96-
pg_lossless_profiles_str = duthost.shell("redis-cli -n 0 KEYS *BUFFER_PROFILE_TABLE:pg_lossless*")["stdout_lines"]
105+
pg_lossless_profiles_str = duthost.shell("sonic-db-cli {} APPL_DB KEYS *BUFFER_PROFILE_TABLE:pg_lossless*"
106+
.format(cli_namespace_prefix))["stdout_lines"]
97107
pg_lossless_profiles_lst = []
98108

99109
for pg_lossless_profile_str in pg_lossless_profiles_str:
@@ -109,8 +119,14 @@ def get_pg_lossless_profiles(duthost):
109119

110120

111121
@pytest.mark.parametrize("operation", ["replace"])
112-
def test_dynamic_th_config_updates(duthost, ensure_dut_readiness, operation, skip_when_buffer_is_dynamic_model):
113-
pg_lossless_profiles = get_pg_lossless_profiles(duthost)
122+
def test_dynamic_th_config_updates(duthost, ensure_dut_readiness, operation,
123+
skip_when_buffer_is_dynamic_model,
124+
enum_rand_one_frontend_asic_index,
125+
ip_netns_namespace_prefix,
126+
cli_namespace_prefix):
127+
namespace = duthost.get_namespace_from_asic_id(enum_rand_one_frontend_asic_index)
128+
129+
pg_lossless_profiles = get_pg_lossless_profiles(duthost, cli_namespace_prefix)
114130
pytest_require(pg_lossless_profiles, "DUT has no pg_lossless buffer profiles")
115131
new_dynamic_th = "2"
116132
json_patch = []
@@ -123,7 +139,9 @@ def test_dynamic_th_config_updates(duthost, ensure_dut_readiness, operation, ski
123139
}
124140
json_patch.append(individual_patch)
125141

126-
json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch, is_asic_specific=True)
142+
json_patch = format_json_patch_for_multiasic(duthost=duthost, json_data=json_patch,
143+
is_asic_specific=True, asic_namespaces=[namespace])
144+
127145
tmpfile = generate_tmpfile(duthost)
128146
logger.info("tmpfile {} created for json patch of updating dynamic threshold and operation: {}"
129147
.format(tmpfile, operation))
@@ -132,7 +150,8 @@ def test_dynamic_th_config_updates(duthost, ensure_dut_readiness, operation, ski
132150
try:
133151
output = apply_patch(duthost, json_data=json_patch, dest_file=tmpfile)
134152
expect_op_success(duthost, output)
135-
ensure_application_of_updated_config(duthost, new_dynamic_th, pg_lossless_profiles)
153+
ensure_application_of_updated_config(duthost, new_dynamic_th, pg_lossless_profiles,
154+
ip_netns_namespace_prefix, cli_namespace_prefix)
136155
logger.info("Config successfully updated and verified.")
137156
finally:
138157
delete_tmpfile(duthost, tmpfile)

0 commit comments

Comments
 (0)