Commit 8f93f06e authored by Rémi Duraffort's avatar Rémi Duraffort
Browse files

xmlrpc api: allow to show and update worker job limit


Signed-off-by: default avatarRémi Duraffort <remi.duraffort@linaro.org>
parent 8625aacf
......@@ -289,14 +289,15 @@ class SchedulerWorkersAPI(ExposedV2API):
d.hostname for d in worker.device_set.all().order_by("hostname")
],
"last_ping": worker.last_ping,
"job_limit": worker.job_limit,
}
@check_perm("lava_scheduler_app.change_worker")
def update(self, hostname, description=None, health=None):
def update(self, hostname, description=None, health=None, job_limit=None):
"""
Name
----
`scheduler.workers.update` (`hostname`, `description=None`, `health=None`)
`scheduler.workers.update` (`hostname`, `description=None`, `health=None`, `job_limit=None`)
Description
-----------
......@@ -311,6 +312,8 @@ class SchedulerWorkersAPI(ExposedV2API):
Description of the worker
`health`: string
Set worker health ("ACTIVE", "MAINTENANCE" or "RETIRED")
`job_limit`: positive integer
Set job limit for this worker
Return value
------------
......@@ -335,4 +338,9 @@ class SchedulerWorkersAPI(ExposedV2API):
else:
raise xmlrpc.client.Fault(400, "Invalid health: %s" % health)
if job_limit is not None:
if not isinstance(job_limit, int) or job_limit < 0:
raise xmlrpc.client.fault(400, "Invalid job limit")
worker.job_limit = job_limit
worker.save()
......@@ -1772,9 +1772,18 @@ def test_workers_list(setup):
def test_workers_show(setup):
data = server().scheduler.workers.show("example.com")
assert set(data.keys()) == set( # nosec
["hostname", "description", "state", "health", "devices", "last_ping"]
[
"hostname",
"description",
"state",
"health",
"devices",
"last_ping",
"job_limit",
]
)
assert data["hostname"] == "example.com" # nosec
assert data["job_limit"] == 0 # nosec
with pytest.raises(xmlrpc.client.Fault) as exc:
server().scheduler.workers.show("bla")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment