Chromium Code Reviews| 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 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 = {} | 15 self._goma_ctl_env = {} |
| 16 self._cloudtail_pid = None | |
| 16 | 17 |
| 17 @property | 18 @property |
| 18 def service_account_json_path(self): | 19 def service_account_json_path(self): |
| 19 if self.m.platform.is_win: | 20 if self.m.platform.is_win: |
| 20 return 'C:\\creds\\service_accounts\\service-account-goma-client.json' | 21 return 'C:\\creds\\service_accounts\\service-account-goma-client.json' |
| 21 return '/creds/service_accounts/service-account-goma-client.json' | 22 return '/creds/service_accounts/service-account-goma-client.json' |
| 22 | 23 |
| 24 @property | |
| 25 def cloudtail_path(self): | |
| 26 if self.m.platform.is_win: | |
| 27 return 'C:\\infra-tools\\cloudtail' | |
| 28 return '/opt/infra-tools/cloudtail' | |
| 29 | |
| 23 def ensure_goma(self, canary=False): | 30 def ensure_goma(self, canary=False): |
| 24 with self.m.step.nest('ensure_goma'): | 31 with self.m.step.nest('ensure_goma'): |
| 25 with self.m.step.context({'infra_step': True}): | 32 with self.m.step.context({'infra_step': True}): |
| 26 try: | 33 try: |
| 27 self.m.cipd.set_service_account_credentials( | 34 self.m.cipd.set_service_account_credentials( |
| 28 self.service_account_json_path) | 35 self.service_account_json_path) |
| 29 | 36 |
| 30 self.m.cipd.install_client() | 37 self.m.cipd.install_client() |
| 31 goma_package = ('infra_internal/goma/client/%s' % | 38 goma_package = ('infra_internal/goma/client/%s' % |
| 32 self.m.cipd.platform_suffix()) | 39 self.m.cipd.platform_suffix()) |
| 33 # For Windows there's only 64-bit goma client. | 40 # For Windows there's only 64-bit goma client. |
| 34 if self.m.platform.is_win: | 41 if self.m.platform.is_win: |
| 35 goma_package = goma_package.replace('386', 'amd64') | 42 goma_package = goma_package.replace('386', 'amd64') |
| 36 ref='release' | 43 ref='release' |
| 37 if canary: | 44 if canary: |
| 38 ref='candidate' | 45 ref='candidate' |
| 39 self._goma_dir = self.m.path['cache'].join('cipd', 'goma') | 46 self._goma_dir = self.m.path['cache'].join('cipd', 'goma') |
| 40 self.m.cipd.ensure(self._goma_dir, {goma_package: ref}) | 47 self.m.cipd.ensure(self._goma_dir, {goma_package: ref}) |
| 48 | |
| 49 # TODO(tikuta) download cloudtail from cipd here | |
| 50 | |
| 51 | |
| 41 return self._goma_dir | 52 return self._goma_dir |
| 42 except self.m.step.StepFailure: | 53 except self.m.step.StepFailure: |
| 43 # TODO(phajdan.jr): make failures fatal after experiment. | 54 # TODO(phajdan.jr): make failures fatal after experiment. |
| 44 return None | 55 return None |
| 45 | 56 |
| 46 @property | 57 @property |
| 47 def goma_ctl(self): | 58 def goma_ctl(self): |
| 48 return self.m.path.join(self._goma_dir, 'goma_ctl.py') | 59 return self.m.path.join(self._goma_dir, 'goma_ctl.py') |
| 49 | 60 |
| 50 @property | 61 @property |
| 51 def build_data_dir(self): | 62 def build_data_dir(self): |
| 52 return self.m.properties.get('build_data_dir') | 63 return self.m.properties.get('build_data_dir') |
| 53 | 64 |
| 65 def _start_cloudtail(self): | |
| 66 """Start cloudtail to upload compiler_proxy.INFO""" | |
|
ukai
2016/08/16 07:27:09
Raises:
?
tikuta
2016/08/16 07:43:27
Done.
| |
| 67 | |
| 68 assert self._cloudtail_pid is None | |
| 69 | |
| 70 try: | |
| 71 step_result = self.m.python( | |
| 72 name='start cloudtail', | |
| 73 script=self.resource('cloudtail_utils.py'), | |
| 74 args=['--start-cloudtail', | |
| 75 '--cloudtail-path', self.cloudtail_path], | |
| 76 env=self._goma_ctl_env, | |
| 77 stdout=self.m.raw_io.output(), | |
| 78 infra_step=True) | |
| 79 except self.m.step.InfraFailure as e: # pragma: no cover | |
| 80 self.m.python( | |
| 81 name='stop_goma (cloudtail start failure)', | |
| 82 script=self.goma_ctl, | |
| 83 args=['stop'], env=self._goma_ctl_env) | |
| 84 raise e | |
| 85 | |
| 86 self._cloudtail_pid = step_result.stdout | |
| 87 | |
| 88 def _stop_cloudtail(self): | |
| 89 """Stop cloudtail started by _start_cloudtail""" | |
|
ukai
2016/08/16 07:27:09
Raises:
?
tikuta
2016/08/16 07:43:27
Done.
| |
| 90 | |
| 91 assert self._cloudtail_pid is not None | |
| 92 | |
| 93 try: | |
| 94 self.m.python( | |
| 95 name='stop cloudtail', | |
| 96 script=self.resource('cloudtail_utils.py'), | |
| 97 args=['--killed-pid', self._cloudtail_pid], | |
| 98 infra_step=True) | |
| 99 except self.m.step.InfraFailure as e: # pragma: no cover | |
| 100 self.m.python( | |
|
ukai
2016/08/16 07:27:09
already stop goma before _stop_cloudtail?
tikuta
2016/08/16 07:43:27
Ah, I stop to catch exception here.
| |
| 101 name='stop_goma (cloudtail stop failure)', | |
| 102 script=self.goma_ctl, | |
| 103 args=['stop'], env=self._goma_ctl_env) | |
| 104 raise e | |
| 105 | |
| 106 self._cloudtail_pid = None | |
| 107 | |
| 54 def start(self, env=None, **kwargs): | 108 def start(self, env=None, **kwargs): |
| 55 """Start goma compiler_proxy. | 109 """Start goma compiler_proxy. |
| 56 | 110 |
| 57 A user MUST execute ensure_goma beforehand. | 111 A user MUST execute ensure_goma beforehand. |
| 58 It is user's responsibility to handle failure of starting compiler_proxy. | 112 It is user's responsibility to handle failure of starting compiler_proxy. |
| 59 """ | 113 """ |
| 60 assert self._goma_dir | 114 assert self._goma_dir |
| 61 assert not self._goma_started | 115 assert not self._goma_started |
| 62 | 116 |
| 63 if self.build_data_dir: | 117 if self.build_data_dir: |
| 64 self._goma_ctl_env['GOMA_DUMP_STATS_FILE'] = ( | 118 self._goma_ctl_env['GOMA_DUMP_STATS_FILE'] = ( |
| 65 self.m.path.join(self.build_data_dir, 'goma_stats_proto')) | 119 self.m.path.join(self.build_data_dir, 'goma_stats_proto')) |
| 66 self._goma_ctl_env['GOMACTL_CRASH_REPORT_ID_FILE'] = ( | 120 self._goma_ctl_env['GOMACTL_CRASH_REPORT_ID_FILE'] = ( |
| 67 self.m.path.join(self.build_data_dir, 'crash_report_id_file')) | 121 self.m.path.join(self.build_data_dir, 'crash_report_id_file')) |
| 68 | 122 |
| 69 self._goma_ctl_env['GOMA_SERVICE_ACCOUNT_JSON_FILE'] = ( | 123 self._goma_ctl_env['GOMA_SERVICE_ACCOUNT_JSON_FILE'] = ( |
| 70 self.service_account_json_path) | 124 self.service_account_json_path) |
| 71 | 125 |
| 72 goma_ctl_start_env = self._goma_ctl_env.copy() | 126 goma_ctl_start_env = self._goma_ctl_env.copy() |
| 73 | 127 |
| 74 if env is not None: | 128 if env is not None: |
| 75 goma_ctl_start_env.update(env) | 129 goma_ctl_start_env.update(env) |
| 76 | 130 |
| 77 try: | 131 try: |
| 78 self.m.python( | 132 self.m.python( |
| 79 name='start_goma', | 133 name='start_goma', |
| 80 script=self.goma_ctl, | 134 script=self.goma_ctl, |
| 81 args=['restart'], env=goma_ctl_start_env, infra_step=True, **kwargs) | 135 args=['restart'], env=goma_ctl_start_env, infra_step=True, **kwargs) |
| 82 self._goma_started = True | 136 self._goma_started = True |
|
ukai
2016/08/16 07:27:09
might be better to put _start_cloudtail here
and r
tikuta
2016/08/16 07:43:27
Done.
| |
| 83 except self.m.step.InfraFailure as e: # pragma: no cover | 137 except self.m.step.InfraFailure as e: # pragma: no cover |
| 84 upload_logs_name = 'upload_goma_start_failed_logs' | 138 upload_logs_name = 'upload_goma_start_failed_logs' |
| 85 | 139 |
| 86 try: | 140 try: |
| 87 self.m.python( | 141 self.m.python( |
| 88 name='stop_goma (start failure)', | 142 name='stop_goma (start failure)', |
| 89 script=self.goma_ctl, | 143 script=self.goma_ctl, |
| 90 args=['stop'], env=self._goma_ctl_env, **kwargs) | 144 args=['stop'], env=self._goma_ctl_env, **kwargs) |
| 91 except self.m.step.StepFailure: | 145 except self.m.step.StepFailure: |
| 92 upload_logs_name = 'upload_goma_start_and_stop_failed_logs' | 146 upload_logs_name = 'upload_goma_start_and_stop_failed_logs' |
| 93 | 147 |
| 94 self.upload_logs(name=upload_logs_name) | 148 self.upload_logs(name=upload_logs_name) |
| 95 raise e | 149 raise e |
| 96 | 150 |
| 151 self._start_cloudtail() | |
| 152 | |
| 97 def stop(self, ninja_log_outdir=None, ninja_log_compiler=None, | 153 def stop(self, ninja_log_outdir=None, ninja_log_compiler=None, |
| 98 ninja_log_command=None, ninja_log_exit_status=None, **kwargs): | 154 ninja_log_command=None, ninja_log_exit_status=None, **kwargs): |
| 99 """Stop goma compiler_proxy. | 155 """Stop goma compiler_proxy. |
| 100 | 156 |
| 101 A user MUST execute start beforehand. | 157 A user MUST execute start beforehand. |
| 102 It is user's responsibility to handle failure of stopping compiler_proxy. | 158 It is user's responsibility to handle failure of stopping compiler_proxy. |
| 103 """ | 159 """ |
| 104 assert self._goma_dir | 160 assert self._goma_dir |
| 105 assert self._goma_started | 161 assert self._goma_started |
| 106 self.m.python( | 162 self.m.python( |
| 107 name='stop_goma', | 163 name='stop_goma', |
| 108 script=self.goma_ctl, | 164 script=self.goma_ctl, |
| 109 args=['stop'], env=self._goma_ctl_env, **kwargs) | 165 args=['stop'], env=self._goma_ctl_env, **kwargs) |
| 110 | 166 |
| 167 self._stop_cloudtail() | |
|
ukai
2016/08/16 07:27:09
if stop_cloudtail failed, ninja log won't be uploa
tikuta
2016/08/16 07:43:27
Done.
| |
| 111 self.upload_logs(ninja_log_outdir, ninja_log_compiler, ninja_log_command, | 168 self.upload_logs(ninja_log_outdir, ninja_log_compiler, ninja_log_command, |
| 112 ninja_log_exit_status) | 169 ninja_log_exit_status) |
| 113 | 170 |
| 114 self._goma_started = False | 171 self._goma_started = False |
| 115 self._goma_ctl_env = {} | 172 self._goma_ctl_env = {} |
| 116 | 173 |
| 117 def upload_logs(self, ninja_log_outdir=None, ninja_log_compiler=None, | 174 def upload_logs(self, ninja_log_outdir=None, ninja_log_compiler=None, |
| 118 ninja_log_command=None, ninja_log_exit_status=None, | 175 ninja_log_command=None, ninja_log_exit_status=None, |
| 119 name=None): | 176 name=None): |
| 120 args = [ | 177 args = [ |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 140 self._goma_ctl_env['GOMACTL_CRASH_REPORT_ID_FILE'], | 197 self._goma_ctl_env['GOMACTL_CRASH_REPORT_ID_FILE'], |
| 141 '--build-data-dir', self.build_data_dir, | 198 '--build-data-dir', self.build_data_dir, |
| 142 ]) | 199 ]) |
| 143 | 200 |
| 144 self.m.python( | 201 self.m.python( |
| 145 name=name or 'upload_log', | 202 name=name or 'upload_log', |
| 146 script=self.package_repo_resource( | 203 script=self.package_repo_resource( |
| 147 'scripts', 'slave', 'upload_goma_logs.py'), | 204 'scripts', 'slave', 'upload_goma_logs.py'), |
| 148 args=args | 205 args=args |
| 149 ) | 206 ) |
| OLD | NEW |