def _GetSwarmingTaskIdForTryJob(report, revision, step_name, test_name): """Check json output for each task and return id of the one with test result. """ if not report: return None http_client = HttpClientAppengine() step_result = report.get('result', {}).get(revision, {}).get( step_name, {}) pass_fail_counts = step_result.get('pass_fail_counts', {}).get(test_name) task_ids = step_result.get('step_metadata', {}).get('swarm_task_ids', []) if len(task_ids) == 1: return task_ids[0] if not pass_fail_counts: # Test doesn't exist. return task_ids[0] if task_ids else None for task_id in task_ids: output_json = swarming_util.GetIsolatedOutputForTask(task_id, http_client) if output_json: for data in output_json.get('per_iteration_data', []): # If this task doesn't have result, per_iteration_data will look like # [{}, {}, ...] if data: return task_id return None
def FindMatchingWaterfallStep(build_step, test_name): """Finds the matching Waterfall step and checks whether it is supported. Only Swarmed and gtest-based steps are supported at the moment. Args: build_step (BuildStep): A build step on Waterfall or Commit Queue. It will be updated with the matching Waterfall step and whether it is Swarmed and supported. test_name (str): The name of the test. """ build_step.swarmed = False build_step.supported = False http_client = HttpClientAppengine() if build_step.on_cq: wf_master_name, wf_builder_name, wf_build_number, wf_step_name, metadata = ( _GetMatchingWaterfallBuildStep(build_step, http_client)) build_step.wf_master_name = wf_master_name build_step.wf_builder_name = wf_builder_name build_step.wf_build_number = wf_build_number build_step.wf_step_name = wf_step_name if not build_step.has_matching_waterfall_step: return else: build_step.wf_master_name = build_step.master_name build_step.wf_builder_name = build_step.builder_name build_step.wf_build_number = build_step.build_number build_step.wf_step_name = build_step.step_name metadata = buildbot.GetStepLog(build_step.master_name, build_step.builder_name, build_step.build_number, build_step.step_name, http_client, 'step_metadata') if not metadata: logging.error('Couldn\'t get step_metadata') return # Query Swarming for isolated data. build_step.swarmed = True if metadata.get('swarm_task_ids') else False if build_step.swarmed: # Retrieve a sample output from Isolate. task_id = metadata['swarm_task_ids'][0] output = swarming_util.GetIsolatedOutputForTask(task_id, http_client) if output: # Guess from the format. build_step.supported = ( isinstance(output, dict) and isinstance(output.get('all_tests'), list) and test_name in output.get('all_tests', []) and isinstance(output.get('per_iteration_data'), list) and all( isinstance(i, dict) for i in output.get('per_iteration_data')))
def testGetIsolatedOutputForTask(self): task_id = '2944afa502297110' self.http_client._SetResponseForGetRequestSwarmingResult(task_id) self.http_client._SetResponseForPostRequest('shard1_isolated') self.http_client._SetResponseForPostRequest('shard1_url') self.http_client._SetResponseForGetRequestIsolated( 'https://%s/default-gzip/shard1' % (waterfall_config.GetSwarmingSettings().get('isolated_storage_url') ), 'shard1') result = swarming_util.GetIsolatedOutputForTask( task_id, self.http_client) expected_result = json.loads( zlib.decompress(self.http_client._GetData('isolated', 'shard1'))) self.assertEqual(expected_result, result)
def testGetIsolatedOutputForTaskDataError(self, _): self.assertIsNone(swarming_util.GetIsolatedOutputForTask(None, None))
def testGetIsolatedOutputForTaskNoOutputRef(self, _): self.assertIsNone(swarming_util.GetIsolatedOutputForTask(None, None))