2008-08-16 23:26:59 +08:00
|
|
|
import py
|
2009-11-05 04:34:07 +08:00
|
|
|
from py.impl.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):
|
2009-05-12 01:23:57 +08:00
|
|
|
basetemp = request.config.mktemp(
|
2009-06-19 01:02:59 +08:00
|
|
|
"mysetup-%s" % request.function.__name__,
|
2009-05-12 01:23:57 +08:00
|
|
|
numbered=True)
|
2009-04-15 00:30:26 +08:00
|
|
|
self.source = basetemp.mkdir("source")
|
|
|
|
self.dest = basetemp.mkdir("dest")
|
2009-05-21 15:45:43 +08:00
|
|
|
request.getfuncargvalue("_pytest")
|
2008-08-16 23:26:59 +08:00
|
|
|
|
2009-03-21 03:33:05 +08:00
|
|
|
class TestNodeManager:
|
2009-06-28 19:27:34 +08:00
|
|
|
@py.test.mark.xfail
|
2009-12-30 01:02:54 +08:00
|
|
|
def test_rsync_roots_no_roots(self, testdir, mysetup):
|
2009-04-15 00:30:26 +08:00
|
|
|
mysetup.source.ensure("dir1", "file1").write("hello")
|
2009-12-30 01:02:54 +08:00
|
|
|
config = testdir.reparseconfig([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)
|
2009-08-30 02:04:48 +08:00
|
|
|
py.builtin.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-12-30 01:02:54 +08:00
|
|
|
def test_init_rsync_roots(self, testdir, mysetup):
|
2009-04-15 00:30:26 +08:00
|
|
|
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-12-30 01:02:54 +08:00
|
|
|
session = testdir.reparseconfig([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-12-30 01:02:54 +08:00
|
|
|
def test_rsyncignore(self, testdir, mysetup):
|
2009-04-15 00:30:26 +08:00
|
|
|
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-12-30 01:02:54 +08:00
|
|
|
session = testdir.reparseconfig([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-12-30 01:02:54 +08:00
|
|
|
def test_optimise_popen(self, testdir, mysetup):
|
2009-04-15 00:30:26 +08:00
|
|
|
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)
|
2009-12-30 01:02:54 +08:00
|
|
|
config = testdir.reparseconfig([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-12-30 01:02:54 +08:00
|
|
|
config = testdir.reparseconfig([source, '--debug'])
|
2009-03-17 05:17:14 +08:00
|
|
|
assert config.option.debug
|
2009-03-21 03:33:05 +08:00
|
|
|
nodemanager = NodeManager(config, specs)
|
2009-05-21 20:33:09 +08:00
|
|
|
reprec = testdir.getreportrecorder(config).hookrecorder
|
2009-03-21 03:33:05 +08:00
|
|
|
nodemanager.setup_nodes(putevent=[].append)
|
|
|
|
for spec in nodemanager.gwmanager.specs:
|
2009-05-21 20:33:09 +08:00
|
|
|
l = reprec.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-05-21 20:33:09 +08:00
|
|
|
reprec = testdir.inline_run("-d", "--rsyncdir=%s" % testdir.tmpdir,
|
2009-05-21 20:33:15 +08:00
|
|
|
"--tx", specssh, testdir.tmpdir)
|
2009-06-09 00:31:10 +08:00
|
|
|
rep, = reprec.getreports("pytest_runtest_logreport")
|
2009-05-21 20:33:15 +08:00
|
|
|
assert rep.passed
|
2009-03-18 08:38:02 +08:00
|
|
|
|