| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 from common.pipeline_wrapper import BasePipeline | 5 from common.pipeline_wrapper import BasePipeline |
| 6 from common.pipeline_wrapper import pipeline | 6 from common.pipeline_wrapper import pipeline |
| 7 from common.waterfall import buildbucket_client | 7 from common.waterfall import buildbucket_client |
| 8 from common.waterfall import failure_type |
| 8 from model.wf_try_job import WfTryJob | 9 from model.wf_try_job import WfTryJob |
| 9 from model.wf_try_job_data import WfTryJobData | 10 from model.wf_try_job_data import WfTryJobData |
| 10 from waterfall import buildbot | 11 from waterfall import buildbot |
| 11 from waterfall import waterfall_config | 12 from waterfall import waterfall_config |
| 12 from waterfall.try_job_type import TryJobType | |
| 13 | 13 |
| 14 | 14 |
| 15 class ScheduleTryJobPipeline(BasePipeline): | 15 class ScheduleTryJobPipeline(BasePipeline): |
| 16 """A pipeline for scheduling a new try job for current build.""" | 16 """A base pipeline for scheduling a new try job for current build.""" |
| 17 | 17 |
| 18 def _GetBuildProperties( | 18 def _GetBuildProperties( |
| 19 self, master_name, builder_name, build_number, good_revision, | 19 self, master_name, builder_name, build_number, good_revision, |
| 20 bad_revision, try_job_type, suspected_revisions): | 20 bad_revision, try_job_type, suspected_revisions): |
| 21 properties = { | 21 properties = { |
| 22 'recipe': 'findit/chromium/%s' % try_job_type, | 22 'recipe': 'findit/chromium/%s' % ( |
| 23 failure_type.GetDescriptionForFailureType(try_job_type)), |
| 23 'good_revision': good_revision, | 24 'good_revision': good_revision, |
| 24 'bad_revision': bad_revision, | 25 'bad_revision': bad_revision, |
| 25 'target_mastername': master_name, | 26 'target_mastername': master_name, |
| 26 'referenced_build_url': buildbot.CreateBuildUrl( | 27 'referenced_build_url': buildbot.CreateBuildUrl( |
| 27 master_name, builder_name, build_number) | 28 master_name, builder_name, build_number) |
| 28 } | 29 } |
| 29 | 30 |
| 30 if try_job_type == TryJobType.COMPILE: | |
| 31 properties['target_buildername'] = builder_name | |
| 32 else: # try_job_type is 'test'. | |
| 33 properties['target_testername'] = builder_name | |
| 34 | |
| 35 if suspected_revisions: | 31 if suspected_revisions: |
| 36 properties['suspected_revisions'] = suspected_revisions | 32 properties['suspected_revisions'] = suspected_revisions |
| 37 | 33 |
| 38 return properties | 34 return properties |
| 39 | 35 |
| 40 # Arguments number differs from overridden method - pylint: disable=W0221 | 36 def _TriggerTryJob( |
| 41 def run( | 37 self, master_name, builder_name, properties, additional_parameters): |
| 42 self, master_name, builder_name, build_number, good_revision, | |
| 43 bad_revision, try_job_type, compile_targets, targeted_tests, | |
| 44 suspected_revisions): | |
| 45 tryserver_mastername, tryserver_buildername = ( | 38 tryserver_mastername, tryserver_buildername = ( |
| 46 waterfall_config.GetTrybotForWaterfallBuilder( | 39 waterfall_config.GetTrybotForWaterfallBuilder( |
| 47 master_name, builder_name)) | 40 master_name, builder_name)) |
| 48 | 41 |
| 49 properties = self._GetBuildProperties( | |
| 50 master_name, builder_name, build_number, good_revision, bad_revision, | |
| 51 try_job_type, suspected_revisions) | |
| 52 | |
| 53 if try_job_type == TryJobType.COMPILE: | |
| 54 additional_parameters = {'compile_targets': compile_targets} | |
| 55 else: | |
| 56 additional_parameters = {'tests': targeted_tests} | |
| 57 | |
| 58 try_job = buildbucket_client.TryJob( | 42 try_job = buildbucket_client.TryJob( |
| 59 tryserver_mastername, tryserver_buildername, None, properties, [], | 43 tryserver_mastername, tryserver_buildername, None, properties, [], |
| 60 additional_parameters) | 44 additional_parameters) |
| 61 error, build = buildbucket_client.TriggerTryJobs([try_job])[0] | 45 error, build = buildbucket_client.TriggerTryJobs([try_job])[0] |
| 62 | 46 |
| 63 if error: # pragma: no cover | 47 if error: # pragma: no cover |
| 64 raise pipeline.Retry( | 48 raise pipeline.Retry( |
| 65 'Error "%s" occurred. Reason: "%s"' % (error.message, error.reason)) | 49 'Error "%s" occurred. Reason: "%s"' % (error.message, error.reason)) |
| 66 | 50 |
| 67 try_job_result = WfTryJob.Get(master_name, builder_name, build_number) | 51 return build.id |
| 68 build_id = build.id | |
| 69 | 52 |
| 70 if try_job_type == TryJobType.COMPILE: | 53 def _CreateTryJobData( |
| 71 try_job_result.compile_results.append({'try_job_id': build_id}) | 54 self, build_id, master_name, builder_name, build_number, try_job_type, |
| 72 else: | 55 has_compile_targets, has_heuristic_results): |
| 73 try_job_result.test_results.append({'try_job_id': build_id}) | |
| 74 try_job_result.try_job_ids.append(build_id) | |
| 75 try_job_result.put() | |
| 76 | |
| 77 # Create a corresponding WfTryJobData entity to capture as much metadata as | |
| 78 # early as possible. | |
| 79 try_job_data = WfTryJobData.Create(build_id) | 56 try_job_data = WfTryJobData.Create(build_id) |
| 80 try_job_data.master_name = master_name | 57 try_job_data.master_name = master_name |
| 81 try_job_data.builder_name = builder_name | 58 try_job_data.builder_name = builder_name |
| 82 try_job_data.build_number = build_number | 59 try_job_data.build_number = build_number |
| 83 try_job_data.try_job_type = try_job_type | 60 try_job_data.try_job_type = try_job_type |
| 84 try_job_data.has_compile_targets = bool(compile_targets) | 61 try_job_data.has_compile_targets = has_compile_targets |
| 85 try_job_data.has_heuristic_results = bool(suspected_revisions) | 62 try_job_data.has_heuristic_results = has_heuristic_results |
| 86 try_job_data.put() | 63 try_job_data.put() |
| 87 | 64 |
| 88 return build_id | 65 # Arguments number differs from overridden method - pylint: disable=W0221 |
| 66 def run( |
| 67 self, master_name, builder_name, build_number, good_revision, |
| 68 bad_revision, try_job_type, suspected_revisions): |
| 69 raise NotImplementedError() |
| OLD | NEW |