[autotest] Save parent job id, build, board and suite info to tko_jobs.

parent job id is passed in through autoserv commandline. autoserv saves the
value to keyval file in results folder. The parser job then reads the parent
job id from keyval file.

build, board and suite info are parsed from job name. The label column in
tko_jobs is essentially the job name. However, that column has a size limit of
100 characters, thus the name could be truncated. This CL parse the actual job
name to get the build, board and suite info and save to tko_jobs table.

BUG=chromium:509770,chromium:509901
TEST=local test
CQ-DEPEND=CL:285026

Change-Id: I06b073b052a9d07ffd36308b1682a7bc12699898
Reviewed-on: https://chromium-review.googlesource.com/286265
Tested-by: Dan Shi <dshi@chromium.org>
Reviewed-by: Mungyung Ryu <mkryu@google.com>
Commit-Queue: Dan Shi <dshi@chromium.org>
diff --git a/tko/db.py b/tko/db.py
index 68e2b86..80ea5c9 100644
--- a/tko/db.py
+++ b/tko/db.py
@@ -7,6 +7,7 @@
 import common
 from autotest_lib.client.common_lib import global_config
 from autotest_lib.frontend import database_settings_helper
+from autotest_lib.server import site_utils
 from autotest_lib.tko import utils
 
 
@@ -355,7 +356,7 @@
         self.delete('tko_jobs', where)
 
 
-    def insert_job(self, tag, job, commit = None):
+    def insert_job(self, tag, job, parent_job_id=None, commit=None):
         job.machine_idx = self.lookup_machine(job.machine)
         if not job.machine_idx:
             job.machine_idx = self.insert_machine(job, commit=commit)
@@ -371,7 +372,15 @@
                 'queued_time': job.queued_time,
                 'started_time': job.started_time,
                 'finished_time': job.finished_time,
-                'afe_job_id': afe_job_id}
+                'afe_job_id': afe_job_id,
+                'afe_parent_job_id': parent_job_id}
+        if job.label:
+            label_info = site_utils.parse_job_name(job.label)
+            if label_info:
+                data['build'] = label_info.get('build', None)
+                data['build_version'] = label_info.get('build_version', None)
+                data['board'] = label_info.get('board', None)
+                data['suite'] = label_info.get('suite', None)
         is_update = hasattr(job, 'index')
         if is_update:
             self.update('tko_jobs', data, {'job_idx': job.index}, commit=commit)