| 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 model import wf_analysis_status | 11 from model import analysis_status |
| 12 from model.wf_swarming_task import WfSwarmingTask | 12 from model.wf_swarming_task import WfSwarmingTask |
| 13 from pipeline_wrapper import BasePipeline | 13 from pipeline_wrapper import BasePipeline |
| 14 from waterfall import swarming_util | 14 from waterfall import swarming_util |
| 15 from waterfall import waterfall_config | 15 from waterfall import waterfall_config |
| 16 | 16 |
| 17 | 17 |
| 18 def _CheckTestsRunStatuses(output_json): | 18 def _CheckTestsRunStatuses(output_json): |
| 19 """Checks result status for each test run and saves the numbers accordingly. | 19 """Checks result status for each test run and saves the numbers accordingly. |
| 20 | 20 |
| 21 Args: | 21 Args: |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 if task_state not in swarming_util.STATES_RUNNING: | 97 if task_state not in swarming_util.STATES_RUNNING: |
| 98 task_completed = True | 98 task_completed = True |
| 99 task = WfSwarmingTask.Get( | 99 task = WfSwarmingTask.Get( |
| 100 master_name, builder_name, build_number, step_name) | 100 master_name, builder_name, build_number, step_name) |
| 101 if task_state == swarming_util.STATE_COMPLETED: | 101 if task_state == swarming_util.STATE_COMPLETED: |
| 102 outputs_ref = data.get('outputs_ref') | 102 outputs_ref = data.get('outputs_ref') |
| 103 output_json = swarming_util.GetSwarmingTaskFailureLog( | 103 output_json = swarming_util.GetSwarmingTaskFailureLog( |
| 104 outputs_ref, self.HTTP_CLIENT) | 104 outputs_ref, self.HTTP_CLIENT) |
| 105 tests_statuses = _CheckTestsRunStatuses(output_json) | 105 tests_statuses = _CheckTestsRunStatuses(output_json) |
| 106 | 106 |
| 107 task.status = wf_analysis_status.ANALYZED | 107 task.status = analysis_status.COMPLETED |
| 108 task.tests_statuses = tests_statuses | 108 task.tests_statuses = tests_statuses |
| 109 else: | 109 else: |
| 110 task.status = wf_analysis_status.ERROR | 110 task.status = analysis_status.ERROR |
| 111 logging.error('Swarming task stopped with status: %s' % ( | 111 logging.error('Swarming task stopped with status: %s' % ( |
| 112 task_state)) | 112 task_state)) |
| 113 priority_str = swarming_util.GetTagValue( | 113 priority_str = swarming_util.GetTagValue( |
| 114 data.get('tags', {}), 'priority') | 114 data.get('tags', {}), 'priority') |
| 115 if priority_str: | 115 if priority_str: |
| 116 task.parameters['priority'] = int(priority_str) | 116 task.parameters['priority'] = int(priority_str) |
| 117 task.put() | 117 task.put() |
| 118 else: # pragma: no cover | 118 else: # pragma: no cover |
| 119 if task_state == 'RUNNING' and not task_started: | 119 if task_state == 'RUNNING' and not task_started: |
| 120 # swarming task just starts, update status. | 120 # swarming task just starts, update status. |
| 121 task_started = True | 121 task_started = True |
| 122 task = WfSwarmingTask.Get( | 122 task = WfSwarmingTask.Get( |
| 123 master_name, builder_name, build_number, step_name) | 123 master_name, builder_name, build_number, step_name) |
| 124 task.status = wf_analysis_status.ANALYZING | 124 task.status = analysis_status.RUNNING |
| 125 task.put() | 125 task.put() |
| 126 | 126 |
| 127 time.sleep(server_query_interval_seconds) | 127 time.sleep(server_query_interval_seconds) |
| 128 | 128 |
| 129 if time.time() > deadline: | 129 if time.time() > deadline: |
| 130 # Updates status as ERROR. | 130 # Updates status as ERROR. |
| 131 task = WfSwarmingTask.Get( | 131 task = WfSwarmingTask.Get( |
| 132 master_name, builder_name, build_number, step_name) | 132 master_name, builder_name, build_number, step_name) |
| 133 task.status = wf_analysis_status.ERROR | 133 task.status = analysis_status.ERROR |
| 134 task.put() | 134 task.put() |
| 135 logging.error('Swarming task timed out after %d hours.' % timeout_hours) | 135 logging.error('Swarming task timed out after %d hours.' % timeout_hours) |
| 136 break # Stops the loop and return. | 136 break # Stops the loop and return. |
| 137 | 137 |
| 138 # Update swarming task metadate. | 138 # Update swarming task metadate. |
| 139 task = WfSwarmingTask.Get( | 139 task = WfSwarmingTask.Get( |
| 140 master_name, builder_name, build_number, step_name) | 140 master_name, builder_name, build_number, step_name) |
| 141 task.created_time = _ConvertDateTime(data.get('created_ts')) | 141 task.created_time = _ConvertDateTime(data.get('created_ts')) |
| 142 task.started_time = _ConvertDateTime(data.get('started_ts')) | 142 task.started_time = _ConvertDateTime(data.get('started_ts')) |
| 143 task.completed_time = _ConvertDateTime(data.get('completed_ts')) | 143 task.completed_time = _ConvertDateTime(data.get('completed_ts')) |
| 144 task.put() | 144 task.put() |
| 145 | 145 |
| 146 return step_name, (step_name_no_platform, task.classified_tests) | 146 return step_name, (step_name_no_platform, task.classified_tests) |
| OLD | NEW |