fix a bug with pre-job keyvals, introduced in recent refactorings, and added new test to check it

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


git-svn-id: http://test.kernel.org/svn/autotest/trunk@4020 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/scheduler/monitor_db_functional_test.py b/scheduler/monitor_db_functional_test.py
index 228027f..3ada21e 100644
--- a/scheduler/monitor_db_functional_test.py
+++ b/scheduler/monitor_db_functional_test.py
@@ -161,6 +161,16 @@
         return self._pidfile_index[(working_directory, pidfile_name)]
 
 
+    def attached_files(self, working_directory):
+        """
+        Return dict mapping path to contents for attached files with specified
+        paths.
+        """
+        return dict((path, contents) for path, contents
+                    in self._attached_files.get(working_directory, [])
+                    if path is not None)
+
+
     # DroneManager emulation APIs for use by monitor_db
 
     def get_orphaned_autoserv_processes(self):
@@ -981,5 +991,17 @@
         self._check_entry_status(entry, HqeStatus.COMPLETED)
 
 
+    def test_pre_job_keyvals(self):
+        self.test_simple_job()
+        attached_files = self.mock_drone_manager.attached_files(
+                '1-my_user/host1')
+        job_keyval_path = '1-my_user/host1/keyval'
+        self.assert_(job_keyval_path in attached_files, attached_files)
+        keyval_contents = attached_files[job_keyval_path]
+        keyval_dict = dict(line.strip().split('=', 1)
+                           for line in keyval_contents.splitlines())
+        self.assert_('job_queued' in keyval_dict, keyval_dict)
+
+
 if __name__ == '__main__':
     unittest.main()