1
mirror of https://github.com/home-assistant/supervisor synced 2024-10-02 06:19:58 +02:00

Add jobs decorator to add-ons/snapshot/core and remove 404 hack (#2280)

* Add jobs decorator to add-ons/snapshot/core and remove 404 hack

* add to repair
This commit is contained in:
Pascal Vizeli 2020-11-21 10:47:15 +01:00 committed by GitHub
parent 01e27dfa2f
commit 1427e0ae96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 8 deletions

View File

@ -18,6 +18,7 @@ from ..exceptions import (
HomeAssistantAPIError, HomeAssistantAPIError,
HostAppArmorError, HostAppArmorError,
) )
from ..jobs.decorator import Job, JobCondition
from ..resolution.const import ContextType, IssueType, SuggestionType from ..resolution.const import ContextType, IssueType, SuggestionType
from ..store.addon import AddonStore from ..store.addon import AddonStore
from ..utils import check_exception_chain from ..utils import check_exception_chain
@ -141,6 +142,13 @@ class AddonManager(CoreSysAttributes):
_LOGGER.warning("Can't stop Add-on %s: %s", addon.slug, err) _LOGGER.warning("Can't stop Add-on %s: %s", addon.slug, err)
self.sys_capture_exception(err) self.sys_capture_exception(err)
@Job(
conditions=[
JobCondition.FREE_SPACE,
JobCondition.INTERNET_HOST,
JobCondition.HEALTHY,
]
)
async def install(self, slug: str) -> None: async def install(self, slug: str) -> None:
"""Install an add-on.""" """Install an add-on."""
if slug in self.local: if slug in self.local:
@ -235,6 +243,13 @@ class AddonManager(CoreSysAttributes):
_LOGGER.info("Add-on '%s' successfully removed", slug) _LOGGER.info("Add-on '%s' successfully removed", slug)
@Job(
conditions=[
JobCondition.FREE_SPACE,
JobCondition.INTERNET_HOST,
JobCondition.HEALTHY,
]
)
async def update(self, slug: str) -> None: async def update(self, slug: str) -> None:
"""Update add-on.""" """Update add-on."""
if slug not in self.local: if slug not in self.local:
@ -277,6 +292,13 @@ class AddonManager(CoreSysAttributes):
if last_state == AddonState.STARTED: if last_state == AddonState.STARTED:
await addon.start() await addon.start()
@Job(
conditions=[
JobCondition.FREE_SPACE,
JobCondition.INTERNET_HOST,
JobCondition.HEALTHY,
]
)
async def rebuild(self, slug: str) -> None: async def rebuild(self, slug: str) -> None:
"""Perform a rebuild of local build add-on.""" """Perform a rebuild of local build add-on."""
if slug not in self.local: if slug not in self.local:
@ -312,6 +334,13 @@ class AddonManager(CoreSysAttributes):
if last_state == AddonState.STARTED: if last_state == AddonState.STARTED:
await addon.start() await addon.start()
@Job(
conditions=[
JobCondition.FREE_SPACE,
JobCondition.INTERNET_HOST,
JobCondition.HEALTHY,
]
)
async def restore(self, slug: str, tar_file: tarfile.TarFile) -> None: async def restore(self, slug: str, tar_file: tarfile.TarFile) -> None:
"""Restore state of an add-on.""" """Restore state of an add-on."""
if slug not in self.local: if slug not in self.local:
@ -334,6 +363,7 @@ class AddonManager(CoreSysAttributes):
with suppress(HomeAssistantAPIError): with suppress(HomeAssistantAPIError):
await self.sys_ingress.update_hass_panel(addon) await self.sys_ingress.update_hass_panel(addon)
@Job(conditions=[JobCondition.FREE_SPACE, JobCondition.INTERNET_HOST])
async def repair(self) -> None: async def repair(self) -> None:
"""Repair local add-ons.""" """Repair local add-ons."""
needs_repair: List[Addon] = [] needs_repair: List[Addon] = []

View File

@ -156,14 +156,7 @@ class DockerInterface(CoreSysAttributes):
docker_image.tag(image, tag="latest") docker_image.tag(image, tag="latest")
except docker.errors.APIError as err: except docker.errors.APIError as err:
_LOGGER.error("Can't install %s:%s -> %s.", image, tag, err) _LOGGER.error("Can't install %s:%s -> %s.", image, tag, err)
if err.status_code == 404: if err.status_code == 429:
free_space = self.sys_host.info.free_space
_LOGGER.info(
"This error is often caused by not having enough disk space available. "
"Available space in /data is: %s GiB",
free_space,
)
elif err.status_code == 429:
self.sys_resolution.create_issue( self.sys_resolution.create_issue(
IssueType.DOCKER_RATELIMIT, IssueType.DOCKER_RATELIMIT,
ContextType.SYSTEM, ContextType.SYSTEM,

View File

@ -21,6 +21,7 @@ from ..exceptions import (
HomeAssistantError, HomeAssistantError,
HomeAssistantUpdateError, HomeAssistantUpdateError,
) )
from ..jobs.decorator import Job, JobCondition
from ..resolution.const import ContextType, IssueType from ..resolution.const import ContextType, IssueType
from ..utils import convert_to_ascii, process_lock from ..utils import convert_to_ascii, process_lock
@ -152,6 +153,13 @@ class HomeAssistantCore(CoreSysAttributes):
await self.instance.cleanup() await self.instance.cleanup()
@process_lock @process_lock
@Job(
conditions=[
JobCondition.FREE_SPACE,
JobCondition.HEALTHY,
JobCondition.INTERNET_HOST,
]
)
async def update(self, version: Optional[str] = None) -> None: async def update(self, version: Optional[str] = None) -> None:
"""Update HomeAssistant version.""" """Update HomeAssistant version."""
version = version or self.sys_homeassistant.latest_version version = version or self.sys_homeassistant.latest_version
@ -409,6 +417,12 @@ class HomeAssistantCore(CoreSysAttributes):
self._error_state = True self._error_state = True
raise HomeAssistantCrashError() raise HomeAssistantCrashError()
@Job(
conditions=[
JobCondition.FREE_SPACE,
JobCondition.INTERNET_HOST,
]
)
async def repair(self): async def repair(self):
"""Repair local Home Assistant data.""" """Repair local Home Assistant data."""
if await self.instance.exists(): if await self.instance.exists():

View File

@ -7,6 +7,7 @@ from typing import Set
from ..const import FOLDER_HOMEASSISTANT, SNAPSHOT_FULL, SNAPSHOT_PARTIAL, CoreState from ..const import FOLDER_HOMEASSISTANT, SNAPSHOT_FULL, SNAPSHOT_PARTIAL, CoreState
from ..coresys import CoreSysAttributes from ..coresys import CoreSysAttributes
from ..exceptions import AddonsError from ..exceptions import AddonsError
from ..jobs.decorator import Job, JobCondition
from ..utils.dt import utcnow from ..utils.dt import utcnow
from .snapshot import Snapshot from .snapshot import Snapshot
from .utils import create_slug from .utils import create_slug
@ -121,6 +122,7 @@ class SnapshotManager(CoreSysAttributes):
self.snapshots_obj[snapshot.slug] = snapshot self.snapshots_obj[snapshot.slug] = snapshot
return snapshot return snapshot
@Job(conditions=[JobCondition.FREE_SPACE, JobCondition.HEALTHY])
async def do_snapshot_full(self, name="", password=None): async def do_snapshot_full(self, name="", password=None):
"""Create a full snapshot.""" """Create a full snapshot."""
if self.lock.locked(): if self.lock.locked():
@ -156,6 +158,7 @@ class SnapshotManager(CoreSysAttributes):
self.sys_core.state = CoreState.RUNNING self.sys_core.state = CoreState.RUNNING
self.lock.release() self.lock.release()
@Job(conditions=[JobCondition.FREE_SPACE, JobCondition.HEALTHY])
async def do_snapshot_partial( async def do_snapshot_partial(
self, name="", addons=None, folders=None, password=None self, name="", addons=None, folders=None, password=None
): ):
@ -207,6 +210,14 @@ class SnapshotManager(CoreSysAttributes):
self.sys_core.state = CoreState.RUNNING self.sys_core.state = CoreState.RUNNING
self.lock.release() self.lock.release()
@Job(
conditions=[
JobCondition.FREE_SPACE,
JobCondition.HEALTHY,
JobCondition.INTERNET_HOST,
JobCondition.INTERNET_SYSTEM,
]
)
async def do_restore_full(self, snapshot, password=None): async def do_restore_full(self, snapshot, password=None):
"""Restore a snapshot.""" """Restore a snapshot."""
if self.lock.locked(): if self.lock.locked():
@ -283,6 +294,14 @@ class SnapshotManager(CoreSysAttributes):
self.sys_core.state = CoreState.RUNNING self.sys_core.state = CoreState.RUNNING
self.lock.release() self.lock.release()
@Job(
conditions=[
JobCondition.FREE_SPACE,
JobCondition.HEALTHY,
JobCondition.INTERNET_HOST,
JobCondition.INTERNET_SYSTEM,
]
)
async def do_restore_partial( async def do_restore_partial(
self, snapshot, homeassistant=False, addons=None, folders=None, password=None self, snapshot, homeassistant=False, addons=None, folders=None, password=None
): ):