OLD | NEW |
1 import common | 1 import common |
2 import os | 2 import os |
3 from autotest_lib.frontend.afe import models as afe_models, model_logic | 3 from autotest_lib.frontend.afe import models as afe_models, model_logic |
4 from autotest_lib.frontend.planner import models, model_attributes | 4 from autotest_lib.frontend.planner import models, model_attributes |
| 5 from autotest_lib.frontend.planner import failure_actions |
5 from autotest_lib.client.common_lib import global_config, utils | 6 from autotest_lib.client.common_lib import global_config, utils |
6 | 7 |
7 | 8 |
8 PLANNER_LABEL_PREFIX = 'planner_' | 9 PLANNER_LABEL_PREFIX = 'planner_' |
9 PLANNER_ATOMIC_GROUP_NAME = 'planner_global_atomic_group' | 10 PLANNER_ATOMIC_GROUP_NAME = 'planner_global_atomic_group' |
10 SERVER = global_config.global_config.get_config_value('SERVER', 'hostname') | 11 SERVER = global_config.global_config.get_config_value('SERVER', 'hostname') |
11 LAZY_LOADED_FILES = {} | 12 LAZY_LOADED_FILES = {} |
12 | 13 |
13 | 14 |
14 def create_plan_label(plan): | 15 def create_plan_label(plan): |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 """ | 105 """ |
105 if host.blocked: | 106 if host.blocked: |
106 return None | 107 return None |
107 | 108 |
108 test_configs = plan.testconfig_set.order_by('execution_order') | 109 test_configs = plan.testconfig_set.order_by('execution_order') |
109 for test_config in test_configs: | 110 for test_config in test_configs: |
110 afe_jobs = plan.job_set.filter(test_config=test_config) | 111 afe_jobs = plan.job_set.filter(test_config=test_config) |
111 afe_job_ids = afe_jobs.values_list('afe_job', flat=True) | 112 afe_job_ids = afe_jobs.values_list('afe_job', flat=True) |
112 hqes = afe_models.HostQueueEntry.objects.filter(job__id__in=afe_job_ids, | 113 hqes = afe_models.HostQueueEntry.objects.filter(job__id__in=afe_job_ids, |
113 host=host.host) | 114 host=host.host) |
114 if not hqes: | 115 if not hqes and not bool(test_config.skipped_hosts.filter(host=host)): |
115 return test_config.id | 116 return test_config |
116 for hqe in hqes: | 117 for hqe in hqes: |
117 if not hqe.complete: | 118 if not hqe.complete: |
118 # HostQueueEntry still active for this host, | 119 # HostQueueEntry still active for this host, |
119 # should not run another test | 120 # should not run another test |
120 return None | 121 return None |
121 | 122 |
122 # All HQEs related to this host are complete | 123 # All HQEs related to this host are complete |
123 host.complete = True | 124 host.complete = True |
124 host.save() | 125 host.save() |
125 return None | 126 return None |
(...skipping 26 matching lines...) Expand all Loading... |
152 """ | 153 """ |
153 host = afe_models.Host.objects.get(hostname=hostname) | 154 host = afe_models.Host.objects.get(hostname=hostname) |
154 | 155 |
155 planner_host = models.Host.objects.get(plan=plan, host=host) | 156 planner_host = models.Host.objects.get(plan=plan, host=host) |
156 test_run, _ = models.TestRun.objects.get_or_create(plan=plan, | 157 test_run, _ = models.TestRun.objects.get_or_create(plan=plan, |
157 test_job=planner_job, | 158 test_job=planner_job, |
158 tko_test=tko_test, | 159 tko_test=tko_test, |
159 host=planner_host) | 160 host=planner_host) |
160 test_run.status = status | 161 test_run.status = status |
161 test_run.save() | 162 test_run.save() |
| 163 |
| 164 |
| 165 def _site_process_host_action_dummy(host, action): |
| 166 return False |
| 167 |
| 168 |
| 169 def process_host_action(host, action): |
| 170 """ |
| 171 Takes the specified action on the host |
| 172 """ |
| 173 HostAction = failure_actions.HostAction |
| 174 if action not in HostAction.values: |
| 175 raise ValueError('Unexpected host action %s' % action) |
| 176 |
| 177 site_process = utils.import_site_function( |
| 178 __file__, 'autotest_lib.frontend.planner.site_rpc_utils', |
| 179 'site_process_host_action', _site_process_host_action_dummy) |
| 180 |
| 181 if not site_process(host, action): |
| 182 # site_process_host_action returns True and and only if it matched a |
| 183 # site-specific processing option |
| 184 if action == HostAction.BLOCK: |
| 185 host.blocked = True |
| 186 elif action == HostAction.UNBLOCK: |
| 187 host.blocked = False |
| 188 else: |
| 189 assert action == HostAction.REINSTALL |
| 190 raise NotImplemented('TODO: implement reinstall') |
| 191 |
| 192 host.save() |
| 193 |
| 194 |
| 195 def process_test_action(planner_job, action): |
| 196 """ |
| 197 Takes the specified action for this planner job |
| 198 """ |
| 199 TestAction = failure_actions.TestAction |
| 200 if action not in TestAction.values: |
| 201 raise ValueError('Unexpected test action %s' % action) |
| 202 |
| 203 if action == TestAction.SKIP: |
| 204 # Do nothing |
| 205 pass |
| 206 else: |
| 207 assert action == TestAction.RERUN |
| 208 planner_job.requires_rerun = True |
| 209 planner_job.save() |
OLD | NEW |