[svn r62975] - use "popen" instead of localhost if you want popen-gateways

- have a default joinpath

--HG--
branch : trunk
This commit is contained in:
hpk 2009-03-16 17:53:52 +01:00
parent e2bbee8bbd
commit f01040b193
2 changed files with 39 additions and 31 deletions

View File

@ -4,7 +4,7 @@
Host specification strings and implied gateways: Host specification strings and implied gateways:
socket:hostname:port:path SocketGateway socket:hostname:port:path SocketGateway
localhost[:path] PopenGateway popen[-executable][:path] PopenGateway
[ssh:]spec:path SshGateway [ssh:]spec:path SshGateway
* [SshGateway] * [SshGateway]
@ -23,9 +23,9 @@ from py.__.test import event
class GatewaySpec(object): class GatewaySpec(object):
type = "ssh" type = "ssh"
def __init__(self, spec): def __init__(self, spec, defaultjoinpath="pyexecnetcache"):
if spec == "localhost" or spec.startswith("localhost:"): if spec == "popen" or spec.startswith("popen:"):
self.address = "localhost" self.address = "popen"
self.joinpath = spec[len(self.address)+1:] self.joinpath = spec[len(self.address)+1:]
self.type = "popen" self.type = "popen"
elif spec.startswith("socket:"): elif spec.startswith("socket:"):
@ -42,6 +42,8 @@ class GatewaySpec(object):
parts = spec.split(":", 1) parts = spec.split(":", 1)
self.address = parts.pop(0) self.address = parts.pop(0)
self.joinpath = parts and parts.pop(0) or "" self.joinpath = parts and parts.pop(0) or ""
if not self.joinpath and not self.inplacelocal():
self.joinpath = defaultjoinpath
def inplacelocal(self): def inplacelocal(self):
return bool(self.type == "popen" and not self.joinpath) return bool(self.type == "popen" and not self.joinpath)

View File

