Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(326)

Unified Diff: scripts/slave/recipe_modules/perf_try/build_state.py

Issue 2061893003: Build delegation for perf tryjobs (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/build.git@master
Patch Set: Fix errors found by robertocn Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..42e8aef80380a21cde5e528b6a0cca8fed229e87
--- /dev/null
+++ b/scripts/slave/recipe_modules/perf_try/build_state.py
@@ -0,0 +1,95 @@
+"""
+ 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):
+
+ SUCCESS, WARNINGS, FAILURE, SKIPPED, EXCEPTION = range(5)
+
+ 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
+ self.build_number = None
+
+ def _get_build_file_path(self, commit_hash):
+ revision_suffix = '%s.zip' % commit_hash
+ return self._get_platform_gs_prefix() + revision_suffix
+
+ #Duplicate code from auto_bisect.revision_state._get_platform_gs_prefix
+ def _get_platform_gs_prefix(self):
prasadv 2016/06/15 17:55:14 I don't think we should store these perf tryjob bu
Ziqi Xiong 2016/06/21 22:21:26 Done.
+ 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:
+ return 'gs://chrome-perf/Mac Builder/full-build-mac_'
+ return 'gs://chrome-perf/Linux Builder/full-build-linux'
+
+ #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.api
+ self.build_archived = self._gsutil_file_exists(self.build_file_path)
+ 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):
prasadv 2016/06/15 17:55:14 I think we should use buildbucket apis to determin
Ziqi Xiong 2016/06/17 18:41:31 Done.
prasadv 2016/06/20 18:31:47 Can you please check the feasibility of using buil
Ziqi Xiong 2016/06/21 22:21:26 Done.
+ 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:
+ 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]
« scripts/slave/recipe_modules/perf_try/api.py ('K') | « scripts/slave/recipe_modules/perf_try/api.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698