From 807b304d66a4e88e8091f430665a57b7a069020c Mon Sep 17 00:00:00 2001 From: Alexander Allen Date: Wed, 12 May 2021 15:51:42 -0400 Subject: [PATCH] [psud] Add PSU Hardware Revision to Redis STATE_DB (#179) Added "hardware revision" field to list of platform fields to sync to STATE_DB for the PSU. Also updated relevant unit tests. Now that hardware revision exists as a platform 2.0 field for all devices, it is appropriate to synchronize this field to STATE_DB for PSUs as is done with all other fields. This will allow this field to be exposed to CLI tools through psushow in the future which reads state from STATE_DB. --- sonic-psud/scripts/psud | 2 ++ sonic-psud/tests/mock_platform.py | 5 +++++ sonic-psud/tests/test_DaemonPsud.py | 3 ++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/sonic-psud/scripts/psud b/sonic-psud/scripts/psud index 8a41fc054e09..6be6f2934e1f 100644 --- a/sonic-psud/scripts/psud +++ b/sonic-psud/scripts/psud @@ -48,6 +48,7 @@ PSU_INFO_KEY_TEMPLATE = 'PSU {}' PSU_INFO_PRESENCE_FIELD = 'presence' PSU_INFO_MODEL_FIELD = 'model' PSU_INFO_SERIAL_FIELD = 'serial' +PSU_INFO_REV_FIELD = 'revision' PSU_INFO_STATUS_FIELD = 'status' PSU_INFO_TEMP_FIELD = 'temp' PSU_INFO_TEMP_TH_FIELD = 'temp_threshold' @@ -510,6 +511,7 @@ class DaemonPsud(daemon_base.DaemonBase): fvs = swsscommon.FieldValuePairs( [(PSU_INFO_MODEL_FIELD, str(try_get(psu.get_model, NOT_AVAILABLE))), (PSU_INFO_SERIAL_FIELD, str(try_get(psu.get_serial, NOT_AVAILABLE))), + (PSU_INFO_REV_FIELD, str(try_get(psu.get_revision, NOT_AVAILABLE))), (PSU_INFO_TEMP_FIELD, str(temperature)), (PSU_INFO_TEMP_TH_FIELD, str(temperature_threshold)), (PSU_INFO_VOLTAGE_FIELD, str(voltage)), diff --git a/sonic-psud/tests/mock_platform.py b/sonic-psud/tests/mock_platform.py index 6a0bb35174cc..8d3b13c5253e 100644 --- a/sonic-psud/tests/mock_platform.py +++ b/sonic-psud/tests/mock_platform.py @@ -273,6 +273,7 @@ def __init__(self, presence=True, model='Module Model', serial='Module Serial', + revision='Module Revision', status=True, voltage=12.0, current=8.0, @@ -287,6 +288,7 @@ def __init__(self, self._presence = presence self._model = model self._serial = serial + self._revision = revision self._status = status self._position_in_parent = position_in_parent self._replaceable = replaceable @@ -365,6 +367,9 @@ def get_model(self): def get_serial(self): return self._serial + def get_revision(self): + return self._revision + def get_status(self): return self._status diff --git a/sonic-psud/tests/test_DaemonPsud.py b/sonic-psud/tests/test_DaemonPsud.py index 1168866577c8..0234ec79f7b6 100644 --- a/sonic-psud/tests/test_DaemonPsud.py +++ b/sonic-psud/tests/test_DaemonPsud.py @@ -148,13 +148,14 @@ def test_update_single_psu_data(self): psud._wrapper_get_psu_presence.return_value = True psud._wrapper_get_psu_status.return_value = True - psu1 = MockPsu('PSU 1', 0, True, 'Fake Model', '12345678') + psu1 = MockPsu('PSU 1', 0, True, 'Fake Model', '12345678', '1234') psud.platform_chassis = MockChassis() psud.platform_chassis._psu_list.append(psu1) expected_fvp = psud.swsscommon.FieldValuePairs( [(psud.PSU_INFO_MODEL_FIELD, 'Fake Model'), (psud.PSU_INFO_SERIAL_FIELD, '12345678'), + (psud.PSU_INFO_REV_FIELD, '1234'), (psud.PSU_INFO_TEMP_FIELD, '30.0'), (psud.PSU_INFO_TEMP_TH_FIELD, '50.0'), (psud.PSU_INFO_VOLTAGE_FIELD, '12.0'),