Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Split IPMIStrategy to sensor, sel, and dcmi strategies #167

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions src/hw_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,6 @@ def check(self) -> bool:
class IPMIStrategy(APTStrategyABC):
"""Strategy for installing ipmi."""

# Because IPMISTrategy now encompasses all of
# HWTool.IPMI_SENSOR, HWTool.IPMI_SEL and HWTool.IPMI_DCMI,
# we will need some refactoring here to avoid misleading log
# messages. The installation should be good since all of these
# tools require the same `freeipmi-tools` to be installed.
_name = HWTool.IPMI_SENSOR
pkg = "freeipmi-tools"

def install(self) -> None:
Expand All @@ -322,13 +316,31 @@ def install(self) -> None:
def remove(self) -> None:
# Skip removing because we afriad this cause dependency error
# for other services on the same machine.
logger.info("IPMIStrategy skip removing %s", self.pkg)
logger.info("%s skip removing %s", self._name, self.pkg)

def check(self) -> bool:
"""Check package status."""
return check_deb_pkg_installed(self.pkg)


class IPMISENSORStrategy(IPMIStrategy):
"""Strategy for installing ipmi."""

_name = HWTool.IPMI_SENSOR


class IPMISELStrategy(IPMIStrategy):
"""Strategy for installing ipmi."""

_name = HWTool.IPMI_SEL


class IPMIDCMIStrategy(IPMIStrategy):
"""Strategy for installing ipmi."""

_name = HWTool.IPMI_DCMI


class RedFishStrategy(StrategyABC): # pylint: disable=R0903
"""Install strategy for redfish.

Expand Down Expand Up @@ -490,7 +502,9 @@ def strategies(self) -> List[StrategyABC]:
SAS2IRCUStrategy(),
SAS3IRCUStrategy(),
SSACLIStrategy(),
IPMIStrategy(),
IPMISELStrategy(),
IPMIDCMIStrategy(),
IPMISENSORStrategy(),
RedFishStrategy(),
]

Expand Down
50 changes: 46 additions & 4 deletions tests/unit/test_hw_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
APTStrategyABC,
HWToolHelper,
InvalidCredentialsError,
IPMIStrategy,
IPMIDCMIStrategy,
IPMISELStrategy,
IPMISENSORStrategy,
PercCLIStrategy,
ResourceChecksumError,
ResourceFileSizeZeroError,
Expand Down Expand Up @@ -673,11 +675,11 @@ def test_remove(self, mock_apt):
mock_repos.disable.assert_not_called()


class TestIPMIStrategy(unittest.TestCase):
class TestIPMISENSORStrategy(unittest.TestCase):
@mock.patch("apt_helpers.get_candidate_version")
@mock.patch("apt_helpers.apt")
def test_install(self, mock_apt, mock_candidate_version):
strategy = IPMIStrategy()
strategy = IPMISENSORStrategy()
mock_candidate_version.return_value = "some-candidate-version"
strategy.install()

Expand All @@ -687,7 +689,47 @@ def test_install(self, mock_apt, mock_candidate_version):

@mock.patch("hw_tools.apt")
def test_remove(self, mock_apt):
strategy = IPMIStrategy()
strategy = IPMISENSORStrategy()
strategy.remove()

mock_apt.remove_package.assert_not_called()


class TestIPMISELStrategy(unittest.TestCase):
@mock.patch("apt_helpers.get_candidate_version")
@mock.patch("apt_helpers.apt")
def test_install(self, mock_apt, mock_candidate_version):
strategy = IPMISELStrategy()
mock_candidate_version.return_value = "some-candidate-version"
strategy.install()

mock_apt.add_package.assert_called_with(
"freeipmi-tools", version="some-candidate-version", update_cache=False
)

@mock.patch("hw_tools.apt")
def test_remove(self, mock_apt):
strategy = IPMISELStrategy()
strategy.remove()

mock_apt.remove_package.assert_not_called()


class TestIPMIDCMIStrategy(unittest.TestCase):
@mock.patch("apt_helpers.get_candidate_version")
@mock.patch("apt_helpers.apt")
def test_install(self, mock_apt, mock_candidate_version):
strategy = IPMIDCMIStrategy()
mock_candidate_version.return_value = "some-candidate-version"
strategy.install()

mock_apt.add_package.assert_called_with(
"freeipmi-tools", version="some-candidate-version", update_cache=False
)

@mock.patch("hw_tools.apt")
def test_remove(self, mock_apt):
strategy = IPMIDCMIStrategy()
strategy.remove()

mock_apt.remove_package.assert_not_called()
Expand Down
Loading