diff --git a/sonic-psud/scripts/psud b/sonic-psud/scripts/psud index ce588589c..3bcae4c76 100644 --- a/sonic-psud/scripts/psud +++ b/sonic-psud/scripts/psud @@ -125,15 +125,6 @@ def get_psu_key(psu_index): return PSU_INFO_KEY_TEMPLATE.format(psu_index) -def psu_db_update(psu_tbl, psu_num): - for psu_index in range(1, psu_num + 1): - fvs = swsscommon.FieldValuePairs([(PSU_INFO_PRESENCE_FIELD, - 'true' if _wrapper_get_psu_presence(psu_index) else 'false'), - (PSU_INFO_STATUS_FIELD, - 'true' if _wrapper_get_psu_status(psu_index) else 'false')]) - psu_tbl.set(get_psu_key(psu_index), fvs) - - # try get information from platform API and return a default value if we catch NotImplementedError def try_get(callback, default=None): """ @@ -443,7 +434,6 @@ class DaemonPsud(daemon_base.DaemonBase): return False self._update_psu_entity_info() - psu_db_update(self.psu_tbl, self.num_psus) self.update_psu_data() self._update_led_color() @@ -606,6 +596,8 @@ class DaemonPsud(daemon_base.DaemonBase): (PSU_INFO_IN_CURRENT_FIELD, str(in_current)), (PSU_INFO_IN_VOLTAGE_FIELD, str(in_voltage)), (PSU_INFO_POWER_MAX_FIELD, str(max_power)), + (PSU_INFO_PRESENCE_FIELD, 'true' if _wrapper_get_psu_presence(index) else 'false'), + (PSU_INFO_STATUS_FIELD, 'true' if _wrapper_get_psu_status(index) else 'false'), ]) self.psu_tbl.set(name, fvs) diff --git a/sonic-psud/tests/test_DaemonPsud.py b/sonic-psud/tests/test_DaemonPsud.py index 805c76cc0..05d7d5dda 100644 --- a/sonic-psud/tests/test_DaemonPsud.py +++ b/sonic-psud/tests/test_DaemonPsud.py @@ -162,6 +162,8 @@ def _construct_expected_fvp(self, power=100.0, power_warning_suppress_threshold= (psud.PSU_INFO_IN_VOLTAGE_FIELD, '220.25'), (psud.PSU_INFO_IN_CURRENT_FIELD, '0.72'), (psud.PSU_INFO_POWER_MAX_FIELD, 'N/A'), + (psud.PSU_INFO_PRESENCE_FIELD, 'true'), + (psud.PSU_INFO_STATUS_FIELD, 'true'), ]) return expected_fvp diff --git a/sonic-psud/tests/test_psud.py b/sonic-psud/tests/test_psud.py index 405ec30c6..b95a4986a 100644 --- a/sonic-psud/tests/test_psud.py +++ b/sonic-psud/tests/test_psud.py @@ -96,70 +96,6 @@ def test_wrapper_get_psu_status(): psud.platform_psuutil.get_psu_status.assert_called_with(1) -@mock.patch('psud._wrapper_get_psu_presence', mock.MagicMock()) -@mock.patch('psud._wrapper_get_psu_status', mock.MagicMock()) -def test_psu_db_update(): - psu_tbl = mock.MagicMock() - - psud._wrapper_get_psu_presence.return_value = True - psud._wrapper_get_psu_status.return_value = True - expected_fvp = psud.swsscommon.FieldValuePairs( - [(psud.PSU_INFO_PRESENCE_FIELD, 'true'), - (psud.PSU_INFO_STATUS_FIELD, 'true'), - ]) - psud.psu_db_update(psu_tbl, 1) - assert psu_tbl.set.call_count == 1 - psu_tbl.set.assert_called_with(psud.PSU_INFO_KEY_TEMPLATE.format(1), expected_fvp) - - psu_tbl.set.reset_mock() - - psud._wrapper_get_psu_presence.return_value = False - psud._wrapper_get_psu_status.return_value = True - expected_fvp = psud.swsscommon.FieldValuePairs( - [(psud.PSU_INFO_PRESENCE_FIELD, 'false'), - (psud.PSU_INFO_STATUS_FIELD, 'true'), - ]) - psud.psu_db_update(psu_tbl, 1) - assert psu_tbl.set.call_count == 1 - psu_tbl.set.assert_called_with(psud.PSU_INFO_KEY_TEMPLATE.format(1), expected_fvp) - - psu_tbl.set.reset_mock() - - psud._wrapper_get_psu_presence.return_value = True - psud._wrapper_get_psu_status.return_value = False - expected_fvp = psud.swsscommon.FieldValuePairs( - [(psud.PSU_INFO_PRESENCE_FIELD, 'true'), - (psud.PSU_INFO_STATUS_FIELD, 'false'), - ]) - psud.psu_db_update(psu_tbl, 1) - assert psu_tbl.set.call_count == 1 - psu_tbl.set.assert_called_with(psud.PSU_INFO_KEY_TEMPLATE.format(1), expected_fvp) - - psu_tbl.set.reset_mock() - - psud._wrapper_get_psu_presence.return_value = False - psud._wrapper_get_psu_status.return_value = False - expected_fvp = psud.swsscommon.FieldValuePairs( - [(psud.PSU_INFO_PRESENCE_FIELD, 'false'), - (psud.PSU_INFO_STATUS_FIELD, 'false'), - ]) - psud.psu_db_update(psu_tbl, 1) - assert psu_tbl.set.call_count == 1 - psu_tbl.set.assert_called_with(psud.PSU_INFO_KEY_TEMPLATE.format(1), expected_fvp) - - psu_tbl.set.reset_mock() - - psud._wrapper_get_psu_presence.return_value = True - psud._wrapper_get_psu_status.return_value = True - expected_fvp = psud.swsscommon.FieldValuePairs( - [(psud.PSU_INFO_PRESENCE_FIELD, 'true'), - (psud.PSU_INFO_STATUS_FIELD, 'true'), - ]) - psud.psu_db_update(psu_tbl, 32) - assert psu_tbl.set.call_count == 32 - psu_tbl.set.assert_called_with(psud.PSU_INFO_KEY_TEMPLATE.format(32), expected_fvp) - - def test_log_on_status_changed(): normal_log = "Normal log message" abnormal_log = "Abnormal log message"