diff mbox

[Branch,~linaro-validation/lava-scheduler/trunk] Rev 55: lava-scheduler now reads a log file to configure logging

Message ID 20110727222543.2887.31407.launchpad@loganberry.canonical.com
State Accepted
Headers show

Commit Message

Michael-Doyle Hudson July 27, 2011, 10:25 p.m. UTC
Merge authors:
  Michael Hudson-Doyle (mwhudson)
Related merge proposals:
  https://code.launchpad.net/~mwhudson/lava-scheduler/config-file-for-daemon/+merge/69403
  proposed by: Michael Hudson-Doyle (mwhudson)
  review: Approve - Zygmunt Krynicki (zkrynicki)
------------------------------------------------------------
revno: 55 [merge]
committer: Michael-Doyle Hudson <michael.hudson@linaro.org>
branch nick: trunk
timestamp: Thu 2011-07-28 10:23:48 +1200
message:
  lava-scheduler now reads a log file to configure logging
added:
  lava-scheduler
  lava_scheduler_daemon/config.py
renamed:
  lava-scheduler => lava_scheduler_daemon/main.py*
modified:
  lava_scheduler_daemon/board.py
  lava_scheduler_daemon/service.py
  lava_scheduler_daemon/main.py*


--
lp:lava-scheduler
https://code.launchpad.net/~linaro-validation/lava-scheduler/trunk

You are subscribed to branch lp:lava-scheduler.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-scheduler/trunk/+edit-subscription
diff mbox

Patch

=== added file 'lava-scheduler'
--- lava-scheduler	1970-01-01 00:00:00 +0000
+++ lava-scheduler	2011-07-27 07:02:12 +0000
@@ -0,0 +1,11 @@ 
+#!/usr/bin/python
+
+import os
+
+# The following line is mangled to point at the debian settings file
+# at package build time.
+os.environ['DJANGO_SETTINGS_MODULE'] = 'lava_server.settings.development'
+
+from lava_scheduler_daemon.main import main
+
+main()

=== modified file 'lava_scheduler_daemon/board.py'
--- lava_scheduler_daemon/board.py	2011-07-26 01:01:46 +0000
+++ lava_scheduler_daemon/board.py	2011-07-27 06:50:34 +0000
@@ -190,7 +190,7 @@ 
                 self._check_call = self.reactor.callLater(
                     10, self._checkForJob)
             return
-        self.logger.debug("starting job %r", job_data)
+        self.logger.info("starting job %r", job_data)
         self.running_job = self.job_cls(
             job_data, self.dispatcher, self.reactor)
         d = self.running_job.run()

=== added file 'lava_scheduler_daemon/config.py'
--- lava_scheduler_daemon/config.py	1970-01-01 00:00:00 +0000
+++ lava_scheduler_daemon/config.py	2011-07-27 06:59:51 +0000
@@ -0,0 +1,35 @@ 
+from ConfigParser import ConfigParser
+import os
+from StringIO import StringIO
+
+#from xdg.BaseDirectory import load_config_paths
+
+defaults = {
+    'logging': StringIO(
+'''
+[logging]
+level = INFO
+destination = -
+'''),
+    }
+
+# python xdg isn't installable via pip, so...
+def load_config_paths(name):
+    for directory in os.path.expanduser("~/.config"), '/etc/xdg':
+        path = os.path.join(directory, name)
+        if os.path.isdir(path):
+            yield path
+
+
+def get_config(name):
+    config_files = []
+    for directory in load_config_paths('lava-scheduler'):
+        path = os.path.join(directory, '%s.conf' % name)
+        if os.path.exists(path):
+            config_files.append(path)
+    config_files.reverse()
+    fp = ConfigParser()
+    if name in defaults:
+        fp.readfp(defaults[name])
+    fp.read(config_files)
+    return fp

=== renamed file 'lava-scheduler' => 'lava_scheduler_daemon/main.py' (properties changed: +x to -x)
--- lava-scheduler	2011-07-27 00:28:03 +0000
+++ lava_scheduler_daemon/main.py	2011-07-27 06:59:51 +0000
@@ -1,4 +1,3 @@ 
-#!/usr/bin/env python
 import logging
 import os
 import sys
@@ -6,28 +5,36 @@ 
 from twisted.internet import reactor
 
 from lava_scheduler_daemon.service import BoardSet
+from lava_scheduler_daemon.config import get_config
 
-os.environ['DJANGO_SETTINGS_MODULE'] = 'lava_server.settings.development'
 from lava_scheduler_daemon.dbjobsource import DatabaseJobSource
 
-source = DatabaseJobSource()
-
-if sys.argv[1:] == ['--use-fake']:
-    dispatcher = os.path.join(
-        os.path.dirname(os.path.abspath(__file__)), 'fake-dispatcher')
-elif sys.argv[1:]:
-    print >>sys.stderr, "invalid options %r" % sys.argv[1:]
-    sys.exit(1)
-else:
-    dispatcher = 'lava-dispatch'
-
-service = BoardSet(source, dispatcher, reactor)
-reactor.callWhenRunning(service.startService)
-
-logger = logging.getLogger('')
-handler = logging.StreamHandler(sys.stdout)
-handler.setFormatter(logging.Formatter("[%(name)s] %(message)s"))
-logger.addHandler(handler)
-logger.setLevel(logging.DEBUG)
-
-reactor.run()
+def main():
+    source = DatabaseJobSource()
+
+    if sys.argv[1:] == ['--use-fake']:
+        dispatcher = os.path.join(
+            os.path.dirname(os.path.abspath(__file__)), 'fake-dispatcher')
+    elif sys.argv[1:]:
+        print >>sys.stderr, "invalid options %r" % sys.argv[1:]
+        sys.exit(1)
+    else:
+        dispatcher = 'lava-dispatch'
+
+    service = BoardSet(source, dispatcher, reactor)
+    reactor.callWhenRunning(service.startService)
+
+    logger = logging.getLogger('')
+    config = get_config('logging')
+    level = config.get("logging", "level")
+    destination = config.get("logging", 'destination', None)
+    if destination == '-':
+        handler = logging.StreamHandler(sys.stdout)
+    else:
+        handler = logging.FileHandler(destination)
+    handler.setFormatter(
+        logging.Formatter("[%(levelname)s] [%(name)s] %(message)s"))
+    logger.addHandler(handler)
+    logger.setLevel(getattr(logging, level))
+
+    reactor.run()

=== modified file 'lava_scheduler_daemon/service.py'
--- lava_scheduler_daemon/service.py	2011-07-06 21:59:57 +0000
+++ lava_scheduler_daemon/service.py	2011-07-27 06:59:33 +0000
@@ -20,10 +20,12 @@ 
         self._update_boards_call.clock = reactor
 
     def _updateBoards(self):
-        self.logger.info("Refreshing board list")
+        self.logger.debug("Refreshing board list")
         return self.source.getBoardList().addCallback(self._cbUpdateBoards)
 
     def _cbUpdateBoards(self, board_names):
+        if set(board_names) == set(self.boards):
+            return
         self.logger.info("New board list %s", board_names)
         new_boards = {}
         for board_name in board_names: