Revert "[autotest] Use provisioning in place of parameterized jobs."

This reverts commit ca14cc94db12a404c840ebb4b8e8dffe66245e3c.

BUG=chromium:680656

Change-Id: Ic596fb29e15c4a9309e099c83ab36723131d8743
Reviewed-on: https://chromium-review.googlesource.com/427999
Reviewed-by: Simran Basi <sbasi@chromium.org>
Commit-Queue: Don Garrett <dgarrett@chromium.org>
Tested-by: Don Garrett <dgarrett@chromium.org>
diff --git a/frontend/afe/rpc_interface.py b/frontend/afe/rpc_interface.py
index 0110ba7..27e2ea3 100644
--- a/frontend/afe/rpc_interface.py
+++ b/frontend/afe/rpc_interface.py
@@ -1,4 +1,5 @@
-# pylint: disable=missing-docstring
+# pylint: disable-msg=C0111
+
 """\
 Functions to expose over the RPC interface.
 
@@ -39,6 +40,7 @@
 import common
 from autotest_lib.client.common_lib import control_data
 from autotest_lib.client.common_lib import priorities
+from autotest_lib.client.common_lib.cros import dev_server
 # TODO(akeshet): Replace with monarch stats once we know how to instrument rpc
 # server with ts_mon.
 from autotest_lib.client.common_lib.cros.graphite import autotest_stats
@@ -1027,10 +1029,42 @@
     if args:
         control_file = tools.inject_vars({'args': args}, control_file)
 
-    if image:
-        version_label = provision.cros_version_to_label(image)
-        dependencies += (version_label,)
+    if image is None:
+        return rpc_utils.create_job_common(
+                **rpc_utils.get_create_job_common_args(locals()))
+
+    # Translate the image name, in case its a relative build name.
+    ds = dev_server.ImageServer.resolve(image)
+    image = ds.translate(image)
+
+    # 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')
+
+    # TODO(crbug.com/502638): save firmware build etc to parameterized_job.
+
+    # 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()))