[svn r63150] fix hostmanager to work with new xspecs

--HG--
branch : trunk
This commit is contained in:
hpk 2009-03-20 18:29:08 +01:00
parent c8da61a7d3
commit 5740cfebd6
4 changed files with 72 additions and 100 deletions

View File

@ -4,21 +4,20 @@ from py.__.test.dsession.masterslave import MasterNode
from py.__.execnet.gwmanage import GatewayManager
from py.__.test import event
def getconfiggwspecs(config):
def getxspecs(config):
if config.option.numprocesses:
if config.option.executable:
s = 'popen:%s' % config.option.executable
s = 'popen//python=%s' % config.option.executable
else:
s = 'popen'
gwspecs = [s] * config.option.numprocesses
xspecs = [s] * config.option.numprocesses
else:
gwspecs = config.option.gateways
if not gwspecs:
gwspecs = config.getvalue("gateways")
else:
gwspecs = gwspecs.split(",")
assert gwspecs is not None
return gwspecs
xspecs = config.option.xspecs
if not xspecs:
xspecs = config.getvalue("xspecs")
assert xspecs is not None
#print "option value for xspecs", xspecs
return [py.execnet.XSpec(x) for x in xspecs]
def getconfigroots(config):
roots = config.option.rsyncdirs
@ -45,7 +44,7 @@ class HostManager(object):
def __init__(self, config, hosts=None):
self.config = config
if hosts is None:
hosts = getconfiggwspecs(self.config)
hosts = getxspecs(self.config)
self.roots = getconfigroots(config)
self.gwmanager = GatewayManager(hosts)
@ -82,7 +81,7 @@ class HostManager(object):
self.makegateways()
options = {
'ignores': self.config_getignores(),
'verbose': 1, # self.config.option.verbose
'verbose': self.config.option.verbose,
}
if self.roots:
# send each rsync root

View File

