Support for job keyvals
* can be passed as an argument to create_job, stored in AFE DB
* scheduler reads them from the AFE DB and writes them to the job-level keyval file before the job starts
* parser reads them from the keyval file and writes them to the TKO DB in a new table

Since the field name "key" happens to be a MySQL keyword, I went ahead and made db.py support proper quoting of field names.  Evetually it'd be really nice to deprecate db.py and use Django models exclusively, but that is a far-off dream.

Still lacking support in the AFE and TKO web clients and CLIs, at least the TKO part will be coming soon

Signed-off-by: Steve Howard <showard@google.com>


git-svn-id: http://test.kernel.org/svn/autotest/trunk@4123 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/scheduler/monitor_db.py b/scheduler/monitor_db.py
index f4cb804..4164732 100755
--- a/scheduler/monitor_db.py
+++ b/scheduler/monitor_db.py
@@ -2097,7 +2097,8 @@
 
     def prolog(self):
         queued_key, queued_time = self._job_queued_keyval(self.job)
-        keyval_dict = {queued_key: queued_time}
+        keyval_dict = self.job.keyval_dict()
+        keyval_dict[queued_key] = queued_time
         group_name = self.queue_entries[0].get_group_name()
         if group_name:
             keyval_dict['host_group_name'] = group_name
@@ -3214,6 +3215,10 @@
         self._owner_model = None # caches model instance of owner
 
 
+    def model(self):
+        return models.Job.objects.get(id=self.id)
+
+
     def owner_model(self):
         # work around the fact that the Job owner field is a string, not a
         # foreign key
@@ -3250,6 +3255,10 @@
                 queue_entry.set_status(status)
 
 
+    def keyval_dict(self):
+        return self.model().keyval_dict()
+
+
     def _atomic_and_has_started(self):
         """
         @returns True if any of the HostQueueEntries associated with this job
@@ -3579,8 +3588,7 @@
 
     def request_abort(self):
         """Request that this Job be aborted on the next scheduler cycle."""
-        self_model = models.Job.objects.get(id=self.id)
-        self_model.abort()
+        self.model().abort()
 
 
     def schedule_delayed_callback_task(self, queue_entry):