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

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: rebase 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
17 # options for upload_goma_logs.py
18 # TODO(tikuta) set these variables
Paweł Hajdan Jr. 2016/08/09 07:04:36 Why is this a TODO? If we're not setting/using som
tikuta 2016/08/09 07:58:09 Done.
19 self._ninja_log_outdir = None
20 self._ninja_log_compiler = None
21 self._ninja_log_command = None
22 self._ninja_log_exit_status = None
23
24 self._build_data_dir = None
25
26
15 @property 27 @property
16 def service_account_json_path(self): 28 def service_account_json_path(self):
17 if self.m.platform.is_win: 29 if self.m.platform.is_win:
18 return 'C:\\creds\\service_accounts\\service-account-goma-client.json' 30 return 'C:\\creds\\service_accounts\\service-account-goma-client.json'
19 return '/creds/service_accounts/service-account-goma-client.json' 31 return '/creds/service_accounts/service-account-goma-client.json'
20 32
21 def ensure_goma(self, canary=False): 33 def ensure_goma(self, canary=False):
22 with self.m.step.nest('ensure_goma'): 34 with self.m.step.nest('ensure_goma'):
23 with self.m.step.context({'infra_step': True}): 35 with self.m.step.context({'infra_step': True}):
24 try: 36 try:
25 self.m.cipd.set_service_account_credentials( 37 self.m.cipd.set_service_account_credentials(
26 self.service_account_json_path) 38 self.service_account_json_path)
27 39
28 self.m.cipd.install_client() 40 self.m.cipd.install_client()
29 goma_package = ('infra_internal/goma/client/%s' % 41 goma_package = ('infra_internal/goma/client/%s' %
30 self.m.cipd.platform_suffix()) 42 self.m.cipd.platform_suffix())
31 # For Windows there's only 64-bit goma client. 43 # For Windows there's only 64-bit goma client.
32 if self.m.platform.is_win: 44 if self.m.platform.is_win:
33 goma_package = goma_package.replace('386', 'amd64') 45 goma_package = goma_package.replace('386', 'amd64')
34 ref='release' 46 ref='release'
35 if canary: 47 if canary:
36 ref='candidate' 48 ref='candidate'
37 self._goma_dir = self.m.path['cache'].join('cipd', 'goma') 49 self._goma_dir = self.m.path['cache'].join('cipd', 'goma')
38 self.m.cipd.ensure(self._goma_dir, {goma_package: ref}) 50 self.m.cipd.ensure(self._goma_dir, {goma_package: ref})
39 return self._goma_dir 51 return self._goma_dir
40 except self.m.step.StepFailure: 52 except self.m.step.StepFailure:
41 # TODO(phajdan.jr): make failures fatal after experiment. 53 # TODO(phajdan.jr): make failures fatal after experiment.
42 return None 54 return None
43 55
56 @property
57 def goma_ctl(self):
58 return self.m.path.join(self._goma_dir, 'goma_ctl.py')
59
44 def start(self, env=None, **kwargs): 60 def start(self, env=None, **kwargs):
45 """Start goma compiler_proxy. 61 """Start goma compiler_proxy.
46 62
47 A user MUST execute ensure_goma beforehand. 63 A user MUST execute ensure_goma beforehand.
48 It is user's responsibility to handle failure of starting compiler_proxy. 64 It is user's responsibility to handle failure of starting compiler_proxy.
49 """ 65 """
50 assert self._goma_dir 66 assert self._goma_dir
51 assert not self._goma_started 67 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 68
61 def stop(self, goma_dir=None, **kwargs): 69 if self.m.properties.get('build_data_dir'):
Paweł Hajdan Jr. 2016/08/09 07:04:36 Would it fit better in the ctor, or a dedicated me
tikuta 2016/08/09 07:58:09 Done.
70 self._build_data_dir = self.m.properties.get('build_data_dir')
71 self._goma_ctl_env['GOMA_DUMP_STATS_FILE'] = (
72 self.m.path.join(self._build_data_dir, 'goma_stats_proto'))
73 self._goma_ctl_env['GOMACTL_CRASH_REPORT_ID_FILE'] = (
74 self.m.path.join(self._build_data_dir, 'crash_report_id_file'))
75
76 self._goma_ctl_env['GOMA_SERVICE_ACCOUNT_JSON_FILE'] = (
77 self.service_account_json_path)
78
79 if env:
80 self._goma_ctl_env.update(env)
Paweł Hajdan Jr. 2016/08/09 07:04:36 This introduces state that survives this one metho
tikuta 2016/08/09 07:58:09 Done.
81
82 try:
83 self.m.python(
84 name='start_goma',
85 script=self.goma_ctl,
86 args=['restart'], env=self._goma_ctl_env, **kwargs)
Paweł Hajdan Jr. 2016/08/09 07:04:36 Set infra_step=True here.
tikuta 2016/08/09 07:58:09 Done.
87 self._goma_started = True
88 except self.m.step.StepFailure as e:
89 upload_logs_name = 'upload_goma_start_failed_logs'
90
91 try:
92 self.m.python(
93 name='stop_goma (start failure)',
94 script=self.goma_ctl,
95 args=['stop'], env=self._goma_ctl_env, **kwargs)
96 except self.m.step.StepFailure:
97 upload_logs_name = 'upload_goma_start_and_stop_failed_logs'
98
99 self.upload_logs(upload_logs_name)
100 raise self.m.step.InfraFailure('Infra goma start failure: %s' % e)
Paweł Hajdan Jr. 2016/08/09 07:04:36 This way you'd be able to just re-raise the _same_
tikuta 2016/08/09 07:58:10 Done.
101
102 def stop(self, **kwargs):
62 """Stop goma compiler_proxy. 103 """Stop goma compiler_proxy.
63 104
64 A user MUST execute start beforehand. 105 A user MUST execute start beforehand.
65 It is user's responsibility to handle failure of stopping compiler_proxy. 106 It is user's responsibility to handle failure of stopping compiler_proxy.
66 """ 107 """
67 assert self._goma_dir 108 assert self._goma_dir
68 assert self._goma_started 109 assert self._goma_started
69 self.m.python( 110 self.m.python(
70 name='stop_goma', 111 name='stop_goma',
71 script=self.m.path.join(self._goma_dir, 'goma_ctl.py'), 112 script=self.goma_ctl,
72 args=['stop'], **kwargs) 113 args=['stop'], env=self._goma_ctl_env, **kwargs)
114
115 self.upload_logs()
116
73 self._goma_started = False 117 self._goma_started = False
118 self._goma_ctl_env = {}
119
120
121 def upload_logs(self, name=None):
122 args = [
123 '--upload-compiler-proxy-info'
124 ]
125
126 if self._ninja_log_outdir:
127 args.extend([
128 '--ninja-log-outdir', self._ninja_log_outdir,
129 '--ninja-log-compiler', self._ninja_log_compiler,
130 '--ninja-log-command', self._ninja_log_command,
131 '--ninja-log-exit-status', self._ninja_log_exit_status,
132 ])
133
134 if self._build_data_dir:
135 args.extend([
136 '--goma-stats-file', self._goma_ctl_env['GOMA_DUMP_STATS_FILE'],
137 '--goma-crash-report-id-file',
138 self._goma_ctl_env['GOMACTL_CRASH_REPORT_ID_FILE'],
139 '--build-data-dir', self._build_data_dir,
140 ])
141
142 self.m.python(
143 name=name or 'upload_log',
144 script=self.package_repo_resource(
145 'scripts', 'slave', 'upload_goma_logs.py'),
146 args=args
147 )
OLDNEW
« no previous file with comments | « scripts/slave/recipe_modules/goma/__init__.py ('k') | scripts/slave/recipe_modules/goma/example.expected/linux.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698