Пример #1
0
    def _CreateCompileRerunBuild(self, commit_position=6000002):
        rerun_commit = GitilesCommit(
            gitiles_host=self.context.gitiles_host,
            gitiles_project=self.context.gitiles_project,
            gitiles_ref=self.context.gitiles_ref,
            gitiles_id=str(commit_position),
            commit_position=commit_position)

        rerun_builder = BuilderID(project='chromium',
                                  bucket='findit',
                                  builder='findit-variables')

        rerun_build = CompileRerunBuild.Create(
            luci_project=rerun_builder.project,
            luci_bucket=rerun_builder.bucket,
            luci_builder=rerun_builder.builder,
            build_id=8000000000789,
            legacy_build_number=60789,
            gitiles_host=rerun_commit.gitiles_host,
            gitiles_project=rerun_commit.gitiles_project,
            gitiles_ref=rerun_commit.gitiles_ref,
            gitiles_id=rerun_commit.gitiles_id,
            commit_position=rerun_commit.commit_position,
            status=1,
            create_time=datetime(2019, 3, 28),
            parent_key=self.analysis.key)
        rerun_build.put()
        return rerun_build
Пример #2
0
 def _CreateRerunBuild(self, rerun_builder, new_build, rerun_commit,
                       analysis_key):
     return CompileRerunBuild.Create(
         luci_project=rerun_builder.project,
         luci_bucket=rerun_builder.bucket,
         luci_builder=rerun_builder.builder,
         build_id=new_build.id,
         legacy_build_number=new_build.number,
         gitiles_host=rerun_commit.gitiles_host,
         gitiles_project=rerun_commit.gitiles_project,
         gitiles_ref=rerun_commit.gitiles_ref,
         gitiles_id=rerun_commit.gitiles_id,
         commit_position=rerun_commit.commit_position,
         status=new_build.status,
         create_time=new_build.create_time.ToDatetime(),
         parent_key=analysis_key)
Пример #3
0
    def testProcessRerunBuildResultBuildPassed(self, mock_compile_failures,
                                               mock_analysis):
        build_id = 8000000000123
        build_number = 123
        builder = BuilderID(project='chromeos',
                            bucket='postsubmit',
                            builder='findit-variable')
        build = Build(id=build_id,
                      builder=builder,
                      number=build_number,
                      status=common_pb2.SUCCESS,
                      tags=[{
                          'key': 'analyzed_build_id',
                          'value': str(self.analyzed_build_id)
                      }])
        build.input.gitiles_commit.host = 'gitiles.host.com'
        build.input.gitiles_commit.project = 'project/name'
        build.input.gitiles_commit.ref = 'ref/heads/master'
        build.input.gitiles_commit.id = 'git_sha_6543221'
        build.create_time.FromDatetime(datetime(2019, 4, 9))
        step1 = Step(name='s1', status=common_pb2.SUCCESS)
        step2 = Step(name=self.compile_step_name, status=common_pb2.SUCCESS)
        build.steps.extend([step1, step2])

        CompileRerunBuild.Create(luci_project=self.context.luci_project_name,
                                 luci_bucket=build.builder.bucket,
                                 luci_builder=build.builder.builder,
                                 build_id=build_id,
                                 legacy_build_number=build_number,
                                 gitiles_host=self.context.gitiles_host,
                                 gitiles_project=self.context.gitiles_project,
                                 gitiles_ref=self.context.gitiles_ref,
                                 gitiles_id='git_sha_6543221',
                                 commit_position=6543221,
                                 status=build.status,
                                 create_time=build.create_time.ToDatetime(),
                                 parent_key=self.analysis.key).put()

        self.assertTrue(
            compile_analysis.OnCompileRerunBuildCompletion(
                self.context, build))
        self.assertFalse(mock_compile_failures.called)
        rerun_build = CompileRerunBuild.get_by_id(build_id,
                                                  parent=self.analysis.key)
        self.assertEqual({}, rerun_build.GetFailuresInBuild())

        self.assertTrue(mock_analysis.called)
Пример #4
0
 def _CreateCompileRerunBuild(self, build_id, commit_position,
                              analysis_key):
     build = CompileRerunBuild.Create(
         luci_project='chromium',
         luci_bucket='ci',
         luci_builder='Linux Builder',
         build_id=build_id,
         legacy_build_number=11111,
         gitiles_host='chromium.googlesource.com',
         gitiles_project='chromium/src',
         gitiles_ref='refs/heads/master',
         gitiles_id='git_hash',
         commit_position=commit_position,
         status=1,
         create_time=datetime(2019, 3, 28),
         parent_key=analysis_key)
     build.put()
