From patchwork Thu Dec 1 03:15:16 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: 5408 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 CAA0123E0F for ; Thu, 1 Dec 2011 03:15:20 +0000 (UTC) Received: from mail-lpp01m010-f52.google.com (mail-lpp01m010-f52.google.com [209.85.215.52]) by fiordland.canonical.com (Postfix) with ESMTP id B1131A182F0 for ; Thu, 1 Dec 2011 03:15:20 +0000 (UTC) Received: by mail-lpp01m010-f52.google.com with SMTP id h2so746102laa.11 for ; Wed, 30 Nov 2011 19:15:20 -0800 (PST) Received: by 10.152.123.9 with SMTP id lw9mr389667lab.12.1322709319459; Wed, 30 Nov 2011 19:15:19 -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 h6cs44813lal; Wed, 30 Nov 2011 19:15:19 -0800 (PST) Received: by 10.180.87.102 with SMTP id w6mr3561520wiz.23.1322709317236; Wed, 30 Nov 2011 19:15:17 -0800 (PST) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id m48si1516614weq.122.2011.11.30.19.15.17 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 30 Nov 2011 19:15:17 -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 1RVx7E-00034U-Sk for ; Thu, 01 Dec 2011 03:15:16 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id CC743E014A for ; Thu, 1 Dec 2011 03:15:16 +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: 99 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-validation/lava-scheduler/trunk] Rev 99: make the scheduler monitor a management command Message-Id: <20111201031516.31205.87152.launchpad@ackee.canonical.com> Date: Thu, 01 Dec 2011 03:15:16 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="14414"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: f718c6d4799624ccf566bdc854f45f64751194b8 Merge authors: Michael Hudson-Doyle (mwhudson) ------------------------------------------------------------ revno: 99 [merge] committer: Michael Hudson-Doyle branch nick: trunk timestamp: Thu 2011-12-01 16:08:59 +1300 message: make the scheduler monitor a management command added: lava_scheduler_app/management/commands/schedulermonitor.py modified: lava_scheduler_app/management/commands/scheduler.py lava_scheduler_daemon/board.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 === modified file 'lava_scheduler_app/management/commands/scheduler.py' --- lava_scheduler_app/management/commands/scheduler.py 2011-11-21 22:11:47 +0000 +++ lava_scheduler_app/management/commands/scheduler.py 2011-12-01 02:33:35 +0000 @@ -17,7 +17,7 @@ # along with LAVA Scheduler. If not, see . -from django.core.management.base import BaseCommand, CommandError +from django.core.management.base import BaseCommand from optparse import make_option @@ -62,10 +62,9 @@ def handle(self, *args, **options): import os - from twisted.internet import defer, reactor + from twisted.internet import reactor from lava_scheduler_daemon.service import BoardSet - from lava_scheduler_daemon.config import get_config from lava_scheduler_daemon.dbjobsource import DatabaseJobSource === added file 'lava_scheduler_app/management/commands/schedulermonitor.py' --- lava_scheduler_app/management/commands/schedulermonitor.py 1970-01-01 00:00:00 +0000 +++ lava_scheduler_app/management/commands/schedulermonitor.py 2011-12-01 03:03:31 +0000 @@ -0,0 +1,77 @@ +# 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 optparse import make_option +import simplejson + +from django.core.management.base import BaseCommand + +from lava_scheduler_daemon.dbjobsource import DatabaseJobSource + + +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): + from twisted.internet import reactor + from lava_scheduler_daemon.board import Job + source = DatabaseJobSource() + dispatcher, board_name, json_file = args + job = Job( + simplejson.load(open(json_file)), dispatcher, + source, board_name, reactor) + def run(): + job.run().addCallback(lambda result: reactor.stop()) + reactor.callWhenRunning(run) + self._configure_logging(options['loglevel'], options['logfile']) + reactor.run() === modified file 'lava_scheduler_daemon/board.py' --- lava_scheduler_daemon/board.py 2011-08-24 10:33:21 +0000 +++ lava_scheduler_daemon/board.py 2011-12-01 03:03:31 +0000 @@ -141,11 +141,13 @@ fd, self._json_file = tempfile.mkstemp() with os.fdopen(fd, 'wb') as f: json.dump(json_data, f) + args = [ + 'setsid', 'lava-server', 'manage', 'schedulermonitor', + self.dispatcher, str(self.board_name), self._json_file] + self.logger.info('executing "%s"', ' '.join(args)) self.reactor.spawnProcess( SimplePP(d), 'setsid', childFDs={0:0, 1:1, 2:2}, - env=None, args=[ - 'setsid', 'lava-scheduler-monitor', self.dispatcher, - str(self.board_name), self._json_file]) + env=None, args=args) d.addBoth(self._exited) return d