[svn r63104] * introduce rsync events

* only rsync once if a gateway is specified multiply

--HG--
branch : trunk
This commit is contained in:
hpk 2009-03-20 01:34:59 +01:00
parent 877a7a32d8
commit 22b4ff7f06
6 changed files with 55 additions and 37 deletions

View File

@ -147,20 +147,22 @@ class GatewayManager:
""" perform rsync to all remote hosts. """ perform rsync to all remote hosts.
""" """
rsync = HostRSync(source, verbose=verbose, ignores=ignores) rsync = HostRSync(source, verbose=verbose, ignores=ignores)
added = False seen = {}
for gateway in self.gateways: for gateway in self.gateways:
spec = gateway.spec spec = gateway.spec
if not spec.inplacelocal(): if not spec.inplacelocal():
self.trace("add_target_host %r" %(gateway,)) key = spec.type, spec.address, spec.joinpath
if key in seen:
continue
def finished(): def finished():
if notify: if notify:
notify("rsyncrootready", spec, source) notify("rsyncrootready", spec, source)
rsync.add_target_host(gateway, finished=finished) rsync.add_target_host(gateway, finished=finished)
added = True seen[key] = gateway
if added: if seen:
self.trace("rsyncing %r" % source) self.notify("gwmanage_rsyncstart", source=source, gateways=seen.values())
rsync.send() rsync.send()
self.trace("rsyncing %r finished" % source) self.notify("gwmanage_rsyncfinish", source=source, gateways=seen.values())
else: else:
self.trace("rsync: nothing to do.") self.trace("rsync: nothing to do.")

View File

@ -50,18 +50,18 @@ class TestGatewayManagerPopen:
assert dest.join("dir1", "dir2").check() assert dest.join("dir1", "dir2").check()
assert dest.join("dir1", "dir2", 'hello').check() assert dest.join("dir1", "dir2", 'hello').check()
def XXXtest_ssh_rsync_samehost_twice(self): def test_hostmanage_rsync_same_popen_twice(self, source, dest, eventrecorder):
#XXX we have no easy way to have a temp directory remotely! hm = GatewayManager(["popen::%s" %dest] * 2)
option = py.test.config.option hm.makegateways()
if option.sshhost is None: source.ensure("dir1", "dir2", "hello")
py.test.skip("no known ssh target, use -S to set one") hm.rsync(source)
host1 = Host("%s" % (option.sshhost, )) event = eventrecorder.popevent("gwmanage_rsyncstart")
host2 = Host("%s" % (option.sshhost, )) source2 = event.kwargs['source']
hm = HostManager(config, hosts=[host1, host2]) gws = event.kwargs['gateways']
events = [] assert source2 == source
hm.init_rsync(events.append) assert len(gws) == 1
print events assert hm.gateways[0] == gws[0]
assert 0 event = eventrecorder.popevent("gwmanage_rsyncfinish")
def test_multi_chdir_popen_with_path(self, testdir): def test_multi_chdir_popen_with_path(self, testdir):
import os import os
@ -132,4 +132,3 @@ class TestHRSync:
gw.exit() gw.exit()
assert dest.join(source.basename, "hello.py").check() assert dest.join(source.basename, "hello.py").check()
assert len(finished) == 1 assert len(finished) == 1

View File

@ -147,9 +147,7 @@ class TestHostManager:
ev = sorter.getfirstnamed("itemtestreport") ev = sorter.getfirstnamed("itemtestreport")
assert ev.passed assert ev.passed
@py.test.mark.xfail("implement double-rsync test") def test_rsync_samehost_twice(self):
def test_ssh_rsync_samehost_twice(self):
sshhost = getsshhost(withpython=True)
host1 = Host("%s" % (sshhost, )) host1 = Host("%s" % (sshhost, ))
host2 = Host("%s" % (sshhost, )) host2 = Host("%s" % (sshhost, ))
hm = HostManager(config, hosts=[host1, host2]) hm = HostManager(config, hosts=[host1, host2])

View File

@ -161,6 +161,12 @@ class PytestPluginHooks:
def pyevent_gateway_exit(self, gateway): def pyevent_gateway_exit(self, gateway):
""" called when gateway is being exited. """ """ called when gateway is being exited. """
def pyevent_gwmanage_rsyncstart(self, source, gateways):
""" called before rsyncing a directory to remote gateways takes place. """
def pyevent_gwmanage_rsyncfinish(self, source, gateways):
""" called after rsyncing a directory to remote gateways takes place. """
def pyevent_trace(self, category, msg): def pyevent_trace(self, category, msg):
""" called for tracing events. """ """ called for tracing events. """

View File

