separate region exceptions

This commit is contained in:
Devaev Maxim 2019-09-12 02:13:52 +03:00
parent 8214a20d4a
commit 6ce9f4c7a9
5 changed files with 15 additions and 18 deletions

View File

@ -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

View File

@ -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)

View File

@ -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")
# =====

View File

@ -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")
# =====

View File

@ -24,10 +24,14 @@ 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: