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

Side by Side Diff: scripts/slave/recipe_modules/goma/api.py

Issue 2207273003: Implement upload_logs() in recipe_modules/goma (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/build.git@master
Patch Set: change for coverage Created 4 years, 4 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 unified diff | Download patch
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from recipe_engine import recipe_api 5 from recipe_engine import recipe_api
6 6
7 class GomaApi(recipe_api.RecipeApi): 7 class GomaApi(recipe_api.RecipeApi):
8 """GomaApi contains helper functions for using goma.""" 8 """GomaApi contains helper functions for using goma."""
9 9
10 def __init__(self, **kwargs): 10 def __init__(self, **kwargs):
11 super(GomaApi, self).__init__(**kwargs) 11 super(GomaApi, self).__init__(**kwargs)
12 self._goma_dir = None 12 self._goma_dir = None
13 self._goma_started = False 13 self._goma_started = False
14 14
15 self._goma_ctl_env = {}
16
15 @property 17 @property
16 def service_account_json_path(self): 18 def service_account_json_path(self):
17 if self.m.platform.is_win: 19 if self.m.platform.is_win:
18 return 'C:\\creds\\service_accounts\\service-account-goma-client.json' 20 return 'C:\\creds\\service_accounts\\service-account-goma-client.json'
19 return '/creds/service_accounts/service-account-goma-client.json' 21 return '/creds/service_accounts/service-account-goma-client.json'
20 22
21 def ensure_goma(self, canary=False): 23 def ensure_goma(self, canary=False):
22 with self.m.step.nest('ensure_goma'): 24 with self.m.step.nest('ensure_goma'):
23 with self.m.step.context({'infra_step': True}): 25 with self.m.step.context({'infra_step': True}):
24 try: 26 try:
25 self.m.cipd.set_service_account_credentials( 27 self.m.cipd.set_service_account_credentials(
26 self.service_account_json_path) 28 self.service_account_json_path)
27 29
28 self.m.cipd.install_client() 30 self.m.cipd.install_client()
29 goma_package = ('infra_internal/goma/client/%s' % 31 goma_package = ('infra_internal/goma/client/%s' %
30 self.m.cipd.platform_suffix()) 32 self.m.cipd.platform_suffix())
31 # For Windows there's only 64-bit goma client. 33 # For Windows there's only 64-bit goma client.
32 if self.m.platform.is_win: 34 if self.m.platform.is_win:
33 goma_package = goma_package.replace('386', 'amd64') 35 goma_package = goma_package.replace('386', 'amd64')
34 ref='release' 36 ref='release'
35 if canary: 37 if canary:
36 ref='candidate' 38 ref='candidate'
37 self._goma_dir = self.m.path['cache'].join('cipd', 'goma') 39 self._goma_dir = self.m.path['cache'].join('cipd', 'goma')
38 self.m.cipd.ensure(self._goma_dir, {goma_package: ref}) 40 self.m.cipd.ensure(self._goma_dir, {goma_package: ref})
39 return self._goma_dir 41 return self._goma_dir
40 except self.m.step.StepFailure: 42 except self.m.step.StepFailure:
41 # TODO(phajdan.jr): make failures fatal after experiment. 43 # TODO(phajdan.jr): make failures fatal after experiment.
42 return None 44 return None
43 45
46 @property
47 def goma_ctl(self):
48 return self.m.path.join(self._goma_dir, 'goma_ctl.py')
49
50 @property
51 def build_data_dir(self):
52 return self.m.properties.get('build_data_dir')
53
44 def start(self, env=None, **kwargs): 54 def start(self, env=None, **kwargs):
45 """Start goma compiler_proxy. 55 """Start goma compiler_proxy.
46 56
47 A user MUST execute ensure_goma beforehand. 57 A user MUST execute ensure_goma beforehand.
48 It is user's responsibility to handle failure of starting compiler_proxy. 58 It is user's responsibility to handle failure of starting compiler_proxy.
49 """ 59 """
50 assert self._goma_dir 60 assert self._goma_dir
51 assert not self._goma_started 61 assert not self._goma_started
52 if not env:
53 env = {}
54 env.update({'GOMA_SERVICE_ACCOUNT_JSON_FILE': self.service_account_json_path })
55 self.m.python(
56 name='start_goma',
57 script=self.m.path.join(self._goma_dir, 'goma_ctl.py'),
58 args=['restart'], env=env, **kwargs)
59 self._goma_started = True
60 62
61 def stop(self, goma_dir=None, **kwargs): 63 if self.build_data_dir:
64 self._goma_ctl_env['GOMA_DUMP_STATS_FILE'] = (
65 self.m.path.join(self.build_data_dir, 'goma_stats_proto'))
66 self._goma_ctl_env['GOMACTL_CRASH_REPORT_ID_FILE'] = (
67 self.m.path.join(self.build_data_dir, 'crash_report_id_file'))
68
69 self._goma_ctl_env['GOMA_SERVICE_ACCOUNT_JSON_FILE'] = (
70 self.service_account_json_path)
71
72 goma_ctl_start_env = self._goma_ctl_env.copy()
73
74 if env is not None:
75 goma_ctl_start_env.update(env)
76
77 try:
78 self.m.python(
79 name='start_goma',
80 script=self.goma_ctl,
81 args=['restart'], env=goma_ctl_start_env, infra_step=True, **kwargs)
82 self._goma_started = True
83 except self.m.step.InfraFailure as e: # pragma: no cover
84 upload_logs_name = 'upload_goma_start_failed_logs'
85
86 try:
87 self.m.python(
88 name='stop_goma (start failure)',
89 script=self.goma_ctl,
90 args=['stop'], env=self._goma_ctl_env, **kwargs)
91 except self.m.step.StepFailure:
92 upload_logs_name = 'upload_goma_start_and_stop_failed_logs'
93
94 self.upload_logs(name=upload_logs_name)
95 raise e
96
97 def stop(self, ninja_log_outdir=None, ninja_log_compiler=None,
98 ninja_log_command=None, ninja_log_exit_status=None, **kwargs):
62 """Stop goma compiler_proxy. 99 """Stop goma compiler_proxy.
63 100
64 A user MUST execute start beforehand. 101 A user MUST execute start beforehand.
65 It is user's responsibility to handle failure of stopping compiler_proxy. 102 It is user's responsibility to handle failure of stopping compiler_proxy.
66 """ 103 """
67 assert self._goma_dir 104 assert self._goma_dir
68 assert self._goma_started 105 assert self._goma_started
69 self.m.python( 106 self.m.python(
70 name='stop_goma', 107 name='stop_goma',
71 script=self.m.path.join(self._goma_dir, 'goma_ctl.py'), 108 script=self.goma_ctl,
72 args=['stop'], **kwargs) 109 args=['stop'], env=self._goma_ctl_env, **kwargs)
110
111 self.upload_logs(ninja_log_outdir, ninja_log_compiler, ninja_log_command,
112 ninja_log_exit_status)
113
73 self._goma_started = False 114 self._goma_started = False
115 self._goma_ctl_env = {}
116
117 def upload_logs(self, ninja_log_outdir=None, ninja_log_compiler=None,
118 ninja_log_command=None, ninja_log_exit_status=None,
119 name=None):
120 args = [
121 '--upload-compiler-proxy-info'
122 ]
123
124 if ninja_log_outdir:
125 assert ninja_log_compiler is not None
126 assert ninja_log_command is not None
127 assert ninja_log_exit_status is not None
128
129 args.extend([
130 '--ninja-log-outdir', ninja_log_outdir,
131 '--ninja-log-compiler', ninja_log_compiler,
132 '--ninja-log-command', ninja_log_command,
133 '--ninja-log-exit-status', ninja_log_exit_status,
134 ])
135
136 if self.build_data_dir:
137 args.extend([
138 '--goma-stats-file', self._goma_ctl_env['GOMA_DUMP_STATS_FILE'],
139 '--goma-crash-report-id-file',
140 self._goma_ctl_env['GOMACTL_CRASH_REPORT_ID_FILE'],
141 '--build-data-dir', self.build_data_dir,
142 ])
143
144 self.m.python(
145 name=name or 'upload_log',
146 script=self.package_repo_resource(
147 'scripts', 'slave', 'upload_goma_logs.py'),
148 args=args
149 )
OLDNEW
« no previous file with comments | « scripts/slave/recipe_modules/goma/__init__.py ('k') | scripts/slave/recipe_modules/goma/example.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698