def _VerifyMasterId(self, master_id): """Verify that our master id is current and valid.""" super(MasterSlaveLKGMSyncStage, self)._VerifyMasterId(master_id) if not self._run.config.master and not master_id: raise failures_lib.StepFailure( 'Cannot start build without a master_build_id. Did you hit force ' 'build on a slave? Please hit force build on the master instead.')
def PerformStage(self): self.Initialize() self._VerifyMasterId(self._run.options.master_buildbucket_id) version = self._run.options.force_version if self._run.options.master_buildbucket_id: version = self._GetMasterVersion(self._run.options.master_buildbucket_id) next_manifest = None if version: next_manifest = self.ForceVersion(version) else: self.skip_sync = True next_manifest = self.GetNextManifest() if not next_manifest: logging.info('Found no work to do.') if self._run.attrs.manifest_manager.DidLastBuildFail(): raise failures_lib.StepFailure('The previous build failed.') else: raise failures_lib.ExitEarlyException( 'ManifestVersionedSyncStage finished and exited early.') # Log this early on for the release team to grep out before we finish. if self.manifest_manager: self._Print( '\nRELEASETAG: %s\n' % (self.manifest_manager.current_version)) self._SetAndroidVersionIfApplicable(next_manifest) self._SetChromeVersionIfApplicable(next_manifest) # To keep local trybots working, remove restricted checkouts from the # official manifest we get from manifest-versions. with self.LocalizeManifest( next_manifest, filter_cros=self._run.options.local) as new_manifest: self.ManifestCheckout(new_manifest)
class FailStage(generic_stages.BuilderStage): """FailStage always throws an exception""" FAIL_EXCEPTION = failures_lib.StepFailure('Fail stage needs to fail.') def PerformStage(self): """Throw the exception to make us fail.""" raise self.FAIL_EXCEPTION
def PerformStage(self): status = commands.VerifyAFDOArtifacts(self._build_root, self._current_board, self.afdo_type, self.build_api) if not status: raise failures_lib.StepFailure( 'Failed when running the build API.')
def testConvertToStageFailureMessage(self): """Test ConvertToStageFailureMessage.""" failure = failures_lib.StepFailure('step failure message') stage_failure_msg = failure.ConvertToStageFailureMessage( 1, 'HWTest [sanity]') self.assertEqual(stage_failure_msg.stage_name, 'HWTest [sanity]') self.assertEqual(stage_failure_msg.stage_prefix_name, 'HWTest') self.assertEqual(stage_failure_msg.exception_type, 'StepFailure') self.assertEqual(stage_failure_msg.exception_category, 'unknown')
def testGetStageFailureMessageFromExceptionOnStepFailure(self): """Test GetStageFailureMessageFromException on StepFailure.""" exc = failures_lib.StepFailure('step failure message') msg = failures_lib.GetStageFailureMessageFromException( 'CommitQueueSync', 1, exc) self.assertEqual(msg.build_stage_id, 1) self.assertEqual(msg.stage_name, 'CommitQueueSync') self.assertEqual(msg.stage_prefix_name, 'CommitQueueSync') self.assertEqual(msg.exception_type, 'StepFailure') self.assertEqual(msg.exception_category, 'unknown')
def testGetBuildFailureMessageFromResults(self): """Test GetBuildFailureMessageFromResults.""" ex = failures_lib.StepFailure() results_lib.Results.Record('CommitQueueSync', ex) stage = self.ConstructStage() build_failure_msg = stage.GetBuildFailureMessageFromResults() self.assertEqual(build_failure_msg.builder, self.BOT_ID) self.assertTrue( isinstance(build_failure_msg.failure_messages[0], failure_message_lib.StageFailureMessage))
def Run(self): """Have the builder execute the stage.""" skip_stage = self._ShouldSkipStage() previous_record = results_lib.Results.PreviouslyCompletedRecord( self.name) if skip_stage: self._BeginStepForBuildbot(' : [SKIPPED]') elif previous_record is not None: self._BeginStepForBuildbot(' : [PREVIOUSLY PROCESSED]') else: self._BeginStepForBuildbot() try: # Set default values result = None cidb_result = None description = None board = '' elapsed_time = None start_time = time.time() if skip_stage: self._StartBuildStageInCIDB() self._PrintLoudly('Not running Stage %s' % self.name) self.HandleSkip() result = results_lib.Results.SKIPPED return if previous_record: self._StartBuildStageInCIDB() self._PrintLoudly('Stage %s processed previously' % self.name) self.HandleSkip() # Success is stored in the results log for a stage that completed # successfully in a previous run. But, we report the truth to CIDB. result = results_lib.Results.SUCCESS cidb_result = constants.BUILDER_STATUS_SKIPPED # Copy over metadata from the previous record. instead of returning # metadata about the current run. board = previous_record.board elapsed_time = float(previous_record.time) return self._WaitBuildStageInCIDB() ready = self.WaitUntilReady() if not ready: self._PrintLoudly( 'Stage %s precondition failed while waiting to start.' % self.name) # If WaitUntilReady is false, mark stage as skipped in Results and CIDB result = results_lib.Results.SKIPPED return # Ready to start, mark buildStage as inflight in CIDB self._Print('Preconditions for the stage successfully met. ' 'Beginning to execute stage...') self._StartBuildStageInCIDB() start_time = time.time() sys.stdout.flush() sys.stderr.flush() # TODO(davidjames): Verify that PerformStage always returns None. See # crbug.com/264781 self.PerformStage() result = results_lib.Results.SUCCESS except SystemExit as e: if e.code != 0: result, description, _ = self._TopHandleStageException() raise except Exception as e: if isinstance(e, failures_lib.ExitEarlyException): # One stage finished and exited early, not a failure. raise if mox is not None and isinstance(e, mox.Error): raise # Tell the build bot this step failed for the waterfall. result, description, retrying = self._TopHandleStageException() if result not in (results_lib.Results.FORGIVEN, results_lib.Results.SUCCESS): raise failures_lib.StepFailure() elif retrying: raise failures_lib.RetriableStepFailure() except BaseException: result, description, _ = self._TopHandleStageException() raise finally: # Some cases explicitly set a cidb status. For others, infer. if cidb_result is None: cidb_result = self._TranslateResultToCIDBStatus(result) if elapsed_time is None: elapsed_time = time.time() - start_time self._RecordResult(self.name, result, description, prefix=self._prefix, board=board, time=elapsed_time) self._FinishBuildStageInCIDBAndMonarch(cidb_result, elapsed_time) if isinstance(result, BaseException) and self._build_stage_id is not None: _, db = self._run.GetCIDBHandle() if db: failures_lib.ReportStageFailureToCIDB( db, self._build_stage_id, result) self._Finish() sys.stdout.flush() sys.stderr.flush()