[svn r63144] have socket and ssh gateways

--HG--
branch : trunk
This commit is contained in:
hpk 2009-03-20 16:36:45 +01:00
parent 5f3fac94b6
commit e383082b5b
6 changed files with 70 additions and 22 deletions

View File

@ -27,8 +27,8 @@ version = "1.0.0a1"
initpkg(__name__,
description = "pylib and py.test: agile development and test support library",
revision = int('$LastChangedRevision: 63089 $'.split(':')[1][:-1]),
lastchangedate = '$LastChangedDate: 2009-03-19 18:05:41 +0100 (Thu, 19 Mar 2009) $',
revision = int('$LastChangedRevision: 63144 $'.split(':')[1][:-1]),
lastchangedate = '$LastChangedDate: 2009-03-20 16:36:45 +0100 (Fri, 20 Mar 2009) $',
version = version,
url = "http://pylib.org",
download_url = "http://codespeak.net/py/0.9.2/download.html",
@ -152,6 +152,8 @@ initpkg(__name__,
'execnet.PopenGateway' : ('./execnet/register.py', 'PopenGateway'),
'execnet.SshGateway' : ('./execnet/register.py', 'SshGateway'),
'execnet.GatewaySpec' : ('./execnet/gwmanage.py', 'GatewaySpec'),
'execnet.XSpec' : ('./execnet/xspec.py', 'XSpec'),
'execnet.makegateway' : ('./execnet/xspec.py', 'makegateway'),
'execnet.MultiGateway' : ('./execnet/multi.py', 'MultiGateway'),
'execnet.MultiChannel' : ('./execnet/multi.py', 'MultiChannel'),

View File

@ -1,20 +1,45 @@
dist_rsync_roots = ['.'] # XXX
pytest_plugins = 'pytest_doctest', 'pytest_pytester', 'pytest_restdoc'
rsyncignore = ['c-extension/greenlet/build']
import py
class PylibTestPlugin:
class PylibTestconfigPlugin:
def pytest_pyfuncarg_specssh(self, pyfuncitem):
return getspecssh(pyfuncitem.config)
def pytest_pyfuncarg_specsocket(self, pyfuncitem):
return getsocketspec(pyfuncitem.config)
def pytest_addoption(self, parser):
group = parser.addgroup("pylib", "py lib testing options")
group.addoption('--sshhost',
action="store", dest="sshhost", default=None,
help=("target to run tests requiring ssh, e.g. "
"user@codespeak.net"))
group.addoption('--gx',
action="append", dest="gspecs", default=None,
help=("add a global test environment, XSpec-syntax. ")),
group.addoption('--runslowtests',
action="store_true", dest="runslowtests", default=False,
help="run slow tests")
help=("run slow tests"))
ConftestPlugin = PylibTestPlugin
ConftestPlugin = PylibTestconfigPlugin
# configuration information for tests
def getgspecs(config=None):
if config is None:
config = py.test.config
return [py.execnet.XSpec(spec)
for spec in config.getvalueorskip("gspecs")]
def getspecssh(config=None):
xspecs = getgspecs(config)
for spec in xspecs:
if spec.ssh:
if not py.path.local.sysfind("ssh"):
py.test.skip("command not found: ssh")
return spec
def getsocketspec(config=None):
xspecs = getgspecs(config)
for spec in xspecs:
if spec.socket:
return spec

View File

@ -542,8 +542,8 @@ class TestPopenGateway(PopenGatewayTestSetup, BasicRemoteExecution):
ret = channel.receive()
assert ret == 42
@py.test.mark.xfail("fix needed: dying remote process does not cause waitclose() to fail")
def test_waitclose_on_remote_killed(self):
py.test.skip("fix needed: dying remote process does not cause waitclose() to fail")
gw = py.execnet.PopenGateway()
channel = gw.remote_exec("""
import os
@ -591,21 +591,13 @@ class SocketGatewaySetup:
## cls.gw.exit()
## cls.proxygw.exit()
def getsshhost(withpython=False):
sshhost = py.test.config.getvalueorskip("sshhost")
if not withpython and sshhost.find(":") != -1:
sshhost = sshhost.split(":")[0]
ssh = py.path.local.sysfind("ssh")
if not ssh:
py.test.skip("command not found: ssh")
return sshhost
class TestSocketGateway(SocketGatewaySetup, BasicRemoteExecution):
pass
class TestSshGateway(BasicRemoteExecution):
def setup_class(cls):
cls.sshhost = getsshhost()
from py.__.conftest import getspecssh
cls.sshhost = getspecssh().ssh
cls.gw = py.execnet.SshGateway(cls.sshhost)
def test_sshconfig_functional(self):

View File

@ -3,7 +3,6 @@
"""
import py
from test_gateway import getsshhost
class TestGatewaySpec:
"""
@ -88,8 +87,8 @@ class TestGatewaySpecAPI:
assert py.std.sys.executable == py.std.sys.executable
gw.exit()
def test_ssh(self):
sshhost = getsshhost()
def test_ssh(self, specssh):
sshhost = specssh.ssh
spec = py.execnet.GatewaySpec("ssh:" + sshhost)
gw = spec.makegateway()
p = gw.remote_exec("import os ; channel.send(os.getcwd())").receive()

View File

@ -72,3 +72,27 @@ class TestMakegateway:
assert rinfo.executable == cpython26
assert rinfo.cwd == py.std.os.getcwd()
assert rinfo.version_info[:2] == (2,6)
def test_ssh(self, specssh):
sshhost = specssh.ssh
gw = py.execnet.makegateway("ssh=%s" % sshhost)
rinfo = gw._rinfo()
gw2 = py.execnet.SshGateway(sshhost)
rinfo2 = gw2._rinfo()
assert rinfo.executable == rinfo2.executable
assert rinfo.cwd == rinfo2.cwd
assert rinfo.version_info == rinfo2.version_info
def test_socket(self, specsocket):
gw = py.execnet.makegateway("socket=%s" % specsocket.socket)
rinfo = gw._rinfo()
assert rinfo.executable
assert rinfo.cwd
assert rinfo.version_info
# we cannot instantiate a second gateway
#gw2 = py.execnet.SocketGateway(*specsocket.socket.split(":"))
#rinfo2 = gw2._rinfo()
#assert rinfo.executable == rinfo2.executable
#assert rinfo.cwd == rinfo2.cwd
#assert rinfo.version_info == rinfo2.version_info

View File

@ -31,5 +31,11 @@ def makegateway(spec):
spec = XSpec(spec)
if spec.popen:
gw = py.execnet.PopenGateway(python=spec.python)
elif spec.ssh:
gw = py.execnet.SshGateway(spec.ssh, remotepython=spec.python)
elif spec.socket:
assert not spec.python, "socket: specifying python executables not supported"
hostport = spec.socket.split(":")
gw = py.execnet.SocketGateway(*hostport)
gw.spec = spec
return gw