diff options
-rw-r--r-- | kvmd/aiohelpers.py (renamed from kvmd/plugins/msd/otg/helpers.py) | 36 | ||||
-rw-r--r-- | kvmd/plugins/msd/otg/__init__.py | 5 |
2 files changed, 19 insertions, 22 deletions
diff --git a/kvmd/plugins/msd/otg/helpers.py b/kvmd/aiohelpers.py index 2d64bd0c..6357764c 100644 --- a/kvmd/plugins/msd/otg/helpers.py +++ b/kvmd/aiohelpers.py @@ -20,35 +20,31 @@ # ========================================================================== # -from typing import List +import subprocess -from ....logging import get_logger +from typing import List -from .... import aioproc +from .logging import get_logger -from .. import MsdError +from . import tools +from . import aioproc # ===== -async def remount_storage(base_cmd: List[str], rw: bool) -> None: - logger = get_logger(0) +async def remount(name: str, base_cmd: List[str], rw: bool) -> bool: + logger = get_logger(1) mode = ("rw" if rw else "ro") cmd = [ part.format(mode=mode) for part in base_cmd ] - logger.info("Remounting internal storage to %s ...", mode.upper()) + logger.info("Remounting %s storage to %s: %s ...", name, mode.upper(), cmd) try: - await _run_helper(cmd) - except Exception: - logger.error("Can't remount internal storage") - raise - - -# ===== -async def _run_helper(cmd: List[str]) -> None: - logger = get_logger(0) - logger.info("Executing helper %s ...", cmd) - proc = await aioproc.log_process(cmd, logger) - if proc.returncode != 0: - raise MsdError(f"Error while helper execution: pid={proc.pid}; retcode={proc.returncode}") + proc = await aioproc.log_process(cmd, logger) + if proc.returncode != 0: + assert proc.returncode is not None + raise subprocess.CalledProcessError(proc.returncode, cmd) + except Exception as err: + logger.error("Can't remount %s storage: %s", name, tools.efmt(err)) + return False + return True diff --git a/kvmd/plugins/msd/otg/__init__.py b/kvmd/plugins/msd/otg/__init__.py index dcf70557..0b81391d 100644 --- a/kvmd/plugins/msd/otg/__init__.py +++ b/kvmd/plugins/msd/otg/__init__.py @@ -46,6 +46,7 @@ from ....validators.os import valid_printable_filename from ....validators.os import valid_command from .... import aiotools +from .... import aiohelpers from .. import MsdError from .. import MsdIsBusyError @@ -59,7 +60,6 @@ from .. import BaseMsd from .. import MsdImageWriter from . import fs -from . import helpers from .drive import Drive @@ -538,4 +538,5 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes # ===== async def __remount_storage(self, rw: bool) -> None: - await helpers.remount_storage(self.__remount_cmd, rw) + if not (await aiohelpers.remount("MSD", self.__remount_cmd, rw)): + raise MsdError("Can't execute remount helper") |