diff --git a/poetry.lock b/poetry.lock index 2d2423f..bbc443e 100644 --- a/poetry.lock +++ b/poetry.lock @@ -913,7 +913,7 @@ ds9 = ["pyds9 (>=1.8.1,<2.0.0)"] type = "git" url = "https://github.com/sdss/lvmopstools.git" reference = "main" -resolved_reference = "1d3ced52c1b133f76bd50bde6d5cd0fa9a014ccb" +resolved_reference = "9a62a226fdbf73ba91f4b572d2783ddf2b1fa663" [[package]] name = "makefun" diff --git a/pyproject.toml b/pyproject.toml index 348f49f..42b01e1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/src/lvmnps/actor/actor.py b/src/lvmnps/actor/actor.py index 17d90da..15b43de 100644 --- a/src/lvmnps/actor/actor.py +++ b/src/lvmnps/actor/actor.py @@ -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 @@ -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.""" @@ -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]