jamesren | c394022 | 2010-02-19 21:57:37 +0000 | [diff] [blame] | 1 | import common |
| 2 | from autotest_lib.frontend.afe import frontend_test_utils |
| 3 | from autotest_lib.frontend.afe import models as afe_models |
jamesren | 8d0d3d5 | 2010-03-25 20:39:13 +0000 | [diff] [blame] | 4 | from autotest_lib.frontend.tko import models as tko_models |
jamesren | c394022 | 2010-02-19 21:57:37 +0000 | [diff] [blame] | 5 | from autotest_lib.frontend.planner import models |
| 6 | from autotest_lib.client.common_lib import utils |
| 7 | |
| 8 | class PlannerTestMixin(frontend_test_utils.FrontendTestMixin): |
| 9 | _PLAN_NAME = 'plan' |
jamesren | 8d0d3d5 | 2010-03-25 20:39:13 +0000 | [diff] [blame] | 10 | GOOD_STATUS_WORD = 'GOOD' |
| 11 | RUNNING_STATUS_WORD = 'RUNNING' |
jamesren | c394022 | 2010-02-19 21:57:37 +0000 | [diff] [blame] | 12 | |
| 13 | def _planner_common_setup(self): |
| 14 | self._frontend_common_setup() |
| 15 | |
| 16 | plan = models.Plan.objects.create(name=self._PLAN_NAME) |
| 17 | models.Host.objects.create( |
| 18 | plan=plan, host=afe_models.Host.objects.get(hostname='host1')) |
| 19 | models.Host.objects.create( |
| 20 | plan=plan, host=afe_models.Host.objects.get(hostname='host2')) |
| 21 | plan.host_labels.add(afe_models.Label.objects.get(name='label1')) |
| 22 | plan.save() |
| 23 | |
| 24 | self._plan = plan |
| 25 | |
| 26 | |
| 27 | def _planner_common_teardown(self): |
| 28 | self._plan.delete() |
| 29 | self._frontend_common_teardown() |
jamesren | 8d0d3d5 | 2010-03-25 20:39:13 +0000 | [diff] [blame] | 30 | |
| 31 | |
| 32 | def _setup_active_plan(self): |
| 33 | """ |
| 34 | Create an active test plan |
| 35 | |
| 36 | Sets up all the infrastructure for a active test plan. Stores the |
| 37 | following in self: |
| 38 | |
| 39 | _hostname: hostname of the machine under test |
| 40 | _control: the models.ControlFile object |
| 41 | _test_config: the models.TestConfig object |
| 42 | _afe_job: the AFE job started by the plan |
| 43 | _planner_host: the models.Host object |
| 44 | _planner_job: the models.Job object |
| 45 | _tko_machine: the TKO machine (as a tko_models.Machine object) for the |
| 46 | results |
| 47 | _tko_job: the TKO job (as a tko_models.Job object) for the results |
| 48 | _tko_kernel: the TKO kernel (as a tko_models.Kernel object) associated |
| 49 | with the TKO machine |
| 50 | _running_status: the TKO status (as a tko_models.Status object) that |
| 51 | indicates a running TKO test |
| 52 | _good_status: the TKO status (as a tko_models.Status object) that |
| 53 | indicates a completed and passed TKO test |
| 54 | """ |
| 55 | self._hostname = self.hosts[0].hostname |
| 56 | self._control, _ = models.ControlFile.objects.get_or_create( |
| 57 | contents='test_control') |
| 58 | self._test_config = models.TestConfig.objects.create( |
| 59 | plan=self._plan, alias='config', control_file=self._control, |
| 60 | execution_order=1, estimated_runtime=1) |
| 61 | self._afe_job = self._create_job(hosts=(1,)) |
| 62 | self._planner_host = models.Host.objects.create(plan=self._plan, |
| 63 | host=self.hosts[0]) |
| 64 | self._planner_job = models.Job.objects.create( |
| 65 | plan=self._plan, test_config=self._test_config, |
| 66 | afe_job=self._afe_job) |
| 67 | self._tko_machine = tko_models.Machine.objects.create( |
| 68 | hostname=self._hostname) |
| 69 | self._tko_job = tko_models.Job.objects.create( |
| 70 | tag='job', machine=self._tko_machine, |
| 71 | afe_job_id=self._afe_job.id) |
| 72 | self._tko_kernel = tko_models.Kernel.objects.create() |
| 73 | self._running_status = tko_models.Status.objects.create( |
| 74 | word=self.RUNNING_STATUS_WORD) |
| 75 | self._good_status = tko_models.Status.objects.create( |
| 76 | word=self.GOOD_STATUS_WORD) |