@ -71,7 +71,7 @@ def install_slave(host, gateway, config):
""")
channel = PickleChannel(channel)
basetemp = None
if host.type == "popen":
if host.popen:
popenbase = config.ensuretemp("popen")
basetemp = py.path.local.make_numbered_dir(prefix="slave-",
keep=0, rootdir=popenbase)

View File

@ -3,9 +3,7 @@
"""
import py
from py.__.test.dsession.hostmanage import HostManager, getconfiggwspecs, getconfigroots
from py.__.execnet.gwmanage import GatewaySpec as Host
from py.__.execnet.testing.test_gateway import getsshhost
from py.__.test.dsession.hostmanage import HostManager, getxspecs, getconfigroots
from py.__.test import event
@ -16,24 +14,6 @@ def pytest_pyfuncarg_dest(pyfuncitem):
return dest
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?")
def test_hostmanager_rsync_roots_no_roots(self, source, dest):
source.ensure("dir1", "file1").write("hello")
@ -48,32 +28,24 @@ class TestHostManager:
assert p.join("dir1").check()
assert p.join("dir1", "file1").check()
def test_hostmanager_rsync_roots_roots(self, source, dest):
dir2 = source.ensure("dir1", "dir2", dir=1)
def test_popen_rsync_subdir(self, testdir, source, dest):
dir1 = source.mkdir("dir1")
dir2 = dir1.mkdir("dir2")
dir2.ensure("hello")
hm = self.gethostmanager(source,
hosts = ["popen::%s" % dest],
rsyncdirs = ['dir1']
)
assert hm.config.topdir == source
hm.rsync_roots()
assert dest.join("dir1").check()
assert dest.join("dir1", "dir2").check()
assert dest.join("dir1", "dir2", 'hello').check()
def test_hostmanager_init_rsync_topdir_explicit(self, source, dest):
dir2 = source.ensure("dir1", "dir2", dir=1)
dir2.ensure("hello")
hm = self.gethostmanager(source,
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()
for rsyncroot in (dir1, source):
dest.remove()
hm = HostManager(testdir.parseconfig(
"--tx", "popen//chdir=%s" % dest,
"--rsyncdirs", rsyncroot,
source,
))
assert hm.config.topdir == source
hm.rsync_roots()
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()
def test_hostmanager_init_rsync_roots(self, source, dest):
dir2 = source.ensure("dir1", "dir2", dir=1)
@ -85,7 +57,7 @@ class TestHostManager:
"""))
session = py.test.config._reparse([source]).initsession()
hm = HostManager(session.config,
hosts=["popen::" + str(dest)])
hosts=["popen//chdir=%s" % dest])
hm.rsync_roots()
assert dest.join("dir2").check()
assert not dest.join("dir1").check()
@ -102,7 +74,7 @@ class TestHostManager:
"""))
session = py.test.config._reparse([source]).initsession()
hm = HostManager(session.config,
hosts=["popen::" + str(dest)])
hosts=["popen//chdir=%s" % dest])
hm.rsync_roots()
assert dest.join("dir1").check()
assert not dest.join("dir1", "dir2").check()
@ -117,8 +89,8 @@ class TestHostManager:
hm = HostManager(config, hosts=hosts)
hm.rsync_roots()
for gwspec in hm.gwmanager.specs:
assert gwspec.inplacelocal()
assert not gwspec.joinpath
assert gwspec._samefilesystem()
assert not gwspec.chdir
def test_hostmanage_setup_hosts_DEBUG(self, source, EventRecorder):
hosts = ["popen"] * 2
@ -135,48 +107,48 @@ class TestHostManager:
assert l
hm.teardown_hosts()
def test_hostmanage_ssh_setup_hosts(self, testdir):
sshhost = getsshhost(withpython=True)
def test_hostmanage_ssh_setup_hosts(self, specssh, testdir):
testdir.makepyfile(__init__="", test_x="""
def test_one():
pass
""")
sorter = testdir.inline_run("-d", "--rsyncdirs=%s" % testdir.tmpdir,
"--gateways=%s" % sshhost, testdir.tmpdir)
"--tx=%s" % specssh, testdir.tmpdir)
ev = sorter.getfirstnamed("itemtestreport")
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():
config = py.test.config._reparse(['-n3'])
hosts = getconfiggwspecs(config)
assert len(hosts) == 3
def test_getxspecs(self, testdir):
config = testdir.parseconfig("--tx=popen", "--tx", "ssh=xyz")
xspecs = getxspecs(config)
assert len(xspecs) == 2
print xspecs
assert xspecs[0].popen
assert xspecs[1].ssh == "xyz"
def test_getconfiggwspecs_disthosts():
config = py.test.config._reparse(['--gateways=a,b,c'])
hosts = getconfiggwspecs(config)
assert len(hosts) == 3
assert hosts == ['a', 'b', 'c']
def test_getconfigroots(self, testdir):
config = testdir.parseconfig('--rsyncdirs=' + str(testdir.tmpdir))
roots = getconfigroots(config)
assert len(roots) == 1 + 1
assert testdir.tmpdir in roots
def test_getconfigroots(testdir):
config = testdir.parseconfig('--rsyncdirs=' + str(testdir.tmpdir))
roots = getconfigroots(config)
assert len(roots) == 1 + 1
assert testdir.tmpdir in roots
def test_getconfigroots_with_conftest(testdir):
testdir.chdir()
p = py.path.local()
for bn in 'x y z'.split():
p.mkdir(bn)
testdir.makeconftest("""
rsyncdirs= 'x',
""")
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
def test_getconfigroots_with_conftest(self, testdir):
testdir.chdir()
p = py.path.local()
for bn in 'x y z'.split():
p.mkdir(bn)
testdir.makeconftest("""
rsyncdirs= 'x',
""")
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

View File

@ -64,8 +64,8 @@ class DefaultPlugin:
group._addoption('-s', '--nocapture',
action="store_true", dest="nocapture", default=False,
help="disable catching of sys.stdout/stderr output."),
group.addoption('--basetemp', dest="basetemp", default=None,
help="directory to use for this test run.")
group.addoption('--basetemp', dest="basetemp", default=None, metavar="dir",
help="temporary directory for this test run.")
group.addoption('--boxed',
action="store_true", dest="boxed", default=False,
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,...",
help="comma-separated list of directories to rsync. All those roots will be rsynced "
"into a corresponding subdir on the remote sides. ")
group.addoption('--gateways', dest="gateways", default=None, metavar="spec1,spec2,...",
help="comma-separated list of gateway specs, used by test distribution modes")
group.addoption('--tx', dest="xspecs", action="append",
help=("add a test environment, specified in XSpec syntax. examples: "
"--tx popen//python=python2.5 --tx socket=192.168.1.102"))
group._addoption('--exec',
action="store", dest="executable", default=None,
help="python executable to run the tests with.")