@ -87,9 +87,13 @@ class TerminalReporter:
def pyevent_gwmanage_newgateway(self, gateway): def pyevent_gwmanage_newgateway(self, gateway):
self.write_line("%s instantiated gateway from spec %r" %(gateway.id, gateway.spec._spec)) self.write_line("%s instantiated gateway from spec %r" %(gateway.id, gateway.spec._spec))
def pyevent_hostgatewayready(self, event): def pyevent_gwmanage_rsyncstart(self, source, gateways):
if self.config.option.verbose: targets = ", ".join([gw.id for gw in gateways])
self.write_line("HostGatewayReady: %s" %(event.host,)) self.write_line("rsyncstart: %s -> %s" %(source, targets))
def pyevent_gwmanage_rsyncfinish(self, source, gateways):
targets = ", ".join([gw.id for gw in gateways])
self.write_line("rsyncfinish: %s -> %s" %(source, targets))
def pyevent_plugin_registered(self, plugin): def pyevent_plugin_registered(self, plugin):
if self.config.option.traceconfig: if self.config.option.traceconfig:
@ -323,7 +327,6 @@ from py.__.test.dsession.masterslave import makehostup
class TestTerminal: class TestTerminal:
def test_hostup(self, testdir, linecomp): def test_hostup(self, testdir, linecomp):
from py.__.execnet.gwmanage import GatewaySpec
item = testdir.getitem("def test_func(): pass") item = testdir.getitem("def test_func(): pass")
rep = TerminalReporter(item.config, linecomp.stringio) rep = TerminalReporter(item.config, linecomp.stringio)
rep.pyevent_hostup(makehostup()) rep.pyevent_hostup(makehostup())
@ -416,21 +419,31 @@ class TestTerminal:
"InternalException: >*raise ValueError*" "InternalException: >*raise ValueError*"
]) ])
def test_hostready_crash(self, testdir, linecomp): def test_gwmanage_events(self, testdir, linecomp):
from py.__.execnet.gwmanage import GatewaySpec
modcol = testdir.getmodulecol(""" modcol = testdir.getmodulecol("""
def test_one(): def test_one():
pass pass
""", configargs=("-v",)) """, configargs=("-v",))
host1 = GatewaySpec("localhost")
rep = TerminalReporter(modcol.config, file=linecomp.stringio) rep = TerminalReporter(modcol.config, file=linecomp.stringio)
rep.pyevent_hostgatewayready(event.HostGatewayReady(host1, None)) class gw1:
id = "X1"
spec = py.execnet.GatewaySpec("popen")
class gw2:
id = "X2"
spec = py.execnet.GatewaySpec("popen")
rep.pyevent_gwmanage_newgateway(gateway=gw1)
linecomp.assert_contains_lines([ linecomp.assert_contains_lines([
"*HostGatewayReady*" "X1 instantiated gateway from spec*",
]) ])
rep.pyevent_hostdown(event.HostDown(host1, "myerror"))
rep.pyevent_gwmanage_rsyncstart(source="hello", gateways=[gw1, gw2])
linecomp.assert_contains_lines([ linecomp.assert_contains_lines([
"*HostDown*myerror*", "rsyncstart: hello -> X1, X2"
])
rep.pyevent_gwmanage_rsyncfinish(source="hello", gateways=[gw1, gw2])
linecomp.assert_contains_lines([
"rsyncfinish: hello -> X1, X2"
]) ])
def test_writeline(self, testdir, linecomp): def test_writeline(self, testdir, linecomp):

View File

@ -44,7 +44,7 @@ class TestImmutablePickling:
assert config1.topdir == testdir.tmpdir assert config1.topdir == testdir.tmpdir
testdir.chdir() testdir.chdir()
p2config = pickletransport.p1_to_p2(config1) p2config = pickletransport.p1_to_p2(config1)
assert p2config.topdir == config1.topdir assert p2config.topdir.realpath() == config1.topdir.realpath()
config_back = pickletransport.p2_to_p1(p2config) config_back = pickletransport.p2_to_p1(p2config)
assert config_back is config1 assert config_back is config1
@ -160,10 +160,10 @@ class TestConfigPickling:
newcol3 = unpickler.load() newcol3 = unpickler.load()
assert newcol2.config is newcol.config assert newcol2.config is newcol.config
assert newcol2.parent == newcol assert newcol2.parent == newcol
assert newcol2.config.topdir == topdir assert newcol2.config.topdir.realpath() == topdir.realpath()
assert newcol.fspath == topdir assert newcol.fspath.realpath() == topdir.realpath()
assert newcol2.fspath.basename == dir1.basename assert newcol2.fspath.basename == dir1.basename
assert newcol2.fspath.relto(topdir) assert newcol2.fspath.relto(newcol2.config.topdir)
finally: finally:
old.chdir() old.chdir()