When using Django models from a script, make the current user default to an actual database user named "autotest_system".  This allows for simpler, more consistent code.

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


git-svn-id: http://test.kernel.org/svn/autotest/trunk@4114 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/scheduler/monitor_db.py b/scheduler/monitor_db.py
index 9e4a654..d2ee557 100755
--- a/scheduler/monitor_db.py
+++ b/scheduler/monitor_db.py
@@ -2143,6 +2143,9 @@
                 aborted_on.add(t)
 
         # extract some actual, unique aborted by value and write it out
+        # TODO(showard): this conditional is now obsolete, we just need to leave
+        # it in temporarily for backwards compatibility over upgrades.  delete
+        # soon.
         assert len(aborted_by) <= 1
         if len(aborted_by) == 1:
             aborted_by_value = aborted_by.pop()
@@ -3565,9 +3568,8 @@
 
     def request_abort(self):
         """Request that this Job be aborted on the next scheduler cycle."""
-        queue_entries = HostQueueEntry.fetch(where="job_id=%s" % self.id)
-        for hqe in queue_entries:
-            hqe.update_field('aborted', True)
+        self_model = models.Job.objects.get(id=self.id)
+        self_model.abort()
 
 
     def schedule_delayed_callback_task(self, queue_entry):
diff --git a/scheduler/monitor_db_cleanup.py b/scheduler/monitor_db_cleanup.py
index 3912aab..f1eaac4 100644
--- a/scheduler/monitor_db_cleanup.py
+++ b/scheduler/monitor_db_cleanup.py
@@ -65,7 +65,7 @@
             where=['created_on + INTERVAL timeout HOUR < NOW()'])
         for job in query.distinct():
             logging.warning('Aborting job %d due to job timeout', job.id)
-            job.abort(None)
+            job.abort()
 
 
     def _abort_jobs_past_max_runtime(self):
@@ -83,7 +83,7 @@
             id__in=[row[0] for row in rows])
         for queue_entry in query.distinct():
             logging.warning('Aborting entry %s due to max runtime', queue_entry)
-            queue_entry.abort(None)
+            queue_entry.abort()
 
 
     def _check_for_db_inconsistencies(self):
diff --git a/scheduler/monitor_db_unittest.py b/scheduler/monitor_db_unittest.py
index 4f5f472..ac8240b 100755
--- a/scheduler/monitor_db_unittest.py
+++ b/scheduler/monitor_db_unittest.py
@@ -10,7 +10,6 @@
 from autotest_lib.client.common_lib.test_utils import mock
 from autotest_lib.client.common_lib.test_utils import unittest
 from autotest_lib.database import database_connection, migrate
-from autotest_lib.frontend import thread_local
 from autotest_lib.frontend.afe import models
 from autotest_lib.scheduler import monitor_db, drone_manager, email_manager
 from autotest_lib.scheduler import scheduler_config, gc_stats