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

Change PSU key to use get_name API instead of index #446

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions sonic-psud/scripts/psud
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ def _wrapper_get_psu_status(psu_index):
#

def get_psu_key(psu_index):
if platform_chassis is not None:
try:
return platform_chassis.get_psu(psu_index - 1).get_name()
except NotImplementedError:
pass
except IndexError:
#some functionality is expectent on returning an expected key even if the psu object itself does not exist
pass
return PSU_INFO_KEY_TEMPLATE.format(psu_index)


Expand Down
11 changes: 5 additions & 6 deletions sonic-psud/tests/test_DaemonPsud.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,20 +517,19 @@ def test_update_psu_entity_info(self):
assert daemon_psud.log_warning.call_count == 1
daemon_psud.log_warning.assert_called_with("Failed to update PSU data - Test message")

@mock.patch('psud.try_get', mock.MagicMock(return_value=0))
def test_update_single_psu_entity_info(self):
mock_psu1 = MockPsu("PSU 1", 0, True, True)

#creating psu object in slot not used to allow for name specific check
mock_psu1 = MockPsu("PSU 3", 2, True, True)
expected_fvp = psud.swsscommon.FieldValuePairs(
[('position_in_parent', '0'),
[('position_in_parent', '2'),
('parent_name', psud.CHASSIS_INFO_KEY),
])

daemon_psud = psud.DaemonPsud(SYSLOG_IDENTIFIER)
daemon_psud.phy_entity_tbl = mock.MagicMock()

daemon_psud._update_single_psu_entity_info(0, mock_psu1)
daemon_psud.phy_entity_tbl.set.assert_called_with('PSU 0', expected_fvp)
daemon_psud._update_single_psu_entity_info(3, mock_psu1)
daemon_psud.phy_entity_tbl.set.assert_called_with('PSU 3', expected_fvp)

@mock.patch('psud.datetime')
def test_update_psu_fan_data(self, mock_datetime):
Expand Down
11 changes: 11 additions & 0 deletions sonic-psud/tests/test_PsuChassisInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,20 @@ def test_first_run(self):
assert psud.Psu.get_status_master_led() == MockPsu.STATUS_LED_COLOR_GREEN

def test_get_psu_key(self):

#mock test for psu get_name() nonimplementation
psud.platform_chassis = None
assert psud.get_psu_key(0) == psud.PSU_INFO_KEY_TEMPLATE.format(0)
assert psud.get_psu_key(1) == psud.PSU_INFO_KEY_TEMPLATE.format(1)

#create psu objects to test getting name for
mock_psu1 = MockPsu("PSU 1", 0, True, True)
mock_psu2 = MockPsu("PSU 2", 1, True, True)
psud.platform_chassis = MockChassis()
psud.platform_chassis._psu_list = [mock_psu1, mock_psu2]
assert psud.get_psu_key(1) == psud.PSU_INFO_KEY_TEMPLATE.format(1)
assert psud.get_psu_key(2) == psud.PSU_INFO_KEY_TEMPLATE.format(2)

def test_try_get(self):
# Test a proper, working callback
GOOD_CALLBACK_RETURN_VALUE = "This is a test"
Expand Down
1 change: 0 additions & 1 deletion sonic-psud/tests/test_psud.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ def test_wrapper_get_psu_status():
assert psud.platform_psuutil.get_psu_status.call_count == 2
psud.platform_psuutil.get_psu_status.assert_called_with(1)


def test_log_on_status_changed():
normal_log = "Normal log message"
abnormal_log = "Abnormal log message"
Expand Down
Loading