Skip to content

Commit 252910a

Browse files
liorghubyxieca
authored andcommitted
[drop counters] Fix CLI script for unconfigured PGs (#2518)
- 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 "pgdropstat_test.py" including this PR and observe it passes.
1 parent f2bf7ed commit 252910a

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

scripts/pg-drop

+14-7
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,23 @@ class PgDropStat(object):
116116

117117
self.header_list = ['Port']
118118
header_map = pg_drop_type["obj_map"]
119-
single_key = list(header_map.keys())[0]
120-
header_len = len(header_map[single_key])
121-
min_idx = sys.maxsize
122119

123-
for name, counter_oid in header_map[single_key].items():
124-
curr_idx = int(pg_drop_type["idx_func"](counter_oid))
125-
min_idx = min(min_idx, curr_idx)
120+
max_idx = 0
121+
min_idx = sys.maxsize
122+
for port in header_map.keys():
123+
for element in header_map[port].keys():
124+
element_idx = int(element.split(':')[1])
125+
if element_idx > max_idx:
126+
max_idx = element_idx
127+
if min_idx > element_idx:
128+
min_idx = element_idx
129+
130+
if min_idx == sys.maxsize:
131+
print("Header info is not available!")
132+
sys.exit(1)
126133

127134
self.min_idx = min_idx
128-
self.header_list += ["{}{}".format(pg_drop_type["header_prefix"], idx) for idx in range(self.min_idx, self.min_idx + header_len)]
135+
self.header_list += ["{}{}".format(pg_drop_type["header_prefix"], idx) for idx in range(self.min_idx, max_idx + 1)]
129136

130137
def get_counters(self, table_prefix, port_obj, idx_func, counter_name):
131138
"""

0 commit comments

Comments
 (0)