Home | History | Annotate | Download | only in suite_scheduler
      1 # Copyright (c) 2012 The Chromium OS 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 import common
      6 from autotest_lib.client.common_lib import priorities
      7 
      8 import base_event, task
      9 
     10 
     11 class BuildEvent(base_event.BaseEvent):
     12     """Base class for events that come from the build system.
     13 
     14     For example, a new build completing or a new version of Chromium.
     15 
     16     @var _revision: The last git revision we checked for new build artifacts.
     17     """
     18 
     19 
     20     def __init__(self, keyword, manifest_versions, always_handle):
     21         """Constructor.
     22 
     23         @param keyword: the keyword/name of this event, e.g. nightly.
     24         @param manifest_versions: ManifestVersions instance to use for querying.
     25         @param always_handle: If True, make ShouldHandle() always return True.
     26         """
     27         super(BuildEvent, self).__init__(keyword, manifest_versions,
     28                                          always_handle)
     29         self._revision = None
     30 
     31 
     32     def Merge(self, to_merge):
     33         """Merge this event with to_merge, changing all mutable properties.
     34 
     35         self._revision REMAINS UNCHANGED.  That's part of this instance's
     36         identity.
     37 
     38         @param to_merge: A BuildEvent instance to merge into this isntance.
     39         """
     40         super(BuildEvent, self).Merge(to_merge)
     41 
     42 
     43     def Prepare(self):
     44         """Perform any one-time setup that must occur before [Should]Handle().
     45 
     46         Creates initial revision checkpoint.
     47         """
     48         self._revision = self._mv.GetCheckpoint()
     49 
     50 
     51     def ShouldHandle(self):
     52         """True if there's been a new successful build since |self._revision|
     53 
     54         @return True if there's been a new build, false otherwise.
     55         """
     56         if super(BuildEvent, self).ShouldHandle():
     57             return True
     58         else:
     59             return self._mv.AnyManifestsSinceRev(self._revision)
     60 
     61 
     62     def _AllPerBranchBuildsSince(self, board, revision):
     63         """Get all per-branch, per-board builds since git |revision|.
     64 
     65         @param board: the board whose builds we want.
     66         @param revision: the revision to look back until.
     67         @return {branch: [build-name1, build-name2]}
     68         """
     69         all_branch_manifests = self._mv.ManifestsSinceRev(revision, board)
     70         all_branch_builds = {}
     71         for (type, milestone), manifests in all_branch_manifests.iteritems():
     72             branch_name = task.PickBranchName(type, milestone)
     73             for manifest in manifests:
     74                 build = base_event.BuildName(board, type, milestone, manifest)
     75                 all_branch_builds.setdefault(branch_name, []).append(build)
     76         return all_branch_builds
     77 
     78 
     79     def GetBranchBuildsForBoard(self, board):
     80         return self._AllPerBranchBuildsSince(board, self._revision)
     81 
     82 
     83     def GetLaunchControlBuildsForBoard(self, board):
     84         """Get per-branch, per-board builds since last run of this event.
     85 
     86         @param board: the board whose builds we want.
     87 
     88         @return: A list of Launch Control builds for the given board, e.g.,
     89                 ['git_mnc_release/shamu-eng/123',
     90                  'git_mnc_release/shamu-eng/124'].
     91         """
     92         return self._LatestLaunchControlBuilds(board)
     93 
     94 
     95 class NewBuild(BuildEvent):
     96     """Event to trigger when new builds are available from the build system."""
     97     KEYWORD = 'new_build'
     98     PRIORITY = priorities.Priority.POSTBUILD
     99     TIMEOUT = 12  # 12 hours, and builds come out every 6
    100 
    101 
    102     def __init__(self, mv, always_handle):
    103         """Constructor.
    104 
    105         @param mv: ManifestVersions instance to use for querying.
    106         @param always_handle: If True, make ShouldHandle() always return True.
    107         """
    108         super(NewBuild, self).__init__(self.KEYWORD, mv, always_handle)
    109 
    110 
    111     def UpdateCriteria(self):
    112         self._revision = self._mv.GetCheckpoint()
    113