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