From f53baaca04c43dab0a798429ed2969492c055c25 Mon Sep 17 00:00:00 2001 From: vganesan-nokia <67648637+vganesan-nokia@users.noreply.github.com> Date: Tue, 26 Oct 2021 21:16:21 -0400 Subject: [PATCH] [watermarkstat] Fix for error in processing empty array from couters db (#1810) With switch to swsscommon, the get operations return NULL ('') if there are no entries in any table. But the existing code for handling counters values in the case of absence of entries assumes that the get operations return 'None', which was the case with swsssdk. This was causing problem. For PG_WATERMARK_STAT_COUNTER SAI does not support SAI_INGRESS_PRIORITY_GROUP_STAT_XOFF_ROOM_WATERMARK_BYTES and SAI_INGRESS_PRIORITY_GROUP_STAT_SHARED_WATERMARK_BYTES. So there are no objects in the counters db. With swsscommon, in the absence of objects, an empty string ('') is returned instead of 'None'. The code expecting 'None' tries to converts the empty string to integer and throws error. This is fixed by adding check for empty string in addition to 'None'. Signed-off-by: vedganes --- scripts/watermarkstat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/watermarkstat b/scripts/watermarkstat index 7bdc7a015879..ffcec56fa9f7 100755 --- a/scripts/watermarkstat +++ b/scripts/watermarkstat @@ -232,7 +232,7 @@ class Watermarkstat(object): idx = int(idx_func(obj_id)) pos = idx - self.min_idx counter_data = self.counters_db.get(self.counters_db.COUNTERS_DB, full_table_id, watermark) - if counter_data is None: + if counter_data is None or counter_data == '': fields[pos] = STATUS_NA elif fields[pos] != STATUS_NA: fields[pos] = str(int(counter_data))