[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:
parent
d791086561
commit
1d6a72d936
|
@ -106,7 +106,8 @@ class HostRSync(py.execnet.RSync):
|
||||||
return remotepath
|
return remotepath
|
||||||
|
|
||||||
class HostManager(object):
|
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
|
self.config = config
|
||||||
if hosts is None:
|
if hosts is None:
|
||||||
hosts = self.config.getvalue("dist_hosts")
|
hosts = self.config.getvalue("dist_hosts")
|
||||||
|
@ -132,14 +133,21 @@ class HostManager(object):
|
||||||
rsync = HostRSync(ignores=ignores,
|
rsync = HostRSync(ignores=ignores,
|
||||||
verbose=self.config.option.verbose)
|
verbose=self.config.option.verbose)
|
||||||
destrelpath = root.relto(self.config.topdir)
|
destrelpath = root.relto(self.config.topdir)
|
||||||
|
to_send = False
|
||||||
for host in self.hosts:
|
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))
|
reporter(repevent.HostRSyncRootReady(host, root))
|
||||||
remotepath = rsync.add_target_host(
|
if to_send:
|
||||||
host, reporter, destrelpath, finishedcallback=
|
# don't send if we have no targets
|
||||||
lambda host=host, root=root: donecallback(host, root))
|
rsync.send(root)
|
||||||
reporter(repevent.HostRSyncing(host, root, remotepath))
|
|
||||||
rsync.send(root)
|
|
||||||
|
|
||||||
def setup_hosts(self, reporter):
|
def setup_hosts(self, reporter):
|
||||||
self.init_rsync(reporter)
|
self.init_rsync(reporter)
|
||||||
|
@ -153,7 +161,14 @@ class HostManager(object):
|
||||||
def teardown_hosts(self, reporter, channels, nodes,
|
def teardown_hosts(self, reporter, channels, nodes,
|
||||||
waiter=lambda : time.sleep(.1), exitfirst=False):
|
waiter=lambda : time.sleep(.1), exitfirst=False):
|
||||||
for channel in channels:
|
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
|
clean = exitfirst
|
||||||
while not clean:
|
while not clean:
|
||||||
|
@ -166,7 +181,11 @@ class HostManager(object):
|
||||||
|
|
||||||
def kill_channels(self, channels):
|
def kill_channels(self, channels):
|
||||||
for channel in 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):
|
def teardown_gateways(self, reporter, channels):
|
||||||
for channel in channels:
|
for channel in channels:
|
||||||
|
|
|
@ -192,6 +192,19 @@ class TestHostManager(DirSetup):
|
||||||
assert self.dest.join("dir5","file").check()
|
assert self.dest.join("dir5","file").check()
|
||||||
assert not self.dest.join("dir6").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():
|
def test_getpath_relto_home():
|
||||||
x = getpath_relto_home("hello")
|
x = getpath_relto_home("hello")
|
||||||
assert x == py.path.local._gethomedir().join("hello")
|
assert x == py.path.local._gethomedir().join("hello")
|
||||||
|
|
Loading…
Reference in New Issue