From 34ffb8cc679759088d6c7496cd7ab04ca49413e7 Mon Sep 17 00:00:00 2001 From: sudeephb Date: Mon, 22 Apr 2024 16:47:40 +0545 Subject: [PATCH 1/3] Recreate sdr cache if invalid --- prometheus_hardware_exporter/collectors/ipmi_sel.py | 4 +++- prometheus_hardware_exporter/collectors/ipmimonitoring.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/prometheus_hardware_exporter/collectors/ipmi_sel.py b/prometheus_hardware_exporter/collectors/ipmi_sel.py index b492985..ac43299 100644 --- a/prometheus_hardware_exporter/collectors/ipmi_sel.py +++ b/prometheus_hardware_exporter/collectors/ipmi_sel.py @@ -23,7 +23,9 @@ def get_sel_entries(self, time_range: int) -> Optional[List[Dict[str, str]]]: Returns: sel_entries: a list of dictionaries containing sel_sentries, or [] """ - result = self("--output-event-state --interpret-oem-data --entity-sensor-names") + result = self( + "--sdr-cache-recreate --output-event-state --interpret-oem-data --entity-sensor-names" + ) if result.error: logger.error(result.error) return None diff --git a/prometheus_hardware_exporter/collectors/ipmimonitoring.py b/prometheus_hardware_exporter/collectors/ipmimonitoring.py index 8ddb605..8f82010 100644 --- a/prometheus_hardware_exporter/collectors/ipmimonitoring.py +++ b/prometheus_hardware_exporter/collectors/ipmimonitoring.py @@ -20,7 +20,7 @@ def get_sensor_data(self) -> List[Dict[str, str]]: Returns: sensor_data: a list of dictionaries containing sensor data, or [] """ - result = self() + result = self("--sdr-cache-recreate") if result.error: logger.error(result.error) return [] From 3ecca7f6570c685c4d6b7990f8814353ae57fd2e Mon Sep 17 00:00:00 2001 From: sudeephb Date: Wed, 24 Apr 2024 07:34:29 +0545 Subject: [PATCH 2/3] Add comment about --sdr-cache-recreate --- prometheus_hardware_exporter/collectors/ipmi_sel.py | 3 +++ prometheus_hardware_exporter/collectors/ipmimonitoring.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/prometheus_hardware_exporter/collectors/ipmi_sel.py b/prometheus_hardware_exporter/collectors/ipmi_sel.py index ac43299..d475108 100644 --- a/prometheus_hardware_exporter/collectors/ipmi_sel.py +++ b/prometheus_hardware_exporter/collectors/ipmi_sel.py @@ -23,6 +23,9 @@ def get_sel_entries(self, time_range: int) -> Optional[List[Dict[str, str]]]: Returns: sel_entries: a list of dictionaries containing sel_sentries, or [] """ + # --sdr-cache-recreate is required to automatically recreate the SDR cache in case it is + # out of date or invalid. Without this, the service will stop getting ipmi-sel data if the + # cache is out of date. result = self( "--sdr-cache-recreate --output-event-state --interpret-oem-data --entity-sensor-names" ) diff --git a/prometheus_hardware_exporter/collectors/ipmimonitoring.py b/prometheus_hardware_exporter/collectors/ipmimonitoring.py index 8f82010..cce9d35 100644 --- a/prometheus_hardware_exporter/collectors/ipmimonitoring.py +++ b/prometheus_hardware_exporter/collectors/ipmimonitoring.py @@ -20,6 +20,9 @@ def get_sensor_data(self) -> List[Dict[str, str]]: Returns: sensor_data: a list of dictionaries containing sensor data, or [] """ + # --sdr-cache-recreate is required to automatically recreate the SDR cache in case it is + # out of date or invalid. Without this, the service will stop getting sensor data if the + # cache is out of date. result = self("--sdr-cache-recreate") if result.error: logger.error(result.error) From bd13510f4b40c6dc107df205d9c7716eb7b46e84 Mon Sep 17 00:00:00 2001 From: sudeephb Date: Wed, 24 Apr 2024 13:45:03 +0545 Subject: [PATCH 3/3] Update unit tests --- tests/unit/test_ipmi_sel.py | 9 +++++++++ tests/unit/test_ipmimonitoring.py | 2 ++ 2 files changed, 11 insertions(+) diff --git a/tests/unit/test_ipmi_sel.py b/tests/unit/test_ipmi_sel.py index 3a09823..4f4795c 100644 --- a/tests/unit/test_ipmi_sel.py +++ b/tests/unit/test_ipmi_sel.py @@ -51,6 +51,9 @@ def test_00_get_sel_entries_success(self, mock_call): ipmi_sel = IpmiSel(config) payloads = ipmi_sel.get_sel_entries(24 * 60 * 60) expected_sel_entries = SAMPLE_SEL_ENTRIES + mock_call.assert_called_with( + "--sdr-cache-recreate --output-event-state --interpret-oem-data --entity-sensor-names" # noqa: E501 + ) self.assertEqual(payloads, expected_sel_entries) @patch.object(Command, "__call__") @@ -59,6 +62,9 @@ def test_01_get_sel_entries_zero_records(self, mock_call): config = Config() ipmi_sel = IpmiSel(config) payloads = ipmi_sel.get_sel_entries(300) + mock_call.assert_called_with( + "--sdr-cache-recreate --output-event-state --interpret-oem-data --entity-sensor-names" + ) self.assertEqual(payloads, []) @patch.object(Command, "__call__") @@ -67,4 +73,7 @@ def test_02_get_sel_entries_error(self, mock_call): config = Config() ipmi_sel = IpmiSel(config) payloads = ipmi_sel.get_sel_entries(300) + mock_call.assert_called_with( + "--sdr-cache-recreate --output-event-state --interpret-oem-data --entity-sensor-names" + ) self.assertEqual(payloads, None) diff --git a/tests/unit/test_ipmimonitoring.py b/tests/unit/test_ipmimonitoring.py index 8c46ec3..ffbf0a6 100644 --- a/tests/unit/test_ipmimonitoring.py +++ b/tests/unit/test_ipmimonitoring.py @@ -48,6 +48,7 @@ def test_00_get_sensor_data_success(self, mock_call): ipmimonitoring = IpmiMonitoring(config) payloads = ipmimonitoring.get_sensor_data() expected_sensor_entries = SAMPLE_SENSOR_ENTRIES + mock_call.assert_called_with("--sdr-cache-recreate") self.assertEqual(payloads, expected_sensor_entries) @patch.object(Command, "__call__") @@ -56,4 +57,5 @@ def test_00_get_sensor_data_error(self, mock_call): config = Config() ipmimonitoring = IpmiMonitoring(config) payloads = ipmimonitoring.get_sensor_data() + mock_call.assert_called_with("--sdr-cache-recreate") self.assertEqual(payloads, [])