From patchwork Mon Nov 21 23:16:12 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zygmunt Krynicki X-Patchwork-Id: 5248 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 2BB4B23E10 for ; Mon, 21 Nov 2011 23:16:15 +0000 (UTC) Received: from mail-fx0-f52.google.com (mail-fx0-f52.google.com [209.85.161.52]) by fiordland.canonical.com (Postfix) with ESMTP id 14F3CA184A4 for ; Mon, 21 Nov 2011 23:16:15 +0000 (UTC) Received: by faaa26 with SMTP id a26so11686538faa.11 for ; Mon, 21 Nov 2011 15:16:15 -0800 (PST) Received: by 10.152.144.136 with SMTP id sm8mr10316771lab.33.1321917374844; Mon, 21 Nov 2011 15:16:14 -0800 (PST) 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.152.41.198 with SMTP id h6cs148930lal; Mon, 21 Nov 2011 15:16:14 -0800 (PST) Received: by 10.227.206.82 with SMTP id ft18mr10244439wbb.21.1321917373288; Mon, 21 Nov 2011 15:16:13 -0800 (PST) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id fb5si1736692wbb.13.2011.11.21.15.16.13 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 21 Nov 2011 15:16:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) client-ip=91.189.90.7; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) smtp.mail=bounces@canonical.com Received: from ackee.canonical.com ([91.189.89.26]) by indium.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1RSd5w-0002lV-Px for ; Mon, 21 Nov 2011 23:16:12 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id B9666E0100 for ; Mon, 21 Nov 2011 23:16:12 +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: 98 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-validation/lava-scheduler/trunk] Rev 98: Expose lava scheduler as django management command Message-Id: <20111121231612.2865.2011.launchpad@ackee.canonical.com> Date: Mon, 21 Nov 2011 23:16:12 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="14299"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: d68a935d1495a5e5c309c8fd85694848a774c987 ------------------------------------------------------------ revno: 98 committer: Zygmunt Krynicki branch nick: lava-scheduler timestamp: Mon 2011-11-21 23:11:47 +0100 message: Expose lava scheduler as django management command added: lava_scheduler_app/management/ lava_scheduler_app/management/__init__.py lava_scheduler_app/management/commands/ lava_scheduler_app/management/commands/__init__.py lava_scheduler_app/management/commands/scheduler.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 directory 'lava_scheduler_app/management' === added file 'lava_scheduler_app/management/__init__.py' === added directory 'lava_scheduler_app/management/commands' === added file 'lava_scheduler_app/management/commands/__init__.py' === added file 'lava_scheduler_app/management/commands/scheduler.py' --- lava_scheduler_app/management/commands/scheduler.py 1970-01-01 00:00:00 +0000 +++ lava_scheduler_app/management/commands/scheduler.py 2011-11-21 22:11:47 +0000 @@ -0,0 +1,84 @@ +# Copyright (C) 2011 Linaro Limited +# +# Author: Zygmunt Krynicki +# +# This file is part of LAVA Scheduler. +# +# LAVA Scheduler is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License version 3 as +# published by the Free Software Foundation +# +# LAVA Scheduler is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with LAVA Scheduler. If not, see . + + +from django.core.management.base import BaseCommand, CommandError +from optparse import make_option + + +class Command(BaseCommand): + + help = "Run the LAVA test job scheduler" + option_list = BaseCommand.option_list + ( + make_option('--use-fake', + action='store_true', + dest='use_fake', + default=False, + help="Use fake dispatcher (for testing)"), + make_option('--dispatcher', + action="store", + dest="dispatcher", + default="lava-dispatch", + help="Dispatcher command to invoke"), + make_option('-l', '--loglevel', + action='store', + default='WARNING', + help="Log level, default is WARNING"), + make_option('-f', '--logfile', + action='store', + default=None, + help="Path to log file"), + ) + + + def _configure_logging(self, loglevel, logfile=None): + import logging + import sys + logger = logging.getLogger('') + if logfile is None: + handler = logging.StreamHandler(sys.stderr) + else: + handler = logging.FileHandler(logfile) + handler.setFormatter( + logging.Formatter("[%(levelname)s] [%(name)s] %(message)s")) + logger.addHandler(handler) + logger.setLevel(getattr(logging, loglevel.upper())) + + def handle(self, *args, **options): + import os + + from twisted.internet import defer, reactor + + from lava_scheduler_daemon.service import BoardSet + from lava_scheduler_daemon.config import get_config + + from lava_scheduler_daemon.dbjobsource import DatabaseJobSource + + self._configure_logging(options['loglevel'], options['logfile']) + + source = DatabaseJobSource() + + if options['use_fake']: + dispatcher = os.path.join( + os.path.dirname(os.path.dirname(os.path.abspath(__file__))), + 'fake-dispatcher') + else: + dispatcher = options['dispatcher'] + service = BoardSet(source, dispatcher, reactor) + reactor.callWhenRunning(service.startService) + reactor.run()