[svn r38352] made localhost inplace handling safer (and more
redundant, there is an additional flag now, and host.gw_remotepath is None for localhost-inplace hosts) --HG-- branch : trunk
This commit is contained in:
parent
e57df20f4b
commit
e04e08718f
|
@ -12,14 +12,17 @@ class HostInfo(object):
|
||||||
for host
|
for host
|
||||||
"""
|
"""
|
||||||
_hostname2list = {}
|
_hostname2list = {}
|
||||||
localdest = None
|
|
||||||
|
|
||||||
def __init__(self, spec):
|
def __init__(self, spec):
|
||||||
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 not self.relpath and self.hostname != "localhost":
|
if self.hostname == "localhost" and not self.relpath:
|
||||||
self.relpath = "pytestcache-%s" % self.hostname
|
self.inplacelocal = True
|
||||||
|
else:
|
||||||
|
self.inplacelocal = False
|
||||||
|
if not self.relpath:
|
||||||
|
self.relpath = "pytestcache-%s" % self.hostname
|
||||||
assert not parts
|
assert not parts
|
||||||
self.hostid = self._getuniqueid(self.hostname)
|
self.hostid = self._getuniqueid(self.hostname)
|
||||||
|
|
||||||
|
@ -35,20 +38,22 @@ class HostInfo(object):
|
||||||
else:
|
else:
|
||||||
self.gw = py.execnet.SshGateway(self.hostname,
|
self.gw = py.execnet.SshGateway(self.hostname,
|
||||||
remotepython=python)
|
remotepython=python)
|
||||||
relpath = self.relpath or topdir
|
if self.inplacelocal:
|
||||||
assert relpath
|
self.gw.remote_exec(py.code.Source(
|
||||||
channel = self.gw.remote_exec(py.code.Source(
|
sethomedir, "sethomedir()"
|
||||||
gethomedir,
|
)).waitclose()
|
||||||
getpath_relto_home, """
|
self.gw_remotepath = None
|
||||||
import os
|
else:
|
||||||
os.chdir(gethomedir())
|
relpath = self.relpath or topdir or ""
|
||||||
path = %r
|
assert relpath
|
||||||
if path:
|
channel = self.gw.remote_exec(py.code.Source(
|
||||||
path = getpath_relto_home(path)
|
gethomedir,
|
||||||
channel.send(path)
|
sethomedir, "sethomedir()",
|
||||||
""" % str(relpath)
|
getpath_relto_home, """
|
||||||
))
|
channel.send(getpath_relto_home(%r))
|
||||||
self.gw_remotepath = channel.receive()
|
""" % relpath,
|
||||||
|
))
|
||||||
|
self.gw_remotepath = channel.receive()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "<HostInfo %s:%s>" % (self.hostname, self.relpath)
|
return "<HostInfo %s:%s>" % (self.hostname, self.relpath)
|
||||||
|
@ -88,10 +93,11 @@ class HostRSync(py.execnet.RSync):
|
||||||
def add_target_host(self, host, destrelpath="", reporter=lambda x: None):
|
def add_target_host(self, host, destrelpath="", reporter=lambda x: None):
|
||||||
remotepath = host.gw_remotepath
|
remotepath = host.gw_remotepath
|
||||||
key = host.hostname, host.relpath
|
key = host.hostname, host.relpath
|
||||||
if destrelpath:
|
if host.inplacelocal:
|
||||||
remotepath = os.path.join(remotepath, destrelpath)
|
remotepath = self._sourcedir
|
||||||
if host.hostname == "localhost" and remotepath == self._sourcedir:
|
|
||||||
self._synced[key] = True
|
self._synced[key] = True
|
||||||
|
elif destrelpath:
|
||||||
|
remotepath = os.path.join(remotepath, destrelpath)
|
||||||
synced = key in self._synced
|
synced = key in self._synced
|
||||||
reporter(repevent.HostRSyncing(host, py.path.local(self._sourcedir),
|
reporter(repevent.HostRSyncing(host, py.path.local(self._sourcedir),
|
||||||
remotepath, synced))
|
remotepath, synced))
|
||||||
|
@ -187,4 +193,11 @@ def getpath_relto_home(targetpath):
|
||||||
if not os.path.isabs(targetpath):
|
if not os.path.isabs(targetpath):
|
||||||
homedir = gethomedir()
|
homedir = gethomedir()
|
||||||
targetpath = os.path.join(homedir, targetpath)
|
targetpath = os.path.join(homedir, targetpath)
|
||||||
return targetpath
|
return os.path.normpath(targetpath)
|
||||||
|
|
||||||
|
def sethomedir():
|
||||||
|
import os
|
||||||
|
homedir = os.environ.get('HOME', '')
|
||||||
|
if not homedir:
|
||||||
|
homedir = os.environ.get('HOMEPATH', '.')
|
||||||
|
os.chdir(homedir)
|
||||||
|
|
|
@ -111,7 +111,11 @@ def setup_slave(host, config):
|
||||||
channel = host.gw.remote_exec(str(py.code.Source(setup, "setup()")))
|
channel = host.gw.remote_exec(str(py.code.Source(setup, "setup()")))
|
||||||
configrepr = config.make_repr(defaultconftestnames)
|
configrepr = config.make_repr(defaultconftestnames)
|
||||||
#print "sending configrepr", configrepr
|
#print "sending configrepr", configrepr
|
||||||
channel.send(host.gw_remotepath)
|
topdir = host.gw_remotepath
|
||||||
|
if topdir is None:
|
||||||
|
assert host.inplacelocal
|
||||||
|
topdir = config.topdir
|
||||||
|
channel.send(str(topdir))
|
||||||
channel.send(configrepr)
|
channel.send(configrepr)
|
||||||
return channel
|
return channel
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
import py
|
import py
|
||||||
from py.__.test.rsession.hostmanage import HostRSync, HostInfo, HostManager
|
from py.__.test.rsession.hostmanage import HostRSync, HostInfo, HostManager
|
||||||
from py.__.test.rsession.hostmanage import gethomedir, getpath_relto_home
|
from py.__.test.rsession.hostmanage import sethomedir, gethomedir, getpath_relto_home
|
||||||
from py.__.test.rsession import repevent
|
from py.__.test.rsession import repevent
|
||||||
|
|
||||||
class DirSetup:
|
class DirSetup:
|
||||||
|
@ -27,11 +27,13 @@ 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_path(self):
|
def test_path(self):
|
||||||
x = HostInfo("localhost:/tmp")
|
x = HostInfo("localhost:/tmp")
|
||||||
assert x.relpath == "/tmp"
|
assert x.relpath == "/tmp"
|
||||||
assert x.hostname == "localhost"
|
assert x.hostname == "localhost"
|
||||||
|
assert not x.inplacelocal
|
||||||
|
|
||||||
def test_hostid(self):
|
def test_hostid(self):
|
||||||
x = HostInfo("localhost:")
|
x = HostInfo("localhost:")
|
||||||
|
@ -115,6 +117,26 @@ class TestSyncing(DirSetup):
|
||||||
assert 'file.txt' in basenames
|
assert 'file.txt' in basenames
|
||||||
assert 'somedir' in basenames
|
assert 'somedir' in basenames
|
||||||
|
|
||||||
|
def test_hrsync_localhost_inplace(self):
|
||||||
|
h1 = HostInfo("localhost")
|
||||||
|
events = []
|
||||||
|
rsync = HostRSync(self.source)
|
||||||
|
h1.initgateway()
|
||||||
|
rsync.add_target_host(h1, reporter=events.append)
|
||||||
|
assert events
|
||||||
|
l = [x for x in events
|
||||||
|
if isinstance(x, repevent.HostRSyncing)]
|
||||||
|
assert len(l) == 1
|
||||||
|
ev = l[0]
|
||||||
|
assert ev.host == h1
|
||||||
|
assert ev.root == ev.remotepath
|
||||||
|
l = [x for x in events
|
||||||
|
if isinstance(x, repevent.HostRSyncRootReady)]
|
||||||
|
assert len(l) == 1
|
||||||
|
ev = l[0]
|
||||||
|
assert ev.root == self.source
|
||||||
|
assert ev.host == h1
|
||||||
|
|
||||||
def test_hrsync_one_host(self):
|
def test_hrsync_one_host(self):
|
||||||
h1 = self._gethostinfo()
|
h1 = self._gethostinfo()
|
||||||
finished = []
|
finished = []
|
||||||
|
@ -200,11 +222,24 @@ class TestHostManager(DirSetup):
|
||||||
events = []
|
events = []
|
||||||
hm.init_rsync(events.append)
|
hm.init_rsync(events.append)
|
||||||
for host in hosts:
|
for host in hosts:
|
||||||
assert host.gw_remotepath == str(self.source)
|
assert host.inplacelocal
|
||||||
|
assert host.gw_remotepath is None
|
||||||
assert not host.relpath
|
assert not host.relpath
|
||||||
assert events
|
assert events
|
||||||
|
|
||||||
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")
|
||||||
|
x = getpath_relto_home(".")
|
||||||
|
assert x == py.path.local._gethomedir()
|
||||||
|
|
||||||
|
def test_sethomedir():
|
||||||
|
old = py.path.local.get_temproot().chdir()
|
||||||
|
try:
|
||||||
|
sethomedir()
|
||||||
|
curdir = py.path.local()
|
||||||
|
finally:
|
||||||
|
old.chdir()
|
||||||
|
|
||||||
|
assert py.path.local._gethomedir() == curdir
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue