From patchwork Wed Jul 27 22:25:43 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael-Doyle Hudson X-Patchwork-Id: 3181 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id DA47723F18 for ; Wed, 27 Jul 2011 22:25:47 +0000 (UTC) Received: from mail-qw0-f52.google.com (mail-qw0-f52.google.com [209.85.216.52]) by fiordland.canonical.com (Postfix) with ESMTP id 8D406A18054 for ; Wed, 27 Jul 2011 22:25:47 +0000 (UTC) Received: by qwb8 with SMTP id 8so1573481qwb.11 for ; Wed, 27 Jul 2011 15:25:47 -0700 (PDT) Received: by 10.229.236.10 with SMTP id ki10mr255664qcb.274.1311805546799; Wed, 27 Jul 2011 15:25:46 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.229.217.78 with SMTP id hl14cs158866qcb; Wed, 27 Jul 2011 15:25:46 -0700 (PDT) Received: by 10.227.53.210 with SMTP id n18mr319623wbg.63.1311805544656; Wed, 27 Jul 2011 15:25:44 -0700 (PDT) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by mx.google.com with ESMTP id s17si599294wec.52.2011.07.27.15.25.44; Wed, 27 Jul 2011 15:25:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) client-ip=91.189.90.139; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.139 as permitted sender) smtp.mail=bounces@canonical.com Received: from loganberry.canonical.com ([91.189.90.37]) by adelie.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1QmCXv-0001SY-U9 for ; Wed, 27 Jul 2011 22:25:43 +0000 Received: from loganberry.canonical.com (localhost [127.0.0.1]) by loganberry.canonical.com (Postfix) with ESMTP id DF4B82E8067 for ; Wed, 27 Jul 2011 22:25:43 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: lava-scheduler X-Launchpad-Branch: ~linaro-validation/lava-scheduler/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 55 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [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> Date: Wed, 27 Jul 2011 22:25:43 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="13535"; Instance="initZopeless config overlay" X-Launchpad-Hash: ccd45d6db52ac510e71dcb498b405b5d3457cafe 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 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 === 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: