Skip to content

Commit

Permalink
boot_controllers: do not directly import errors from app.errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodong-Yang committed Nov 2, 2023
1 parent 581241e commit ff4ae0f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 41 deletions.
30 changes: 15 additions & 15 deletions otaclient/app/boot_control/_cboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from typing import Generator, Optional


from .. import log_setting
from .. import log_setting, errors as ota_errors
from ..common import (
copytree_identical,
read_str_from_file,
Expand All @@ -30,14 +30,6 @@
write_str_to_file_sync,
)

from ..errors import (
BootControlStartupFailed,
BootControlPlatformUnsupported,
BootControlPostRollbackFailed,
BootControlPostUpdateFailed,
BootControlPreRollbackFailed,
BootControlPreUpdateFailed,
)
from ..proto import wrapper

from ._common import (
Expand Down Expand Up @@ -339,9 +331,9 @@ def __init__(self) -> None:
# init ota-status
self._init_boot_control()
except NotImplementedError as e:
raise BootControlPlatformUnsupported(module=__name__) from e
raise ota_errors.BootControlPlatformUnsupported(module=__name__) from e
except Exception as e:
raise BootControlStartupFailed(
raise ota_errors.BootControlStartupFailed(
f"unspecific boot controller startup failure: {e!r}", module=__name__
) from e

Expand Down Expand Up @@ -514,7 +506,9 @@ def pre_update(self, version: str, *, standby_as_ref: bool, erase_standby=False)
except Exception as e:
_err_msg = f"failed on pre_update: {e!r}"
logger.exception(_err_msg)
raise BootControlPreUpdateFailed(f"{e!r}", module=__name__) from e
raise ota_errors.BootControlPreUpdateFailed(
f"{e!r}", module=__name__
) from e

def post_update(self) -> Generator[None, None, None]:
try:
Expand Down Expand Up @@ -554,7 +548,9 @@ def post_update(self) -> Generator[None, None, None]:
except Exception as e:
_err_msg = f"failed on post_update: {e!r}"
logger.exception(_err_msg)
raise BootControlPostUpdateFailed(_err_msg, module=__name__) from e
raise ota_errors.BootControlPostUpdateFailed(
_err_msg, module=__name__
) from e

def pre_rollback(self):
try:
Expand All @@ -568,7 +564,9 @@ def pre_rollback(self):
except Exception as e:
_err_msg = f"failed on pre_rollback: {e!r}"
logger.exception(_err_msg)
raise BootControlPreRollbackFailed(_err_msg, module=__name__) from e
raise ota_errors.BootControlPreRollbackFailed(
_err_msg, module=__name__
) from e

def post_rollback(self):
try:
Expand All @@ -577,4 +575,6 @@ def post_rollback(self):
except Exception as e:
_err_msg = f"failed on post_rollback: {e!r}"
logger.exception(_err_msg)
raise BootControlPostRollbackFailed(_err_msg, module=__name__) from e
raise ota_errors.BootControlPostRollbackFailed(
_err_msg, module=__name__
) from e
27 changes: 14 additions & 13 deletions otaclient/app/boot_control/_grub.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,14 @@
from pathlib import Path
from pprint import pformat

from .. import log_setting
from .. import log_setting, errors as ota_errors
from ..common import (
re_symlink_atomic,
read_str_from_file,
subprocess_call,
subprocess_check_output,
write_str_to_file_sync,
)
from ..errors import (
BootControlStartupFailed,
BootControlPostRollbackFailed,
BootControlPostUpdateFailed,
BootControlPreRollbackFailed,
BootControlPreUpdateFailed,
)
from ..proto import wrapper

from ._common import (
Expand Down Expand Up @@ -772,7 +765,7 @@ def __init__(self) -> None:
except Exception as e:
_err_msg = f"failed on start grub boot controller: {e!r}"
logger.error(_err_msg)
raise BootControlStartupFailed(_err_msg, module=__name__) from e
raise ota_errors.BootControlStartupFailed(_err_msg, module=__name__) from e

def _update_fstab(self, *, active_slot_fstab: Path, standby_slot_fstab: Path):
"""Update standby fstab based on active slot's fstab and just installed new stanby fstab.
Expand Down Expand Up @@ -891,7 +884,9 @@ def pre_update(self, version: str, *, standby_as_ref: bool, erase_standby=False)
except Exception as e:
_err_msg = f"failed on pre_update: {e!r}"
logger.error(_err_msg)
raise BootControlPreUpdateFailed(_err_msg, module=__name__) from e
raise ota_errors.BootControlPreUpdateFailed(
_err_msg, module=__name__
) from e

def post_update(self) -> Generator[None, None, None]:
try:
Expand Down Expand Up @@ -920,7 +915,9 @@ def post_update(self) -> Generator[None, None, None]:
except Exception as e:
_err_msg = f"failed on post_update: {e!r}"
logger.error(_err_msg)
raise BootControlPostUpdateFailed(_err_msg, module=__name__) from e
raise ota_errors.BootControlPostUpdateFailed(
_err_msg, module=__name__
) from e

def pre_rollback(self):
try:
Expand All @@ -931,7 +928,9 @@ def pre_rollback(self):
except Exception as e:
_err_msg = f"failed on pre_rollback: {e!r}"
logger.error(_err_msg)
raise BootControlPreRollbackFailed(_err_msg, module=__name__) from e
raise ota_errors.BootControlPreRollbackFailed(
_err_msg, module=__name__
) from e

def post_rollback(self):
try:
Expand All @@ -942,4 +941,6 @@ def post_rollback(self):
except Exception as e:
_err_msg = f"failed on pre_rollback: {e!r}"
logger.error(_err_msg)
raise BootControlPostRollbackFailed(_err_msg, module=__name__) from e
raise ota_errors.BootControlPostRollbackFailed(
_err_msg, module=__name__
) from e
27 changes: 14 additions & 13 deletions otaclient/app/boot_control/_rpi_boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,7 @@
from pathlib import Path
from typing import Generator

from .. import log_setting
from ..errors import (
BootControlStartupFailed,
BootControlPostRollbackFailed,
BootControlPostUpdateFailed,
BootControlPreRollbackFailed,
BootControlPreUpdateFailed,
)
from .. import log_setting, errors as ota_errors
from ..proto import wrapper
from ..common import replace_atomic, subprocess_call

Expand Down Expand Up @@ -419,7 +412,7 @@ def __init__(self) -> None:
except Exception as e:
_err_msg = f"failed to start rpi boot controller: {e!r}"
logger.error(_err_msg)
raise BootControlStartupFailed(_err_msg, module=__name__) from e
raise ota_errors.BootControlStartupFailed(_err_msg, module=__name__) from e

def _copy_kernel_for_standby_slot(self):
"""Copy the kernel and initrd_img files from current slot /boot
Expand Down Expand Up @@ -519,7 +512,9 @@ def pre_update(self, version: str, *, standby_as_ref: bool, erase_standby: bool)
except Exception as e:
_err_msg = f"failed on pre_update: {e!r}"
logger.error(_err_msg)
raise BootControlPreUpdateFailed(_err_msg, module=__name__) from e
raise ota_errors.BootControlPreUpdateFailed(
_err_msg, module=__name__
) from e

def pre_rollback(self):
try:
Expand All @@ -530,7 +525,9 @@ def pre_rollback(self):
except Exception as e:
_err_msg = f"failed on pre_rollback: {e!r}"
logger.error(_err_msg)
raise BootControlPreRollbackFailed(_err_msg, module=__name__) from e
raise ota_errors.BootControlPreRollbackFailed(
_err_msg, module=__name__
) from e

def post_rollback(self):
try:
Expand All @@ -541,7 +538,9 @@ def post_rollback(self):
except Exception as e:
_err_msg = f"failed on post_rollback: {e!r}"
logger.error(_err_msg)
raise BootControlPostRollbackFailed(_err_msg, module=__name__) from e
raise ota_errors.BootControlPostRollbackFailed(
_err_msg, module=__name__
) from e

def post_update(self) -> Generator[None, None, None]:
try:
Expand All @@ -556,7 +555,9 @@ def post_update(self) -> Generator[None, None, None]:
except Exception as e:
_err_msg = f"failed on post_update: {e!r}"
logger.error(_err_msg)
raise BootControlPostUpdateFailed(_err_msg, module=__name__) from e
raise ota_errors.BootControlPostUpdateFailed(
_err_msg, module=__name__
) from e

def on_operation_failure(self):
"""Failure registering and cleanup at failure."""
Expand Down

0 comments on commit ff4ae0f

Please sign in to comment.