[svn r38024] avoid that hostmanage.py tests interfere
with the real world (through writing or creating pytestcache-XXX files), semantic change: upon gateway initialization the remote path is not automatically created (this will be done later by rsync anyway) --HG-- branch : trunk
This commit is contained in:
parent
138b0ec79a
commit
1945487f4a
|
@ -37,22 +37,17 @@ class HostInfo(object):
|
||||||
gw = py.execnet.SshGateway(self.hostname,
|
gw = py.execnet.SshGateway(self.hostname,
|
||||||
remotepython=python)
|
remotepython=python)
|
||||||
self.gw = gw
|
self.gw = gw
|
||||||
channel = gw.remote_exec(py.code.Source(gethomedir, """
|
channel = gw.remote_exec(py.code.Source(
|
||||||
|
gethomedir,
|
||||||
|
getpath_relto_home, """
|
||||||
import os
|
import os
|
||||||
targetdir = %r
|
os.chdir(gethomedir())
|
||||||
homedir = gethomedir()
|
newdir = getpath_relto_home(%r)
|
||||||
if not os.path.isabs(targetdir):
|
# we intentionally don't ensure that 'newdir' exists
|
||||||
targetdir = os.path.join(homedir, targetdir)
|
channel.send(newdir)
|
||||||
if not os.path.exists(targetdir):
|
""" % str(self.relpath)
|
||||||
os.makedirs(targetdir)
|
))
|
||||||
os.chdir(homedir)
|
|
||||||
channel.send(targetdir)
|
|
||||||
""" % self.relpath))
|
|
||||||
self.gw_remotepath = channel.receive()
|
self.gw_remotepath = channel.receive()
|
||||||
#print "initialized", gw, "with remotepath", self.gw_remotepath
|
|
||||||
if self.hostname == "localhost":
|
|
||||||
self.localdest = py.path.local(self.gw_remotepath)
|
|
||||||
assert self.localdest.check(dir=1)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "<HostInfo %s:%s>" % (self.hostname, self.relpath)
|
return "<HostInfo %s:%s>" % (self.hostname, self.relpath)
|
||||||
|
@ -186,3 +181,10 @@ def gethomedir():
|
||||||
if not homedir:
|
if not homedir:
|
||||||
homedir = os.environ.get('HOMEPATH', '.')
|
homedir = os.environ.get('HOMEPATH', '.')
|
||||||
return homedir
|
return homedir
|
||||||
|
|
||||||
|
def getpath_relto_home(targetpath):
|
||||||
|
import os
|
||||||
|
if not os.path.isabs(targetpath):
|
||||||
|
homedir = gethomedir()
|
||||||
|
targetpath = os.path.join(homedir, targetpath)
|
||||||
|
return targetpath
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import py
|
import py
|
||||||
from py.__.test.rsession.hostmanage import HostRSync
|
from py.__.test.rsession.hostmanage import HostRSync, HostInfo, HostManager
|
||||||
from py.__.test.rsession.hostmanage import HostInfo, HostManager
|
from py.__.test.rsession.hostmanage import gethomedir, getpath_relto_home
|
||||||
from py.__.test.rsession import repevent
|
from py.__.test.rsession import repevent
|
||||||
|
|
||||||
class DirSetup:
|
class DirSetup:
|
||||||
|
@ -14,7 +14,15 @@ class DirSetup:
|
||||||
self.source = self.tmpdir.ensure("source", dir=1)
|
self.source = self.tmpdir.ensure("source", dir=1)
|
||||||
self.dest = self.tmpdir.join("dest")
|
self.dest = self.tmpdir.join("dest")
|
||||||
|
|
||||||
class TestHostInfo:
|
class TestHostInfo(DirSetup):
|
||||||
|
def _gethostinfo(self, relpath=""):
|
||||||
|
exampledir = self.tmpdir.join("gethostinfo")
|
||||||
|
if relpath:
|
||||||
|
exampledir = exampledir.join(relpath)
|
||||||
|
assert not exampledir.check()
|
||||||
|
hostinfo = HostInfo("localhost:%s" % exampledir)
|
||||||
|
return hostinfo
|
||||||
|
|
||||||
def test_defaultpath(self):
|
def test_defaultpath(self):
|
||||||
x = HostInfo("localhost")
|
x = HostInfo("localhost")
|
||||||
assert x.hostname == "localhost"
|
assert x.hostname == "localhost"
|
||||||
|
@ -39,54 +47,60 @@ class TestHostInfo:
|
||||||
host.initgateway)
|
host.initgateway)
|
||||||
|
|
||||||
def test_remote_has_homedir_as_currentdir(self):
|
def test_remote_has_homedir_as_currentdir(self):
|
||||||
host = HostInfo("localhost")
|
host = self._gethostinfo()
|
||||||
old = py.path.local.get_temproot().chdir()
|
old = py.path.local.get_temproot().chdir()
|
||||||
try:
|
try:
|
||||||
host.initgateway()
|
host.initgateway()
|
||||||
channel = host.gw.remote_exec("""
|
channel = host.gw.remote_exec(py.code.Source(
|
||||||
|
gethomedir, """
|
||||||
import os
|
import os
|
||||||
channel.send(os.getcwd())
|
homedir = gethomedir()
|
||||||
""")
|
curdir = os.getcwd()
|
||||||
dir = channel.receive()
|
channel.send((curdir, homedir))
|
||||||
assert dir == py.path.local._gethomedir()
|
"""))
|
||||||
|
remote_curdir, remote_homedir = channel.receive()
|
||||||
|
assert remote_curdir == remote_homedir
|
||||||
finally:
|
finally:
|
||||||
old.chdir()
|
old.chdir()
|
||||||
|
|
||||||
def test_initgateway_localhost_relpath(self):
|
def test_initgateway_localhost_relpath(self):
|
||||||
name = "pytestcache-localhost"
|
host = HostInfo("localhost:somedir")
|
||||||
x = HostInfo("localhost:%s" % name)
|
host.initgateway()
|
||||||
x.initgateway()
|
assert host.gw
|
||||||
assert x.gw
|
|
||||||
try:
|
try:
|
||||||
homedir = py.path.local._gethomedir()
|
homedir = py.path.local._gethomedir()
|
||||||
expected = homedir.join(name)
|
expected = homedir.join("somedir")
|
||||||
assert x.gw_remotepath == str(expected)
|
assert host.gw_remotepath == str(expected)
|
||||||
assert x.localdest == expected
|
|
||||||
finally:
|
finally:
|
||||||
x.gw.exit()
|
host.gw.exit()
|
||||||
|
|
||||||
|
|
||||||
def test_initgateway_ssh_and_remotepath(self):
|
def test_initgateway_ssh_and_remotepath(self):
|
||||||
option = py.test.config.option
|
option = py.test.config.option
|
||||||
if option.sshtarget is None:
|
if option.sshtarget is None:
|
||||||
py.test.skip("no known ssh target, use -S to set one")
|
py.test.skip("no known ssh target, use -S to set one")
|
||||||
x = HostInfo("%s" % (option.sshtarget, ))
|
host = HostInfo("%s" % (option.sshtarget, ))
|
||||||
x.initgateway()
|
# this test should be careful to not write/rsync anything
|
||||||
assert x.gw
|
# as the remotepath is the default location
|
||||||
assert x.gw_remotepath.endswith(x.relpath)
|
# and may be used in the real world
|
||||||
channel = x.gw.remote_exec("""
|
host.initgateway()
|
||||||
|
assert host.gw
|
||||||
|
assert host.gw_remotepath.endswith(host.relpath)
|
||||||
|
channel = host.gw.remote_exec("""
|
||||||
import os
|
import os
|
||||||
homedir = os.environ['HOME']
|
homedir = os.environ['HOME']
|
||||||
relpath = channel.receive()
|
relpath = channel.receive()
|
||||||
path = os.path.join(homedir, relpath)
|
path = os.path.join(homedir, relpath)
|
||||||
channel.send(path)
|
channel.send(path)
|
||||||
""")
|
""")
|
||||||
channel.send(x.relpath)
|
channel.send(host.relpath)
|
||||||
res = channel.receive()
|
res = channel.receive()
|
||||||
assert res == x.gw_remotepath
|
assert res == host.gw_remotepath
|
||||||
assert x.localdest is None
|
|
||||||
|
|
||||||
class TestSyncing(DirSetup):
|
class TestSyncing(DirSetup):
|
||||||
|
def _gethostinfo(self):
|
||||||
|
hostinfo = HostInfo("localhost:%s" % self.dest)
|
||||||
|
return hostinfo
|
||||||
|
|
||||||
def test_hrsync_filter(self):
|
def test_hrsync_filter(self):
|
||||||
self.source.ensure("dir", "file.txt")
|
self.source.ensure("dir", "file.txt")
|
||||||
self.source.ensure(".svn", "entries")
|
self.source.ensure(".svn", "entries")
|
||||||
|
@ -102,7 +116,7 @@ class TestSyncing(DirSetup):
|
||||||
assert 'somedir' in basenames
|
assert 'somedir' in basenames
|
||||||
|
|
||||||
def test_hrsync_one_host(self):
|
def test_hrsync_one_host(self):
|
||||||
h1 = HostInfo("localhost:%s" % self.dest)
|
h1 = self._gethostinfo()
|
||||||
finished = []
|
finished = []
|
||||||
rsync = HostRSync()
|
rsync = HostRSync()
|
||||||
h1.initgateway()
|
h1.initgateway()
|
||||||
|
@ -112,8 +126,8 @@ class TestSyncing(DirSetup):
|
||||||
assert self.dest.join("hello.py").check()
|
assert self.dest.join("hello.py").check()
|
||||||
|
|
||||||
def test_hrsync_same_host_twice(self):
|
def test_hrsync_same_host_twice(self):
|
||||||
h1 = HostInfo("localhost:%s" % self.dest)
|
h1 = self._gethostinfo()
|
||||||
h2 = HostInfo("localhost:%s" % self.dest)
|
h2 = self._gethostinfo()
|
||||||
finished = []
|
finished = []
|
||||||
rsync = HostRSync()
|
rsync = HostRSync()
|
||||||
l = []
|
l = []
|
||||||
|
@ -178,16 +192,7 @@ 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_reported_once(self):
|
def test_getpath_relto_home():
|
||||||
py.test.skip("XXX not needed any more")
|
x = getpath_relto_home("hello")
|
||||||
dir2 = self.source.ensure("dir1", "dir2", dir=1)
|
assert x == py.path.local._gethomedir().join("hello")
|
||||||
dir5 = self.source.ensure("dir5", "dir6", "bogus")
|
|
||||||
dirf = self.source.ensure("dir3", "file")
|
|
||||||
config = py.test.config._reparse([self.source])
|
|
||||||
hm = HostManager(config,
|
|
||||||
hosts=[HostInfo("localhost:" + str(self.dest))
|
|
||||||
for i in range(3)])
|
|
||||||
events = []
|
|
||||||
hm.init_rsync(reporter=events.append)
|
|
||||||
readies = [i for i in events if isinstance(i, repevent.HostReady)]
|
|
||||||
assert len(readies) == 3
|
|
||||||
|
|
Loading…
Reference in New Issue