[autotest] Fixes for 'Create Job' page when using 'Fetch Tests from Build'

'Fetch Tests from Build' correctly populated the test selector with
the tests supported by the provided image, however, when communicating
with the backend, default test information from the database was being
used. This resulted in the wrong control file being used for the
selected test. In addition, the get_tests_by_build rpc reponse was
missing information required by certain AFE functions, this resulted
in the auto-selection for hostless jobs to break when fetching tests
for an image.

This CL makes it so that when tests are fetched for a particular image,
client state describing the control file is used to find/build
the control file rather than pulling from the default test database.
It also corrects the get_tests_by_build rpc so that the missing
attributes are provided.

BUG=chromium:503385,chromium:503731
DEPLOY=afe
TEST=Tested changes on a moblab.

Change-Id: I54739a4bb6e96cd2517ea59dc0a937d0d81cc000
Reviewed-on: https://chromium-review.googlesource.com/281760
Tested-by: Matthew Sartori <msartori@chromium.org>
Reviewed-by: Dan Shi <dshi@chromium.org>
Reviewed-by: Simran Basi <sbasi@chromium.org>
Commit-Queue: Matthew Sartori <msartori@chromium.org>
diff --git a/frontend/afe/site_rpc_interface.py b/frontend/afe/site_rpc_interface.py
index 1daab8f..e6d7849 100644
--- a/frontend/afe/site_rpc_interface.py
+++ b/frontend/afe/site_rpc_interface.py
@@ -615,7 +615,10 @@
         # values, these must be corrected to avoid the risk of tests
         # being omitted by the AFE.
         # The 'id' is an additional value used in the AFE.
+        # The control_data parsing does not reference 'run_reset', but it
+        # is also used in the AFE and defaults to True.
         test_object['id'] = _id
+        test_object['run_reset'] = True
         test_object['description'] = test_object.get('doc', '')
         test_object['test_time'] = test_object.get('time', 0)
         test_object['test_retry'] = test_object.get('retries', 0)
@@ -630,7 +633,11 @@
 
         test_object['name'] = testname
 
+        # Correct the test path as parse_control_string sets an empty string.
+        test_object['path'] = control_file_path
+
         _id += 1
         test_objects.append(test_object)
 
+    test_objects = sorted(test_objects, key=lambda x: x.get('name'))
     return rpc_utils.prepare_for_serialization(test_objects)