From f743d7ca69eb0e16323c88f885c8d147e5722bc6 Mon Sep 17 00:00:00 2001 From: prem-nokia <122470020+prem-nokia@users.noreply.github.com> Date: Fri, 5 May 2023 18:01:24 -0400 Subject: [PATCH] =?UTF-8?q?PSUD-Delete=20or=20update=20CHASSIS=5FINFO=20ta?= =?UTF-8?q?ble=20PSU/Modules=20data=20if=20added=20or=E2=80=A6=20(#351)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * PSUD-Delete or update CHASSIS_INFO table PSU/Modules data if added or removed. Signed-off-by: prem-nokia * fix swsscommon.py hdel function. * implemented code optimization. Signed-off-by: premsara --------- Signed-off-by: prem-nokia Signed-off-by: premsara --- sonic-psud/scripts/psud | 12 +++++++++--- .../tests/mocked_libs/swsscommon/swsscommon.py | 4 ++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/sonic-psud/scripts/psud b/sonic-psud/scripts/psud index 96ba57935..b52b98948 100644 --- a/sonic-psud/scripts/psud +++ b/sonic-psud/scripts/psud @@ -203,15 +203,19 @@ class PsuChassisInfo(logger.Logger): fvs = swsscommon.FieldValuePairs(dict_len) for index, psu in enumerate(self.chassis.get_all_psus()): + name = try_get(psu.get_name, 'PSU {}'.format(index + 1)) presence = try_get(psu.get_presence) if not presence: + chassis_tbl.hdel(CHASSIS_INFO_POWER_KEY_TEMPLATE.format(1), CHASSIS_INFO_POWER_SUPPLIER_FIELD.format(name)) continue power_good = try_get(psu.get_powergood_status) if not power_good: + supplied_power = 0.0 + fvs[dict_index] = (CHASSIS_INFO_POWER_SUPPLIER_FIELD.format(name), str(supplied_power)) + dict_index += 1 continue - name = try_get(psu.get_name, 'PSU {}'.format(index + 1)) supplied_power = try_get(psu.get_maximum_supplied_power, 0.0) total_supplied_power = total_supplied_power + supplied_power fvs[dict_index] = (CHASSIS_INFO_POWER_SUPPLIER_FIELD.format(name), str(supplied_power)) @@ -219,10 +223,11 @@ class PsuChassisInfo(logger.Logger): for index, power_consumer in enumerate(self.chassis.get_all_fan_drawers()): presence = try_get(power_consumer.get_presence) + name = try_get(power_consumer.get_name, 'FAN-DRAWER {}'.format(index)) if not presence: + chassis_tbl.hdel(CHASSIS_INFO_POWER_KEY_TEMPLATE.format(1), CHASSIS_INFO_POWER_CONSUMER_FIELD.format(name)) continue - name = try_get(power_consumer.get_name, 'FAN-DRAWER {}'.format(index)) fan_drawer_power = try_get(power_consumer.get_maximum_consumed_power, 0.0) total_fan_consumed_power = total_fan_consumed_power + fan_drawer_power fvs[dict_index] = (CHASSIS_INFO_POWER_CONSUMER_FIELD.format(name), str(fan_drawer_power)) @@ -230,10 +235,11 @@ class PsuChassisInfo(logger.Logger): for index, power_consumer in enumerate(self.chassis.get_all_modules()): presence = try_get(power_consumer.get_presence) + name = try_get(power_consumer.get_name, 'MODULE {}'.format(index)) if not presence: + chassis_tbl.hdel(CHASSIS_INFO_POWER_KEY_TEMPLATE.format(1), CHASSIS_INFO_POWER_CONSUMER_FIELD.format(name)) continue - name = try_get(power_consumer.get_name, 'MODULE {}'.format(index)) module_power = try_get(power_consumer.get_maximum_consumed_power, 0.0) total_module_consumed_power = total_module_consumed_power + module_power fvs[dict_index] = (CHASSIS_INFO_POWER_CONSUMER_FIELD.format(name), str(module_power)) diff --git a/sonic-psud/tests/mocked_libs/swsscommon/swsscommon.py b/sonic-psud/tests/mocked_libs/swsscommon/swsscommon.py index 13c49dec1..1da16aa2e 100644 --- a/sonic-psud/tests/mocked_libs/swsscommon/swsscommon.py +++ b/sonic-psud/tests/mocked_libs/swsscommon/swsscommon.py @@ -16,6 +16,10 @@ def _del(self, key): del self.mock_dict[key] pass + def hdel(self, key, value): + del self.mock_dict[key] + pass + def set(self, key, fvs): self.mock_dict[key] = fvs.fv_dict pass