diff --git a/spalloc_client/protocol_client.py b/spalloc_client/protocol_client.py index a82cc5609..3716c4cde 100644 --- a/spalloc_client/protocol_client.py +++ b/spalloc_client/protocol_client.py @@ -381,15 +381,29 @@ def version(self, timeout: Optional[float] = None) -> str: return cast(str, self.call("version", timeout)) def create_job(self, timeout: Optional[float], *args: int, - **kwargs: Union[float, str, List[str], None]) -> int: + owner: Optional[str] = None, + keepalive: Optional[float] = None, + machine: Optional[str] = None, + tags: Optional[List[str]] = None, + min_ratio: Optional[float] = None, + max_dead_boards: Optional[int] = None, + max_dead_links: Optional[int] = None, + require_torus: Optional[bool] = None) -> int: """ Start a new job """ # If no owner, don't bother with the call - if "owner" not in kwargs: + if owner is None: raise SpallocServerException( "owner must be specified for all jobs.") - return cast(int, self.call("create_job", timeout, *args, **kwargs)) + if tags is not None and machine is not None: + raise SpallocServerException( + f"Unexpected {tags=} and {machine=} are both not None") + return cast(int, self.call( + "create_job", timeout, *args, owner=owner, + keepalive=keepalive, machine=machine, tags=tags, + min_ratio=min_ratio, max_dead_boards=max_dead_boards, + max_dead_links =max_dead_links, require_torus=require_torus)) def job_keepalive(self, job_id: int, timeout: Optional[float] = None) -> JsonObject: diff --git a/tests/test_job.py b/tests/test_job.py index 7220cf0ff..74b8d64c7 100644 --- a/tests/test_job.py +++ b/tests/test_job.py @@ -18,7 +18,8 @@ import pytest from mock import Mock # type: ignore[import] from spalloc_client import ( - Job, JobState, JobDestroyedError, ProtocolTimeoutError) + Job, JobState, JobDestroyedError, ProtocolTimeoutError, + SpallocServerException) from spalloc_client._keepalive_process import keep_job_alive from spalloc_client.job import ( _JobStateTuple, _JobMachineInfoTuple, StateChangeTimeoutError, diff --git a/tests/test_protocol_client.py b/tests/test_protocol_client.py index d89acae3d..e1ad3c1a1 100644 --- a/tests/test_protocol_client.py +++ b/tests/test_protocol_client.py @@ -233,10 +233,13 @@ def test_commands_as_methods(c, s, bg_accept): s.send({"return": "Woo"}) no_timeout = None - assert c.create_job(no_timeout, 1, bar=2, owner="dummy") == "Woo" - assert s.recv() == { + assert c.create_job(no_timeout, 1, keepalive=2, owner="dummy") == "Woo" + commands = s.recv() + commands["kwargs"] = {k: v for k, v in commands["kwargs"].items() + if v is not None} + assert commands == { "command": "create_job", "args": [1], "kwargs": { - "bar": 2, "owner": "dummy"}} + "keepalive": 2, "owner": "dummy"}} # Should fail for arbitrary internal method names with pytest.raises(AttributeError):