Skip to content

Commit

Permalink
Add some basic check and troubleshooting code
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Mar 26, 2024
1 parent 90d48b8 commit 7c4d1e4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ section-order = ["future", "standard-library", "typing", "third-party", "sdss",

[tool.ruff.isort.sections]
typing = ["typing"]
sdss = ["sdsstools", "clu"]
sdss = ["sdsstools", "clu", "lvmopstools"]

[tool.pytest.ini_options]
addopts = "--cov lvmnps --cov-report xml --cov-report html --cov-report term"
Expand Down
34 changes: 29 additions & 5 deletions src/lvmnps/actor/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

from typing import TYPE_CHECKING

from lvmopstools.actor import ErrorCodes, LVMActor

from clu import Command
from lvmopstools.actor import CheckError, ErrorData, LVMActor, create_error_codes
from sdsstools.configuration import Configuration

from lvmnps import __version__
from lvmnps import log as nps_log
from lvmnps.actor.commands import lvmnps_command_parser
from lvmnps.exceptions import VerificationError
from lvmnps.nps.core import NPSClient
from lvmnps.nps.implementations import VALID_NPS_TYPES

Expand All @@ -35,6 +35,18 @@
AnyPath = str | PathLike[str]


NPSErrorCodes = create_error_codes(
{
"VERIFICATION_FAILED": ErrorData(
1,
critical=True,
description="NPS verification failed.",
)
},
name="NPSErrorCodes",
)


def get_nps_from_config(config: Configuration) -> NPSClient:
"""Returns an `.NPSClient` instance from the configuration parameters."""

Expand Down Expand Up @@ -105,14 +117,26 @@ async def stop(self):
return await super().stop()

async def _check_internal(self):
return await super()._check_internal()
"""Checks the NPS status."""

try:
result = await self.nps.verify()
if result is False:
raise VerificationError("NPS verification failed.")
except Exception as err:
raise CheckError(str(err), error_code=NPSErrorCodes.VERIFICATION_FAILED)

return True

async def _troubleshoot_internal(
self,
error_code: ErrorCodes,
error_code,
exception: Exception | None = None,
):
return await super()._troubleshoot_internal(error_code, exception)
"""Handles internal troubleshooting."""

if error_code.value == NPSErrorCodes.VERIFICATION_FAILED:
await self.restart(mode="exit")


NPSCommand = Command[NPSActor]

0 comments on commit 7c4d1e4

Please sign in to comment.