=== modified file 'lava_scheduler_app/management/commands/__init__.py'
@@ -0,0 +1,23 @@
+import logging
+import sys
+
+from django.core.management.base import BaseCommand
+
+
+class SchedulerCommand(BaseCommand):
+
+ log_prefix = ''
+
+ def _configure_logging(self, loglevel, logfile=None):
+ logger = logging.getLogger('')
+ if logfile is None:
+ handler = logging.StreamHandler(sys.stderr)
+ else:
+ handler = logging.FileHandler(logfile)
+ fmt = "%(asctime)s [%(levelname)s] [%(name)s] %(message)s"
+ if self.log_prefix:
+ fmt = self.log_prefix + ' ' + fmt
+ handler.setFormatter(logging.Formatter(fmt))
+ logger.addHandler(handler)
+ logger.setLevel(getattr(logging, loglevel.upper()))
+
=== modified file 'lava_scheduler_app/management/commands/scheduler.py'
@@ -17,14 +17,14 @@
# along with LAVA Scheduler. If not, see <http://www.gnu.org/licenses/>.
-from django.core.management.base import BaseCommand
from optparse import make_option
+from lava_scheduler_app.management.commands import SchedulerCommand
-class Command(BaseCommand):
+class Command(SchedulerCommand):
help = "Run the LAVA test job scheduler"
- option_list = BaseCommand.option_list + (
+ option_list = SchedulerCommand.option_list + (
make_option('--use-fake',
action='store_true',
dest='use_fake',
@@ -45,20 +45,6 @@
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
@@ -78,6 +64,8 @@
'fake-dispatcher')
else:
dispatcher = options['dispatcher']
- service = BoardSet(source, dispatcher, reactor)
+ service = BoardSet(
+ source, dispatcher, reactor, log_file=options['logfile'],
+ log_level=options['loglevel'])
reactor.callWhenRunning(service.startService)
reactor.run()
=== modified file 'lava_scheduler_app/management/commands/schedulermonitor.py'
@@ -19,15 +19,15 @@
from optparse import make_option
import simplejson
-from django.core.management.base import BaseCommand
+from lava_scheduler_app.management.commands import SchedulerCommand
from lava_scheduler_daemon.dbjobsource import DatabaseJobSource
-class Command(BaseCommand):
+class Command(SchedulerCommand):
help = "Run the LAVA test job scheduler"
- option_list = BaseCommand.option_list + (
+ option_list = SchedulerCommand.option_list + (
make_option('--use-fake',
action='store_true',
dest='use_fake',
@@ -48,19 +48,7 @@
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("M [%(levelname)s] [%(name)s] %(message)s"))
- logger.addHandler(handler)
- logger.setLevel(getattr(logging, loglevel.upper()))
+ log_prefix = 'M'
def handle(self, *args, **options):
from twisted.internet import reactor
@@ -69,7 +57,8 @@
dispatcher, board_name, json_file = args
job = Job(
simplejson.load(open(json_file)), dispatcher,
- source, board_name, reactor)
+ source, board_name, reactor, log_file=options['logfile'],
+ log_level=options['loglevel'])
def run():
job.run().addCallback(lambda result: reactor.stop())
reactor.callWhenRunning(run)
=== modified file 'lava_scheduler_daemon/board.py'
@@ -64,7 +64,8 @@
logger = logging.getLogger(__name__ + '.Job')
- def __init__(self, job_data, dispatcher, source, board_name, reactor):
+ def __init__(self, job_data, dispatcher, source, board_name, reactor,
+ log_file, log_level):
self.job_data = job_data
self.dispatcher = dispatcher
self.source = source
@@ -126,12 +127,15 @@
logger = logging.getLogger(__name__ + '.MonitorJob')
- def __init__(self, job_data, dispatcher, source, board_name, reactor):
+ def __init__(self, job_data, dispatcher, source, board_name, reactor,
+ log_file, log_level):
self.job_data = job_data
self.dispatcher = dispatcher
self.source = source
self.board_name = board_name
self.reactor = reactor
+ self.log_file = log_file
+ self.log_level = log_level
self._json_file = None
def run(self):
@@ -140,15 +144,12 @@
fd, self._json_file = tempfile.mkstemp()
with os.fdopen(fd, 'wb') as f:
json.dump(json_data, f)
- root_logger = logging.getLogger('')
- root_level_name = logging._levelNames[root_logger.level]
- root_handler = root_logger.handlers[0]
args = [
'setsid', 'lava-server', 'manage', 'schedulermonitor',
self.dispatcher, str(self.board_name), self._json_file,
- '-l', root_level_name]
- if isinstance(root_handler, logging.FileHandler):
- args.extend(['-f', root_handler.baseFilename])
+ '-l', self.log_level]
+ if self.log_file:
+ args.extend(['-f', self.log_file])
self.logger.info('executing "%s"', ' '.join(args))
self.reactor.spawnProcess(
SimplePP(d), 'setsid', childFDs={0:0, 1:1, 2:2},
@@ -212,11 +213,14 @@
job_cls = MonitorJob
- def __init__(self, source, board_name, dispatcher, reactor, job_cls=None):
+ def __init__(self, source, board_name, dispatcher, reactor, log_file,
+ log_level, job_cls=None):
self.source = source
self.board_name = board_name
self.dispatcher = dispatcher
self.reactor = reactor
+ self.log_file = log_file
+ self.log_level = log_level
if job_cls is not None:
self.job_cls = job_cls
self.running_job = None
@@ -297,7 +301,7 @@
self.logger.info("starting job %r", job_data)
self.running_job = self.job_cls(
job_data, self.dispatcher, self.source, self.board_name,
- self.reactor)
+ self.reactor, self.log_file, self.log_level)
d = self.running_job.run()
d.addCallbacks(self._cbJobFinished, self._ebJobFinished)
=== modified file 'lava_scheduler_daemon/service.py'
@@ -11,11 +11,13 @@
logger = logging.getLogger(__name__ + '.BoardSet')
- def __init__(self, source, dispatcher, reactor):
+ def __init__(self, source, dispatcher, reactor, log_file, log_level):
self.source = source
self.boards = {}
self.dispatcher = dispatcher
self.reactor = reactor
+ self.log_file = log_file
+ self.log_level = log_level
self._update_boards_call = LoopingCall(self._updateBoards)
self._update_boards_call.clock = reactor
@@ -34,7 +36,8 @@
new_boards[board_name] = self.boards.pop(board_name)
else:
new_boards[board_name] = Board(
- self.source, board_name, self.dispatcher, self.reactor)
+ self.source, board_name, self.dispatcher, self.reactor,
+ self.log_file, self.log_level)
new_boards[board_name].start()
for board in self.boards.values():
board.stop()
=== modified file 'lava_scheduler_daemon/tests/test_board.py'
@@ -75,7 +75,8 @@
self.fail("Logged warnings: %s" % warnings)
def make_board(self, board_name):
- board = Board(self.source, board_name, 'script', self.clock, TestJob)
+ board = Board(
+ self.source, board_name, 'script', self.clock, job_cls=TestJob)
board.logger.addHandler(self._handler)
board.logger.setLevel(logging.DEBUG)
return board