OLD | NEW |
---|---|
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 import os | 5 import os |
6 | 6 |
7 from recipe_engine import recipe_api | 7 from recipe_engine import recipe_api |
8 | 8 |
9 class GomaApi(recipe_api.RecipeApi): | 9 class GomaApi(recipe_api.RecipeApi): |
10 """GomaApi contains helper functions for using goma.""" | 10 """GomaApi contains helper functions for using goma.""" |
11 | 11 |
12 def __init__(self, **kwargs): | 12 def __init__(self, **kwargs): |
13 super(GomaApi, self).__init__(**kwargs) | 13 super(GomaApi, self).__init__(**kwargs) |
14 self._goma_dir = None | 14 self._goma_dir = None |
15 self._goma_started = False | 15 self._goma_started = False |
16 | 16 |
17 self._goma_ctl_env_init() | 17 self._goma_ctl_env_init() |
18 | 18 |
19 def _goma_ctl_env_init(self): | 19 def _goma_ctl_env_init(self): |
20 self._goma_ctl_env = {} | 20 self._goma_ctl_env = {} |
21 self._cloudtail_pid = None | |
21 | 22 |
22 # Inherit some env vars used in goma_utils.SendGomaTsMon. | 23 # Inherit some env vars used in goma_utils.SendGomaTsMon. |
23 for key in ['BUILDBOT_BUILDERNAME', | 24 for key in ['BUILDBOT_BUILDERNAME', |
24 'BUILDBOT_MASTERNAME', | 25 'BUILDBOT_MASTERNAME', |
25 'BUILDBOT_SLAVENAME', | 26 'BUILDBOT_SLAVENAME', |
26 'BUILDBOT_CLOBBER', | 27 'BUILDBOT_CLOBBER', |
27 'TEST_TMPDIR', | 28 'TEST_TMPDIR', |
28 'TMPDIR', | 29 'TMPDIR', |
29 'TMP', | 30 'TMP', |
30 ]: | 31 ]: |
31 if key in os.environ: # pragma: no cover | 32 if key in os.environ: # pragma: no cover |
32 self._goma_ctl_env[key] = os.environ[key] | 33 self._goma_ctl_env[key] = os.environ[key] |
33 | 34 |
34 @property | 35 @property |
35 def service_account_json_path(self): | 36 def service_account_json_path(self): |
36 if self.m.platform.is_win: | 37 if self.m.platform.is_win: |
37 return 'C:\\creds\\service_accounts\\service-account-goma-client.json' | 38 return 'C:\\creds\\service_accounts\\service-account-goma-client.json' |
38 return '/creds/service_accounts/service-account-goma-client.json' | 39 return '/creds/service_accounts/service-account-goma-client.json' |
39 | 40 |
41 @property | |
42 def cloudtail_path(self): | |
43 if self.m.platform.is_win: | |
44 return 'C:\\infra-tools\\cloudtail' | |
45 return '/opt/infra-tools/cloudtail' | |
46 | |
40 def ensure_goma(self, canary=False): | 47 def ensure_goma(self, canary=False): |
41 with self.m.step.nest('ensure_goma'): | 48 with self.m.step.nest('ensure_goma'): |
42 with self.m.step.context({'infra_step': True}): | 49 with self.m.step.context({'infra_step': True}): |
43 try: | 50 try: |
44 self.m.cipd.set_service_account_credentials( | 51 self.m.cipd.set_service_account_credentials( |
45 self.service_account_json_path) | 52 self.service_account_json_path) |
46 | 53 |
47 self.m.cipd.install_client() | 54 self.m.cipd.install_client() |
48 goma_package = ('infra_internal/goma/client/%s' % | 55 goma_package = ('infra_internal/goma/client/%s' % |
49 self.m.cipd.platform_suffix()) | 56 self.m.cipd.platform_suffix()) |
50 # For Windows there's only 64-bit goma client. | 57 # For Windows there's only 64-bit goma client. |
51 if self.m.platform.is_win: | 58 if self.m.platform.is_win: |
52 goma_package = goma_package.replace('386', 'amd64') | 59 goma_package = goma_package.replace('386', 'amd64') |
53 ref='release' | 60 ref='release' |
54 if canary: | 61 if canary: |
55 ref='candidate' | 62 ref='candidate' |
56 self._goma_dir = self.m.path['cache'].join('cipd', 'goma') | 63 self._goma_dir = self.m.path['cache'].join('cipd', 'goma') |
57 self.m.cipd.ensure(self._goma_dir, {goma_package: ref}) | 64 self.m.cipd.ensure(self._goma_dir, {goma_package: ref}) |
65 | |
66 # TODO(tikuta) download cloudtail from cipd here | |
67 | |
58 return self._goma_dir | 68 return self._goma_dir |
59 except self.m.step.StepFailure: | 69 except self.m.step.StepFailure: |
60 # TODO(phajdan.jr): make failures fatal after experiment. | 70 # TODO(phajdan.jr): make failures fatal after experiment. |
61 return None | 71 return None |
62 | 72 |
63 @property | 73 @property |
64 def goma_ctl(self): | 74 def goma_ctl(self): |
65 return self.m.path.join(self._goma_dir, 'goma_ctl.py') | 75 return self.m.path.join(self._goma_dir, 'goma_ctl.py') |
66 | 76 |
67 @property | 77 @property |
68 def build_data_dir(self): | 78 def build_data_dir(self): |
69 return self.m.properties.get('build_data_dir') | 79 return self.m.properties.get('build_data_dir') |
70 | 80 |
81 def _start_cloudtail(self): | |
82 """Start cloudtail to upload compiler_proxy.INFO | |
83 | |
84 Raises: | |
85 InfraFailure if it fails to start cloudtail | |
86 """ | |
87 | |
88 assert self._cloudtail_pid is None | |
89 | |
90 step_result = self.m.python( | |
91 name='start cloudtail', | |
92 script=self.resource('cloudtail_utils.py'), | |
93 args=['start', | |
94 '--cloudtail-path', self.cloudtail_path], | |
95 env=self._goma_ctl_env, | |
96 stdout=self.m.raw_io.output(), | |
97 step_test_data=( | |
98 lambda: self.m.raw_io.test_api.stream_output('12345')), | |
99 infra_step=True) | |
100 | |
101 self._cloudtail_pid = step_result.stdout | |
102 | |
103 def _stop_cloudtail(self): | |
104 """Stop cloudtail started by _start_cloudtail | |
105 | |
106 Raises: | |
107 InfraFailure if it fails to stop cloudtail | |
108 """ | |
109 | |
110 assert self._cloudtail_pid is not None | |
111 | |
112 self.m.python( | |
113 name='stop cloudtail', | |
114 script=self.resource('cloudtail_utils.py'), | |
115 args=['stop', | |
116 '--killed-pid', self._cloudtail_pid], | |
117 infra_step=True) | |
118 | |
119 self._cloudtail_pid = None | |
120 | |
71 def start(self, env=None, **kwargs): | 121 def start(self, env=None, **kwargs): |
72 """Start goma compiler_proxy. | 122 """Start goma compiler_proxy. |
73 | 123 |
74 A user MUST execute ensure_goma beforehand. | 124 A user MUST execute ensure_goma beforehand. |
75 It is user's responsibility to handle failure of starting compiler_proxy. | 125 It is user's responsibility to handle failure of starting compiler_proxy. |
76 """ | 126 """ |
77 assert self._goma_dir | 127 assert self._goma_dir |
78 assert not self._goma_started | 128 assert not self._goma_started |
79 | 129 |
80 if self.build_data_dir: | 130 if self.build_data_dir: |
(...skipping 12 matching lines...) Expand all Loading... | |
93 | 143 |
94 if env is not None: | 144 if env is not None: |
95 goma_ctl_start_env.update(env) | 145 goma_ctl_start_env.update(env) |
96 | 146 |
97 try: | 147 try: |
98 self.m.python( | 148 self.m.python( |
99 name='start_goma', | 149 name='start_goma', |
100 script=self.goma_ctl, | 150 script=self.goma_ctl, |
101 args=['restart'], env=goma_ctl_start_env, infra_step=True, **kwargs) | 151 args=['restart'], env=goma_ctl_start_env, infra_step=True, **kwargs) |
102 self._goma_started = True | 152 self._goma_started = True |
153 | |
154 self._start_cloudtail() | |
155 | |
103 except self.m.step.InfraFailure as e: # pragma: no cover | 156 except self.m.step.InfraFailure as e: # pragma: no cover |
104 upload_logs_name = 'upload_goma_start_failed_logs' | 157 upload_logs_name = 'upload_goma_start_failed_logs' |
105 | 158 |
106 try: | 159 try: |
107 self.m.python( | 160 self.m.python( |
108 name='stop_goma (start failure)', | 161 name='stop_goma (start failure)', |
109 script=self.goma_ctl, | 162 script=self.goma_ctl, |
110 args=['stop'], env=self._goma_ctl_env, **kwargs) | 163 args=['stop'], env=self._goma_ctl_env, **kwargs) |
111 except self.m.step.StepFailure: | 164 except self.m.step.StepFailure: |
112 upload_logs_name = 'upload_goma_start_and_stop_failed_logs' | 165 upload_logs_name = 'upload_goma_start_and_stop_failed_logs' |
113 | 166 |
114 self.upload_logs(name=upload_logs_name) | 167 self.upload_logs(name=upload_logs_name) |
115 raise e | 168 raise e |
116 | 169 |
117 def stop(self, ninja_log_outdir=None, ninja_log_compiler=None, | 170 def stop(self, ninja_log_outdir=None, ninja_log_compiler=None, |
118 ninja_log_command=None, ninja_log_exit_status=None, **kwargs): | 171 ninja_log_command=None, ninja_log_exit_status=None, **kwargs): |
119 """Stop goma compiler_proxy. | 172 """Stop goma compiler_proxy. |
120 | 173 |
121 A user MUST execute start beforehand. | 174 A user MUST execute start beforehand. |
122 It is user's responsibility to handle failure of stopping compiler_proxy. | 175 It is user's responsibility to handle failure of stopping compiler_proxy. |
176 | |
177 Raises: | |
178 StepFailure if it fails to stop goma or upload logs. | |
123 """ | 179 """ |
180 | |
124 assert self._goma_dir | 181 assert self._goma_dir |
125 assert self._goma_started | 182 assert self._goma_started |
126 self.m.python( | |
127 name='stop_goma', | |
128 script=self.goma_ctl, | |
129 args=['stop'], env=self._goma_ctl_env, **kwargs) | |
130 | 183 |
131 self.upload_logs(ninja_log_outdir, ninja_log_compiler, ninja_log_command, | 184 try: |
132 ninja_log_exit_status) | 185 |
186 self.m.python( | |
187 name='stop_goma', | |
188 script=self.goma_ctl, | |
189 args=['stop'], env=self._goma_ctl_env, **kwargs) | |
190 self.upload_logs(ninja_log_outdir, ninja_log_compiler, ninja_log_command, | |
ukai
2016/08/18 04:04:53
want upload ninja log even if stop goma fails?
tikuta
2016/08/18 06:17:03
Done.
| |
191 ninja_log_exit_status) | |
192 finally: | |
193 self._stop_cloudtail() | |
133 | 194 |
134 self._goma_started = False | 195 self._goma_started = False |
135 self._goma_ctl_env_init() | 196 self._goma_ctl_env_init() |
136 | 197 |
137 | 198 |
138 def upload_logs(self, ninja_log_outdir=None, ninja_log_compiler=None, | 199 def upload_logs(self, ninja_log_outdir=None, ninja_log_compiler=None, |
139 ninja_log_command=None, ninja_log_exit_status=None, | 200 ninja_log_command=None, ninja_log_exit_status=None, |
140 name=None): | 201 name=None): |
141 args = [ | 202 args = [ |
142 '--upload-compiler-proxy-info' | 203 '--upload-compiler-proxy-info' |
(...skipping 19 matching lines...) Expand all Loading... | |
162 '--build-data-dir', self.build_data_dir, | 223 '--build-data-dir', self.build_data_dir, |
163 ]) | 224 ]) |
164 | 225 |
165 self.m.python( | 226 self.m.python( |
166 name=name or 'upload_log', | 227 name=name or 'upload_log', |
167 script=self.package_repo_resource( | 228 script=self.package_repo_resource( |
168 'scripts', 'slave', 'upload_goma_logs.py'), | 229 'scripts', 'slave', 'upload_goma_logs.py'), |
169 args=args, | 230 args=args, |
170 env=self._goma_ctl_env | 231 env=self._goma_ctl_env |
171 ) | 232 ) |
OLD | NEW |