Skip to content

Commit

Permalink
fix name
Browse files Browse the repository at this point in the history
  • Loading branch information
chanchiwai-ray committed Sep 26, 2024
1 parent 64b82b6 commit 9836a1f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
9 changes: 2 additions & 7 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@
from ops.framework import EventBase, StoredState
from ops.model import ActiveStatus, BlockedStatus, MaintenanceStatus

from hw_tools import (
HWTool,
HWToolHelper,
detect_available_tools,
remove_legacy_smartctl_exporter_deb,
)
from hw_tools import HWTool, HWToolHelper, detect_available_tools, remove_legacy_smartctl_exporter
from service import BaseExporter, DCGMExporter, ExporterError, HardwareExporter, SmartCtlExporter

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -135,7 +130,7 @@ def _on_install_or_upgrade(self, event: EventBase) -> None:
"""Install or upgrade charm."""
self.model.unit.status = MaintenanceStatus("Installing resources...")

remove_legacy_smartctl_exporter_deb(self._stored.stored_tools) # type: ignore[arg-type]
remove_legacy_smartctl_exporter(self._stored.stored_tools) # type: ignore[arg-type]

stored_tools = self.get_stored_tools()

Expand Down
8 changes: 4 additions & 4 deletions src/hw_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,13 +595,13 @@ def detect_available_tools() -> Set[HWTool]:
return raid_hw_verifier() | bmc_hw_verifier() | disk_hw_verifier() | nvidia_gpu_verifier()


def remove_legacy_smartctl_exporter_deb(stored_tools: set) -> None:
def remove_legacy_smartctl_exporter(stored_tools: set) -> None:
"""Remove any legacy tool from older revision.
Workaround for migrating smartctl exporter deb package to snap package.
Workaround for migrating legacy smartctl exporter to snap package.
"""
name = "smartctl-exporter"
smartctl_exporter_deb = Path("opt/SmartCtlExporter/")
smartctl_exporter = Path("opt/SmartCtlExporter/")
smartctl_exporter_config_path = Path(f"/etc/{name}-config.yaml")
smartctl_exporter_service_path = Path(f"/etc/systemd/system/{name}.service")
if smartctl_exporter_service_path.exists():
Expand All @@ -610,7 +610,7 @@ def remove_legacy_smartctl_exporter_deb(stored_tools: set) -> None:
smartctl_exporter_service_path.unlink()
if smartctl_exporter_config_path.exists():
smartctl_exporter_config_path.unlink()
if smartctl_exporter_deb.exists():
if smartctl_exporter.exists():
shutil.rmtree("/opt/SmartCtlExporter/")
if "smartctl" in stored_tools:
stored_tools.remove("smartctl")
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_hw_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
raid_hw_verifier,
redfish_available,
remove_deb,
remove_legacy_smartctl_exporter_deb,
remove_legacy_smartctl_exporter,
symlink,
)
from keys import HP_KEYS
Expand Down Expand Up @@ -1148,12 +1148,12 @@ def test_snap_strategy_check(snap_exporter, mock_snap_lib, services, expected):
@mock.patch("hw_tools.Path.exists")
@mock.patch("hw_tools.shutil")
@mock.patch("hw_tools.systemd")
def test_remove_legacy_smartctl_exporter_deb(
def test_remove_legacy_smartctl_exporter(
mock_systemd, mock_shutil, mock_path_exists, mock_path_unlink, legacy_exists
):
stored_tools = {"smartctl"} if legacy_exists else {}
mock_path_exists.return_value = legacy_exists
remove_legacy_smartctl_exporter_deb(stored_tools)
remove_legacy_smartctl_exporter(stored_tools)
if legacy_exists:
mock_systemd.service_stop.assert_called_once()
mock_systemd.service_disable.assert_called_once()
Expand Down

0 comments on commit 9836a1f

Please sign in to comment.