Chromium Code Reviews| Index: scripts/slave/recipe_modules/perf_try/build_state.py |
| diff --git a/scripts/slave/recipe_modules/perf_try/build_state.py b/scripts/slave/recipe_modules/perf_try/build_state.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..40288eb2b07864ef49f7698a3d25ba35d9574399 |
| --- /dev/null |
| +++ b/scripts/slave/recipe_modules/perf_try/build_state.py |
| @@ -0,0 +1,100 @@ |
| +""" |
| + Most code in this class are copied or adapted from revision_state in |
| + auto_bisect module. Future refactoring is needed. |
| +""" |
| + |
| +import json |
| + |
| +class BuildState(object): |
| + |
| + def __init__(self, api, commit_hash): |
| + self.api = api |
| + self.commit_hash = str(commit_hash) |
| + self.build_file_path = self._get_build_file_path(commit_hash) |
| + self.build_archived = False |
| + |
| + def _get_build_file_path(self, commit_hash): |
| + revision_suffix = '%s.zip' % commit_hash |
| + return self._get_platform_gs_prefix() + revision_suffix |
| + |
| + """ |
|
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
|
| + Duplicate code from auto_bisect.revision_state._get_platform_gs_prefix |
| + """ |
| + def _get_platform_gs_prefix(self): |
| + bot_name = self.api.m.properties.get('buildername', '') |
| + if 'win' in bot_name: |
| + if any(b in bot_name for b in ['x64', 'gpu']): |
| + return 'gs://chrome-perf/Win x64 Builder/full-build-win32_' |
| + return 'gs://chrome-perf/Win Builder/full-build-win32_' |
| + if 'android' in bot_name: |
| + if 'nexus9' in bot_name: |
| + return 'gs://chrome-perf/android_perf_rel_arm64/full-build-linux_' |
| + return 'gs://chrome-perf/android_perf_rel/full-build-linux_' |
| + 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
|
| + 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
|
| + |
| + """ |
| + Duplicate code from auto_bisect.revision_state.api |
| + """ |
| + def _gsutil_file_exists(self, path): |
| + """Returns True if a file exists at the given GS path.""" |
| + api = self.api |
| + try: |
| + api.m.gsutil(['ls', path]) |
| + except api.m.step.StepFailure: # pragma: no cover |
| + return False |
| + return True |
| + |
| + """ |
| + Duplicate code from auto_bisect.revision_state.is_build_archived |
| + """ |
| + def is_build_archived(self): |
| + """Checks if the revision is already built and archived.""" |
| + if not self.build_archived: |
| + 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
|
| + self.build_archived = self._gsutil_file_exists(self.build_url) |
| + return self.build_archived |
| + |
| + """ |
| + Duplicate code from auto_bisect.revision_state._fetch_build_info |
| + """ |
| + def _fetch_build_info(self, base_url, build_number): |
| + api = self.api |
| + build_url = '%s/builds/%s?as_text=1' % (base_url, build_number) |
| + fetch_result = api.m.url.fetch( build_url, step_name='fetch build details') |
| + return json.loads(fetch_result or '{}') |
| + |
| + """ |
| + Duplicate code from auto_bisect.revision_state.is_build_failed |
| + """ |
| + def is_build_failed(self): |
| + api = self.api |
| + current_build = None |
| + path = 'json/builders/' + api.get_builder_bot_for_this_platform() |
| + base_url = api.m.properties.get('buildbotURL', 'http://localhost:8041/') |
| + base_url += path |
| + 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
|
| + try: |
| + # Get all the current builds. |
| + builder_state_url = base_url + '?as_text=1' |
| + builder_state = api.m.url.fetch( |
| + builder_state_url, step_name='fetch builder state') |
| + builder_state = json.loads(builder_state or '{}') |
| + for build_number in builder_state.get('cachedBuilds', []): |
| + build = self._fetch_build_info(base_url, build_number) |
| + # Properties is a list of triples (key, value, source) |
| + build_properties = dict([t[:2] for t in build.get('properties', [])]) |
| + if build_properties.get('build_archive_url') == self.build_url: |
| + self.build_number = build_number |
| + current_build = build |
| + break |
| + except (api.m.step.StepFailure, ValueError): # pragma: no cover |
| + # If we cannot get json from buildbot, we cannot determine if a build is |
| + # failed, hence we consider it in progress until it times out. |
| + return False |
| + if self.build_number is None: |
| + # The build hasn't started yet, therefore it's not failed. |
| + return False |
| + if not current_build: |
| + current_build = self._fetch_build_info(base_url, self.build_number) |
| + 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
|