-
Notifications
You must be signed in to change notification settings - Fork 653
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add uninstall addon suggestion to detached_addon_removed (#5105)
- Loading branch information
Showing
5 changed files
with
96 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"""Helpers to fix addon issue by removing it.""" | ||
import logging | ||
|
||
from ...coresys import CoreSys | ||
from ...exceptions import AddonsError, ResolutionFixupError | ||
from ..const import ContextType, IssueType, SuggestionType | ||
from .base import FixupBase | ||
|
||
_LOGGER: logging.Logger = logging.getLogger(__name__) | ||
|
||
|
||
def setup(coresys: CoreSys) -> FixupBase: | ||
"""Check setup function.""" | ||
return FixupAddonExecuteRemove(coresys) | ||
|
||
|
||
class FixupAddonExecuteRemove(FixupBase): | ||
"""Storage class for fixup.""" | ||
|
||
async def process_fixup(self, reference: str | None = None) -> None: | ||
"""Initialize the fixup class.""" | ||
if not (addon := self.sys_addons.get(reference, local_only=True)): | ||
_LOGGER.info("Addon %s already removed", reference) | ||
return | ||
|
||
# Remove addon | ||
_LOGGER.info("Remove addon: %s", reference) | ||
try: | ||
addon.uninstall() | ||
except AddonsError as err: | ||
_LOGGER.error("Could not remove %s due to %s", reference, err) | ||
raise ResolutionFixupError() from None | ||
|
||
@property | ||
def suggestion(self) -> SuggestionType: | ||
"""Return a SuggestionType enum.""" | ||
return SuggestionType.EXECUTE_REMOVE | ||
|
||
@property | ||
def context(self) -> ContextType: | ||
"""Return a ContextType enum.""" | ||
return ContextType.ADDON | ||
|
||
@property | ||
def issues(self) -> list[IssueType]: | ||
"""Return a IssueType enum list.""" | ||
return [IssueType.DETACHED_ADDON_REMOVED] | ||
|
||
@property | ||
def auto(self) -> bool: | ||
"""Return if a fixup can be apply as auto fix.""" | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""Test evaluation base.""" | ||
from unittest.mock import patch | ||
|
||
from supervisor.addons.addon import Addon | ||
from supervisor.coresys import CoreSys | ||
from supervisor.resolution.const import ContextType, IssueType, SuggestionType | ||
from supervisor.resolution.data import Issue, Suggestion | ||
from supervisor.resolution.fixups.addon_execute_remove import FixupAddonExecuteRemove | ||
|
||
|
||
async def test_fixup(coresys: CoreSys, install_addon_ssh: Addon): | ||
"""Test fixup.""" | ||
addon_execute_remove = FixupAddonExecuteRemove(coresys) | ||
|
||
assert addon_execute_remove.auto is False | ||
|
||
coresys.resolution.suggestions = Suggestion( | ||
SuggestionType.EXECUTE_REMOVE, | ||
ContextType.ADDON, | ||
reference=install_addon_ssh.slug, | ||
) | ||
coresys.resolution.issues = Issue( | ||
IssueType.DETACHED_ADDON_REMOVED, | ||
ContextType.ADDON, | ||
reference=install_addon_ssh.slug, | ||
) | ||
|
||
with patch.object(Addon, "uninstall") as uninstall: | ||
await addon_execute_remove() | ||
|
||
assert uninstall.called | ||
|
||
assert len(coresys.resolution.suggestions) == 0 | ||
assert len(coresys.resolution.issues) == 0 |