From 252910ac7e17db73bd91c848bcb4290d23b9c98f Mon Sep 17 00:00:00 2001 From: Lior Avramov <73036155+liorghub@users.noreply.github.com> Date: Tue, 29 Nov 2022 16:53:39 +0200 Subject: [PATCH] [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. --- scripts/pg-drop | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/scripts/pg-drop b/scripts/pg-drop index 6005fdb393..4f58f84ccd 100755 --- a/scripts/pg-drop +++ b/scripts/pg-drop @@ -116,16 +116,23 @@ class PgDropStat(object): self.header_list = ['Port'] header_map = pg_drop_type["obj_map"] - single_key = list(header_map.keys())[0] - header_len = len(header_map[single_key]) - min_idx = sys.maxsize - for name, counter_oid in header_map[single_key].items(): - curr_idx = int(pg_drop_type["idx_func"](counter_oid)) - min_idx = min(min_idx, curr_idx) + max_idx = 0 + min_idx = sys.maxsize + for port in header_map.keys(): + for element in header_map[port].keys(): + element_idx = int(element.split(':')[1]) + if element_idx > max_idx: + max_idx = element_idx + if min_idx > element_idx: + min_idx = element_idx + + if min_idx == sys.maxsize: + print("Header info is not available!") + sys.exit(1) self.min_idx = min_idx - self.header_list += ["{}{}".format(pg_drop_type["header_prefix"], idx) for idx in range(self.min_idx, self.min_idx + header_len)] + self.header_list += ["{}{}".format(pg_drop_type["header_prefix"], idx) for idx in range(self.min_idx, max_idx + 1)] def get_counters(self, table_prefix, port_obj, idx_func, counter_name): """