mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 01:00:29 +08:00
separate region exceptions
This commit is contained in:
parent
8214a20d4a
commit
6ce9f4c7a9
@ -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:
|
class AioExclusiveRegion:
|
||||||
def __init__(self, exc_type: Type[RegionIsBusyError]) -> None:
|
def __init__(self, exc_type: Type[Exception]) -> None:
|
||||||
self.__exc_type = exc_type
|
self.__exc_type = exc_type
|
||||||
self.__busy = False
|
self.__busy = False
|
||||||
|
|
||||||
|
|||||||
@ -42,14 +42,14 @@ import setproctitle
|
|||||||
|
|
||||||
from ...logging import get_logger
|
from ...logging import get_logger
|
||||||
|
|
||||||
from ...aioregion import RegionIsBusyError
|
|
||||||
|
|
||||||
from ...plugins.hid import BaseHid
|
from ...plugins.hid import BaseHid
|
||||||
|
|
||||||
from ...plugins.atx import AtxOperationError
|
from ...plugins.atx import AtxOperationError
|
||||||
|
from ...plugins.atx import AtxIsBusyError
|
||||||
from ...plugins.atx import BaseAtx
|
from ...plugins.atx import BaseAtx
|
||||||
|
|
||||||
from ...plugins.msd import MsdOperationError
|
from ...plugins.msd import MsdOperationError
|
||||||
|
from ...plugins.msd import MsdIsBusyError
|
||||||
from ...plugins.msd import BaseMsd
|
from ...plugins.msd import BaseMsd
|
||||||
|
|
||||||
from ...validators import ValidatorError
|
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))
|
return (await handler(self, request))
|
||||||
|
|
||||||
except RegionIsBusyError as err:
|
except (AtxIsBusyError, MsdIsBusyError) as err:
|
||||||
return _json_exception(err, 409)
|
return _json_exception(err, 409)
|
||||||
except (ValidatorError, AtxOperationError, MsdOperationError) as err:
|
except (ValidatorError, AtxOperationError, MsdOperationError) as err:
|
||||||
return _json_exception(err, 400)
|
return _json_exception(err, 400)
|
||||||
|
|||||||
@ -24,8 +24,6 @@ from typing import Dict
|
|||||||
from typing import AsyncGenerator
|
from typing import AsyncGenerator
|
||||||
from typing import Type
|
from typing import Type
|
||||||
|
|
||||||
from ... import aioregion
|
|
||||||
|
|
||||||
from .. import BasePlugin
|
from .. import BasePlugin
|
||||||
from .. import get_plugin_class
|
from .. import get_plugin_class
|
||||||
|
|
||||||
@ -39,8 +37,9 @@ class AtxOperationError(AtxError):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class AtxIsBusyError(AtxOperationError, aioregion.RegionIsBusyError):
|
class AtxIsBusyError(AtxOperationError):
|
||||||
pass
|
def __init__(self) -> None:
|
||||||
|
super().__init__("Performing another ATX operation, please try again later")
|
||||||
|
|
||||||
|
|
||||||
# =====
|
# =====
|
||||||
|
|||||||
@ -26,8 +26,6 @@ from typing import Dict
|
|||||||
from typing import Type
|
from typing import Type
|
||||||
from typing import AsyncGenerator
|
from typing import AsyncGenerator
|
||||||
|
|
||||||
from ... import aioregion
|
|
||||||
|
|
||||||
from .. import BasePlugin
|
from .. import BasePlugin
|
||||||
from .. import get_plugin_class
|
from .. import get_plugin_class
|
||||||
|
|
||||||
@ -61,8 +59,9 @@ class MsdNotOnKvmError(MsdOperationError):
|
|||||||
super().__init__("MSD is not connected to KVM")
|
super().__init__("MSD is not connected to KVM")
|
||||||
|
|
||||||
|
|
||||||
class MsdIsBusyError(MsdOperationError, aioregion.RegionIsBusyError):
|
class MsdIsBusyError(MsdOperationError):
|
||||||
pass
|
def __init__(self) -> None:
|
||||||
|
super().__init__("Performing another MSD operation, please try again later")
|
||||||
|
|
||||||
|
|
||||||
# =====
|
# =====
|
||||||
|
|||||||
@ -24,10 +24,14 @@ import asyncio
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from kvmd.aioregion import RegionIsBusyError
|
|
||||||
from kvmd.aioregion import AioExclusiveRegion
|
from kvmd.aioregion import AioExclusiveRegion
|
||||||
|
|
||||||
|
|
||||||
|
# =====
|
||||||
|
class RegionIsBusyError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
# =====
|
# =====
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_ok__access_one() -> None:
|
async def test_ok__access_one() -> None:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user