• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2017 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Extra functions for frontend.afe.models.Job objects.
6
7Most of these exist in tightly coupled forms in legacy Autotest code
8(e.g., part of methods with completely unrelated names on Task objects
9under multiple layers of abstract classes).  These are defined here to
10sanely reuse without having to commit to a long refactor of legacy code
11that is getting deleted soon.
12
13It's not really a good idea to define these on the Job class either;
14they are specialized and the Job class already suffers from method
15bloat.
16"""
17
18
19def is_hostless(job):
20    """Return True if the job is hostless.
21
22    @param job: frontend.afe.models.Job instance
23    """
24    return bool(hostnames(job))
25
26
27def hostnames(job):
28    """Return a list of hostnames for a job.
29
30    @param job: frontend.afe.models.Job instance
31    """
32    hqes = job.hostqueueentry_set.all().prefetch_related('host')
33    return [hqe.host.hostname for hqe in hqes if hqe.host is not None]
34
35
36def is_aborted(job):
37    """Return if the job is aborted.
38
39    (This means the job is marked for abortion; the job can still be
40    running.)
41
42    @param job: frontend.afe.models.Job instance
43    """
44    for hqe in job.hostqueueentry_set.all():
45        if hqe.aborted:
46            return True
47    return False
48