From 61ea21d7c3032c3d66c0206a7e5cf49918252b62 Mon Sep 17 00:00:00 2001 From: Nazarii Hnydyn Date: Fri, 29 Jul 2022 00:38:38 +0300 Subject: [PATCH] [watermarkstat] Fix CLI script for unconfigured PG counters (#2239) Signed-off-by: Nazarii Hnydyn nazariig@nvidia.com 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: Azure/sonic-swss#2143 and observe it passes. --- scripts/watermarkstat | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/scripts/watermarkstat b/scripts/watermarkstat index ffcec56fa9..d9dc800c8d 100755 --- a/scripts/watermarkstat +++ b/scripts/watermarkstat @@ -208,16 +208,23 @@ class Watermarkstat(object): self.header_list = ['Port'] header_map = wm_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(wm_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("Object map is empty!", file=sys.stderr) + sys.exit(1) self.min_idx = min_idx - self.header_list += ["{}{}".format(wm_type["header_prefix"], idx) for idx in range(self.min_idx, self.min_idx + header_len)] + self.header_list += ["{}{}".format(wm_type["header_prefix"], idx) for idx in range(self.min_idx, max_idx + 1)] def get_counters(self, table_prefix, port_obj, idx_func, watermark): """