def GetBoundingIsolatedTargets(master_name, builder_name, target_name, commit_position): """Determines the IsolatedTarget instances surrounding a commit position. Args: master_name (str): The name of the master to search by. builder_name (str): The name of the builder to search by. target_name (str): The name of the target to search by, e.g. 'browser_tests'. commit_position (int): The desired commit position to find neighboring IsolatedTargets. Returns: (IsolatedTarget, IsolatedTarget): The lower and upper bound IsolatedTargets. """ upper_bound_targets = ( IsolatedTarget.FindIsolateAtOrAfterCommitPositionByMaster( master_name, builder_name, constants.GITILES_HOST, constants.GITILES_PROJECT, constants.GITILES_REF, target_name, commit_position)) lower_bound_targets = ( IsolatedTarget.FindIsolateBeforeCommitPositionByMaster( master_name, builder_name, constants.GITILES_HOST, constants.GITILES_PROJECT, constants.GITILES_REF, target_name, commit_position)) assert upper_bound_targets, (( 'Unable to detect isolated targets at for {}/{} with minimum commit ' 'position {}').format(master_name, builder_name, commit_position)) assert lower_bound_targets, (( 'Unable to detect isolated targets at for {}/{} below commit position' ' {}').format(master_name, builder_name, commit_position)) return lower_bound_targets[0], upper_bound_targets[0]
def testFindIsolateByMaster(self): before = IsolatedTarget.FindIsolateBeforeCommitPositionByMaster( 'chromium.linux', 'Linux Builder', 'chromium.googlesource.com', 'chromium/src', 'refs/heads/master', 'browser_tests', 55650) self.assertEqual(before[0], IsolatedTarget.get_by_id('843400990909049/browser_tests')) at = IsolatedTarget.FindIsolateAtOrAfterCommitPositionByMaster( 'chromium.linux', 'Linux Builder', 'chromium.googlesource.com', 'chromium/src', 'refs/heads/master', 'browser_tests', 55650) self.assertEqual(at[0], IsolatedTarget.get_by_id('843400990909050/browser_tests')) after = IsolatedTarget.FindIsolateAtOrAfterCommitPositionByMaster( 'chromium.linux', 'Linux Builder', 'chromium.googlesource.com', 'chromium/src', 'refs/heads/master', 'browser_tests', 55655) self.assertEqual(after[0], IsolatedTarget.get_by_id('843400990909051/browser_tests')) latest = IsolatedTarget.FindLatestIsolateByMaster( 'chromium.linux', 'Linux Builder', 'chromium.googlesource.com', 'chromium/src', 'refs/heads/master', 'browser_tests') self.assertEqual(latest[0], IsolatedTarget.get_by_id('843400990909099/browser_tests'))
def RunImpl(self, parameters): """Determines the Isolated sha to run in swarming given a commit position. If the requested commit position maps directly to a build, simply get that existing build's isolated sha. Otherwise, trigger a try job to compile and isolate at that revision and return the resulting sha. """ analysis = ndb.Key(urlsafe=parameters.analysis_urlsafe_key).get() assert analysis master_name = analysis.master_name builder_name = analysis.builder_name commit_position = parameters.commit_position step_name = analysis.step_name isolate_target_name = parameters.step_metadata.isolate_target_name reference_build_info = build_util.GetBuildInfo(master_name, builder_name, analysis.build_number) parent_mastername = (reference_build_info.parent_mastername or master_name) parent_buildername = (reference_build_info.parent_buildername or builder_name) targets = (IsolatedTarget.FindIsolateAtOrAfterCommitPositionByMaster( parent_mastername, parent_buildername, constants.GITILES_HOST, constants.GITILES_PROJECT, constants.GITILES_REF, isolate_target_name, commit_position)) # TODO(crbug.com/872992): Remove this entire branch's fallback logic once # LUCI migration is complete. if not targets: analysis.LogInfo(( 'No IsolatedTargets found for {}/{} with minimum commit position ' '{}. Falling back to searching buildbot').format( master_name, builder_name, commit_position)) _, earliest_containing_build = step_util.GetValidBoundingBuildsForStep( master_name, builder_name, step_name, None, parameters.upper_bound_build_number, commit_position) assert earliest_containing_build, ( 'Unable to find nearest build cycle with minimum commit position ' '{}'.format(commit_position)) build_commit_position = earliest_containing_build.commit_position assert build_commit_position >= commit_position, ( 'Upper bound build commit position {} is before {}'.format( build_commit_position, commit_position)) if build_commit_position == commit_position: # pragma: no branch get_build_sha_parameters = self.CreateInputObjectInstance( GetIsolateShaForBuildParameters, master_name=master_name, builder_name=builder_name, build_number=earliest_containing_build.build_number, step_name=step_name, url=buildbot.CreateBuildUrl( master_name, builder_name, earliest_containing_build.build_number)) yield GetIsolateShaForBuildPipeline(get_build_sha_parameters) return if targets: upper_bound_target = targets[0] if upper_bound_target.commit_position == commit_position: # The requested commit position is that of a found IsolatedTarget. get_target_input = GetIsolateShaForTargetInput( isolated_target_urlsafe_key=upper_bound_target.key.urlsafe( )) yield GetIsolateShaForTargetPipeline(get_target_input) return # The requested commit position needs to be compiled. cache_name = swarmbot_util.GetCacheName( parent_mastername, parent_buildername, suffix=flake_constants.FLAKE_CACHE_SUFFIX) test_name = analysis.test_name try_job = flake_try_job.GetTryJob(master_name, builder_name, step_name, test_name, parameters.revision) run_flake_try_job_parameters = self.CreateInputObjectInstance( RunFlakeTryJobParameters, analysis_urlsafe_key=parameters.analysis_urlsafe_key, revision=parameters.revision, flake_cache_name=cache_name, dimensions=parameters.dimensions, isolate_target_name=isolate_target_name, urlsafe_try_job_key=try_job.key.urlsafe()) with pipeline.InOrder(): try_job_result = yield RunFlakeTryJobPipeline( run_flake_try_job_parameters) get_isolate_sha_from_try_job_input = self.CreateInputObjectInstance( GetIsolateShaForTryJobParameters, try_job_result=try_job_result, step_name=step_name) yield GetIsolateShaForTryJobPipeline( get_isolate_sha_from_try_job_input)