2008-08-16 23:26:59 +08:00
|
|
|
import py
|
2009-03-22 03:31:09 +08:00
|
|
|
from py.__.test.dist.nodemanage import NodeManager
|
2008-08-16 23:26:59 +08:00
|
|
|
|
2009-04-15 00:30:26 +08:00
|
|
|
class pytest_funcarg__mysetup:
|
|
|
|
def __init__(self, request):
|
|
|
|
basetemp = request.config.ensuretemp(request.getfspath().purebasename)
|
|
|
|
basetemp = basetemp.mkdir(request.funcname)
|
|
|
|
self.source = basetemp.mkdir("source")
|
|
|
|
self.dest = basetemp.mkdir("dest")
|
2008-08-16 23:26:59 +08:00
|
|
|
|
2009-03-21 03:33:05 +08:00
|
|
|
class TestNodeManager:
|
2009-03-18 08:38:02 +08:00
|
|
|
@py.test.mark.xfail("consider / forbid implicit rsyncdirs?")
|
2009-04-15 00:30:26 +08:00
|
|
|
def test_rsync_roots_no_roots(self, mysetup):
|
|
|
|
mysetup.source.ensure("dir1", "file1").write("hello")
|
2009-03-04 01:42:32 +08:00
|
|
|
config = py.test.config._reparse([source])
|
2009-04-15 00:30:26 +08:00
|
|
|
nodemanager = NodeManager(config, ["popen//chdir=%s" % mysetup.dest])
|
2009-03-21 03:33:05 +08:00
|
|
|
assert nodemanager.config.topdir == source == config.topdir
|
|
|
|
nodemanager.rsync_roots()
|
|
|
|
p, = nodemanager.gwmanager.multi_exec("import os ; channel.send(os.getcwd())").receive_each()
|
2009-03-04 01:42:32 +08:00
|
|
|
p = py.path.local(p)
|
|
|
|
print "remote curdir", p
|
2009-04-15 00:30:26 +08:00
|
|
|
assert p == mysetup.dest.join(config.topdir.basename)
|
2009-03-04 01:42:32 +08:00
|
|
|
assert p.join("dir1").check()
|
|
|
|
assert p.join("dir1", "file1").check()
|
|
|
|
|
2009-03-23 04:44:45 +08:00
|
|
|
def test_popen_nodes_are_ready(self, testdir):
|
|
|
|
nodemanager = NodeManager(testdir.parseconfig(
|
|
|
|
"--tx", "3*popen"))
|
|
|
|
|
|
|
|
nodemanager.setup_nodes([].append)
|
|
|
|
nodemanager.wait_nodesready(timeout=2.0)
|
|
|
|
|
2009-04-15 00:30:26 +08:00
|
|
|
def test_popen_rsync_subdir(self, testdir, mysetup):
|
|
|
|
source, dest = mysetup.source, mysetup.dest
|
|
|
|
dir1 = mysetup.source.mkdir("dir1")
|
2009-03-21 01:29:08 +08:00
|
|
|
dir2 = dir1.mkdir("dir2")
|
2008-08-16 23:26:59 +08:00
|
|
|
dir2.ensure("hello")
|
2009-03-21 01:29:08 +08:00
|
|
|
for rsyncroot in (dir1, source):
|
|
|
|
dest.remove()
|
2009-03-21 03:33:05 +08:00
|
|
|
nodemanager = NodeManager(testdir.parseconfig(
|
2009-03-21 01:29:08 +08:00
|
|
|
"--tx", "popen//chdir=%s" % dest,
|
2009-03-22 04:07:45 +08:00
|
|
|
"--rsyncdir", rsyncroot,
|
2009-03-21 01:29:08 +08:00
|
|
|
source,
|
|
|
|
))
|
2009-03-21 03:33:05 +08:00
|
|
|
assert nodemanager.config.topdir == source
|
|
|
|
nodemanager.rsync_roots()
|
2009-03-21 01:29:08 +08:00
|
|
|
if rsyncroot == source:
|
|
|
|
dest = dest.join("source")
|
|
|
|
assert dest.join("dir1").check()
|
|
|
|
assert dest.join("dir1", "dir2").check()
|
|
|
|
assert dest.join("dir1", "dir2", 'hello').check()
|
2009-03-21 05:13:47 +08:00
|
|
|
nodemanager.gwmanager.exit()
|
2008-08-16 23:26:59 +08:00
|
|
|
|
2009-04-15 00:30:26 +08:00
|
|
|
def test_init_rsync_roots(self, mysetup):
|
|
|
|
source, dest = mysetup.source, mysetup.dest
|
2009-02-27 18:18:27 +08:00
|
|
|
dir2 = source.ensure("dir1", "dir2", dir=1)
|
|
|
|
source.ensure("dir1", "somefile", dir=1)
|
2008-08-16 23:26:59 +08:00
|
|
|
dir2.ensure("hello")
|
2009-02-27 18:18:27 +08:00
|
|
|
source.ensure("bogusdir", "file")
|
|
|
|
source.join("conftest.py").write(py.code.Source("""
|
2009-03-17 05:17:14 +08:00
|
|
|
rsyncdirs = ['dir1/dir2']
|
2008-08-16 23:26:59 +08:00
|
|
|
"""))
|
2009-02-27 18:18:27 +08:00
|
|
|
session = py.test.config._reparse([source]).initsession()
|
2009-03-21 03:33:05 +08:00
|
|
|
nodemanager = NodeManager(session.config, ["popen//chdir=%s" % dest])
|
|
|
|
nodemanager.rsync_roots()
|
2009-02-27 18:18:27 +08:00
|
|
|
assert dest.join("dir2").check()
|
|
|
|
assert not dest.join("dir1").check()
|
|
|
|
assert not dest.join("bogus").check()
|
|
|
|
|
2009-04-15 00:30:26 +08:00
|
|
|
def test_rsyncignore(self, mysetup):
|
|
|
|
source, dest = mysetup.source, mysetup.dest
|
2009-02-27 18:18:27 +08:00
|
|
|
dir2 = source.ensure("dir1", "dir2", dir=1)
|
|
|
|
dir5 = source.ensure("dir5", "dir6", "bogus")
|
|
|
|
dirf = source.ensure("dir5", "file")
|
2008-08-16 23:26:59 +08:00
|
|
|
dir2.ensure("hello")
|
2009-02-27 18:18:27 +08:00
|
|
|
source.join("conftest.py").write(py.code.Source("""
|
2009-03-17 05:17:14 +08:00
|
|
|
rsyncdirs = ['dir1', 'dir5']
|
|
|
|
rsyncignore = ['dir1/dir2', 'dir5/dir6']
|
2008-08-16 23:26:59 +08:00
|
|
|
"""))
|
2009-02-27 18:18:27 +08:00
|
|
|
session = py.test.config._reparse([source]).initsession()
|
2009-03-21 03:33:05 +08:00
|
|
|
nodemanager = NodeManager(session.config,
|
|
|
|
["popen//chdir=%s" % dest])
|
|
|
|
nodemanager.rsync_roots()
|
2009-02-27 18:18:27 +08:00
|
|
|
assert dest.join("dir1").check()
|
|
|
|
assert not dest.join("dir1", "dir2").check()
|
|
|
|
assert dest.join("dir5","file").check()
|
|
|
|
assert not dest.join("dir6").check()
|
2008-08-16 23:26:59 +08:00
|
|
|
|
2009-04-15 00:30:26 +08:00
|
|
|
def test_optimise_popen(self, mysetup):
|
|
|
|
source, dest = mysetup.source, mysetup.dest
|
2009-03-21 03:33:05 +08:00
|
|
|
specs = ["popen"] * 3
|
2009-03-17 05:17:14 +08:00
|
|
|
source.join("conftest.py").write("rsyncdirs = ['a']")
|
2009-03-04 01:42:32 +08:00
|
|
|
source.ensure('a', dir=1)
|
|
|
|
config = py.test.config._reparse([source])
|
2009-03-21 03:33:05 +08:00
|
|
|
nodemanager = NodeManager(config, specs)
|
|
|
|
nodemanager.rsync_roots()
|
|
|
|
for gwspec in nodemanager.gwmanager.specs:
|
2009-03-21 01:29:08 +08:00
|
|
|
assert gwspec._samefilesystem()
|
|
|
|
assert not gwspec.chdir
|
2008-08-16 23:26:59 +08:00
|
|
|
|
2009-04-15 00:30:26 +08:00
|
|
|
def test_setup_DEBUG(self, mysetup, testdir):
|
|
|
|
source = mysetup.source
|
2009-03-21 03:33:05 +08:00
|
|
|
specs = ["popen"] * 2
|
2009-03-17 05:17:14 +08:00
|
|
|
source.join("conftest.py").write("rsyncdirs = ['a']")
|
2009-03-04 01:42:32 +08:00
|
|
|
source.ensure('a', dir=1)
|
2009-03-17 05:17:14 +08:00
|
|
|
config = py.test.config._reparse([source, '--debug'])
|
|
|
|
assert config.option.debug
|
2009-03-21 03:33:05 +08:00
|
|
|
nodemanager = NodeManager(config, specs)
|
2009-04-09 22:03:09 +08:00
|
|
|
sorter = testdir.geteventrecorder(config.pluginmanager).callrecorder
|
2009-03-21 03:33:05 +08:00
|
|
|
nodemanager.setup_nodes(putevent=[].append)
|
|
|
|
for spec in nodemanager.gwmanager.specs:
|
2009-04-09 08:12:10 +08:00
|
|
|
l = sorter.getcalls("pytest_trace")
|
2009-03-17 05:17:14 +08:00
|
|
|
assert l
|
2009-03-21 03:33:05 +08:00
|
|
|
nodemanager.teardown_nodes()
|
2009-03-17 05:17:14 +08:00
|
|
|
|
2009-03-21 03:33:05 +08:00
|
|
|
def test_ssh_setup_nodes(self, specssh, testdir):
|
2009-03-18 08:38:02 +08:00
|
|
|
testdir.makepyfile(__init__="", test_x="""
|
|
|
|
def test_one():
|
|
|
|
pass
|
|
|
|
""")
|
2009-03-22 04:07:45 +08:00
|
|
|
sorter = testdir.inline_run("-d", "--rsyncdir=%s" % testdir.tmpdir,
|
2009-03-21 01:29:08 +08:00
|
|
|
"--tx=%s" % specssh, testdir.tmpdir)
|
2009-04-09 07:33:48 +08:00
|
|
|
ev = sorter.getfirstnamed(pytest_itemtestreport)
|
2009-03-18 08:38:02 +08:00
|
|
|
assert ev.passed
|
|
|
|
|