[autotest] Consolidate methods required to setup a scheduler.

Move methods/classes that will be helpful in setting up another scheduler
process into scheduler_lib:
1. Make a connection manager capable of managing connections.
   Create, access, close the database connection through this manager.
2. Cleanup setup_logging so it's usable by multiple schedulers if they
   just change the name of the logfile.

TEST=Ran suites, unittests.
BUG=chromium:344613
DEPLOY=Scheduler

Change-Id: Id0031df96948d386416ce7cfc754f80456930b95
Reviewed-on: https://chromium-review.googlesource.com/199957
Reviewed-by: Prashanth B <beeps@chromium.org>
Tested-by: Prashanth B <beeps@chromium.org>
Commit-Queue: Prashanth B <beeps@chromium.org>
diff --git a/scheduler/monitor_db_unittest.py b/scheduler/monitor_db_unittest.py
index 5b12c91..62bf6b4 100755
--- a/scheduler/monitor_db_unittest.py
+++ b/scheduler/monitor_db_unittest.py
@@ -12,9 +12,10 @@
 from autotest_lib.scheduler import agent_task
 from autotest_lib.scheduler import monitor_db, drone_manager, email_manager
 from autotest_lib.scheduler import pidfile_monitor
-from autotest_lib.scheduler import scheduler_config, gc_stats, host_scheduler
+from autotest_lib.scheduler import scheduler_config, gc_stats
 from autotest_lib.scheduler import monitor_db_cleanup
 from autotest_lib.scheduler import monitor_db_functional_test
+from autotest_lib.scheduler import scheduler_lib
 from autotest_lib.scheduler import scheduler_models
 
 _DEBUG = False
@@ -101,7 +102,9 @@
         self._database.connect(db_type='django')
         self._database.debug = _DEBUG
 
-        self.god.stub_with(monitor_db, '_db', self._database)
+        connection_manager = scheduler_lib.ConnectionManager(autocommit=False)
+        self.god.stub_with(connection_manager, 'db_connection', self._database)
+        self.god.stub_with(monitor_db, '_db_manager', connection_manager)
         self.god.stub_with(monitor_db.BaseDispatcher,
                            '_get_pending_queue_entries',
                            self._get_pending_hqes)
@@ -1021,7 +1024,7 @@
                 dummy_test_agent)
 
         # Attempted to schedule on a host that already has an agent.
-        self.assertRaises(host_scheduler.SchedulerError,
+        self.assertRaises(scheduler_lib.SchedulerError,
                           self._dispatcher._schedule_running_host_queue_entries)