Commit a04086dd authored by Florent Jacquet's avatar Florent Jacquet Committed by Neil Williams
Browse files

api: add get_recent_jobs_for_device

This API function returns the last jobs asked for a given device as a list of
dictionaries containing the job ID, its description (the name), and its status.
The typical use case is to build a custom reporting tool outside LAVA by
querying this function, and then asking for job details once you know which job
to look for.

Change-Id: I2acd5415ed6ff90d2f64e40d520d79d09c2f4cf3
Signed-off-by: default avatarFlorent Jacquet <>
parent 8bbd298f
......@@ -320,6 +320,86 @@ class SchedulerAPI(ExposedAPI):
return all_device_types
def get_recent_jobs_for_device(self, device, count=1, restrict_to_user=False):
`get_recent_jobs_for_device` (`device`, `count=1`, `restrict_to_user=False`)
Get details of recently finished jobs for a given device. Limits the list
to test jobs submitted by the user making the query if restrict_to_user is set to
True. Get only the most recent job by default, but count can be set higher to
get for example the last 10 jobs.
`device`: string
Name of the device for which you want the jobs
`count`: integer (Optional, default=1)
Number of last jobs you want
`restrict_to_user`: boolean (Optional, default=False)
Fetch only the jobs submitted by the user making the query if set to True
Return value
This function returns a list of dictionaries, which correspond to the
list of recently finished jobs informations (Complete or Incomplete)
for this device, ordered from youngest to oldest.
'description': 'mainline--armada-370-db--multi_v7_defconfig--network',
'id': 359828,
'status': 'Complete'
'description': 'mainline--armada-370-db--multi_v7_defconfig--sata',
'id': 359827
'status': 'Incomplete'
if not device:
raise xmlrpclib.Fault(
400, "Bad request: device was not specified."
if count < 0:
raise xmlrpclib.Fault(
400, "Bad request: count must not be negative."
device_obj = Device.objects.get(hostname=device)
except Device.DoesNotExist:
raise xmlrpclib.Fault(
404, "Device '%s' was not found." % device
if not device_obj.is_visible_to(self.user):
raise xmlrpclib.Fault(
403, "Device '%s' not available to user '%s'." %
(device, self.user)
job_qs = TestJob.objects.filter(
status__in=(TestJob.COMPLETE, TestJob.INCOMPLETE),
if restrict_to_user:
job_qs = job_qs.filter(submitter=self.user)
job_list = []
for job in job_qs.all()[:count]:
job_dict = {
"description": job.description,
"status": job.get_status_display(),
if not job.can_view(self.user):
job_dict["id"] = None
return job_list
def get_device_type_by_alias(self, alias):
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