diff --git a/src/hw_tools.py b/src/hw_tools.py index 5fde688d..a5604fbb 100644 --- a/src/hw_tools.py +++ b/src/hw_tools.py @@ -323,19 +323,19 @@ def check(self) -> bool: class IPMIStrategy(APTStrategyABC): """Strategy for installing ipmi.""" - pkg = "freeipmi-tools" + freeipmi_pkg = "freeipmi-tools" def install(self) -> None: - apt_helpers.add_pkg_with_candidate_version(self.pkg) + apt_helpers.add_pkg_with_candidate_version(self.freeipmi_pkg) def remove(self) -> None: # Skip removing because this may cause dependency error # for other services on the same machine. - logger.info("%s skip removing %s", self._name, self.pkg) + logger.info("%s skip removing %s", self._name, self.freeipmi_pkg) def check(self) -> bool: """Check package status.""" - return check_deb_pkg_installed(self.pkg) + return check_deb_pkg_installed(self.freeipmi_pkg) class IPMISENSORStrategy(IPMIStrategy): @@ -345,10 +345,34 @@ class IPMISENSORStrategy(IPMIStrategy): class IPMISELStrategy(IPMIStrategy): - """Strategy for installing ipmi.""" + """Strategy for installing ipmi. + + The ipmiseld daemon polls the system event log (SEL) + of specified hosts and stores the logs into the local syslog. + + Grafana agent will then forward the logs to Loki. + """ _name = HWTool.IPMI_SEL + ipmiseld_pkg = "freeipmi-ipmiseld" + + def install(self) -> None: + super().install() + apt_helpers.add_pkg_with_candidate_version(self.ipmiseld_pkg) + + def remove(self) -> None: + # Skip removing because this may cause dependency error + # for other services on the same machine. + super().remove() + logger.info("%s skip removing %s", self._name, self.ipmiseld_pkg) + + def check(self) -> bool: + """Check package status.""" + parent_pkg_installed = super().check() + child_pkg_installed = check_deb_pkg_installed(self.ipmiseld_pkg) + return parent_pkg_installed and child_pkg_installed + class IPMIDCMIStrategy(IPMIStrategy): """Strategy for installing ipmi.""" diff --git a/tests/functional/test_charm.py b/tests/functional/test_charm.py index 3a87ac3c..15a8bae5 100644 --- a/tests/functional/test_charm.py +++ b/tests/functional/test_charm.py @@ -402,6 +402,13 @@ async def test_ipmi_sel_metrics(self, ops_test, unit, provided_collectors): if not assert_metrics(metrics.get("ipmi_sel"), expected_metric_values): pytest.fail("Expected metrics not present!") + check_active_cmd = "systemctl is-active ipmiseld" + logging.info("Check whether ipmiseld service is active.") + for unit in ops_test.model.applications[APP_NAME].units: + results = await run_command_on_unit(ops_test, unit.name, check_active_cmd) + assert results.get("return-code") == 0 + assert results.get("stdout").strip() == "active" + @pytest.mark.parametrize("version", ["1", "2"]) async def test_lsi_sas_metrics(self, ops_test, unit, provided_collectors, version): """Tests for lsi_sas_{1,2} specific metrics.""" diff --git a/tests/unit/test_hw_tools.py b/tests/unit/test_hw_tools.py index ac451c96..96a86dd5 100644 --- a/tests/unit/test_hw_tools.py +++ b/tests/unit/test_hw_tools.py @@ -702,9 +702,12 @@ def test_install(self, mock_apt, mock_candidate_version): mock_candidate_version.return_value = "some-candidate-version" strategy.install() - mock_apt.add_package.assert_called_with( + mock_apt.add_package.assert_any_call( "freeipmi-tools", version="some-candidate-version", update_cache=False ) + mock_apt.add_package.assert_any_call( + "freeipmi-ipmiseld", version="some-candidate-version", update_cache=False + ) @mock.patch("hw_tools.apt") def test_remove(self, mock_apt):