def testGetBuildStages(self):
     """Test the GetBuildStages functionality."""
     bbv2 = buildbucket_v2.BuildbucketV2()
     start_time = Timestamp()
     start_time.GetCurrentTime()
     step = step_pb2.Step(name='stage_name',
                          start_time=start_time,
                          status=2)
     build_with_steps = build_pb2.Build(steps=[step])
     get_build_fn = self.PatchObject(bbv2,
                                     'GetBuild',
                                     return_value=build_with_steps)
     get_build_status_fn = self.PatchObject(
         bbv2,
         'GetBuildStatus',
         return_value={'build_config': 'something-paladin'})
     expected_result = [{
         'name':
         'stage_name',
         'start_time':
         datetime.fromtimestamp(start_time.seconds),
         'finish_time':
         None,
         'buildbucket_id':
         1234,
         'status':
         constants.BUILDER_STATUS_INFLIGHT,
         'build_config':
         'something-paladin'
     }]
     self.assertEqual(bbv2.GetBuildStages(1234), expected_result)
     get_build_fn.assert_called_once_with(1234, properties='steps')
     get_build_status_fn.assert_called_once_with(1234)
예제 #2
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 testGetBuildStatusWithValidId(self):
     """Tests for GetBuildStatus with a valid ID."""
     properties_dict = {
         'cidb_id': '1234',
         'bot_id': 'swarm-cros-34',
         'cbb_branch': 'master',
         'cbb_config': 'sludge-paladin-tryjob',
         'cbb_master_build_id': '4321',
         'platform_version': '11721.0.0',
         'milestone_version': '74',
         'full_version': 'R74-11721.0.0-b3457724',
         'critical': '1',
         'build_type': 'Try',
     }
     start_time = Timestamp()
     start_time.GetCurrentTime()
     fake_properties = Struct(
         fields={
             key: Value(string_value=value)
             for key, value in properties_dict.items()
         })
     fake_output = build_pb2.Build.Output(properties=fake_properties)
     fake_build = build_pb2.Build(id=1234,
                                  start_time=start_time,
                                  status=2,
                                  output=fake_output)
     self.PatchObject(buildbucket_v2.BuildbucketV2,
                      'GetBuild',
                      return_value=fake_build)
     expected_valid_status = {
         'build_config': 'sludge-paladin-tryjob',
         'start_time': datetime.fromtimestamp(start_time.seconds),
         'finish_time': None,
         'id': 1234,
         'status': constants.BUILDER_STATUS_INFLIGHT,
         'chrome_version': None,
         'platform_version': '11721.0.0',
         'milestone_version': '74',
         'full_version': 'R74-11721.0.0-b3457724',
         'important': 1,
         'buildbucket_id': 1234,
         'summary': None,
         'master_build_id': 4321,
         'bot_hostname': 'swarm-cros-34',
         'builder_name': None,
         'build_number': None,
         'buildbot_generation': None,
         'waterfall': None,
         'deadline': None,
         'build_type': 'Try',
         'metadata_url': None,
         'toolchain_url': None,
         'branch': 'master'
     }
     bbv2 = buildbucket_v2.BuildbucketV2()
     status = bbv2.GetBuildStatus(1234)
     self.assertEqual(status, expected_valid_status)
예제 #4
0
 def testGetKilledChildBuildsWithValidId(self):
   """Test a valid query flow."""
   bbv2 = buildbucket_v2.BuildbucketV2()
   buildbucket_id = 1234
   expected_child_builds = [8921795536486453568, 8921795536486453567]
   fake_properties = Struct(fields={
       'killed_child_builds': Value(string_value=str(expected_child_builds))
   })
   fake_output = build_pb2.Build.Output(properties=fake_properties)
   fake_build = build_pb2.Build(id=1234, output=fake_output)
   self.PatchObject(buildbucket_v2.BuildbucketV2, 'GetBuild',
                    return_value=fake_build)
   builds = bbv2.GetKilledChildBuilds(buildbucket_id)
   self.assertEqual(builds, expected_child_builds)
예제 #5
0
 def testGetChildStatusesSuccess(self):
   """Test GetChildStatuses when RPC succeeds."""
   bbv2 = buildbucket_v2.BuildbucketV2()
   fake_search_build_response = rpc_pb2.SearchBuildsResponse()
   self.PatchObject(bbv2, 'SearchBuild',
                    return_value=fake_search_build_response)
   self.assertEqual(bbv2.GetChildStatuses(1234), [])
   fake_build = build_pb2.Build(id=2341)
   fake_search_build_response = rpc_pb2.SearchBuildsResponse(
       builds=[fake_build])
   self.PatchObject(bbv2, 'SearchBuild',
                    return_value=fake_search_build_response)
   get_build_status = self.PatchObject(bbv2, 'GetBuildStatus')
   bbv2.GetChildStatuses(1234)
   get_build_status.assert_called_once_with(2341)