Example #1
0
 def testSkipFailedBuildNotMatchingGitilesProject(self, mocked_GetV2Build, *_):
   build = Build()
   build.input.gitiles_commit.host = 'wrong.host.com'
   build.input.gitiles_commit.project = 'wrong/project'
   mocked_GetV2Build.return_value = build
   self.assertFalse(
       api.OnBuildCompletion('project', 'ci', 'builder', 123, 'FAILURE'))
   mocked_GetV2Build.assert_called_once_with(
       123, fields=FieldMask(paths=['*']))
Example #2
0
 def testOnRerunBuildCompletionNotTriggeredByFindit(self, mocked_GetV2Build,
                                                    *_):
   build = Build()
   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'
   mocked_GetV2Build.return_value = build
   self.assertFalse(
       api.OnBuildCompletion('project', 'ci', 'builder-rerun', 123, 'SUCCESS'))
   mocked_GetV2Build.assert_called_once_with(
       123, fields=FieldMask(paths=['*']))
Example #3
0
 def testValidFailedBuild(self, mocked_OnBuildFailure, mocked_GetV2Build,
                          *_):
     build = Build()
     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'
     mocked_GetV2Build.return_value = build
     self.assertTrue(
         api.OnBuildCompletion('project', 'ci', 'builder', 123, 'FAILURE'))
     mocked_GetV2Build.assert_called_once_with(
         123, fields=FieldMask(paths=['*']))
     mocked_OnBuildFailure.assert_called_once_with(
         Context(luci_project_name='project',
                 gitiles_host='gitiles.host.com',
                 gitiles_project='project/name',
                 gitiles_ref='ref/heads/master',
                 gitiles_id='git_sha'), build)
Example #4
0
 def testOnRerunBuildCompletion(self, mocked_OnRerunBuildCompletion,
                                mocked_GetV2Build, *_):
     build = Build()
     build.created_by = 'user:{}'.format(DEFAULT_SERVICE_ACCOUNT)
     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'
     mocked_GetV2Build.return_value = build
     self.assertTrue(
         api.OnBuildCompletion('project', 'ci', 'r_builder', 123,
                               'SUCCESS'))
     mocked_GetV2Build.assert_called_once_with(
         123, fields=FieldMask(paths=['*']))
     mocked_OnRerunBuildCompletion.assert_called_once_with(
         Context(luci_project_name='project',
                 gitiles_host='gitiles.host.com',
                 gitiles_project='project/name',
                 gitiles_ref='ref/heads/master',
                 gitiles_id='git_sha'), build)
    def HandlePost(self):
        # The data of self.request.body is from
        # findit/handlers/completed_build_pubsub_ingestor.py, and its format is:
        # {
        #   "project": "chromuim",
        #   "bucket": "ci",
        #   "builder_name": "Linux Builder",
        #   "build_id": 123243434,
        #   "build_result": "FAILURE",
        # }
        try:
            build = json.loads(self.request.body)
        except ValueError:
            logging.debug(self.request.body)
            raise

        project = build['project']
        bucket = build['bucket'].split('.')[-1]  # "luci.chromium.ci" => "ci"
        builder_name = build['builder_name']
        build_id = build['build_id']
        build_result = build['build_result']

        api.OnBuildCompletion(project, bucket, builder_name, build_id,
                              build_result)
Example #6
0
 def testSkipNotFailedBuild(self, *_):
     self.assertFalse(
         api.OnBuildCompletion('project', 'ci', 'builder', 123, 'SUCCESS'))
Example #7
0
 def testNoSupportedBuilder(self, *_):
     self.assertFalse(
         api.OnBuildCompletion('project', 'ci', 'unsupported-builder', 123,
                               'FAILURE'))