[svn r62994] introducing internal MultiGateway class
--HG-- branch : trunk
This commit is contained in:
parent
7ed26c2929
commit
8a8ae5fe5d
|
@ -94,31 +94,46 @@ class MultiChannel:
|
||||||
for ch in self._channels:
|
for ch in self._channels:
|
||||||
ch.waitclose()
|
ch.waitclose()
|
||||||
|
|
||||||
|
class MultiGateway:
|
||||||
|
def __init__(self, gateways):
|
||||||
|
self.gateways = gateways
|
||||||
|
def remote_exec(self, source):
|
||||||
|
channels = []
|
||||||
|
for gw in self.gateways:
|
||||||
|
channels.append(gw.remote_exec(source))
|
||||||
|
return MultiChannel(channels)
|
||||||
|
|
||||||
class GatewayManager:
|
class GatewayManager:
|
||||||
def __init__(self, specs):
|
def __init__(self, specs):
|
||||||
self.spec2gateway = {}
|
self.specs = [GatewaySpec(spec) for spec in specs]
|
||||||
for spec in specs:
|
self.gateways = []
|
||||||
self.spec2gateway[GatewaySpec(spec)] = None
|
|
||||||
|
|
||||||
def trace(self, msg):
|
def trace(self, msg):
|
||||||
py._com.pyplugins.notify("trace", "gatewaymanage", msg)
|
py._com.pyplugins.notify("trace", "gatewaymanage", msg)
|
||||||
|
|
||||||
def makegateways(self):
|
def makegateways(self):
|
||||||
for spec, value in self.spec2gateway.items():
|
assert not self.gateways
|
||||||
assert value is None
|
for spec in self.specs:
|
||||||
self.trace("makegateway %s" %(spec))
|
self.trace("makegateway %s" %(spec))
|
||||||
self.spec2gateway[spec] = spec.makegateway()
|
self.gateways.append(spec.makegateway())
|
||||||
|
|
||||||
|
def getgateways(self, remote=True, inplacelocal=True):
|
||||||
|
l = []
|
||||||
|
for gw in self.gateways:
|
||||||
|
if gw.spec.inplacelocal():
|
||||||
|
if inplacelocal:
|
||||||
|
l.append(gw)
|
||||||
|
else:
|
||||||
|
if remote:
|
||||||
|
l.append(gw)
|
||||||
|
return MultiGateway(gateways=l)
|
||||||
|
|
||||||
def multi_exec(self, source, inplacelocal=True):
|
def multi_exec(self, source, inplacelocal=True):
|
||||||
""" remote execute code on all gateways.
|
""" remote execute code on all gateways.
|
||||||
@param inplacelocal=False: don't send code to inplacelocal hosts.
|
@param inplacelocal=False: don't send code to inplacelocal hosts.
|
||||||
"""
|
"""
|
||||||
source = py.code.Source(source)
|
multigw = self.getgateways(inplacelocal=inplacelocal)
|
||||||
channels = []
|
return multigw.remote_exec(source)
|
||||||
for spec, gw in self.spec2gateway.items():
|
|
||||||
if inplacelocal or not spec.inplacelocal():
|
|
||||||
channels.append(gw.remote_exec(source))
|
|
||||||
return MultiChannel(channels)
|
|
||||||
|
|
||||||
def multi_chdir(self, basename, inplacelocal=True):
|
def multi_chdir(self, basename, inplacelocal=True):
|
||||||
""" perform a remote chdir to the given path, may be relative.
|
""" perform a remote chdir to the given path, may be relative.
|
||||||
|
@ -132,7 +147,8 @@ class GatewayManager:
|
||||||
"""
|
"""
|
||||||
rsync = HostRSync(source, verbose=verbose, ignores=ignores)
|
rsync = HostRSync(source, verbose=verbose, ignores=ignores)
|
||||||
added = False
|
added = False
|
||||||
for spec, gateway in self.spec2gateway.items():
|
for gateway in self.gateways:
|
||||||
|
spec = gateway.spec
|
||||||
if not spec.inplacelocal():
|
if not spec.inplacelocal():
|
||||||
self.trace("add_target_host %r" %(gateway,))
|
self.trace("add_target_host %r" %(gateway,))
|
||||||
def finished():
|
def finished():
|
||||||
|
@ -148,8 +164,8 @@ class GatewayManager:
|
||||||
self.trace("rsync: nothing to do.")
|
self.trace("rsync: nothing to do.")
|
||||||
|
|
||||||
def exit(self):
|
def exit(self):
|
||||||
while self.spec2gateway:
|
while self.gateways:
|
||||||
spec, gw = self.spec2gateway.popitem()
|
gw = self.gateways.pop()
|
||||||
self.trace("exiting gateway %s" % gw)
|
self.trace("exiting gateway %s" % gw)
|
||||||
gw.exit()
|
gw.exit()
|
||||||
|
|
||||||
|
|
|
@ -106,21 +106,21 @@ class TestGatewayManagerPopen:
|
||||||
def test_hostmanager_popen_makegateway(self):
|
def test_hostmanager_popen_makegateway(self):
|
||||||
hm = GatewayManager(["popen"] * 2)
|
hm = GatewayManager(["popen"] * 2)
|
||||||
hm.makegateways()
|
hm.makegateways()
|
||||||
assert len(hm.spec2gateway) == 2
|
assert len(hm.gateways) == 2
|
||||||
hm.exit()
|
hm.exit()
|
||||||
assert not len(hm.spec2gateway)
|
assert not len(hm.gateways)
|
||||||
|
|
||||||
def test_hostmanager_popens_rsync(self, source):
|
def test_hostmanager_popens_rsync(self, source):
|
||||||
hm = GatewayManager(["popen"] * 2)
|
hm = GatewayManager(["popen"] * 2)
|
||||||
hm.makegateways()
|
hm.makegateways()
|
||||||
assert len(hm.spec2gateway) == 2
|
assert len(hm.gateways) == 2
|
||||||
for gw in hm.spec2gateway.values():
|
for gw in hm.gateways:
|
||||||
gw.remote_exec = None
|
gw.remote_exec = None
|
||||||
l = []
|
l = []
|
||||||
hm.rsync(source, notify=lambda *args: l.append(args))
|
hm.rsync(source, notify=lambda *args: l.append(args))
|
||||||
assert not l
|
assert not l
|
||||||
hm.exit()
|
hm.exit()
|
||||||
assert not len(hm.spec2gateway)
|
assert not len(hm.gateways)
|
||||||
|
|
||||||
def test_hostmanager_rsync_popen_with_path(self, source, dest):
|
def test_hostmanager_rsync_popen_with_path(self, source, dest):
|
||||||
hm = GatewayManager(["popen:%s" %dest] * 1)
|
hm = GatewayManager(["popen:%s" %dest] * 1)
|
||||||
|
@ -129,7 +129,7 @@ class TestGatewayManagerPopen:
|
||||||
l = []
|
l = []
|
||||||
hm.rsync(source, notify=lambda *args: l.append(args))
|
hm.rsync(source, notify=lambda *args: l.append(args))
|
||||||
assert len(l) == 1
|
assert len(l) == 1
|
||||||
assert l[0] == ("rsyncrootready", hm.spec2gateway.keys()[0], source)
|
assert l[0] == ("rsyncrootready", hm.gateways[0].spec, source)
|
||||||
hm.exit()
|
hm.exit()
|
||||||
dest = dest.join(source.basename)
|
dest = dest.join(source.basename)
|
||||||
assert dest.join("dir1").check()
|
assert dest.join("dir1").check()
|
||||||
|
|
|
@ -99,7 +99,8 @@ class HostManager(object):
|
||||||
|
|
||||||
self.trace_hoststatus()
|
self.trace_hoststatus()
|
||||||
|
|
||||||
for host, gateway in self.gwmanager.spec2gateway.items():
|
for gateway in self.gwmanager.gateways:
|
||||||
|
host = gateway.spec
|
||||||
host.node = MasterNode(host,
|
host.node = MasterNode(host,
|
||||||
gateway,
|
gateway,
|
||||||
self.config,
|
self.config,
|
||||||
|
|
|
@ -25,7 +25,7 @@ class TestHostManager:
|
||||||
config = py.test.config._reparse(args)
|
config = py.test.config._reparse(args)
|
||||||
assert config.topdir == source
|
assert config.topdir == source
|
||||||
hm = HostManager(config)
|
hm = HostManager(config)
|
||||||
assert hm.gwmanager.spec2gateway
|
assert hm.gwmanager.specs
|
||||||
return hm
|
return hm
|
||||||
|
|
||||||
def xxtest_hostmanager_custom_hosts(self, source, dest):
|
def xxtest_hostmanager_custom_hosts(self, source, dest):
|
||||||
|
@ -114,7 +114,7 @@ class TestHostManager:
|
||||||
config = py.test.config._reparse([source])
|
config = py.test.config._reparse([source])
|
||||||
hm = HostManager(config, hosts=hosts)
|
hm = HostManager(config, hosts=hosts)
|
||||||
hm.rsync_roots()
|
hm.rsync_roots()
|
||||||
for gwspec in hm.gwmanager.spec2gateway:
|
for gwspec in hm.gwmanager.specs:
|
||||||
assert gwspec.inplacelocal()
|
assert gwspec.inplacelocal()
|
||||||
assert not gwspec.joinpath
|
assert not gwspec.joinpath
|
||||||
|
|
||||||
|
@ -127,20 +127,12 @@ class TestHostManager:
|
||||||
hm = HostManager(config, hosts=hosts)
|
hm = HostManager(config, hosts=hosts)
|
||||||
evrec = EventRecorder(config.bus, debug=True)
|
evrec = EventRecorder(config.bus, debug=True)
|
||||||
hm.setup_hosts(putevent=[].append)
|
hm.setup_hosts(putevent=[].append)
|
||||||
for host in hm.gwmanager.spec2gateway:
|
for host in hm.gwmanager.specs:
|
||||||
l = evrec.getnamed("trace")
|
l = evrec.getnamed("trace")
|
||||||
print evrec.events
|
print evrec.events
|
||||||
assert l
|
assert l
|
||||||
hm.teardown_hosts()
|
hm.teardown_hosts()
|
||||||
|
|
||||||
def test_hostmanage_simple_ssh_test(self, testdir):
|
|
||||||
rp = testdir.mkdir('xyz123')
|
|
||||||
rp.ensure("__init__.py")
|
|
||||||
p = testdir.makepyfile("def test_123(): import xyz123")
|
|
||||||
result = testdir.runpytest(p, '-d', "--hosts=popen", '--rsyncdirs=' + str(rp))
|
|
||||||
assert result.ret == 0
|
|
||||||
assert result.stdout.str().find("1 passed") != -1
|
|
||||||
|
|
||||||
@py.test.mark.xfail("implement double-rsync test")
|
@py.test.mark.xfail("implement double-rsync test")
|
||||||
def test_ssh_rsync_samehost_twice(self):
|
def test_ssh_rsync_samehost_twice(self):
|
||||||
option = py.test.config.option
|
option = py.test.config.option
|
||||||
|
|
|
@ -36,7 +36,7 @@ class TmpTestdir:
|
||||||
def __init__(self, pyfuncitem):
|
def __init__(self, pyfuncitem):
|
||||||
self.pyfuncitem = pyfuncitem
|
self.pyfuncitem = pyfuncitem
|
||||||
# XXX remove duplication with tmpdir plugin
|
# XXX remove duplication with tmpdir plugin
|
||||||
basetmp = py.test.ensuretemp("testdir")
|
basetmp = pyfuncitem._config.ensuretemp("testdir")
|
||||||
name = pyfuncitem.name
|
name = pyfuncitem.name
|
||||||
for i in range(100):
|
for i in range(100):
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue