Explicitly release pidfiles after we're done with them.  This does it in a kind of lazy way, but it should work just fine.  Also extended the new scheduler functional test with a few more cases and added a test to check pidfile release under these various cases.  In the process, I changed how some of the code works to allow the tests to more cleanly express their intentions.

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


git-svn-id: http://test.kernel.org/svn/autotest/trunk@3804 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/scheduler/monitor_db.py b/scheduler/monitor_db.py
index 3ea83f7..1c62491 100755
--- a/scheduler/monitor_db.py
+++ b/scheduler/monitor_db.py
@@ -1732,8 +1732,11 @@
     def cleanup(self):
         super(SpecialAgentTask, self).cleanup()
         self.task.finish()
-        if self.monitor and self.monitor.has_process():
-            self._copy_results([self.task])
+        if self.monitor:
+            if self.monitor.has_process():
+                self._copy_results([self.task])
+            if self.monitor.pidfile_id is not None:
+                _drone_manager.unregister_pidfile(self.monitor.pidfile_id)
 
 
 class RepairTask(SpecialAgentTask):
@@ -2727,6 +2730,7 @@
                       models.HostQueueEntry.Status.ABORTED):
             self.update_field('complete', True)
             self.update_field('active', False)
+            self._on_complete()
 
         should_email_status = (status.lower() in _notify_email_statuses or
                                'all' in _notify_email_statuses)
@@ -2736,6 +2740,16 @@
         self._email_on_job_complete()
 
 
+    def _on_complete(self):
+        if not self.execution_subdir:
+            return
+        # unregister any possible pidfiles associated with this queue entry
+        for pidfile_name in _ALL_PIDFILE_NAMES:
+            pidfile_id = _drone_manager.get_pidfile_id_from(
+                    self.execution_path(), pidfile_name=pidfile_name)
+            _drone_manager.unregister_pidfile(pidfile_id)
+
+
     def _email_on_status(self, status):
         hostname = self._get_hostname()