Skip to content

Commit

Permalink
PSUD-Delete or update CHASSIS_INFO table PSU/Modules data if added or… (
Browse files Browse the repository at this point in the history
#351)

* PSUD-Delete or update CHASSIS_INFO table PSU/Modules data if added or removed.

Signed-off-by: prem-nokia <premnath.saravanan@nokia.com>

* fix swsscommon.py hdel function.

* implemented code optimization.

Signed-off-by: premsara <premnath.saravanan@nokia.com>

---------

Signed-off-by: prem-nokia <premnath.saravanan@nokia.com>
Signed-off-by: premsara <premnath.saravanan@nokia.com>
  • Loading branch information
prem-nokia authored May 5, 2023
1 parent 95c7670 commit f743d7c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 9 additions & 3 deletions sonic-psud/scripts/psud
Original file line number Diff line number Diff line change
Expand Up @@ -203,37 +203,43 @@ 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))
dict_index += 1

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))
dict_index += 1

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))
Expand Down
4 changes: 4 additions & 0 deletions sonic-psud/tests/mocked_libs/swsscommon/swsscommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f743d7c

Please sign in to comment.