-
Notifications
You must be signed in to change notification settings - Fork 221
[thermalctld] Use platform API for PSU fan name #767
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -201,6 +201,14 @@ class FanUpdater(logger.Logger): | |
| self.drawer_table = swsscommon.Table(state_db, FanUpdater.FAN_DRAWER_INFO_TABLE_NAME) | ||
| self.phy_entity_table = swsscommon.Table(state_db, PHYSICAL_ENTITY_INFO_TABLE) | ||
|
|
||
| def get_psu_key(self, psu_index): | ||
| if self.chassis is not None: | ||
| try: | ||
| return self.chassis.get_psu(psu_index).get_name() | ||
| except (NotImplementedError, AttributeError): | ||
| pass | ||
| return 'PSU {}'.format(psu_index + 1) | ||
|
Comment on lines
+206
to
+210
|
||
|
|
||
| def __del__(self): | ||
| if self.table: | ||
| table_keys = self.table.getKeys() | ||
|
|
@@ -308,7 +316,7 @@ class FanUpdater(logger.Logger): | |
| """ | ||
| drawer_name = NOT_AVAILABLE if fan_type != FanType.DRAWER else str(try_get(parent.get_name)) | ||
| if fan_type == FanType.PSU: | ||
| parent_name = try_get(parent.get_name, default='PSU {}'.format(parent_index + 1)) | ||
| parent_name = self.get_psu_key(parent_index) | ||
| elif fan_type == FanType.MODULE: | ||
| parent_name = try_get(parent.get_name, default='Module {}'.format(parent_index + 1)) | ||
| else: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -289,6 +289,37 @@ def test_update_module_fans(self): | |
| else: | ||
| fan_updater.log_warning.assert_called_with("Failed to update module fan status - Exception('Test message',)") | ||
|
|
||
| def test_get_psu_key_returns_psu_name(self): | ||
| """Test get_psu_key returns PSU name from platform API""" | ||
| chassis = MockChassis() | ||
| psu = MockPsu() | ||
| psu._name = 'PSU0' | ||
| chassis._psu_list.append(psu) | ||
| fan_updater = thermalctld.FanUpdater(chassis, threading.Event()) | ||
| assert fan_updater.get_psu_key(0) == 'PSU0' | ||
|
|
||
| def test_get_psu_key_attribute_error(self): | ||
| """Test get_psu_key falls back when get_psu returns None (AttributeError on .get_name())""" | ||
| chassis = MockChassis() | ||
| # No PSUs added, so get_psu(index) returns None and .get_name() raises AttributeError | ||
| fan_updater = thermalctld.FanUpdater(chassis, threading.Event()) | ||
| assert fan_updater.get_psu_key(0) == 'PSU 1' | ||
| assert fan_updater.get_psu_key(1) == 'PSU 2' | ||
|
|
||
| def test_get_psu_key_not_implemented_error(self): | ||
| """Test get_psu_key falls back to 1-based 'PSU <index+1>' when get_name raises NotImplementedError""" | ||
| chassis = MockChassis() | ||
| psu = MockPsu() | ||
| psu.get_name = mock.MagicMock(side_effect=NotImplementedError) | ||
| chassis._psu_list.append(psu) | ||
| fan_updater = thermalctld.FanUpdater(chassis, threading.Event()) | ||
| assert fan_updater.get_psu_key(0) == 'PSU 1' | ||
|
|
||
| def test_get_psu_key_chassis_none(self): | ||
| """Test get_psu_key falls back to 1-based 'PSU <index+1>' when chassis is None""" | ||
| fan_updater = thermalctld.FanUpdater(None, threading.Event()) | ||
| assert fan_updater.get_psu_key(0) == 'PSU 1' | ||
|
|
||
|
Comment on lines
+292
to
+322
|
||
| class TestLiquidCoolingUpdater(object): | ||
| def test_update(self): | ||
| mock_chassis = MockChassis() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FanUpdater.get_psu_key() is a new public helper but it currently has no docstring, while the surrounding public methods in this file are documented. Please add a short docstring describing expected indexing (0-based vs 1-based) and fallback behavior.