[autotest]: Run suites from AFE.

* Updated the AFE to allow for suite runs. When an image is provided
the create_job RPC will redirect to the create_suite_job RPC instead.

* Updated create_suite_job to allow for a control_file to be supplied.
create_suite_job will use this control file rather than what the
devserver stages when it creates the suite job.

* Removed the parameterized job code from create_job as it is not used
and broken.

* The create_job page now includes a 'Pool' text box to specify for
these jobs.

BUG=chromium:358579
TEST=Able to launch suite jobs from run_suite and AFE. And regular tests
kicked off via the AFE still work as well. rpc_interface and
site_rpc_interface unittests, suite_scheduler unittests.
DEPLOY=apache,afe,suite_scheduler

Change-Id: I53312419c32740e78fc07598babeb497c162ba81
Reviewed-on: https://chromium-review.googlesource.com/194349
Reviewed-by: Simran Basi <sbasi@chromium.org>
Commit-Queue: Simran Basi <sbasi@chromium.org>
Tested-by: Simran Basi <sbasi@chromium.org>
diff --git a/frontend/afe/rpc_interface.py b/frontend/afe/rpc_interface.py
index b3acb0e..271a7d5 100644
--- a/frontend/afe/rpc_interface.py
+++ b/frontend/afe/rpc_interface.py
@@ -33,9 +33,10 @@
 
 import datetime
 import common
-from autotest_lib.client.common_lib import error, priorities
+from autotest_lib.client.common_lib import priorities
 from autotest_lib.frontend.afe import models, model_logic, model_attributes
 from autotest_lib.frontend.afe import control_file, rpc_utils
+from autotest_lib.frontend.afe import site_rpc_interface
 
 def get_parameterized_autoupdate_image_url(job):
     """Get the parameterized autoupdate image url from a parameterized job."""
@@ -495,6 +496,30 @@
         raise
 
 
+def create_job_page_handler(name, priority, control_file, control_type,
+                            image=None, hostless=False, **kwargs):
+    """\
+    Create and enqueue a job.
+
+    @param name name of this job
+    @param priority Integer priority of this job.  Higher is more important.
+    @param control_file String contents of the control file.
+    @param control_type Type of control file, Client or Server.
+    @param kwargs extra args that will be required by create_suite_job or
+                  create_job.
+
+    @returns The created Job id number.
+    """
+    control_file = rpc_utils.encode_ascii(control_file)
+
+    if image and hostless:
+        return site_rpc_interface.create_suite_job(
+                name=name, control_file=control_file, priority=priority,
+                build=image, **kwargs)
+    return create_job(name, priority, control_file, control_type, image=image,
+                      hostless=hostless, **kwargs)
+
+
 def create_job(name, priority, control_file, control_type,
                hosts=(), meta_hosts=(), one_time_hosts=(),
                atomic_group_name=None, synch_count=None, is_template=False,
@@ -502,7 +527,7 @@
                run_verify=False, email_list='', dependencies=(),
                reboot_before=None, reboot_after=None, parse_failed_repair=None,
                hostless=False, keyvals=None, drone_set=None, image=None,
-               parent_job_id=None, test_retry=0, run_reset=True):
+               parent_job_id=None, test_retry=0, run_reset=True, **kwargs):
     """\
     Create and enqueue a job.
 
@@ -527,7 +552,6 @@
     this job will be parsed as part of the job.
     @param hostless if true, create a hostless job
     @param keyvals dict of keyvals to associate with the job
-
     @param hosts List of hosts to run job on.
     @param meta_hosts List where each entry is a label name, and for each entry
     one host will be chosen from that label to run the job on.
@@ -536,48 +560,14 @@
     @param drone_set The name of the drone set to run this test on.
     @param image OS image to install before running job.
     @param parent_job_id id of a job considered to be parent of created job.
-    @param test_retry: Number of times to retry test if the test did not
+    @param test_retry Number of times to retry test if the test did not
                        complete successfully. (optional, default: 0)
-    @param run_reset: Should the host be reset before running the test?
+    @param run_reset Should the host be reset before running the test?
+    @param kwargs extra keyword args. NOT USED.
 
     @returns The created Job id number.
     """
-    # Force control files to only contain ascii characters.
-    try:
-        control_file.encode('ascii')
-    except UnicodeDecodeError as e:
-        raise error.ControlFileMalformed(str(e))
-
-    if image is None:
-        return rpc_utils.create_job_common(
-                **rpc_utils.get_create_job_common_args(locals()))
-
-    # When image is supplied use a known parameterized test already in the
-    # database to pass the OS image path from the front end, through the
-    # scheduler, and finally to autoserv as the --image parameter.
-
-    # The test autoupdate_ParameterizedJob is in afe_autotests and used to
-    # instantiate a Test object and from there a ParameterizedJob.
-    known_test_obj = models.Test.smart_get('autoupdate_ParameterizedJob')
-    known_parameterized_job = models.ParameterizedJob.objects.create(
-            test=known_test_obj)
-
-    # autoupdate_ParameterizedJob has a single parameter, the image parameter,
-    # stored in the table afe_test_parameters.  We retrieve and set this
-    # instance of the parameter to the OS image path.
-    image_parameter = known_test_obj.testparameter_set.get(test=known_test_obj,
-                                                           name='image')
-    known_parameterized_job.parameterizedjobparameter_set.create(
-            test_parameter=image_parameter, parameter_value=image,
-            parameter_type='string')
-
-    # By passing a parameterized_job to create_job_common the job entry in
-    # the afe_jobs table will have the field parameterized_job_id set.
-    # The scheduler uses this id in the afe_parameterized_jobs table to
-    # match this job to our known test, and then with the
-    # afe_parameterized_job_parameters table to get the actual image path.
     return rpc_utils.create_job_common(
-            parameterized_job=known_parameterized_job.id,
             **rpc_utils.get_create_job_common_args(locals()))