diff --git a/sonic-psud/scripts/psud b/sonic-psud/scripts/psud index 3bcae4c76..c27000d7c 100644 --- a/sonic-psud/scripts/psud +++ b/sonic-psud/scripts/psud @@ -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) diff --git a/sonic-psud/tests/test_DaemonPsud.py b/sonic-psud/tests/test_DaemonPsud.py index 05d7d5dda..ca866eca0 100644 --- a/sonic-psud/tests/test_DaemonPsud.py +++ b/sonic-psud/tests/test_DaemonPsud.py @@ -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): diff --git a/sonic-psud/tests/test_PsuChassisInfo.py b/sonic-psud/tests/test_PsuChassisInfo.py index f40836268..196ef2d48 100644 --- a/sonic-psud/tests/test_PsuChassisInfo.py +++ b/sonic-psud/tests/test_PsuChassisInfo.py @@ -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" diff --git a/sonic-psud/tests/test_psud.py b/sonic-psud/tests/test_psud.py index b95a4986a..463ee9edd 100644 --- a/sonic-psud/tests/test_psud.py +++ b/sonic-psud/tests/test_psud.py @@ -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"