From c31b2117a88fec09f4498a715a8819a226cf8867 Mon Sep 17 00:00:00 2001 From: orfar1994 Date: Mon, 18 Jul 2022 08:44:12 +0300 Subject: [PATCH 1/3] add psu input voltage and current to mlnx Signed-off-by: orfar1994 --- .../mlnx-platform-api/sonic_platform/psu.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py b/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py index 69f2f8930cc4..fe0fc221e3c6 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py @@ -196,6 +196,8 @@ class Psu(FixedPsu): PSU_CURRENT = "power/psu{}_curr" PSU_POWER = "power/psu{}_power" PSU_VPD = "eeprom/psu{}_vpd" + PSU_CURRENT_IN = "power/psu{}_curr_in" + PSU_VOLT_IN = "power/psu{}_volt_in" shared_led = None @@ -207,7 +209,10 @@ def __init__(self, psu_index): self._psu_voltage_max = None self._psu_voltage_capability = None + self.psu_voltage_in = os.path.join(PSU_PATH, self.PSU_VOLT_IN.format(self.index)) + self.psu_current = os.path.join(PSU_PATH, self.PSU_CURRENT.format(self.index)) + self.psu_current_in = os.path.join(PSU_PATH, self.PSU_CURRENT_IN.format(self.index)) self.psu_power = os.path.join(PSU_PATH, self.PSU_POWER.format(self.index)) self.psu_power_max = self.psu_power + "_max" self.psu_presence = os.path.join(PSU_PATH, "thermal/psu{}_status".format(self.index)) @@ -457,6 +462,30 @@ def get_maximum_supplied_power(self): else: return None + def get_input_voltage(self): + """ + Retrieves current PSU voltage input + + Returns: + A float number, the input voltage in volts, + e.g. 12.1 + """ + if self.get_powergood_status(): + voltage = utils.read_int_from_file(self.psu_voltage_in, log_func=logger.log_info) + return float(voltage) / 1000 + return None + + def get_input_current(self): + """ + Retrieves the input current draw of the power supply + + Returns: + A float number, the electric current in amperes, e.g 15.4 + """ + if self.get_powergood_status(): + amperes = utils.read_int_from_file(self.psu_current_in, log_func=logger.log_info) + return float(amperes) / 1000 + return None class InvalidPsuVolWA: """This class is created as a workaround for a known hardware issue that the PSU voltage threshold could be a From 029a2187f4ec0de9f8dbb942c83f99b2f898f635 Mon Sep 17 00:00:00 2001 From: orfar1994 Date: Wed, 20 Jul 2022 13:44:05 +0300 Subject: [PATCH 2/3] Add psu unitests Signed-off-by: orfar1994 --- platform/mellanox/mlnx-platform-api/tests/test_psu.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/platform/mellanox/mlnx-platform-api/tests/test_psu.py b/platform/mellanox/mlnx-platform-api/tests/test_psu.py index 68260ef630f7..5deb72bfb0e1 100644 --- a/platform/mellanox/mlnx-platform-api/tests/test_psu.py +++ b/platform/mellanox/mlnx-platform-api/tests/test_psu.py @@ -49,6 +49,8 @@ def test_fixed_psu(self): assert psu.is_replaceable() is False assert psu.get_temperature() is None assert psu.get_temperature_high_threshold() is None + assert psu.get_input_voltage() is None + assert psu.get_input_current() is None @mock.patch('os.path.exists', mock.MagicMock(return_value=True)) def test_psu(self): @@ -64,7 +66,9 @@ def test_psu(self): psu.psu_current: 20345, psu.psu_power: 30456, psu.psu_temp: 40567, - psu.psu_temp_threshold: 50678 + psu.psu_temp_threshold: 50678, + psu.psu_voltage_in: 102345, + psu.psu_current_in: 676, } def mock_read_int_from_file(file_path, **kwargs): @@ -85,6 +89,8 @@ def mock_read_int_from_file(file_path, **kwargs): assert psu.get_power() is None assert psu.get_temperature() is None assert psu.get_temperature_high_threshold() is None + assert psu.get_input_voltage() is None + assert psu.get_input_current() is None mock_sysfs_content[psu.psu_oper_status] = 1 assert psu.get_voltage() == 10.234 @@ -94,6 +100,8 @@ def mock_read_int_from_file(file_path, **kwargs): assert psu.get_power() == 0.030456 assert psu.get_temperature() == 40.567 assert psu.get_temperature_high_threshold() == 50.678 + assert psu.get_input_voltage() == 102.345 + assert psu.get_input_current() == 0.676 assert psu.get_position_in_parent() == 1 assert psu.is_replaceable() is True From e6e00d61ca6a0b3c52d5c8365c725ac7d0adc892 Mon Sep 17 00:00:00 2001 From: orfar1994 Date: Wed, 20 Jul 2022 15:23:12 +0300 Subject: [PATCH 3/3] add input vol and current to fixed psu Signed-off-by: orfar1994 --- .../mlnx-platform-api/sonic_platform/psu.py | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py b/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py index fe0fc221e3c6..05f38f62a0f1 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/psu.py @@ -190,7 +190,25 @@ def get_temperature_high_threshold(self): """ return None - + def get_input_voltage(self): + """ + Retrieves current PSU voltage input + + Returns: + A float number, the input voltage in volts, + e.g. 12.1 + """ + return None + + def get_input_current(self): + """ + Retrieves the input current draw of the power supply + + Returns: + A float number, the electric current in amperes, e.g 15.4 + """ + return None + class Psu(FixedPsu): """Platform-specific Psu class""" PSU_CURRENT = "power/psu{}_curr"