diff mbox

[Branch,~linaro-validation/lava-scheduler/trunk] Rev 99: make the scheduler monitor a management command

Message ID 20111201031516.31205.87152.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Michael-Doyle Hudson Dec. 1, 2011, 3:15 a.m. UTC
Merge authors:
  Michael Hudson-Doyle (mwhudson)
------------------------------------------------------------
revno: 99 [merge]
committer: Michael Hudson-Doyle <michael.hudson@linaro.org>
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
diff mbox

Patch

=== 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 <http://www.gnu.org/licenses/>.
 
 
-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 <zygmunt.krynicki@linaro.org>
+#
+# 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 <http://www.gnu.org/licenses/>.
+
+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