2008-08-16 23:26:59 +08:00
|
|
|
import py
|
|
|
|
import sys, os
|
2009-03-23 04:44:45 +08:00
|
|
|
from py.__.test.dist.txnode import TXNode
|
2009-03-04 01:42:32 +08:00
|
|
|
from py.__.execnet.gwmanage import GatewayManager
|
2008-08-16 23:26:59 +08:00
|
|
|
|
|
|
|
|
2009-03-21 03:33:05 +08:00
|
|
|
class NodeManager(object):
|
|
|
|
def __init__(self, config, specs=None):
|
2009-03-04 01:42:32 +08:00
|
|
|
self.config = config
|
2009-03-21 03:33:05 +08:00
|
|
|
if specs is None:
|
2009-03-21 09:31:27 +08:00
|
|
|
specs = self.config.getxspecs()
|
|
|
|
self.roots = self.config.getrsyncdirs()
|
2009-03-21 03:33:05 +08:00
|
|
|
self.gwmanager = GatewayManager(specs)
|
2009-03-21 03:04:36 +08:00
|
|
|
self.nodes = []
|
2009-03-23 04:44:45 +08:00
|
|
|
self._nodesready = py.std.threading.Event()
|
2009-03-04 01:42:32 +08:00
|
|
|
|
2009-03-21 05:17:15 +08:00
|
|
|
def trace(self, msg):
|
2009-05-08 00:01:53 +08:00
|
|
|
self.config.hook.pytest_trace(category="nodemanage", msg=msg)
|
2009-03-17 05:17:14 +08:00
|
|
|
|
|
|
|
def config_getignores(self):
|
|
|
|
return self.config.getconftest_pathlist("rsyncignore")
|
2009-03-04 01:42:32 +08:00
|
|
|
|
|
|
|
def rsync_roots(self):
|
|
|
|
""" make sure that all remote gateways
|
|
|
|
have the same set of roots in their
|
|
|
|
current directory.
|
|
|
|
"""
|
|
|
|
self.makegateways()
|
|
|
|
options = {
|
2009-03-17 05:17:14 +08:00
|
|
|
'ignores': self.config_getignores(),
|
2009-03-21 01:29:08 +08:00
|
|
|
'verbose': self.config.option.verbose,
|
2009-03-04 01:42:32 +08:00
|
|
|
}
|
|
|
|
if self.roots:
|
|
|
|
# send each rsync root
|
|
|
|
for root in self.roots:
|
|
|
|
self.gwmanager.rsync(root, **options)
|
|
|
|
else:
|
2009-03-19 01:54:45 +08:00
|
|
|
XXX # do we want to care for situations without explicit rsyncdirs?
|
2009-03-17 05:17:14 +08:00
|
|
|
# we transfer our topdir as the root
|
2009-03-04 01:42:32 +08:00
|
|
|
self.gwmanager.rsync(self.config.topdir, **options)
|
2009-03-17 05:17:14 +08:00
|
|
|
# and cd into it
|
2009-03-04 01:42:32 +08:00
|
|
|
self.gwmanager.multi_chdir(self.config.topdir.basename, inplacelocal=False)
|
2008-08-16 23:26:59 +08:00
|
|
|
|
2009-03-21 05:17:15 +08:00
|
|
|
def makegateways(self):
|
|
|
|
# we change to the topdir sot that
|
|
|
|
# PopenGateways will have their cwd
|
|
|
|
# such that unpickling configs will
|
|
|
|
# pick it up as the right topdir
|
|
|
|
# (for other gateways this chdir is irrelevant)
|
2009-03-23 04:44:45 +08:00
|
|
|
self.trace("making gateways")
|
2009-03-21 05:17:15 +08:00
|
|
|
old = self.config.topdir.chdir()
|
|
|
|
try:
|
|
|
|
self.gwmanager.makegateways()
|
|
|
|
finally:
|
|
|
|
old.chdir()
|
2009-03-17 05:17:14 +08:00
|
|
|
|
2009-03-21 03:33:05 +08:00
|
|
|
def setup_nodes(self, putevent):
|
2009-03-04 01:42:32 +08:00
|
|
|
self.rsync_roots()
|
2009-03-23 04:44:45 +08:00
|
|
|
self.trace("setting up nodes")
|
2009-03-17 19:53:09 +08:00
|
|
|
for gateway in self.gwmanager.gateways:
|
2009-03-23 04:44:45 +08:00
|
|
|
node = TXNode(gateway, self.config, putevent, slaveready=self._slaveready)
|
|
|
|
gateway.node = node # to keep node alive
|
|
|
|
self.trace("started node %r" % node)
|
|
|
|
|
|
|
|
def _slaveready(self, node):
|
|
|
|
#assert node.gateway == node.gateway
|
|
|
|
#assert node.gateway.node == node
|
|
|
|
self.nodes.append(node)
|
|
|
|
self.trace("%s slave node ready %r" % (node.gateway.id, node))
|
|
|
|
if len(self.nodes) == len(self.gwmanager.gateways):
|
|
|
|
self._nodesready.set()
|
|
|
|
|
|
|
|
def wait_nodesready(self, timeout=None):
|
|
|
|
self._nodesready.wait(timeout)
|
|
|
|
if not self._nodesready.isSet():
|
|
|
|
raise IOError("nodes did not get ready for %r secs" % timeout)
|
2008-08-16 23:26:59 +08:00
|
|
|
|
2009-03-21 03:33:05 +08:00
|
|
|
def teardown_nodes(self):
|
2009-03-23 01:41:36 +08:00
|
|
|
# XXX do teardown nodes?
|
2009-03-04 01:42:32 +08:00
|
|
|
self.gwmanager.exit()
|
2009-03-21 04:38:50 +08:00
|
|
|
|