| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 import unittest | 3 import unittest |
| 4 import common | 4 import common |
| 5 from autotest_lib.frontend import setup_django_environment | 5 from autotest_lib.frontend import setup_django_environment |
| 6 from autotest_lib.frontend.planner import planner_test_utils, model_attributes | 6 from autotest_lib.frontend.planner import planner_test_utils, model_attributes |
| 7 from autotest_lib.frontend.planner import rpc_interface, models, rpc_utils | 7 from autotest_lib.frontend.planner import rpc_interface, models, rpc_utils |
| 8 from autotest_lib.frontend.planner import failure_actions |
| 8 from autotest_lib.frontend.afe import model_logic | 9 from autotest_lib.frontend.afe import model_logic |
| 9 from autotest_lib.frontend.afe import models as afe_models | 10 from autotest_lib.frontend.afe import models as afe_models |
| 10 from autotest_lib.frontend.tko import models as tko_models | 11 from autotest_lib.frontend.tko import models as tko_models |
| 11 | 12 |
| 12 | 13 |
| 14 class DummyTestConfig(object): |
| 15 def __init__(self): |
| 16 self.id = object() |
| 17 self.alias = object() |
| 18 |
| 19 |
| 13 class RpcInterfaceTest(unittest.TestCase, | 20 class RpcInterfaceTest(unittest.TestCase, |
| 14 planner_test_utils.PlannerTestMixin): | 21 planner_test_utils.PlannerTestMixin): |
| 15 def setUp(self): | 22 def setUp(self): |
| 16 self._planner_common_setup() | 23 self._planner_common_setup() |
| 17 self.god.stub_function(rpc_utils, 'start_plan') | 24 self.god.stub_function(rpc_utils, 'start_plan') |
| 18 | 25 |
| 19 | 26 |
| 20 def tearDown(self): | 27 def tearDown(self): |
| 21 self._planner_common_teardown() | 28 self._planner_common_teardown() |
| 22 | 29 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 hosts = rpc_interface.get_hosts(self._PLAN_NAME) | 74 hosts = rpc_interface.get_hosts(self._PLAN_NAME) |
| 68 self.assertEqual(set(('host1', 'host2', 'host3')), set(hosts)) | 75 self.assertEqual(set(('host1', 'host2', 'host3')), set(hosts)) |
| 69 | 76 |
| 70 afe_models.Host.objects.get(hostname='host3').labels.clear() | 77 afe_models.Host.objects.get(hostname='host3').labels.clear() |
| 71 | 78 |
| 72 hosts = rpc_interface.get_hosts(self._PLAN_NAME) | 79 hosts = rpc_interface.get_hosts(self._PLAN_NAME) |
| 73 self.assertEqual(set(('host1', 'host2')), set(hosts)) | 80 self.assertEqual(set(('host1', 'host2')), set(hosts)) |
| 74 | 81 |
| 75 | 82 |
| 76 def test_get_next_test_configs(self): | 83 def test_get_next_test_configs(self): |
| 77 DUMMY_CONFIGS = {'host1': object(), | 84 DUMMY_CONFIGS = {'host1': DummyTestConfig(), |
| 78 'host2': object()} | 85 'host2': DummyTestConfig()} |
| 79 DUMMY_COMPLETE = object() | 86 DUMMY_COMPLETE = object() |
| 80 self.god.stub_function(rpc_utils, 'compute_next_test_config') | 87 self.god.stub_function(rpc_utils, 'compute_next_test_config') |
| 81 | 88 |
| 82 for host in models.Host.objects.filter(plan=self._plan): | 89 for host in models.Host.objects.filter(plan=self._plan): |
| 83 rpc_utils.compute_next_test_config.expect_call( | 90 rpc_utils.compute_next_test_config.expect_call( |
| 84 self._plan, host).and_return( | 91 self._plan, host).and_return( |
| 85 DUMMY_CONFIGS[host.host.hostname]) | 92 DUMMY_CONFIGS[host.host.hostname]) |
| 86 | 93 |
| 87 def _dummy_check_for_completion(plan): | 94 def _dummy_check_for_completion(plan): |
| 88 plan.complete = DUMMY_COMPLETE | 95 plan.complete = DUMMY_COMPLETE |
| 89 rpc_utils.check_for_completion = _dummy_check_for_completion | 96 rpc_utils.check_for_completion = _dummy_check_for_completion |
| 90 | 97 |
| 91 result = rpc_interface.get_next_test_configs(self._plan.id) | 98 result = rpc_interface.get_next_test_configs(self._plan.id) |
| 92 | 99 |
| 93 self.god.check_playback() | 100 self.god.check_playback() |
| 94 self.assertEqual(result['complete'], DUMMY_COMPLETE) | 101 self.assertEqual(result['complete'], DUMMY_COMPLETE) |
| 95 for config in result['next_configs']: | 102 for config in result['next_configs']: |
| 96 self.assertTrue(config['host'] in DUMMY_CONFIGS) | 103 self.assertTrue(config['host'] in DUMMY_CONFIGS) |
| 97 self.assertEqual(config['next_test_config_id'], | 104 self.assertEqual(config['next_test_config_id'], |
| 98 DUMMY_CONFIGS[config['host']]) | 105 DUMMY_CONFIGS[config['host']].id) |
| 106 self.assertEqual(config['next_test_config_alias'], |
| 107 DUMMY_CONFIGS[config['host']].alias) |
| 99 | 108 |
| 100 | 109 |
| 101 def test_update_test_runs(self): | 110 def test_update_test_runs(self): |
| 102 self._setup_active_plan() | 111 self._setup_active_plan() |
| 103 | 112 |
| 104 self.god.stub_function(rpc_utils, 'compute_test_run_status') | 113 self.god.stub_function(rpc_utils, 'compute_test_run_status') |
| 105 self.god.stub_function(rpc_utils, 'add_test_run') | 114 self.god.stub_function(rpc_utils, 'add_test_run') |
| 106 | 115 |
| 107 # No TKO tests | 116 # No TKO tests |
| 108 self.assertEqual([], rpc_interface.update_test_runs(self._plan.id)) | 117 self.assertEqual([], rpc_interface.update_test_runs(self._plan.id)) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 rpc_utils.add_test_run.expect_call( | 156 rpc_utils.add_test_run.expect_call( |
| 148 self._plan, self._planner_job, tko_test, self._hostname, | 157 self._plan, self._planner_job, tko_test, self._hostname, |
| 149 model_attributes.TestRunStatus.PASSED) | 158 model_attributes.TestRunStatus.PASSED) |
| 150 self.assertEqual(rpc_interface.update_test_runs(self._plan.id), | 159 self.assertEqual(rpc_interface.update_test_runs(self._plan.id), |
| 151 [{'status': model_attributes.TestRunStatus.PASSED, | 160 [{'status': model_attributes.TestRunStatus.PASSED, |
| 152 'tko_test_idx': tko_test.test_idx, | 161 'tko_test_idx': tko_test.test_idx, |
| 153 'hostname': self._hostname}]) | 162 'hostname': self._hostname}]) |
| 154 self.god.check_playback() | 163 self.god.check_playback() |
| 155 | 164 |
| 156 | 165 |
| 166 def test_process_failure(self): |
| 167 self._setup_active_plan() |
| 168 tko_test = tko_models.Test.objects.create(job=self._tko_job, |
| 169 machine=self._tko_machine, |
| 170 kernel=self._tko_kernel, |
| 171 status=self._running_status) |
| 172 failure = models.TestRun.objects.create( |
| 173 plan=self._plan, |
| 174 test_job=self._planner_job, |
| 175 tko_test=tko_test, |
| 176 host=self._planner_host, |
| 177 status=model_attributes.TestRunStatus.FAILED, |
| 178 finalized=True, seen=False, triaged=False) |
| 179 host_action = failure_actions.HostAction.UNBLOCK |
| 180 test_action = failure_actions.TestAction.SKIP |
| 181 labels = ['label1', 'label2'] |
| 182 keyvals = {'key1': 'value1', |
| 183 'key2': 'value2'} |
| 184 bugs = ['bug1', 'bug2'] |
| 185 reason = 'overriden reason' |
| 186 invalidate = True |
| 187 |
| 188 self.god.stub_function(rpc_utils, 'process_host_action') |
| 189 self.god.stub_function(rpc_utils, 'process_test_action') |
| 190 |
| 191 rpc_utils.process_host_action.expect_call(self._planner_host, |
| 192 host_action) |
| 193 rpc_utils.process_test_action.expect_call(self._planner_job, |
| 194 test_action) |
| 195 |
| 196 rpc_interface.process_failure(failure.id, host_action, test_action, |
| 197 labels, keyvals, bugs, reason, invalidate) |
| 198 failure = models.TestRun.objects.get(id=failure.id) |
| 199 |
| 200 self.assertEqual( |
| 201 set(failure.tko_test.testlabel_set.all()), |
| 202 set(tko_models.TestLabel.objects.filter(name__in=labels))) |
| 203 self.assertEqual( |
| 204 set(failure.tko_test.job.jobkeyval_set.all()), |
| 205 set(tko_models.JobKeyval.objects.filter( |
| 206 key__in=keyvals.iterkeys()))) |
| 207 self.assertEqual(set(failure.bugs.all()), |
| 208 set(models.Bug.objects.filter(external_uid__in=bugs))) |
| 209 self.assertEqual(failure.tko_test.reason, reason) |
| 210 self.assertEqual(failure.invalidated, invalidate) |
| 211 self.assertTrue(failure.seen) |
| 212 self.assertTrue(failure.triaged) |
| 213 self.god.check_playback() |
| 214 |
| 215 |
| 157 if __name__ == '__main__': | 216 if __name__ == '__main__': |
| 158 unittest.main() | 217 unittest.main() |
| OLD | NEW |