diff options
author | Devaev Maxim <[email protected]> | 2019-09-12 02:13:52 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2019-09-12 02:13:52 +0300 |
commit | 6ce9f4c7a970a01f9feca77eb6156d6fadb91202 (patch) | |
tree | 5c7b4b53979138128cc0d7e0b36e95ef0c3dbf47 | |
parent | 8214a20d4af3fdb59bb35bd8f83d3d9977de8f35 (diff) |
separate region exceptions
-rw-r--r-- | kvmd/aioregion.py | 7 | ||||
-rw-r--r-- | kvmd/apps/kvmd/server.py | 6 | ||||
-rw-r--r-- | kvmd/plugins/atx/__init__.py | 7 | ||||
-rw-r--r-- | kvmd/plugins/msd/__init__.py | 7 | ||||
-rw-r--r-- | testenv/tests/test_aioregion.py | 6 |
5 files changed, 15 insertions, 18 deletions
diff --git a/kvmd/aioregion.py b/kvmd/aioregion.py index 0b57e801..4d5e16bc 100644 --- a/kvmd/aioregion.py +++ b/kvmd/aioregion.py @@ -26,13 +26,8 @@ from typing import Type # ===== -class RegionIsBusyError(Exception): - def __init__(self) -> None: - super().__init__("Performing another operation, please try again later") - - class AioExclusiveRegion: - def __init__(self, exc_type: Type[RegionIsBusyError]) -> None: + def __init__(self, exc_type: Type[Exception]) -> None: self.__exc_type = exc_type self.__busy = False diff --git a/kvmd/apps/kvmd/server.py b/kvmd/apps/kvmd/server.py index a0c14224..2f4b5aa7 100644 --- a/kvmd/apps/kvmd/server.py +++ b/kvmd/apps/kvmd/server.py @@ -42,14 +42,14 @@ import setproctitle from ...logging import get_logger -from ...aioregion import RegionIsBusyError - from ...plugins.hid import BaseHid from ...plugins.atx import AtxOperationError +from ...plugins.atx import AtxIsBusyError from ...plugins.atx import BaseAtx from ...plugins.msd import MsdOperationError +from ...plugins.msd import MsdIsBusyError from ...plugins.msd import BaseMsd from ...validators import ValidatorError @@ -187,7 +187,7 @@ def _exposed(http_method: str, path: str, auth_required: bool=True) -> Callable: return (await handler(self, request)) - except RegionIsBusyError as err: + except (AtxIsBusyError, MsdIsBusyError) as err: return _json_exception(err, 409) except (ValidatorError, AtxOperationError, MsdOperationError) as err: return _json_exception(err, 400) diff --git a/kvmd/plugins/atx/__init__.py b/kvmd/plugins/atx/__init__.py index da08afd5..902e3e7c 100644 --- a/kvmd/plugins/atx/__init__.py +++ b/kvmd/plugins/atx/__init__.py @@ -24,8 +24,6 @@ from typing import Dict from typing import AsyncGenerator from typing import Type -from ... import aioregion - from .. import BasePlugin from .. import get_plugin_class @@ -39,8 +37,9 @@ class AtxOperationError(AtxError): pass -class AtxIsBusyError(AtxOperationError, aioregion.RegionIsBusyError): - pass +class AtxIsBusyError(AtxOperationError): + def __init__(self) -> None: + super().__init__("Performing another ATX operation, please try again later") # ===== diff --git a/kvmd/plugins/msd/__init__.py b/kvmd/plugins/msd/__init__.py index 2c46a663..fa31e00b 100644 --- a/kvmd/plugins/msd/__init__.py +++ b/kvmd/plugins/msd/__init__.py @@ -26,8 +26,6 @@ from typing import Dict from typing import Type from typing import AsyncGenerator -from ... import aioregion - from .. import BasePlugin from .. import get_plugin_class @@ -61,8 +59,9 @@ class MsdNotOnKvmError(MsdOperationError): super().__init__("MSD is not connected to KVM") -class MsdIsBusyError(MsdOperationError, aioregion.RegionIsBusyError): - pass +class MsdIsBusyError(MsdOperationError): + def __init__(self) -> None: + super().__init__("Performing another MSD operation, please try again later") # ===== diff --git a/testenv/tests/test_aioregion.py b/testenv/tests/test_aioregion.py index 601f5280..4448bc54 100644 --- a/testenv/tests/test_aioregion.py +++ b/testenv/tests/test_aioregion.py @@ -24,11 +24,15 @@ import asyncio import pytest -from kvmd.aioregion import RegionIsBusyError from kvmd.aioregion import AioExclusiveRegion # ===== +class RegionIsBusyError(Exception): + pass + + +# ===== @pytest.mark.asyncio async def test_ok__access_one() -> None: region = AioExclusiveRegion(RegionIsBusyError) |