Add Planner RPC utils unit tests

Signed-off-by: James Ren <jamesren@google.com>


git-svn-id: http://test.kernel.org/svn/autotest/trunk@4346 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/frontend/planner/planner_test_utils.py b/frontend/planner/planner_test_utils.py
index 6aa2d3b..f7c0dcd 100644
--- a/frontend/planner/planner_test_utils.py
+++ b/frontend/planner/planner_test_utils.py
@@ -1,11 +1,14 @@
 import common
 from autotest_lib.frontend.afe import frontend_test_utils
 from autotest_lib.frontend.afe import models as afe_models
+from autotest_lib.frontend.tko import models as tko_models
 from autotest_lib.frontend.planner import models
 from autotest_lib.client.common_lib import utils
 
 class PlannerTestMixin(frontend_test_utils.FrontendTestMixin):
     _PLAN_NAME = 'plan'
+    GOOD_STATUS_WORD = 'GOOD'
+    RUNNING_STATUS_WORD = 'RUNNING'
 
     def _planner_common_setup(self):
         self._frontend_common_setup()
@@ -24,3 +27,50 @@
     def _planner_common_teardown(self):
         self._plan.delete()
         self._frontend_common_teardown()
+
+
+    def _setup_active_plan(self):
+        """
+        Create an active test plan
+
+        Sets up all the infrastructure for a active test plan. Stores the
+        following in self:
+
+        _hostname: hostname of the machine under test
+        _control: the models.ControlFile object
+        _test_config: the models.TestConfig object
+        _afe_job: the AFE job started by the plan
+        _planner_host: the models.Host object
+        _planner_job: the models.Job object
+        _tko_machine: the TKO machine (as a tko_models.Machine object) for the
+                      results
+        _tko_job: the TKO job (as a tko_models.Job object) for the results
+        _tko_kernel: the TKO kernel (as a tko_models.Kernel object) associated
+                     with the TKO machine
+        _running_status: the TKO status (as a tko_models.Status object) that
+                         indicates a running TKO test
+        _good_status: the TKO status (as a tko_models.Status object) that
+                      indicates a completed and passed TKO test
+        """
+        self._hostname = self.hosts[0].hostname
+        self._control, _ = models.ControlFile.objects.get_or_create(
+                contents='test_control')
+        self._test_config = models.TestConfig.objects.create(
+                plan=self._plan, alias='config', control_file=self._control,
+                execution_order=1, estimated_runtime=1)
+        self._afe_job = self._create_job(hosts=(1,))
+        self._planner_host = models.Host.objects.create(plan=self._plan,
+                                                        host=self.hosts[0])
+        self._planner_job = models.Job.objects.create(
+                plan=self._plan, test_config=self._test_config,
+                afe_job=self._afe_job)
+        self._tko_machine = tko_models.Machine.objects.create(
+                hostname=self._hostname)
+        self._tko_job = tko_models.Job.objects.create(
+                tag='job', machine=self._tko_machine,
+                afe_job_id=self._afe_job.id)
+        self._tko_kernel = tko_models.Kernel.objects.create()
+        self._running_status = tko_models.Status.objects.create(
+                word=self.RUNNING_STATUS_WORD)
+        self._good_status = tko_models.Status.objects.create(
+                word=self.GOOD_STATUS_WORD)