[svn r38389] completing the picture: now if you don't have rsync_roots
specified, the config.topdir is transfered but it is transferred to the "remotepath.join(topdir.basename)" (not actual code) to avoid random such rsyncs to destroy/affect remote filesystem state. --HG-- branch : trunk
This commit is contained in:
parent
f88bbf1b83
commit
fa94900836
|
@ -13,17 +13,23 @@ class HostInfo(object):
|
||||||
"""
|
"""
|
||||||
_hostname2list = {}
|
_hostname2list = {}
|
||||||
|
|
||||||
def __init__(self, spec):
|
def __init__(self, spec, addrel=""):
|
||||||
parts = spec.split(':', 1)
|
parts = spec.split(':', 1)
|
||||||
self.hostname = parts.pop(0)
|
self.hostname = parts.pop(0)
|
||||||
self.relpath = parts and parts.pop(0) or ""
|
self.relpath = parts and parts.pop(0) or ""
|
||||||
if self.hostname == "localhost" and not self.relpath:
|
if self.hostname == "localhost" and not self.relpath:
|
||||||
self.inplacelocal = True
|
self.inplacelocal = True
|
||||||
|
if addrel:
|
||||||
|
raise ValueError("inplace localhosts cannot have "
|
||||||
|
"additional path %r" % addrel)
|
||||||
else:
|
else:
|
||||||
self.inplacelocal = False
|
self.inplacelocal = False
|
||||||
if not self.relpath:
|
if not self.relpath:
|
||||||
self.relpath = "pytestcache-%s" % self.hostname
|
self.relpath = "pytestcache-%s" % self.hostname
|
||||||
|
if addrel:
|
||||||
|
self.relpath += "/" + addrel # XXX too os-dependent
|
||||||
assert not parts
|
assert not parts
|
||||||
|
assert self.inplacelocal or self.relpath
|
||||||
self.hostid = self._getuniqueid(self.hostname)
|
self.hostid = self._getuniqueid(self.hostname)
|
||||||
|
|
||||||
def _getuniqueid(self, hostname):
|
def _getuniqueid(self, hostname):
|
||||||
|
@ -32,7 +38,7 @@ class HostInfo(object):
|
||||||
l.append(hostid)
|
l.append(hostid)
|
||||||
return hostid
|
return hostid
|
||||||
|
|
||||||
def initgateway(self, python="python", topdir=None):
|
def initgateway(self, python="python"):
|
||||||
if self.hostname == "localhost":
|
if self.hostname == "localhost":
|
||||||
self.gw = py.execnet.PopenGateway(python=python)
|
self.gw = py.execnet.PopenGateway(python=python)
|
||||||
else:
|
else:
|
||||||
|
@ -44,14 +50,13 @@ class HostInfo(object):
|
||||||
)).waitclose()
|
)).waitclose()
|
||||||
self.gw_remotepath = None
|
self.gw_remotepath = None
|
||||||
else:
|
else:
|
||||||
relpath = self.relpath or topdir or ""
|
assert self.relpath
|
||||||
assert relpath
|
|
||||||
channel = self.gw.remote_exec(py.code.Source(
|
channel = self.gw.remote_exec(py.code.Source(
|
||||||
gethomedir,
|
gethomedir,
|
||||||
sethomedir, "sethomedir()",
|
sethomedir, "sethomedir()",
|
||||||
getpath_relto_home, """
|
getpath_relto_home, """
|
||||||
channel.send(getpath_relto_home(%r))
|
channel.send(getpath_relto_home(%r))
|
||||||
""" % relpath,
|
""" % self.relpath,
|
||||||
))
|
))
|
||||||
self.gw_remotepath = channel.receive()
|
self.gw_remotepath = channel.receive()
|
||||||
|
|
||||||
|
@ -116,19 +121,21 @@ class HostRSync(py.execnet.RSync):
|
||||||
class HostManager(object):
|
class HostManager(object):
|
||||||
def __init__(self, config, hosts=None):
|
def __init__(self, config, hosts=None):
|
||||||
self.config = config
|
self.config = config
|
||||||
if hosts is None:
|
|
||||||
hosts = self.config.getvalue("dist_hosts")
|
|
||||||
hosts = [HostInfo(x) for x in hosts]
|
|
||||||
self.hosts = hosts
|
|
||||||
roots = self.config.getvalue_pathlist("dist_rsync_roots")
|
roots = self.config.getvalue_pathlist("dist_rsync_roots")
|
||||||
|
addrel = ""
|
||||||
if roots is None:
|
if roots is None:
|
||||||
roots = [self.config.topdir]
|
roots = [self.config.topdir]
|
||||||
|
addrel = self.config.topdir.basename
|
||||||
self.roots = roots
|
self.roots = roots
|
||||||
|
if hosts is None:
|
||||||
|
hosts = self.config.getvalue("dist_hosts")
|
||||||
|
hosts = [HostInfo(x, addrel) for x in hosts]
|
||||||
|
self.hosts = hosts
|
||||||
|
|
||||||
def prepare_gateways(self, reporter):
|
def prepare_gateways(self, reporter):
|
||||||
python = self.config.getvalue("dist_remotepython")
|
python = self.config.getvalue("dist_remotepython")
|
||||||
for host in self.hosts:
|
for host in self.hosts:
|
||||||
host.initgateway(python=python, topdir=self.config.topdir)
|
host.initgateway(python=python)
|
||||||
reporter(repevent.HostGatewayReady(host, self.roots))
|
reporter(repevent.HostGatewayReady(host, self.roots))
|
||||||
host.gw.host = host
|
host.gw.host = host
|
||||||
|
|
||||||
|
@ -140,7 +147,7 @@ class HostManager(object):
|
||||||
rsync = HostRSync(root, ignores=ignores,
|
rsync = HostRSync(root, ignores=ignores,
|
||||||
verbose=self.config.option.verbose)
|
verbose=self.config.option.verbose)
|
||||||
if root == self.config.topdir:
|
if root == self.config.topdir:
|
||||||
destrelpath =""
|
destrelpath = ""
|
||||||
else:
|
else:
|
||||||
destrelpath = root.basename
|
destrelpath = root.basename
|
||||||
for host in self.hosts:
|
for host in self.hosts:
|
||||||
|
|
|
@ -27,7 +27,15 @@ class TestHostInfo(DirSetup):
|
||||||
x = HostInfo("localhost:")
|
x = HostInfo("localhost:")
|
||||||
assert x.hostname == "localhost"
|
assert x.hostname == "localhost"
|
||||||
assert not x.relpath
|
assert not x.relpath
|
||||||
assert x.inplacelocal
|
|
||||||
|
def test_addrel(self):
|
||||||
|
py.test.raises(ValueError, """
|
||||||
|
HostInfo("localhost:", addrel="whatever")
|
||||||
|
""")
|
||||||
|
host = HostInfo("localhost:/tmp", addrel="base")
|
||||||
|
assert host.relpath == "/tmp/base"
|
||||||
|
host = HostInfo("localhost:tmp", addrel="base2")
|
||||||
|
assert host.relpath == "tmp/base2"
|
||||||
|
|
||||||
def test_path(self):
|
def test_path(self):
|
||||||
x = HostInfo("localhost:/tmp")
|
x = HostInfo("localhost:/tmp")
|
||||||
|
@ -161,6 +169,16 @@ class TestSyncing(DirSetup):
|
||||||
assert not res2
|
assert not res2
|
||||||
|
|
||||||
class TestHostManager(DirSetup):
|
class TestHostManager(DirSetup):
|
||||||
|
def gethostmanager(self, dist_hosts):
|
||||||
|
self.source.join("conftest.py").write(py.code.Source("""
|
||||||
|
dist_hosts = %r
|
||||||
|
""" % (dist_hosts,)))
|
||||||
|
config = py.test.config._reparse([self.source])
|
||||||
|
assert config.topdir == self.source
|
||||||
|
hm = HostManager(config)
|
||||||
|
assert hm.hosts
|
||||||
|
return hm
|
||||||
|
|
||||||
def test_hostmanager_custom_hosts(self):
|
def test_hostmanager_custom_hosts(self):
|
||||||
config = py.test.config._reparse([self.source])
|
config = py.test.config._reparse([self.source])
|
||||||
hm = HostManager(config, hosts=[1,2,3])
|
hm = HostManager(config, hosts=[1,2,3])
|
||||||
|
@ -169,15 +187,15 @@ class TestHostManager(DirSetup):
|
||||||
def test_hostmanager_init_rsync_topdir(self):
|
def test_hostmanager_init_rsync_topdir(self):
|
||||||
dir2 = self.source.ensure("dir1", "dir2", dir=1)
|
dir2 = self.source.ensure("dir1", "dir2", dir=1)
|
||||||
dir2.ensure("hello")
|
dir2.ensure("hello")
|
||||||
config = py.test.config._reparse([self.source])
|
hm = self.gethostmanager(
|
||||||
assert config.topdir == self.source
|
dist_hosts = ["localhost:%s" % self.dest]
|
||||||
hm = HostManager(config,
|
)
|
||||||
hosts=[HostInfo("localhost:" + str(self.dest))])
|
assert hm.config.topdir == self.source
|
||||||
events = []
|
hm.init_rsync([].append)
|
||||||
hm.init_rsync(reporter=events.append)
|
dest = self.dest.join(self.source.basename)
|
||||||
assert self.dest.join("dir1").check()
|
assert dest.join("dir1").check()
|
||||||
assert self.dest.join("dir1", "dir2").check()
|
assert dest.join("dir1", "dir2").check()
|
||||||
assert self.dest.join("dir1", "dir2", 'hello').check()
|
assert dest.join("dir1", "dir2", 'hello').check()
|
||||||
|
|
||||||
def test_hostmanager_init_rsync_rsync_roots(self):
|
def test_hostmanager_init_rsync_rsync_roots(self):
|
||||||
dir2 = self.source.ensure("dir1", "dir2", dir=1)
|
dir2 = self.source.ensure("dir1", "dir2", dir=1)
|
||||||
|
|
Loading…
Reference in New Issue