@ -13,17 +13,17 @@ from py.__.execnet.gwmanage import HostRSync
class TestGatewaySpec: class TestGatewaySpec:
""" """
socket:hostname:port:path SocketGateway socket:hostname:port:path SocketGateway
localhost[:path] PopenGateway popen[-executable][:path] PopenGateway
[ssh:]spec:path SshGateway [ssh:]spec:path SshGateway
* [SshGateway] * [SshGateway]
""" """
def test_localhost_nopath(self): def test_popen_nopath(self):
for joinpath in ('', ':abc', ':ab:cd', ':/x/y'): for joinpath in ('', ':abc', ':ab:cd', ':/x/y'):
spec = GatewaySpec("localhost" + joinpath) spec = GatewaySpec("popen" + joinpath)
assert spec.address == "localhost" assert spec.address == "popen"
assert spec.joinpath == joinpath[1:] assert spec.joinpath == joinpath[1:]
assert spec.type == "popen" assert spec.type == "popen"
spec2 = GatewaySpec("localhost" + joinpath) spec2 = GatewaySpec("popen" + joinpath)
self._equality(spec, spec2) self._equality(spec, spec2)
if joinpath == "": if joinpath == "":
assert spec.inplacelocal() assert spec.inplacelocal()
@ -37,19 +37,25 @@ class TestGatewaySpec:
specstring = prefix + hostpart + joinpath specstring = prefix + hostpart + joinpath
spec = GatewaySpec(specstring) spec = GatewaySpec(specstring)
assert spec.address == hostpart assert spec.address == hostpart
if joinpath[1:]:
assert spec.joinpath == joinpath[1:] assert spec.joinpath == joinpath[1:]
else:
assert spec.joinpath == "pyexecnetcache"
assert spec.type == "ssh" assert spec.type == "ssh"
spec2 = GatewaySpec(specstring) spec2 = GatewaySpec(specstring)
self._equality(spec, spec2) self._equality(spec, spec2)
assert not spec.inplacelocal() assert not spec.inplacelocal()
def test_socket(self): def test_socket(self):
for hostpart in ('x.y', 'x', 'localhost'): for hostpart in ('x.y', 'x', 'popen'):
for port in ":80", ":1000": for port in ":80", ":1000":
for joinpath in ('', ':abc', ':abc:de'): for joinpath in ('', ':abc', ':abc:de'):
spec = GatewaySpec("socket:" + hostpart + port + joinpath) spec = GatewaySpec("socket:" + hostpart + port + joinpath)
assert spec.address == (hostpart, int(port[1:])) assert spec.address == (hostpart, int(port[1:]))
if joinpath[1:]:
assert spec.joinpath == joinpath[1:] assert spec.joinpath == joinpath[1:]
else:
assert spec.joinpath == "pyexecnetcache"
assert spec.type == "socket" assert spec.type == "socket"
spec2 = GatewaySpec("socket:" + hostpart + port + joinpath) spec2 = GatewaySpec("socket:" + hostpart + port + joinpath)
self._equality(spec, spec2) self._equality(spec, spec2)
@ -62,23 +68,23 @@ class TestGatewaySpec:
class TestGatewaySpecAPI: class TestGatewaySpecAPI:
def test_localhost_nopath_makegateway(self, testdir): def test_popen_nopath_makegateway(self, testdir):
spec = GatewaySpec("localhost") spec = GatewaySpec("popen")
gw = spec.makegateway() gw = spec.makegateway()
p = gw.remote_exec("import os; channel.send(os.getcwd())").receive() p = gw.remote_exec("import os; channel.send(os.getcwd())").receive()
curdir = py.std.os.getcwd() curdir = py.std.os.getcwd()
assert curdir == p assert curdir == p
gw.exit() gw.exit()
def test_localhost_makegateway(self, testdir): def test_popen_makegateway(self, testdir):
spec = GatewaySpec("localhost:" + str(testdir.tmpdir)) spec = GatewaySpec("popen:" + str(testdir.tmpdir))
gw = spec.makegateway() gw = spec.makegateway()
p = gw.remote_exec("import os; channel.send(os.getcwd())").receive() p = gw.remote_exec("import os; channel.send(os.getcwd())").receive()
assert spec.joinpath == p assert spec.joinpath == p
gw.exit() gw.exit()
def test_localhost_makegateway_python(self, testdir): def test_popen_makegateway_python(self, testdir):
spec = GatewaySpec("localhost") spec = GatewaySpec("popen")
gw = spec.makegateway(python=py.std.sys.executable) gw = spec.makegateway(python=py.std.sys.executable)
res = gw.remote_exec("import sys ; channel.send(sys.executable)").receive() res = gw.remote_exec("import sys ; channel.send(sys.executable)").receive()
assert py.std.sys.executable == res assert py.std.sys.executable == res
@ -96,16 +102,16 @@ class TestGatewaySpecAPI:
gw = py.execnet.PopenGateway() gw = py.execnet.PopenGateway()
spec = GatewaySpec("ssh:" + sshhost) spec = GatewaySpec("ssh:" + sshhost)
class TestGatewayManagerLocalhost: class TestGatewayManagerPopen:
def test_hostmanager_localhosts_makegateway(self): def test_hostmanager_popen_makegateway(self):
hm = GatewayManager(["localhost"] * 2) hm = GatewayManager(["popen"] * 2)
hm.makegateways() hm.makegateways()
assert len(hm.spec2gateway) == 2 assert len(hm.spec2gateway) == 2
hm.exit() hm.exit()
assert not len(hm.spec2gateway) assert not len(hm.spec2gateway)
def test_hostmanager_localhosts_rsync(self, source): def test_hostmanager_popens_rsync(self, source):
hm = GatewayManager(["localhost"] * 2) hm = GatewayManager(["popen"] * 2)
hm.makegateways() hm.makegateways()
assert len(hm.spec2gateway) == 2 assert len(hm.spec2gateway) == 2
for gw in hm.spec2gateway.values(): for gw in hm.spec2gateway.values():
@ -116,8 +122,8 @@ class TestGatewayManagerLocalhost:
hm.exit() hm.exit()
assert not len(hm.spec2gateway) assert not len(hm.spec2gateway)
def test_hostmanager_rsync_localhost_with_path(self, source, dest): def test_hostmanager_rsync_popen_with_path(self, source, dest):
hm = GatewayManager(["localhost:%s" %dest] * 1) hm = GatewayManager(["popen:%s" %dest] * 1)
hm.makegateways() hm.makegateways()
source.ensure("dir1", "dir2", "hello") source.ensure("dir1", "dir2", "hello")
l = [] l = []
@ -143,9 +149,9 @@ class TestGatewayManagerLocalhost:
print events print events
assert 0 assert 0
def test_multi_chdir_localhost_with_path(self, testdir): def test_multi_chdir_popen_with_path(self, testdir):
import os import os
hm = GatewayManager(["localhost:hello"] * 2) hm = GatewayManager(["popen:hello"] * 2)
testdir.tmpdir.chdir() testdir.tmpdir.chdir()
hellopath = testdir.tmpdir.mkdir("hello") hellopath = testdir.tmpdir.mkdir("hello")
hm.makegateways() hm.makegateways()
@ -161,9 +167,9 @@ class TestGatewayManagerLocalhost:
assert l[0].startswith(curwd) assert l[0].startswith(curwd)
assert l[0].endswith("world") assert l[0].endswith("world")
def test_multi_chdir_localhost(self, testdir): def test_multi_chdir_popen(self, testdir):
import os import os
hm = GatewayManager(["localhost"] * 2) hm = GatewayManager(["popen"] * 2)
testdir.tmpdir.chdir() testdir.tmpdir.chdir()
hellopath = testdir.tmpdir.mkdir("hello") hellopath = testdir.tmpdir.mkdir("hello")
hm.makegateways() hm.makegateways()
@ -222,7 +228,7 @@ class TestHRSync:
assert 'somedir' in basenames assert 'somedir' in basenames
def test_hrsync_one_host(self, source, dest): def test_hrsync_one_host(self, source, dest):
spec = GatewaySpec("localhost:%s" % dest) spec = GatewaySpec("popen:%s" % dest)
gw = spec.makegateway() gw = spec.makegateway()
finished = [] finished = []
rsync = HostRSync(source) rsync = HostRSync(source)