def GetBuildHistory(self,
                        build_config,
                        num_results,
                        ignore_build_id=None,
                        start_date=None,
                        end_date=None,
                        branch=None,
                        start_build_id=None):
        """Returns basic information about most recent builds for build config.

    By default this function returns the most recent builds. Some arguments can
    restrict the result to older builds.

    Args:
      build_config: config name of the build to get history.
      num_results: Number of builds to search back. Set this to
          CIDBConnection.NUM_RESULTS_NO_LIMIT to request no limit on the number
          of results.
      ignore_build_id: (Optional) Ignore a specific build. This is most useful
          to ignore the current build when querying recent past builds from a
          build in flight.
      start_date: (Optional, type: datetime.date) Get builds that occured on or
          after this date.
      end_date: (Optional, type:datetime.date) Get builds that occured on or
          before this date.
      branch: (Optional) Return only results for this branch.
      start_build_id: (Optional) The oldest build for which data should
          be retrieved.

    Returns:
      A sorted list of dicts containing up to |number| dictionaries for
      build statuses in descending order (if |reverse| is True, ascending
      order).
    """
        builder = build_pb2.BuilderID(project='chromeos', bucket='general')
        tags = [common_pb2.StringPair(key='cbb_config', value=build_config)]
        create_time = DateToTimeRange(start_date, end_date)
        if ignore_build_id:
            num_results += 1
        if branch:
            tags.append(common_pb2.StringPair(key='cbb_branch', value=branch))
        build = None
        if start_build_id:
            build = rpc_pb2.BuildRange(start_build_id=int(start_build_id))
        build_predicate = rpc_pb2.BuildPredicate(builder=builder,
                                                 tags=tags,
                                                 create_time=create_time,
                                                 build=build)
        search_result = self.SearchBuild(build_predicate,
                                         page_size=num_results)
        build_ids = [build.id for build in search_result.builds]
        if ignore_build_id:
            if ignore_build_id in build_ids:
                build_ids = [x for x in build_ids if ignore_build_id != x]
            else:
                # If we do not find ignore_build_id, we ignore the last (i.e. oldest)
                # build in order to return num_results elements.
                build_ids = build_ids[:-1]

        return [self.GetBuildStatus(x) for x in build_ids]
Ejemplo n.º 2
0
 def testGetBuildHistoryOtherArgs(self):
   """Test GetBuildHistory's processing of (args - ignore_build_id)."""
   builder = build_pb2.BuilderID(project='chromeos', bucket='general')
   tags = [common_pb2.StringPair(key='cbb_config',
                                 value='something-paladin'),
           common_pb2.StringPair(key='cbb_branch',
                                 value='master')]
   start_date = date(2019, 4, 16)
   create_time = buildbucket_v2.DateToTimeRange(start_date)
   fake_build = rpc_pb2.BuildRange(start_build_id=1234)
   fake_predicate = rpc_pb2.BuildPredicate(
       builder=builder, tags=tags, create_time=create_time, build=fake_build)
   bbv2 = buildbucket_v2.BuildbucketV2()
   search_fn = self.PatchObject(bbv2, 'SearchBuild')
   self.PatchObject(bbv2, 'GetBuildStatus')
   bbv2.GetBuildHistory('something-paladin', 10, start_date=start_date,
                        branch='master', start_build_id=1234)
   search_fn.assert_called_once_with(fake_predicate, page_size=10)
 def testSearchBuildExceptionCases(self):
     """Test scenarios where SearchBuild raises an Exception."""
     bbv2 = buildbucket_v2.BuildbucketV2()
     builder = build_pb2.BuilderID(project='chromeos', bucket='general')
     tag = common_pb2.StringPair(key='cbb_master_buildbucket_id',
                                 value=str(1234))
     build_predicate = rpc_pb2.BuildPredicate(builder=builder, tags=[tag])
     with self.assertRaises(AssertionError):
         bbv2.SearchBuild(None, None, 100)
     with self.assertRaises(AssertionError):
         bbv2.SearchBuild(build_predicate, None, None)
     with self.assertRaises(AssertionError):
         bbv2.SearchBuild(build_predicate, 'str_fields', 100)
Ejemplo n.º 4
0
 def testSearchBuild(self):
   """Test redirection to the underlying RPC call."""
   bbv2 = buildbucket_v2.BuildbucketV2()
   builder = build_pb2.BuilderID(project='chromeos', bucket='general')
   tag = common_pb2.StringPair(key='cbb_master_buildbucket_id',
                               value=str(1234))
   build_predicate = rpc_pb2.BuildPredicate(
       builder=builder, tags=[tag])
   fields = field_mask_pb2.FieldMask()
   search_builds_fn = self.PatchObject(bbv2.client, 'SearchBuilds')
   bbv2.SearchBuild(build_predicate, fields=fields, page_size=123)
   search_builds_fn.assert_called_once_with(rpc_pb2.SearchBuildsRequest(
       predicate=build_predicate, fields=fields, page_size=123))
Ejemplo n.º 5
0
 def testGetBuildHistoryIgnoreIdWithoutId(self):
   """Test GetBuildHistory ignore_build_id logic when ID is absent."""
   bbv2 = buildbucket_v2.BuildbucketV2()
   builder = build_pb2.BuilderID(project='chromeos', bucket='general')
   tags = [common_pb2.StringPair(key='cbb_config',
                                 value='something-paladin')]
   build_list = [build_pb2.Build(id=1234),
                 build_pb2.Build(id=2341)]
   search_fn = self.PatchObject(
       bbv2, 'SearchBuild',
       return_value=rpc_pb2.SearchBuildsResponse(builds=build_list))
   status_fn = self.PatchObject(bbv2, 'GetBuildStatus')
   bbv2.GetBuildHistory('something-paladin', 1, ignore_build_id=1000)
   fake_predicate = rpc_pb2.BuildPredicate(
       builder=builder, tags=tags, create_time=None, build=None)
   search_fn.assert_called_with(fake_predicate, page_size=2)
   status_fn.assert_called_with(1234)
    def GetChildStatuses(self, buildbucket_id):
        """Retrieve statuses of all the child builds.

    Args:
      buildbucket_id: buildbucket_id of the parent/master build.

    Returns:
      A list of dictionary corresponding to each child build with keys like
      start_time, end_time, status, version info, critical, build_config, etc.
    """
        builder = build_pb2.BuilderID(project='chromeos', bucket='general')
        tag = common_pb2.StringPair(key='cbb_master_buildbucket_id',
                                    value=str(buildbucket_id))
        build_predicate = rpc_pb2.BuildPredicate(builder=builder, tags=[tag])
        child_builds = self.SearchBuild(build_predicate, page_size=200)
        return [
            self.GetBuildStatus(child_build.id)
            for child_build in child_builds.builds
        ]