[svn r38107] * Have optimise_localhost flag and a test for it (but not turning it on

by default, this will be done later)
* two other occurences of possibly-failing channel.send

--HG--
branch : trunk
This commit is contained in:
fijal 2007-02-07 20:24:38 +01:00
parent d791086561
commit 1d6a72d936
2 changed files with 41 additions and 9 deletions

View File

@ -106,7 +106,8 @@ class HostRSync(py.execnet.RSync):
return remotepath
class HostManager(object):
def __init__(self, config, hosts=None):
def __init__(self, config, hosts=None, optimise_localhost=False):
self.optimise_localhost = optimise_localhost
self.config = config
if hosts is None:
hosts = self.config.getvalue("dist_hosts")
@ -132,14 +133,21 @@ class HostManager(object):
rsync = HostRSync(ignores=ignores,
verbose=self.config.option.verbose)
destrelpath = root.relto(self.config.topdir)
to_send = False
for host in self.hosts:
def donecallback(host, root):
if host.hostname != 'localhost' or not self.optimise_localhost:
def donecallback(host=host, root=root):
reporter(repevent.HostRSyncRootReady(host, root))
remotepath = rsync.add_target_host(
host, reporter, destrelpath, finishedcallback=
donecallback)
reporter(repevent.HostRSyncing(host, root, remotepath))
to_send = True
else:
reporter(repevent.HostRSyncRootReady(host, root))
remotepath = rsync.add_target_host(
host, reporter, destrelpath, finishedcallback=
lambda host=host, root=root: donecallback(host, root))
reporter(repevent.HostRSyncing(host, root, remotepath))
rsync.send(root)
if to_send:
# don't send if we have no targets
rsync.send(root)
def setup_hosts(self, reporter):
self.init_rsync(reporter)
@ -153,7 +161,14 @@ class HostManager(object):
def teardown_hosts(self, reporter, channels, nodes,
waiter=lambda : time.sleep(.1), exitfirst=False):
for channel in channels:
channel.send(None)
try:
channel.send(None)
except IOError:
print "Sending error, channel IOError"
print channel._getremoterror()
# XXX: this should go as soon as we'll have proper detection
# of hanging nodes and such
raise
clean = exitfirst
while not clean:
@ -166,7 +181,11 @@ class HostManager(object):
def kill_channels(self, channels):
for channel in channels:
channel.send(42)
try:
channel.send(42)
except IOError:
print "Sending error, channel IOError"
print channel._getremoterror()
def teardown_gateways(self, reporter, channels):
for channel in channels:

View File

@ -192,6 +192,19 @@ class TestHostManager(DirSetup):
assert self.dest.join("dir5","file").check()
assert not self.dest.join("dir6").check()
def test_hostmanager_rsync_optimise_localhost(self):
dir1 = self.source.ensure("opt_localhost1", dir=1)
config = py.test.config._reparse([self.source])
hm = HostManager(config,
hosts=[HostInfo("localhost:" + str(self.dest))],
optimise_localhost=True)
events = []
hm.init_rsync(reporter=events.append)
rr = [i for i in events if isinstance(i, repevent.HostRSyncRootReady)]
assert len(rr) == 1
hr = [i for i in events if isinstance(i, repevent.HostRSyncing)]
assert len(hr) == 0
def test_getpath_relto_home():
x = getpath_relto_home("hello")
assert x == py.path.local._gethomedir().join("hello")