Skip to content

Commit

Permalink
Add actor-restart command
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Mar 26, 2024
1 parent c37e09d commit 1d3ced5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ include = ["src/lvmopstools/*.yaml"]
lvmtools = 'lvmopstools.__main__:lvmopstools'

[tool.poetry.dependencies]
python = "^3.10,<3.13"
python = "^3.10"
sdsstools = "^1.3.1"
sdss-clu = "^2.2.3"
astropy = "^6.0.0"
Expand Down
18 changes: 17 additions & 1 deletion src/lvmopstools/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,21 @@ async def actor_state(command: Command[LVMActor], *args, **kwargs):
return command.finish(state={"code": code, "flags": flags, "error": None})


@click.command(cls=CluCommand, name="actor-restart")
@click.option(
"--mode",
"-m",
type=click.Choice(["exit", "reload"]),
default="exit",
help="How to restart the actor.",
)
async def actor_restart(command: Command[LVMActor], mode: str = "exit"):
"""Restarts the actor."""

await command.actor.restart(mode=mode)
return command.finish()


class CheckError(Exception):
"""An exception raised when the :obj:`.LVMActor` check fails."""

Expand Down Expand Up @@ -208,8 +223,9 @@ def __init__(
self.restart_after = restart_after
self.restart_mode = restart_mode

# Actor state command.
# Additional commands.
self.parser.add_command(actor_state)
self.parser.add_command(actor_restart)

# Add keywords in schema for the actor state.
assert self.model and self.model.schema, "Model schema not defined"
Expand Down
17 changes: 15 additions & 2 deletions tests/test_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class NewErrorCodes(enum.Enum):
SOME_FAILURE_MODE = 1


async def test_actor_state(lvm_actor: LVMActor):
async def test_command_actor_state(lvm_actor: LVMActor):
assert isinstance(lvm_actor, LVMActor)

cmd = await lvm_actor.invoke_mock_command("actor-state")
Expand All @@ -60,7 +60,7 @@ async def test_actor_state(lvm_actor: LVMActor):
lvm_actor._troubleshoot_internal.assert_not_called()


async def test_actor_state_no_model(lvm_actor: LVMActor):
async def test_command_actor_state_no_model(lvm_actor: LVMActor):
assert isinstance(lvm_actor, LVMActor)

lvm_actor.model = None
Expand All @@ -73,6 +73,19 @@ async def test_actor_state_no_model(lvm_actor: LVMActor):
assert cmd.replies[-1].body["state"]["error"] is None


async def test_command_actor_restart(lvm_actor: LVMActor, mocker: MockerFixture):
assert isinstance(lvm_actor, LVMActor)

lvm_actor.restart = mocker.AsyncMock()

cmd = await lvm_actor.invoke_mock_command("actor-restart")
await cmd

assert cmd.status.did_succeed

lvm_actor.restart.assert_called_once()


def test_get_error_codes():
assert ErrorCodes.UNKNOWN == ErrorCodes.get_error_code(9999)

Expand Down

0 comments on commit 1d3ced5

Please sign in to comment.