def TriggerRerunBuild(context, analyzed_build_id, referred_build, analysis_key,
                      rerun_builder, rerun_commit, output_targets):
  """Triggers a rerun build if there's no existing one.

  Creates and saves a CompileRerunBuild entity if a new build is triggered.

  Checking for existing build and saving new build are in one transaction to
  make sure no duplicated rerun builds can be triggered.

  Args:
    context (findit_v2.services.context.Context): Scope of the analysis.
    analyzed_build_id (int): Build id of the build that's being analyzed.
    referred_build (buildbucket build.proto): Info about the build being
      referred to trigger new rerun builds. This build could be the analyzed
      build or a previous rerun build in the same analysis.
    analysis_key (Key to CompileFailureAnalysis): Key to the running analysis.
    rerun_builder (BuilderId): Builder to rerun the build.
    rerun_commit (GitilesCommit): Gitiles commit the build runs on.
    output_targets (dict): A dict of targets the rerun build should re-compile.
    {
      'compile': ['target1.o', ...]
    }
  """
  # Check if there's a running build on that commit already.
  existing_builds = CompileRerunBuild.SearchBuildOnCommit(
      analysis_key, rerun_commit)
  if existing_builds:
    # TODO(crbug/957760): Re-trigger the build if the existing one(s) ended with
    # unexpected failures.
    logging.debug('Found existing rerun build for analysis %s on commit %d.',
                  analysis_key.urlsafe(), rerun_commit.commit_position)
    return

  rerun_tags = _GetRerunBuildTags(analyzed_build_id)
  input_properties = _GetRerunBuildInputProperties(context, referred_build,
                                                   output_targets)
  if not input_properties:
    logging.error(
        'Failed to get input properties to trigger rerun build'
        'for build %d.', analyzed_build_id)
    return

  gitiles_commit_pb = common_pb2.GitilesCommit(
      project=rerun_commit.gitiles_project,
      host=rerun_commit.gitiles_host,
      ref=rerun_commit.gitiles_ref,
      id=rerun_commit.gitiles_id)
  new_build = buildbucket_client.TriggerV2Build(
      rerun_builder, gitiles_commit_pb, input_properties, tags=rerun_tags)

  if not new_build:
    logging.error(
        'Failed to trigger rerun build for %s in build %d,'
        'on commit %s', output_targets, analyzed_build_id,
        rerun_commit.gitiles_id)
    return

  CompileRerunBuild.Create(
      luci_project=rerun_builder.project,
      luci_bucket=rerun_builder.bucket,
      luci_builder=rerun_builder.builder,
      build_id=new_build.id,
      legacy_build_number=new_build.number,
      gitiles_host=rerun_commit.gitiles_host,
      gitiles_project=rerun_commit.gitiles_project,
      gitiles_ref=rerun_commit.gitiles_ref,
      gitiles_id=rerun_commit.gitiles_id,
      commit_position=rerun_commit.commit_position,
      status=new_build.status,
      create_time=new_build.create_time.ToDatetime(),
      parent_key=analysis_key).put()
Пример #6
0
    def testProcessRerunBuildResult(self, mock_compile_failures):
        build_id = 8000000000123
        build_number = 123
        builder = BuilderID(project='chromeos',
                            bucket='postsubmit',
                            builder='findit-variable')
        build = Build(id=build_id,
                      builder=builder,
                      number=build_number,
                      status=common_pb2.FAILURE,
                      tags=[{
                          'key': 'analyzed_build_id',
                          'value': str(self.analyzed_build_id)
                      }])
        build.input.gitiles_commit.host = 'gitiles.host.com'
        build.input.gitiles_commit.project = 'project/name'
        build.input.gitiles_commit.ref = 'ref/heads/master'
        build.input.gitiles_commit.id = 'git_sha_6543221'
        build.create_time.FromDatetime(datetime(2019, 4, 9))
        step1 = Step(name='s1', status=common_pb2.SUCCESS)
        step2 = Step(name=self.compile_step_name, status=common_pb2.FAILURE)
        build.steps.extend([step1, step2])
        output_target = json.dumps({
            'category': 'chromeos-base',
            'packageName': 'target2'
        })
        build.output.properties['build_compile_failure_output'] = {
            'failures': [
                {
                    'output_targets': [output_target],
                    'rule': 'emerge'
                },
            ],
            'failed_step': self.compile_step_name
        }

        mock_compile_failures.return_value = {
            self.compile_step_name: {
                'failures': {
                    frozenset(['target1.o', 'target2.o']): {
                        'rule': 'CXX',
                        'first_failed_build': {
                            'id': build_id,
                            'number': build_number,
                            'commit_id': 'git_sha_6543221'
                        },
                        'last_passed_build': None
                    },
                },
                'first_failed_build': {
                    'id': build_id,
                    'number': build_number,
                    'commit_id': 'git_sha_6543221'
                },
                'last_passed_build': None
            },
        }

        CompileRerunBuild.Create(luci_project=self.context.luci_project_name,
                                 luci_bucket=build.builder.bucket,
                                 luci_builder=build.builder.builder,
                                 build_id=build_id,
                                 legacy_build_number=build_number,
                                 gitiles_host=self.context.gitiles_host,
                                 gitiles_project=self.context.gitiles_project,
                                 gitiles_ref=self.context.gitiles_ref,
                                 gitiles_id='git_sha_6543221',
                                 commit_position=6543221,
                                 status=build.status,
                                 create_time=build.create_time.ToDatetime(),
                                 parent_key=self.analysis.key).put()

        self.assertTrue(
            compile_api._ProcessAndSaveRerunBuildResult(
                self.context, self.analyzed_build_id, build))
        rerun_build = CompileRerunBuild.get_by_id(build_id,
                                                  parent=self.analysis.key)
        self.assertItemsEqual(
            ['target1.o', 'target2.o'],
            rerun_build.GetFailedTargets()[self.compile_step_name])