Skip to content

Commit

Permalink
more e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nebfield committed Nov 6, 2024
1 parent 268e73a commit 094fedd
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 30 deletions.
1 change: 1 addition & 0 deletions pyvatti/src/pyvatti/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class GlobflowParams(BaseModel):
outdir: str
config_application: str
config_crypt4gh: str
secret_key: str


class Secrets(BaseModel):
Expand Down
10 changes: 5 additions & 5 deletions pyvatti/src/pyvatti/jobstates.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


class States(str, enum.Enum):
REQUESTED = "requested"
CREATED = "created"
DEPLOYED = "deployed"
FAILED = "failed"
SUCCEEDED = "succeeded"
REQUESTED = "Requested"
CREATED = "Created"
DEPLOYED = "Deployed"
FAILED = "Failed"
SUCCEEDED = "Succeeded"
16 changes: 4 additions & 12 deletions pyvatti/src/pyvatti/notifymodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SeqeraLog(BaseModel):
Parse the seqera status to a job machine state:
>>> log.get_job_state()
<States.SUCCEEDED: 'succeeded'>
<States.SUCCEEDED: 'Succeeded'>
A job can take time to start. During this time you'll get empty responses from the Seqera API:
Expand Down Expand Up @@ -103,23 +103,15 @@ def get_job_state(self) -> Optional[States]:
return state


class BackendEvents(str, enum.Enum):
"""Events recognised by the backend"""

STARTED = "started"
ERROR = "error"
COMPLETED = "completed"


class BackendStatusMessage(BaseModel):
"""A message updating the backend about job state
>>> from datetime import datetime
>>> d = {"run_name": "INTP123456", "utc_time": datetime(1999, 12, 31), "event": BackendEvents.COMPLETED}
>>> d = {"run_name": "INTP123456", "utc_time": datetime(1999, 12, 31), "event": States.DEPLOYED }
>>> BackendStatusMessage(**d).model_dump_json()
'{"run_name":"INTP123456","utc_time":"1999-12-31T00:00:00","event":"completed"}'
'{"run_name":"INTP123456","utc_time":"1999-12-31T00:00:00","event":"Deployed"}'
"""

run_name: str
utc_time: PastDatetime
event: BackendEvents
event: States
18 changes: 6 additions & 12 deletions pyvatti/src/pyvatti/pgsjob.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from pyvatti.config import Settings, K8SNamespace
from pyvatti.jobstates import States
from pyvatti.messagemodels import JobRequest
from pyvatti.notifymodels import SeqeraLog, BackendStatusMessage, BackendEvents
from pyvatti.notifymodels import SeqeraLog, BackendStatusMessage

from pyvatti.resources import GoogleResourceHandler, DummyResourceHandler

Expand All @@ -35,7 +35,7 @@ class PolygenicScoreJob(Machine):
On instantiation the default job state is requested:
>>> job.state
<States.REQUESTED: 'requested'>
<States.REQUESTED: 'Requested'>
Normally creating a resource requires some parameters from a message, but not in dry run mdoe:
Expand All @@ -56,7 +56,7 @@ class PolygenicScoreJob(Machine):
>>> job.trigger("succeed") # doctest: +ELLIPSIS
Sending state notification: States.SUCCEEDED
msg='{"run_name":"INT123456","utc_time":...,"event":"completed"}' prepared to send to pipeline-notify topic (PYTEST RUNNING)
msg='{"run_name":"INT123456","utc_time":...,"event":"Succeeded"}' prepared to send to pipeline-notify topic (PYTEST RUNNING)
Deleting all resources: INT123456
...
Expand All @@ -72,7 +72,7 @@ class PolygenicScoreJob(Machine):
>>> bad_job = PolygenicScoreJob("INT789123", dry_run=True)
>>> bad_job.trigger("error") # doctest: +ELLIPSIS
Sending state notification: States.FAILED
msg='{"run_name":"INT789123","utc_time":"...","event":"error"}' prepared to send to pipeline-notify topic (PYTEST RUNNING)
msg='{"run_name":"INT789123","utc_time":"...","event":"Failed"}' prepared to send to pipeline-notify topic (PYTEST RUNNING)
Deleting all resources: INT789123
...
Expand Down Expand Up @@ -125,12 +125,6 @@ class PolygenicScoreJob(Machine):
States.SUCCEEDED: "succeed",
States.DEPLOYED: "deploy",
}
# map from states to events recognised by the backend
state_event_map: ClassVar[dict] = {
States.FAILED: BackendEvents.ERROR,
States.SUCCEEDED: BackendEvents.COMPLETED,
States.DEPLOYED: BackendEvents.STARTED,
}

def __init__(
self, intp_id: str, settings: Optional[Settings] = None, dry_run: bool = False
Expand Down Expand Up @@ -171,6 +165,7 @@ def __init__(

def handle_error(self, event):
logger.warning(f"Exception raised for {self.intp_id}")
logger.warning(event.error)
if isinstance(event.error, MachineError):
logger.warning(f"Couldn't trigger error state for {self.intp_id}")
raise event.error
Expand All @@ -197,9 +192,8 @@ def notify(self, _: EventData):
"""Notify the backend about the job state"""
# bootstrap_server_host: str, bootstrap_server_port: int
logger.info(f"Sending state notification: {self.state}")
event: str = self.state_event_map[self.state]
msg: str = BackendStatusMessage(
run_name=self.intp_id, utc_time=datetime.now(), event=event
run_name=self.intp_id, utc_time=datetime.now(), event=self.state
).model_dump_json()
if "pytest" in sys.modules:
logger.info(
Expand Down
2 changes: 1 addition & 1 deletion pyvatti/tests/test_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_render(message):
"""Test a values.yaml helm file is templated and rendered correctly"""
settings = Settings(
TOWER_TOKEN="test",
TOWER_WORKSPACE="test",
TOWER_WORKSPACE=000000,
GLOBUS_DOMAIN="https://example.com",
GLOBUS_CLIENT_ID="test",
GLOBUS_CLIENT_SECRET="test",
Expand Down

0 comments on commit 094fedd

Please sign in to comment.