Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jul 3, 2024
1 parent a650846 commit f9b2ea2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
11 changes: 6 additions & 5 deletions anta/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
import httpcore
from aiocache import Cache
from aiocache.plugins import HitMissRatioPlugin
from asynceapi import Device, EapiCommandError
from asyncssh import SSHClientConnection, SSHClientConnectionOptions
from httpx import ConnectError, HTTPError, Limits, TimeoutException

from anta import __DEBUG__
from anta.logger import anta_log_exception, exc_to_str
from anta.models import AntaCommand
from asynceapi import Device, EapiCommandError

if TYPE_CHECKING:
from collections.abc import Iterator
Expand Down Expand Up @@ -332,7 +332,7 @@ async def _handle_eapi_command_error(self, exception: EapiCommandError, anta_com
logger.error("Command '%s' is not supported on %s (%s).", anta_command.command, self.name, self.hw_model)

# Collect the commands that were not executed
await self._collect(anta_commands=anta_commands[err_at + 1:], req_format=req_format, req_id=req_id)
await self._collect(anta_commands=anta_commands[err_at + 1 :], req_format=req_format, req_id=req_id)

def _handle_timeout_exception(self, exception: TimeoutException, anta_commands: list[AntaCommand]) -> None:
"""Handle TimeoutException exceptions."""
Expand All @@ -357,7 +357,9 @@ def _handle_connect_os_error(self, exception: ConnectError | OSError, anta_comma
for anta_command in anta_commands:
anta_command.errors = [exc_to_str(exception)]

if (isinstance(exc := exception.__cause__, httpcore.ConnectError) and isinstance(os_error := exc.__context__, OSError)) or isinstance(os_error := exception, OSError):
if (isinstance(exc := exception.__cause__, httpcore.ConnectError) and isinstance(os_error := exc.__context__, OSError)) or isinstance(
os_error := exception, OSError
):
if isinstance(os_error.__cause__, OSError):
os_error = os_error.__cause__
logger.error("A local OS error occurred while connecting to %s: %s.", self.name, os_error)
Expand Down Expand Up @@ -385,8 +387,7 @@ async def _collect(self, anta_commands: list[AntaCommand], *, req_format: Litera
collection_id: An identifier used to build the eAPI request ID.
"""
commands = [
{"cmd": anta_command.command, "revision": anta_command.revision}
if anta_command.revision else {"cmd": anta_command.command}
{"cmd": anta_command.command, "revision": anta_command.revision} if anta_command.revision else {"cmd": anta_command.command}
for anta_command in anta_commands
]

Expand Down
3 changes: 3 additions & 0 deletions anta/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def render(self, **params: str | int | bool) -> AntaCommand:
use_cache=self.use_cache,
)


class CommandWeight(Enum):
"""Enum to define the weight of a command.
Expand All @@ -138,6 +139,7 @@ class CommandWeight(Enum):
MEDIUM = "medium"
HEAVY = "heavy"


class AntaCommand(BaseModel):
"""Class to define a command.
Expand Down Expand Up @@ -660,6 +662,7 @@ def test(self) -> None:
"""


class AntaTestManager:
"""TODO: Add docstring.
Expand Down
1 change: 1 addition & 0 deletions anta/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def prepare_tests(

return device_to_tests


async def run_device_tests(device: AntaDevice, test_definitions: set[AntaTestDefinition], batch_size: int) -> list[TestResult]:
"""Run tests for a specific device using the AntaTestManager."""
manager = AntaTestManager(device=device, batch_size=batch_size)
Expand Down

0 comments on commit f9b2ea2

Please sign in to comment.