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 | 6 from autotest_lib.frontend.planner import planner_test_utils |
7 from autotest_lib.frontend.afe import model_logic, models as afe_models | 7 from autotest_lib.frontend.afe import model_logic, models as afe_models |
8 from autotest_lib.frontend.afe import rpc_interface as afe_rpc_interface | 8 from autotest_lib.frontend.planner import models, rpc_utils, failure_actions |
9 from autotest_lib.frontend.planner import models, rpc_utils | |
10 from autotest_lib.client.common_lib import utils, host_queue_entry_states | 9 from autotest_lib.client.common_lib import utils, host_queue_entry_states |
11 | 10 |
12 | 11 |
13 class RpcUtilsTest(unittest.TestCase, | 12 class RpcUtilsTest(unittest.TestCase, |
14 planner_test_utils.PlannerTestMixin): | 13 planner_test_utils.PlannerTestMixin): |
15 def setUp(self): | 14 def setUp(self): |
16 self._planner_common_setup() | 15 self._planner_common_setup() |
17 | 16 |
18 | 17 |
19 def tearDown(self): | 18 def tearDown(self): |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 self.assertEqual( | 100 self.assertEqual( |
102 None, rpc_utils.compute_next_test_config(self._plan, | 101 None, rpc_utils.compute_next_test_config(self._plan, |
103 self._planner_host)) | 102 self._planner_host)) |
104 self.assertFalse(self._planner_host.complete) | 103 self.assertFalse(self._planner_host.complete) |
105 | 104 |
106 hqe = self._afe_job.hostqueueentry_set.all()[0] | 105 hqe = self._afe_job.hostqueueentry_set.all()[0] |
107 hqe.status = host_queue_entry_states.Status.COMPLETED | 106 hqe.status = host_queue_entry_states.Status.COMPLETED |
108 hqe.save() | 107 hqe.save() |
109 | 108 |
110 self.assertEqual( | 109 self.assertEqual( |
111 test_config.id, | 110 test_config, |
112 rpc_utils.compute_next_test_config(self._plan, | 111 rpc_utils.compute_next_test_config(self._plan, |
113 self._planner_host)) | 112 self._planner_host)) |
114 self.assertFalse(self._planner_host.complete) | 113 self.assertFalse(self._planner_host.complete) |
115 | 114 |
116 afe_job = self._create_job(hosts=(1,)) | 115 afe_job = self._create_job(hosts=(1,)) |
117 planner_job = models.Job.objects.create(plan=self._plan, | 116 planner_job = models.Job.objects.create(plan=self._plan, |
118 test_config=test_config, | 117 test_config=test_config, |
119 afe_job=afe_job) | 118 afe_job=afe_job) |
120 | 119 |
121 self.assertEqual( | 120 self.assertEqual( |
122 None, rpc_utils.compute_next_test_config(self._plan, | 121 None, rpc_utils.compute_next_test_config(self._plan, |
123 self._planner_host)) | 122 self._planner_host)) |
124 self.assertFalse(self._planner_host.complete) | 123 self.assertFalse(self._planner_host.complete) |
125 | 124 |
126 hqe = afe_job.hostqueueentry_set.all()[0] | 125 hqe = afe_job.hostqueueentry_set.all()[0] |
127 hqe.status = host_queue_entry_states.Status.COMPLETED | 126 hqe.status = host_queue_entry_states.Status.COMPLETED |
128 hqe.save() | 127 hqe.save() |
129 | 128 |
130 self.assertEqual( | 129 self.assertEqual( |
131 None, rpc_utils.compute_next_test_config(self._plan, | 130 None, rpc_utils.compute_next_test_config(self._plan, |
132 self._planner_host)) | 131 self._planner_host)) |
133 self.assertTrue(self._planner_host.complete) | 132 self.assertTrue(self._planner_host.complete) |
134 | 133 |
135 | 134 |
| 135 def _replace_site_process_host_action(self, replacement): |
| 136 self.god.stub_function(utils, 'import_site_function') |
| 137 utils.import_site_function.expect_any_call().and_return(replacement) |
| 138 |
| 139 |
| 140 def _remove_site_process_host_action(self): |
| 141 def _site_process_host_action_dummy(host, action): |
| 142 return False |
| 143 self._replace_site_process_host_action(_site_process_host_action_dummy) |
| 144 |
| 145 |
| 146 def test_process_host_action_block(self): |
| 147 self._remove_site_process_host_action() |
| 148 host = models.Host.objects.create(plan=self._plan, host=self.hosts[0], |
| 149 blocked=False) |
| 150 assert not host.blocked |
| 151 |
| 152 rpc_utils.process_host_action(host, failure_actions.HostAction.BLOCK) |
| 153 host = models.Host.objects.get(id=host.id) |
| 154 |
| 155 self.assertTrue(host.blocked) |
| 156 self.god.check_playback() |
| 157 |
| 158 |
| 159 def test_process_host_action_unblock(self): |
| 160 self._remove_site_process_host_action() |
| 161 host = models.Host.objects.create(plan=self._plan, host=self.hosts[0], |
| 162 blocked=True) |
| 163 assert host.blocked |
| 164 |
| 165 rpc_utils.process_host_action(host, failure_actions.HostAction.UNBLOCK) |
| 166 host = models.Host.objects.get(id=host.id) |
| 167 |
| 168 self.assertFalse(host.blocked) |
| 169 self.god.check_playback() |
| 170 |
| 171 |
| 172 def test_process_host_action_site(self): |
| 173 self._remove_site_process_host_action |
| 174 action = object() |
| 175 failure_actions.HostAction.values.append(action) |
| 176 host = models.Host.objects.create(plan=self._plan, host=self.hosts[0]) |
| 177 |
| 178 self.assertRaises(AssertionError, rpc_utils.process_host_action, |
| 179 host, action) |
| 180 self.god.check_playback() |
| 181 |
| 182 self._called = False |
| 183 def _site_process_host_action(host, action): |
| 184 self._called = True |
| 185 return True |
| 186 self._replace_site_process_host_action(_site_process_host_action) |
| 187 |
| 188 rpc_utils.process_host_action(host, action) |
| 189 |
| 190 self.assertTrue(self._called) |
| 191 self.god.check_playback() |
| 192 |
| 193 |
| 194 def test_process_test_action_skip(self): |
| 195 self._setup_active_plan() |
| 196 planner_job = self._planner_job |
| 197 assert not planner_job.requires_rerun |
| 198 |
| 199 rpc_utils.process_test_action(planner_job, |
| 200 failure_actions.TestAction.SKIP) |
| 201 planner_job = models.Job.objects.get(id=planner_job.id) |
| 202 |
| 203 self.assertFalse(planner_job.requires_rerun) |
| 204 |
| 205 |
| 206 def test_process_test_action_rerun(self): |
| 207 self._setup_active_plan() |
| 208 planner_job = self._planner_job |
| 209 assert not planner_job.requires_rerun |
| 210 |
| 211 rpc_utils.process_test_action(planner_job, |
| 212 failure_actions.TestAction.RERUN) |
| 213 planner_job = models.Job.objects.get(id=planner_job.id) |
| 214 |
| 215 self.assertTrue(planner_job.requires_rerun) |
| 216 |
| 217 |
136 if __name__ == '__main__': | 218 if __name__ == '__main__': |
137 unittest.main() | 219 unittest.main() |
OLD | NEW |