2007-01-24 22:24:01 +08:00
|
|
|
"""
|
|
|
|
Node code for Master.
|
|
|
|
"""
|
|
|
|
import py
|
|
|
|
from py.__.test.rsession.outcome import ReprOutcome
|
|
|
|
from py.__.test.rsession import report
|
|
|
|
|
|
|
|
class MasterNode(object):
|
|
|
|
def __init__(self, channel, reporter, done_dict):
|
|
|
|
self.channel = channel
|
|
|
|
self.reporter = reporter
|
|
|
|
|
|
|
|
def callback(outcome):
|
|
|
|
item = self.pending.pop()
|
|
|
|
if not item in done_dict:
|
|
|
|
self.receive_result(outcome, item)
|
|
|
|
done_dict[item] = True
|
|
|
|
channel.setcallback(callback)
|
|
|
|
self.pending = []
|
|
|
|
|
|
|
|
def receive_result(self, outcomestring, item):
|
|
|
|
repr_outcome = ReprOutcome(outcomestring)
|
|
|
|
# send finish report
|
|
|
|
self.reporter(report.ReceivedItemOutcome(
|
|
|
|
self.channel, item, repr_outcome))
|
|
|
|
|
|
|
|
def send(self, item):
|
|
|
|
if item is StopIteration:
|
|
|
|
self.channel.send(42)
|
|
|
|
else:
|
|
|
|
self.pending.insert(0, item)
|
2007-01-26 19:49:59 +08:00
|
|
|
#itemspec = item.listnames()[1:]
|
2007-01-27 05:46:11 +08:00
|
|
|
self.channel.send(item.get_collector_trail())
|
2007-01-24 22:24:01 +08:00
|
|
|
# send start report
|
|
|
|
self.reporter(report.SendItem(self.channel, item))
|
|
|
|
|
|
|
|
def itemgen(colitems, reporter, keyword, reporterror):
|
2007-01-25 00:46:46 +08:00
|
|
|
for x in colitems:
|
2007-01-24 22:24:01 +08:00
|
|
|
for y in x.tryiter(reporterror = lambda x: reporterror(reporter, x), keyword = keyword):
|
|
|
|
yield y
|
|
|
|
|
|
|
|
def randomgen(items, done_dict):
|
|
|
|
""" Generator, which randomly gets all the tests from items as long
|
|
|
|
as they're not in done_dict
|
|
|
|
"""
|
|
|
|
import random
|
|
|
|
while items:
|
|
|
|
values = items.keys()
|
|
|
|
item = values[int(random.random()*len(values))]
|
|
|
|
if item in done_dict:
|
|
|
|
del items[item]
|
|
|
|
else:
|
|
|
|
yield item
|
|
|
|
|
|
|
|
def dispatch_loop(masternodes, itemgenerator, shouldstop,
|
|
|
|
waiter = lambda: py.std.time.sleep(0.1),
|
|
|
|
max_tasks_per_node=None):
|
|
|
|
if not max_tasks_per_node:
|
2007-01-25 00:46:46 +08:00
|
|
|
max_tasks_per_node = py.test.config.getvalue("dist_taskspernode")
|
2007-01-24 22:24:01 +08:00
|
|
|
all_tests = {}
|
|
|
|
while 1:
|
|
|
|
try:
|
|
|
|
for node in masternodes:
|
|
|
|
if len(node.pending) < max_tasks_per_node:
|
|
|
|
item = itemgenerator.next()
|
|
|
|
all_tests[item] = True
|
|
|
|
if shouldstop():
|
|
|
|
for _node in masternodes:
|
|
|
|
_node.send(StopIteration) # magic connector
|
|
|
|
return None
|
|
|
|
node.send(item)
|
|
|
|
except StopIteration:
|
|
|
|
break
|
|
|
|
waiter()
|
|
|
|
return all_tests
|
|
|
|
|
2007-01-25 00:46:46 +08:00
|
|
|
def setup_slave(gateway, pkgpath, config):
|
2007-01-24 22:24:01 +08:00
|
|
|
from py.__.test.rsession import slave
|
|
|
|
import os
|
|
|
|
ch = gateway.remote_exec(str(py.code.Source(slave.setup, "setup()")))
|
|
|
|
#if hasattr(gateway, 'sshaddress'):
|
|
|
|
# assert not os.path.isabs(pkgpath)
|
|
|
|
ch.send(str(pkgpath))
|
2007-01-25 00:46:46 +08:00
|
|
|
ch.send(config.make_repr(defaultconftestnames))
|
2007-01-24 22:24:01 +08:00
|
|
|
return ch
|
2007-01-25 00:46:46 +08:00
|
|
|
|
|
|
|
defaultconftestnames = ['dist_nicelevel']
|