Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 collections import defaultdict | 5 from collections import defaultdict |
| 6 import datetime | 6 import datetime |
| 7 import logging | 7 import logging |
| 8 import time | 8 import time |
| 9 | 9 |
| 10 from common.http_client_appengine import HttpClientAppengine as HttpClient | 10 from common.http_client_appengine import HttpClientAppengine as HttpClient |
| 11 from common.pipeline_wrapper import BasePipeline | 11 from common.pipeline_wrapper import BasePipeline |
| 12 from model import analysis_status | 12 from model import analysis_status |
| 13 from waterfall import swarming_util | 13 from waterfall import swarming_util |
| 14 from waterfall import waterfall_config | 14 from waterfall import waterfall_config |
| 15 | 15 |
| 16 | 16 |
| 17 _ACCEPTED_EXIT_CODE = [0, 1] | |
|
lijeffrey
2016/09/08 03:41:00
nit: _ACCEPTED_EXIT_CODES
on that note, how about
stgao
2016/09/08 04:16:00
+1
We also need comments for possible exit codes,
chanli
2016/09/08 21:16:56
Done.
chanli
2016/09/08 21:16:56
Since the name for each exit_code is self_explaine
| |
| 18 | |
| 19 | |
| 17 class ProcessBaseSwarmingTaskResultPipeline(BasePipeline): | 20 class ProcessBaseSwarmingTaskResultPipeline(BasePipeline): |
| 18 """A pipeline for monitoring swarming task and processing task result. | 21 """A pipeline for monitoring swarming task and processing task result. |
| 19 | 22 |
| 20 This pipeline waits for result for a swarming task and processes the result to | 23 This pipeline waits for result for a swarming task and processes the result to |
| 21 generate a dict for statuses for each test run. | 24 generate a dict for statuses for each test run. |
| 22 """ | 25 """ |
| 23 | 26 |
| 24 HTTP_CLIENT = HttpClient() | 27 HTTP_CLIENT = HttpClient() |
| 25 | 28 |
| 26 def _CheckTestsRunStatuses(self, output_json): | 29 def _CheckTestsRunStatuses(self, output_json): |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 task_started = False | 82 task_started = False |
| 80 task_completed = False | 83 task_completed = False |
| 81 tests_statuses = {} | 84 tests_statuses = {} |
| 82 step_name_no_platform = None | 85 step_name_no_platform = None |
| 83 | 86 |
| 84 while not task_completed: | 87 while not task_completed: |
| 85 # Keeps monitoring the swarming task, waits for it to complete. | 88 # Keeps monitoring the swarming task, waits for it to complete. |
| 86 data = swarming_util.GetSwarmingTaskResultById( | 89 data = swarming_util.GetSwarmingTaskResultById( |
| 87 task_id, self.HTTP_CLIENT) | 90 task_id, self.HTTP_CLIENT) |
| 88 task_state = data['state'] | 91 task_state = data['state'] |
| 92 exit_code = (data['exit_code'] if | |
| 93 task_state == swarming_util.STATE_COMPLETED else None) | |
| 89 step_name_no_platform = swarming_util.GetTagValue( | 94 step_name_no_platform = swarming_util.GetTagValue( |
| 90 data.get('tags', {}), 'ref_name') | 95 data.get('tags', {}), 'ref_name') |
| 91 if task_state not in swarming_util.STATES_RUNNING: | 96 if task_state not in swarming_util.STATES_RUNNING: |
| 92 task_completed = True | 97 task_completed = True |
| 93 task = self._GetSwarmingTask(*call_args) | 98 task = self._GetSwarmingTask(*call_args) |
| 94 if task_state == swarming_util.STATE_COMPLETED: | 99 if (task_state == swarming_util.STATE_COMPLETED and |
| 100 int(exit_code) in _ACCEPTED_EXIT_CODE): | |
| 95 outputs_ref = data.get('outputs_ref') | 101 outputs_ref = data.get('outputs_ref') |
| 96 output_json = swarming_util.GetSwarmingTaskFailureLog( | 102 output_json = swarming_util.GetSwarmingTaskFailureLog( |
| 97 outputs_ref, self.HTTP_CLIENT) | 103 outputs_ref, self.HTTP_CLIENT) |
| 98 tests_statuses = self._CheckTestsRunStatuses( | 104 tests_statuses = self._CheckTestsRunStatuses( |
| 99 output_json, *call_args) | 105 output_json, *call_args) |
| 100 task.status = analysis_status.COMPLETED | 106 task.status = analysis_status.COMPLETED |
| 101 task.tests_statuses = tests_statuses | 107 task.tests_statuses = tests_statuses |
| 102 else: | 108 else: |
| 103 task.status = analysis_status.ERROR | 109 task.status = analysis_status.ERROR |
| 104 logging.error('Swarming task stopped with status: %s' % ( | 110 logging.error('Swarming task stopped with status: %s and' |
| 105 task_state)) | 111 ' exit_code: %s' % (task_state, exit_code)) |
| 106 priority_str = swarming_util.GetTagValue( | 112 priority_str = swarming_util.GetTagValue( |
| 107 data.get('tags', {}), 'priority') | 113 data.get('tags', {}), 'priority') |
| 108 if priority_str: | 114 if priority_str: |
| 109 task.parameters['priority'] = int(priority_str) | 115 task.parameters['priority'] = int(priority_str) |
| 110 task.put() | 116 task.put() |
| 111 else: # pragma: no cover | 117 else: # pragma: no cover |
| 112 if task_state == 'RUNNING' and not task_started: | 118 if task_state == 'RUNNING' and not task_started: |
| 113 # swarming task just starts, update status. | 119 # swarming task just starts, update status. |
| 114 task_started = True | 120 task_started = True |
| 115 task = self._GetSwarmingTask(*call_args) | 121 task = self._GetSwarmingTask(*call_args) |
| 116 task.status = analysis_status.RUNNING | 122 task.status = analysis_status.RUNNING |
| 117 task.put() | 123 task.put() |
| 118 time.sleep(server_query_interval_seconds) | 124 time.sleep(server_query_interval_seconds) |
| 119 if time.time() > deadline: | 125 if time.time() > deadline: |
| 120 # Updates status as ERROR. | 126 # Updates status as ERROR. |
| 121 task = self._GetSwarmingTask(*call_args) | 127 task = self._GetSwarmingTask(*call_args) |
| 122 task.status = analysis_status.ERROR | 128 task.status = analysis_status.ERROR |
| 123 task.put() | 129 task.put() |
| 124 logging.error('Swarming task timed out after %d hours.' % timeout_hours) | 130 logging.error('Swarming task timed out after %d hours.' % timeout_hours) |
| 125 break # Stops the loop and return. | 131 break # Stops the loop and return. |
| 126 # Update swarming task metadate. | 132 # Update swarming task metadate. |
| 127 task = self._GetSwarmingTask(*call_args) | 133 task = self._GetSwarmingTask(*call_args) |
| 128 task.created_time = self._ConvertDateTime(data.get('created_ts')) | 134 task.created_time = self._ConvertDateTime(data.get('created_ts')) |
| 129 task.started_time = self._ConvertDateTime(data.get('started_ts')) | 135 task.started_time = self._ConvertDateTime(data.get('started_ts')) |
| 130 task.completed_time = self._ConvertDateTime(data.get('completed_ts')) | 136 task.completed_time = self._ConvertDateTime(data.get('completed_ts')) |
| 131 task.put() | 137 task.put() |
| 132 | 138 |
| 133 return step_name, step_name_no_platform | 139 return step_name, step_name_no_platform |
| OLD | NEW |