[svn r63150] fix hostmanager to work with new xspecs
--HG-- branch : trunk
This commit is contained in:
parent
c8da61a7d3
commit
5740cfebd6
|
@ -4,21 +4,20 @@ from py.__.test.dsession.masterslave import MasterNode
|
||||||
from py.__.execnet.gwmanage import GatewayManager
|
from py.__.execnet.gwmanage import GatewayManager
|
||||||
from py.__.test import event
|
from py.__.test import event
|
||||||
|
|
||||||
def getconfiggwspecs(config):
|
def getxspecs(config):
|
||||||
if config.option.numprocesses:
|
if config.option.numprocesses:
|
||||||
if config.option.executable:
|
if config.option.executable:
|
||||||
s = 'popen:%s' % config.option.executable
|
s = 'popen//python=%s' % config.option.executable
|
||||||
else:
|
else:
|
||||||
s = 'popen'
|
s = 'popen'
|
||||||
gwspecs = [s] * config.option.numprocesses
|
xspecs = [s] * config.option.numprocesses
|
||||||
else:
|
else:
|
||||||
gwspecs = config.option.gateways
|
xspecs = config.option.xspecs
|
||||||
if not gwspecs:
|
if not xspecs:
|
||||||
gwspecs = config.getvalue("gateways")
|
xspecs = config.getvalue("xspecs")
|
||||||
else:
|
assert xspecs is not None
|
||||||
gwspecs = gwspecs.split(",")
|
#print "option value for xspecs", xspecs
|
||||||
assert gwspecs is not None
|
return [py.execnet.XSpec(x) for x in xspecs]
|
||||||
return gwspecs
|
|
||||||
|
|
||||||
def getconfigroots(config):
|
def getconfigroots(config):
|
||||||
roots = config.option.rsyncdirs
|
roots = config.option.rsyncdirs
|
||||||
|
@ -45,7 +44,7 @@ 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:
|
if hosts is None:
|
||||||
hosts = getconfiggwspecs(self.config)
|
hosts = getxspecs(self.config)
|
||||||
self.roots = getconfigroots(config)
|
self.roots = getconfigroots(config)
|
||||||
self.gwmanager = GatewayManager(hosts)
|
self.gwmanager = GatewayManager(hosts)
|
||||||
|
|
||||||
|
@ -82,7 +81,7 @@ class HostManager(object):
|
||||||
self.makegateways()
|
self.makegateways()
|
||||||
options = {
|
options = {
|
||||||
'ignores': self.config_getignores(),
|
'ignores': self.config_getignores(),
|
||||||
'verbose': 1, # self.config.option.verbose
|
'verbose': self.config.option.verbose,
|
||||||
}
|
}
|
||||||
if self.roots:
|
if self.roots:
|
||||||
# send each rsync root
|
# send each rsync root
|
||||||
|
|
|
@ -71,7 +71,7 @@ def install_slave(host, gateway, config):
|
||||||
""")
|
""")
|
||||||
channel = PickleChannel(channel)
|
channel = PickleChannel(channel)
|
||||||
basetemp = None
|
basetemp = None
|
||||||
if host.type == "popen":
|
if host.popen:
|
||||||
popenbase = config.ensuretemp("popen")
|
popenbase = config.ensuretemp("popen")
|
||||||
basetemp = py.path.local.make_numbered_dir(prefix="slave-",
|
basetemp = py.path.local.make_numbered_dir(prefix="slave-",
|
||||||
keep=0, rootdir=popenbase)
|
keep=0, rootdir=popenbase)
|
||||||
|
|
|
@ -3,9 +3,7 @@
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import py
|
import py
|
||||||
from py.__.test.dsession.hostmanage import HostManager, getconfiggwspecs, getconfigroots
|
from py.__.test.dsession.hostmanage import HostManager, getxspecs, getconfigroots
|
||||||
from py.__.execnet.gwmanage import GatewaySpec as Host
|
|
||||||
from py.__.execnet.testing.test_gateway import getsshhost
|
|
||||||
|
|
||||||
from py.__.test import event
|
from py.__.test import event
|
||||||
|
|
||||||
|
@ -16,24 +14,6 @@ def pytest_pyfuncarg_dest(pyfuncitem):
|
||||||
return dest
|
return dest
|
||||||
|
|
||||||
class TestHostManager:
|
class TestHostManager:
|
||||||
def gethostmanager(self, source, hosts, rsyncdirs=None):
|
|
||||||
def opt(optname, l):
|
|
||||||
return '%s=%s' % (optname, ",".join(map(str, l)))
|
|
||||||
args = [opt('--gateways', hosts)]
|
|
||||||
if rsyncdirs:
|
|
||||||
args.append(opt('--rsyncdir', [source.join(x, abs=True) for x in rsyncdirs]))
|
|
||||||
args.append(source)
|
|
||||||
config = py.test.config._reparse(args)
|
|
||||||
assert config.topdir == source
|
|
||||||
hm = HostManager(config)
|
|
||||||
assert hm.gwmanager.specs
|
|
||||||
return hm
|
|
||||||
|
|
||||||
def xxtest_hostmanager_custom_hosts(self, source, dest):
|
|
||||||
session = py.test.config._reparse([source]).initsession()
|
|
||||||
hm = HostManager(session.config, hosts=[1,2,3])
|
|
||||||
assert hm.hosts == [1,2,3]
|
|
||||||
|
|
||||||
@py.test.mark.xfail("consider / forbid implicit rsyncdirs?")
|
@py.test.mark.xfail("consider / forbid implicit rsyncdirs?")
|
||||||
def test_hostmanager_rsync_roots_no_roots(self, source, dest):
|
def test_hostmanager_rsync_roots_no_roots(self, source, dest):
|
||||||
source.ensure("dir1", "file1").write("hello")
|
source.ensure("dir1", "file1").write("hello")
|
||||||
|
@ -48,32 +28,24 @@ class TestHostManager:
|
||||||
assert p.join("dir1").check()
|
assert p.join("dir1").check()
|
||||||
assert p.join("dir1", "file1").check()
|
assert p.join("dir1", "file1").check()
|
||||||
|
|
||||||
def test_hostmanager_rsync_roots_roots(self, source, dest):
|
def test_popen_rsync_subdir(self, testdir, source, dest):
|
||||||
dir2 = source.ensure("dir1", "dir2", dir=1)
|
dir1 = source.mkdir("dir1")
|
||||||
|
dir2 = dir1.mkdir("dir2")
|
||||||
dir2.ensure("hello")
|
dir2.ensure("hello")
|
||||||
hm = self.gethostmanager(source,
|
for rsyncroot in (dir1, source):
|
||||||
hosts = ["popen::%s" % dest],
|
dest.remove()
|
||||||
rsyncdirs = ['dir1']
|
hm = HostManager(testdir.parseconfig(
|
||||||
)
|
"--tx", "popen//chdir=%s" % dest,
|
||||||
assert hm.config.topdir == source
|
"--rsyncdirs", rsyncroot,
|
||||||
hm.rsync_roots()
|
source,
|
||||||
assert dest.join("dir1").check()
|
))
|
||||||
assert dest.join("dir1", "dir2").check()
|
assert hm.config.topdir == source
|
||||||
assert dest.join("dir1", "dir2", 'hello').check()
|
hm.rsync_roots()
|
||||||
|
if rsyncroot == source:
|
||||||
def test_hostmanager_init_rsync_topdir_explicit(self, source, dest):
|
dest = dest.join("source")
|
||||||
dir2 = source.ensure("dir1", "dir2", dir=1)
|
assert dest.join("dir1").check()
|
||||||
dir2.ensure("hello")
|
assert dest.join("dir1", "dir2").check()
|
||||||
hm = self.gethostmanager(source,
|
assert dest.join("dir1", "dir2", 'hello').check()
|
||||||
hosts = ["popen::%s" % dest],
|
|
||||||
rsyncdirs = [str(source)]
|
|
||||||
)
|
|
||||||
assert hm.config.topdir == source
|
|
||||||
hm.rsync_roots()
|
|
||||||
dest = dest.join(source.basename)
|
|
||||||
assert dest.join("dir1").check()
|
|
||||||
assert dest.join("dir1", "dir2").check()
|
|
||||||
assert dest.join("dir1", "dir2", 'hello').check()
|
|
||||||
|
|
||||||
def test_hostmanager_init_rsync_roots(self, source, dest):
|
def test_hostmanager_init_rsync_roots(self, source, dest):
|
||||||
dir2 = source.ensure("dir1", "dir2", dir=1)
|
dir2 = source.ensure("dir1", "dir2", dir=1)
|
||||||
|
@ -85,7 +57,7 @@ class TestHostManager:
|
||||||
"""))
|
"""))
|
||||||
session = py.test.config._reparse([source]).initsession()
|
session = py.test.config._reparse([source]).initsession()
|
||||||
hm = HostManager(session.config,
|
hm = HostManager(session.config,
|
||||||
hosts=["popen::" + str(dest)])
|
hosts=["popen//chdir=%s" % dest])
|
||||||
hm.rsync_roots()
|
hm.rsync_roots()
|
||||||
assert dest.join("dir2").check()
|
assert dest.join("dir2").check()
|
||||||
assert not dest.join("dir1").check()
|
assert not dest.join("dir1").check()
|
||||||
|
@ -102,7 +74,7 @@ class TestHostManager:
|
||||||
"""))
|
"""))
|
||||||
session = py.test.config._reparse([source]).initsession()
|
session = py.test.config._reparse([source]).initsession()
|
||||||
hm = HostManager(session.config,
|
hm = HostManager(session.config,
|
||||||
hosts=["popen::" + str(dest)])
|
hosts=["popen//chdir=%s" % dest])
|
||||||
hm.rsync_roots()
|
hm.rsync_roots()
|
||||||
assert dest.join("dir1").check()
|
assert dest.join("dir1").check()
|
||||||
assert not dest.join("dir1", "dir2").check()
|
assert not dest.join("dir1", "dir2").check()
|
||||||
|
@ -117,8 +89,8 @@ class TestHostManager:
|
||||||
hm = HostManager(config, hosts=hosts)
|
hm = HostManager(config, hosts=hosts)
|
||||||
hm.rsync_roots()
|
hm.rsync_roots()
|
||||||
for gwspec in hm.gwmanager.specs:
|
for gwspec in hm.gwmanager.specs:
|
||||||
assert gwspec.inplacelocal()
|
assert gwspec._samefilesystem()
|
||||||
assert not gwspec.joinpath
|
assert not gwspec.chdir
|
||||||
|
|
||||||
def test_hostmanage_setup_hosts_DEBUG(self, source, EventRecorder):
|
def test_hostmanage_setup_hosts_DEBUG(self, source, EventRecorder):
|
||||||
hosts = ["popen"] * 2
|
hosts = ["popen"] * 2
|
||||||
|
@ -135,48 +107,48 @@ class TestHostManager:
|
||||||
assert l
|
assert l
|
||||||
hm.teardown_hosts()
|
hm.teardown_hosts()
|
||||||
|
|
||||||
def test_hostmanage_ssh_setup_hosts(self, testdir):
|
def test_hostmanage_ssh_setup_hosts(self, specssh, testdir):
|
||||||
sshhost = getsshhost(withpython=True)
|
|
||||||
testdir.makepyfile(__init__="", test_x="""
|
testdir.makepyfile(__init__="", test_x="""
|
||||||
def test_one():
|
def test_one():
|
||||||
pass
|
pass
|
||||||
""")
|
""")
|
||||||
|
|
||||||
sorter = testdir.inline_run("-d", "--rsyncdirs=%s" % testdir.tmpdir,
|
sorter = testdir.inline_run("-d", "--rsyncdirs=%s" % testdir.tmpdir,
|
||||||
"--gateways=%s" % sshhost, testdir.tmpdir)
|
"--tx=%s" % specssh, testdir.tmpdir)
|
||||||
ev = sorter.getfirstnamed("itemtestreport")
|
ev = sorter.getfirstnamed("itemtestreport")
|
||||||
assert ev.passed
|
assert ev.passed
|
||||||
|
|
||||||
|
class TestOptionsAndConfiguration:
|
||||||
|
def test_getxspecs_numprocesses(self, testdir):
|
||||||
|
config = testdir.parseconfig("-n3")
|
||||||
|
xspecs = getxspecs(config)
|
||||||
|
assert len(xspecs) == 3
|
||||||
|
|
||||||
def test_getconfiggwspecs_numprocesses():
|
def test_getxspecs(self, testdir):
|
||||||
config = py.test.config._reparse(['-n3'])
|
config = testdir.parseconfig("--tx=popen", "--tx", "ssh=xyz")
|
||||||
hosts = getconfiggwspecs(config)
|
xspecs = getxspecs(config)
|
||||||
assert len(hosts) == 3
|
assert len(xspecs) == 2
|
||||||
|
print xspecs
|
||||||
|
assert xspecs[0].popen
|
||||||
|
assert xspecs[1].ssh == "xyz"
|
||||||
|
|
||||||
def test_getconfiggwspecs_disthosts():
|
def test_getconfigroots(self, testdir):
|
||||||
config = py.test.config._reparse(['--gateways=a,b,c'])
|
config = testdir.parseconfig('--rsyncdirs=' + str(testdir.tmpdir))
|
||||||
hosts = getconfiggwspecs(config)
|
roots = getconfigroots(config)
|
||||||
assert len(hosts) == 3
|
assert len(roots) == 1 + 1
|
||||||
assert hosts == ['a', 'b', 'c']
|
assert testdir.tmpdir in roots
|
||||||
|
|
||||||
def test_getconfigroots(testdir):
|
def test_getconfigroots_with_conftest(self, testdir):
|
||||||
config = testdir.parseconfig('--rsyncdirs=' + str(testdir.tmpdir))
|
testdir.chdir()
|
||||||
roots = getconfigroots(config)
|
p = py.path.local()
|
||||||
assert len(roots) == 1 + 1
|
for bn in 'x y z'.split():
|
||||||
assert testdir.tmpdir in roots
|
p.mkdir(bn)
|
||||||
|
testdir.makeconftest("""
|
||||||
def test_getconfigroots_with_conftest(testdir):
|
rsyncdirs= 'x',
|
||||||
testdir.chdir()
|
""")
|
||||||
p = py.path.local()
|
config = testdir.parseconfig(testdir.tmpdir, '--rsyncdirs=y,z')
|
||||||
for bn in 'x y z'.split():
|
roots = getconfigroots(config)
|
||||||
p.mkdir(bn)
|
assert len(roots) == 3 + 1
|
||||||
testdir.makeconftest("""
|
assert py.path.local('y') in roots
|
||||||
rsyncdirs= 'x',
|
assert py.path.local('z') in roots
|
||||||
""")
|
assert testdir.tmpdir.join('x') in roots
|
||||||
config = testdir.parseconfig(testdir.tmpdir, '--rsyncdirs=y,z')
|
|
||||||
roots = getconfigroots(config)
|
|
||||||
assert len(roots) == 3 + 1
|
|
||||||
assert py.path.local('y') in roots
|
|
||||||
assert py.path.local('z') in roots
|
|
||||||
assert testdir.tmpdir.join('x') in roots
|
|
||||||
|
|
||||||
|
|
|
@ -64,8 +64,8 @@ class DefaultPlugin:
|
||||||
group._addoption('-s', '--nocapture',
|
group._addoption('-s', '--nocapture',
|
||||||
action="store_true", dest="nocapture", default=False,
|
action="store_true", dest="nocapture", default=False,
|
||||||
help="disable catching of sys.stdout/stderr output."),
|
help="disable catching of sys.stdout/stderr output."),
|
||||||
group.addoption('--basetemp', dest="basetemp", default=None,
|
group.addoption('--basetemp', dest="basetemp", default=None, metavar="dir",
|
||||||
help="directory to use for this test run.")
|
help="temporary directory for this test run.")
|
||||||
group.addoption('--boxed',
|
group.addoption('--boxed',
|
||||||
action="store_true", dest="boxed", default=False,
|
action="store_true", dest="boxed", default=False,
|
||||||
help="box each test run in a separate process"),
|
help="box each test run in a separate process"),
|
||||||
|
@ -97,8 +97,9 @@ class DefaultPlugin:
|
||||||
group.addoption('--rsyncdirs', dest="rsyncdirs", default=None, metavar="dir1,dir2,...",
|
group.addoption('--rsyncdirs', dest="rsyncdirs", default=None, metavar="dir1,dir2,...",
|
||||||
help="comma-separated list of directories to rsync. All those roots will be rsynced "
|
help="comma-separated list of directories to rsync. All those roots will be rsynced "
|
||||||
"into a corresponding subdir on the remote sides. ")
|
"into a corresponding subdir on the remote sides. ")
|
||||||
group.addoption('--gateways', dest="gateways", default=None, metavar="spec1,spec2,...",
|
group.addoption('--tx', dest="xspecs", action="append",
|
||||||
help="comma-separated list of gateway specs, used by test distribution modes")
|
help=("add a test environment, specified in XSpec syntax. examples: "
|
||||||
|
"--tx popen//python=python2.5 --tx socket=192.168.1.102"))
|
||||||
group._addoption('--exec',
|
group._addoption('--exec',
|
||||||
action="store", dest="executable", default=None,
|
action="store", dest="executable", default=None,
|
||||||
help="python executable to run the tests with.")
|
help="python executable to run the tests with.")
|
||||||
|
|
Loading…
Reference in New Issue