Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 """ | |
| 2 Most code in this class are copied or adapted from revision_state in | |
| 3 auto_bisect module. Future refactoring is needed. | |
| 4 """ | |
| 5 | |
| 6 import json | |
| 7 | |
| 8 class BuildState(object): | |
| 9 | |
| 10 def __init__(self, api, commit_hash): | |
| 11 self.api = api | |
| 12 self.commit_hash = str(commit_hash) | |
| 13 self.build_file_path = self._get_build_file_path(commit_hash) | |
| 14 self.build_archived = False | |
| 15 | |
| 16 def _get_build_file_path(self, commit_hash): | |
| 17 revision_suffix = '%s.zip' % commit_hash | |
| 18 return self._get_platform_gs_prefix() + revision_suffix | |
| 19 | |
| 20 """ | |
|
RobertoCN
2016/06/14 18:37:49
This string should be a comment instead, same for
Ziqi Xiong
2016/06/17 18:41:30
Fixed in patchset: 20001
| |
| 21 Duplicate code from auto_bisect.revision_state._get_platform_gs_prefix | |
| 22 """ | |
| 23 def _get_platform_gs_prefix(self): | |
| 24 bot_name = self.api.m.properties.get('buildername', '') | |
| 25 if 'win' in bot_name: | |
| 26 if any(b in bot_name for b in ['x64', 'gpu']): | |
| 27 return 'gs://chrome-perf/Win x64 Builder/full-build-win32_' | |
| 28 return 'gs://chrome-perf/Win Builder/full-build-win32_' | |
| 29 if 'android' in bot_name: | |
| 30 if 'nexus9' in bot_name: | |
| 31 return 'gs://chrome-perf/android_perf_rel_arm64/full-build-linux_' | |
| 32 return 'gs://chrome-perf/android_perf_rel/full-build-linux_' | |
| 33 if 'mac' in bot_name: | |
|
RobertoCN
2016/06/14 18:37:48
What about Linux?
Ziqi Xiong
2016/06/17 18:41:30
Fixed in patchset: 20001
| |
| 34 return 'gs://chrome-perf/Mac Builder/full-build-mac_' | |
|
RobertoCN
2016/06/14 18:37:49
There is no default return. In the case where buil
Ziqi Xiong
2016/06/17 18:41:30
Fixed in patchset: 20001
| |
| 35 | |
| 36 """ | |
| 37 Duplicate code from auto_bisect.revision_state.api | |
| 38 """ | |
| 39 def _gsutil_file_exists(self, path): | |
| 40 """Returns True if a file exists at the given GS path.""" | |
| 41 api = self.api | |
| 42 try: | |
| 43 api.m.gsutil(['ls', path]) | |
| 44 except api.m.step.StepFailure: # pragma: no cover | |
| 45 return False | |
| 46 return True | |
| 47 | |
| 48 """ | |
| 49 Duplicate code from auto_bisect.revision_state.is_build_archived | |
| 50 """ | |
| 51 def is_build_archived(self): | |
| 52 """Checks if the revision is already built and archived.""" | |
| 53 if not self.build_archived: | |
| 54 api = self.bisector.api | |
|
RobertoCN
2016/06/14 18:37:48
bisector doesn't exist in this scope (or in this m
Ziqi Xiong
2016/06/17 18:41:30
Fixed in patchset: 20001
| |
| 55 self.build_archived = self._gsutil_file_exists(self.build_url) | |
| 56 return self.build_archived | |
| 57 | |
| 58 """ | |
| 59 Duplicate code from auto_bisect.revision_state._fetch_build_info | |
| 60 """ | |
| 61 def _fetch_build_info(self, base_url, build_number): | |
| 62 api = self.api | |
| 63 build_url = '%s/builds/%s?as_text=1' % (base_url, build_number) | |
| 64 fetch_result = api.m.url.fetch( build_url, step_name='fetch build details') | |
| 65 return json.loads(fetch_result or '{}') | |
| 66 | |
| 67 """ | |
| 68 Duplicate code from auto_bisect.revision_state.is_build_failed | |
| 69 """ | |
| 70 def is_build_failed(self): | |
| 71 api = self.api | |
| 72 current_build = None | |
| 73 path = 'json/builders/' + api.get_builder_bot_for_this_platform() | |
| 74 base_url = api.m.properties.get('buildbotURL', 'http://localhost:8041/') | |
| 75 base_url += path | |
| 76 if self.build_number is None: | |
|
RobertoCN
2016/06/14 18:37:49
This attribute needs to be initialized to None in
Ziqi Xiong
2016/06/17 18:41:30
Fixed in patchset: 20001
| |
| 77 try: | |
| 78 # Get all the current builds. | |
| 79 builder_state_url = base_url + '?as_text=1' | |
| 80 builder_state = api.m.url.fetch( | |
| 81 builder_state_url, step_name='fetch builder state') | |
| 82 builder_state = json.loads(builder_state or '{}') | |
| 83 for build_number in builder_state.get('cachedBuilds', []): | |
| 84 build = self._fetch_build_info(base_url, build_number) | |
| 85 # Properties is a list of triples (key, value, source) | |
| 86 build_properties = dict([t[:2] for t in build.get('properties', [])]) | |
| 87 if build_properties.get('build_archive_url') == self.build_url: | |
| 88 self.build_number = build_number | |
| 89 current_build = build | |
| 90 break | |
| 91 except (api.m.step.StepFailure, ValueError): # pragma: no cover | |
| 92 # If we cannot get json from buildbot, we cannot determine if a build is | |
| 93 # failed, hence we consider it in progress until it times out. | |
| 94 return False | |
| 95 if self.build_number is None: | |
| 96 # The build hasn't started yet, therefore it's not failed. | |
| 97 return False | |
| 98 if not current_build: | |
| 99 current_build = self._fetch_build_info(base_url, self.build_number) | |
| 100 return current_build.get('results') in [FAILURE, SKIPPED, EXCEPTION] | |
|
RobertoCN
2016/06/14 18:37:48
These constants are not defined
Ziqi Xiong
2016/06/17 18:41:30
Fixed in patchset: 20001
| |
| OLD | NEW |