Skip to content

Commit 61ea21d

Browse files
nazariigyxieca
authored andcommitted
[watermarkstat] Fix CLI script for unconfigured PG counters (#2239)
Signed-off-by: Nazarii Hnydyn [email protected] Propagating #2220 with resolved review comments What I did Since PG counters are created only if they are configured in the switch, it is not enough to relay only on the first entry in the DB when building the output table of watermarkstat script. We need to go over all configured counters, check what is the max configured, and build the table accordingly. How I did it Iterate all configured PG buffers for all ports and find the max index. Build the output table according to the max index. How to verify it Run test "iface_namingmode/test_iface_namingmode.py" including this PR: sonic-net/sonic-swss#2143 and observe it passes.
1 parent e206e2d commit 61ea21d

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

scripts/watermarkstat

+14-7
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,23 @@ class Watermarkstat(object):
208208

209209
self.header_list = ['Port']
210210
header_map = wm_type["obj_map"]
211-
single_key = list(header_map.keys())[0]
212-
header_len = len(header_map[single_key])
213-
min_idx = sys.maxsize
214211

215-
for name, counter_oid in header_map[single_key].items():
216-
curr_idx = int(wm_type["idx_func"](counter_oid))
217-
min_idx = min(min_idx, curr_idx)
212+
max_idx = 0
213+
min_idx = sys.maxsize
214+
for port in header_map.keys():
215+
for element in header_map[port].keys():
216+
element_idx = int(element.split(':')[1])
217+
if element_idx > max_idx:
218+
max_idx = element_idx
219+
if min_idx > element_idx:
220+
min_idx = element_idx
221+
222+
if min_idx == sys.maxsize:
223+
print("Object map is empty!", file=sys.stderr)
224+
sys.exit(1)
218225

219226
self.min_idx = min_idx
220-
self.header_list += ["{}{}".format(wm_type["header_prefix"], idx) for idx in range(self.min_idx, self.min_idx + header_len)]
227+
self.header_list += ["{}{}".format(wm_type["header_prefix"], idx) for idx in range(self.min_idx, max_idx + 1)]
221228

222229
def get_counters(self, table_prefix, port_obj, idx_func, watermark):
223230
"""

0 commit comments

Comments
 (0)