[autotest]: Restore create_job parameterized job functionality.

Turns out the lab admin's use parameterized jobs to reimage devices
through the AFE. We deleted this logic as we thought it was not used.
This is restoring the same code we deleted.

Logic originally removed in:
https://chromium-review.googlesource.com/#/c/194349/

BUG=chromium:372640
TEST=Able to specify an image and kick off a non-suite job and have
the device be reimaged.
DEPLOY=apache

Change-Id: I7c2f0e752362257da3aadb5a3b167b1847840f09
Reviewed-on: https://chromium-review.googlesource.com/201963
Tested-by: Simran Basi <sbasi@chromium.org>
Reviewed-by: Jay Kim <yongjaek@chromium.org>
Commit-Queue: Jay Kim <yongjaek@chromium.org>
diff --git a/frontend/afe/rpc_interface.py b/frontend/afe/rpc_interface.py
index 271a7d5..80e2197 100644
--- a/frontend/afe/rpc_interface.py
+++ b/frontend/afe/rpc_interface.py
@@ -567,7 +567,36 @@
 
     @returns The created Job id number.
     """
+    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()))