Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Mellanox] add PSU input voltage and current #11510

Merged
merged 3 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion platform/mellanox/mlnx-platform-api/sonic_platform/psu.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,32 @@ 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"
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

Expand All @@ -207,7 +227,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))
Expand Down Expand Up @@ -457,6 +480,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
Expand Down
10 changes: 9 additions & 1 deletion platform/mellanox/mlnx-platform-api/tests/test_psu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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
Expand All @@ -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
Expand Down