Skip to content

Commit

Permalink
Add ipmiseld intergration (canonical#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
zxhdaze authored Jun 7, 2024
1 parent 911814c commit 19c4dfe
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
34 changes: 29 additions & 5 deletions src/hw_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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."""
Expand Down
7 changes: 7 additions & 0 deletions tests/functional/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/test_hw_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 19c4dfe

Please sign in to comment.