[svn r63020] allow to specify python executable in gatewayspecs, fix a few tests
--HG-- branch : trunk
This commit is contained in:
		
							parent
							
								
									fcaefb841b
								
							
						
					
					
						commit
						6f93561002
					
				| 
						 | 
					@ -24,11 +24,17 @@ from py.__.execnet.channel import RemoteError
 | 
				
			||||||
NO_ENDMARKER_WANTED = object()
 | 
					NO_ENDMARKER_WANTED = object()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class GatewaySpec(object):
 | 
					class GatewaySpec(object):
 | 
				
			||||||
 | 
					    python = "python" 
 | 
				
			||||||
    def __init__(self, spec, defaultjoinpath="pyexecnetcache"):
 | 
					    def __init__(self, spec, defaultjoinpath="pyexecnetcache"):
 | 
				
			||||||
        if spec == "popen" or spec.startswith("popen:"):
 | 
					        if spec == "popen" or spec.startswith("popen:"):
 | 
				
			||||||
            self.address = "popen"
 | 
					            parts = spec.split(":", 2)
 | 
				
			||||||
            self.joinpath = spec[len(self.address)+1:]
 | 
					            self.type = self.address = parts.pop(0)
 | 
				
			||||||
            self.type = "popen"
 | 
					            if parts:
 | 
				
			||||||
 | 
					                self.python = parts.pop(0)
 | 
				
			||||||
 | 
					            if parts:
 | 
				
			||||||
 | 
					                self.joinpath = parts.pop(0)
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
 | 
					                self.joinpath = ""
 | 
				
			||||||
        elif spec.startswith("socket:"):
 | 
					        elif spec.startswith("socket:"):
 | 
				
			||||||
            parts = spec[7:].split(":", 2)
 | 
					            parts = spec[7:].split(":", 2)
 | 
				
			||||||
            self.address = parts.pop(0)
 | 
					            self.address = parts.pop(0)
 | 
				
			||||||
| 
						 | 
					@ -40,8 +46,9 @@ class GatewaySpec(object):
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            if spec.startswith("ssh:"):
 | 
					            if spec.startswith("ssh:"):
 | 
				
			||||||
                spec = spec[4:]
 | 
					                spec = spec[4:]
 | 
				
			||||||
            parts = spec.split(":", 1)
 | 
					            parts = spec.split(":", 2)
 | 
				
			||||||
            self.address = parts.pop(0)
 | 
					            self.address = parts.pop(0)
 | 
				
			||||||
 | 
					            self.python = parts and parts.pop(0) or "python"
 | 
				
			||||||
            self.joinpath = parts and parts.pop(0) or ""
 | 
					            self.joinpath = parts and parts.pop(0) or ""
 | 
				
			||||||
            self.type = "ssh"
 | 
					            self.type = "ssh"
 | 
				
			||||||
        if not self.joinpath and not self.inplacelocal():
 | 
					        if not self.joinpath and not self.inplacelocal():
 | 
				
			||||||
| 
						 | 
					@ -54,13 +61,13 @@ class GatewaySpec(object):
 | 
				
			||||||
        return "<GatewaySpec %s:%s>" % (self.address, self.joinpath)
 | 
					        return "<GatewaySpec %s:%s>" % (self.address, self.joinpath)
 | 
				
			||||||
    __repr__ = __str__
 | 
					    __repr__ = __str__
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def makegateway(self, python=None, waitclose=True):
 | 
					    def makegateway(self, waitclose=True):
 | 
				
			||||||
        if self.type == "popen":
 | 
					        if self.type == "popen":
 | 
				
			||||||
            gw = py.execnet.PopenGateway(python=python)
 | 
					            gw = py.execnet.PopenGateway(python=self.python)
 | 
				
			||||||
        elif self.type == "socket":
 | 
					        elif self.type == "socket":
 | 
				
			||||||
            gw = py.execnet.SocketGateway(*self.address)
 | 
					            gw = py.execnet.SocketGateway(*self.address)
 | 
				
			||||||
        elif self.type == "ssh":
 | 
					        elif self.type == "ssh":
 | 
				
			||||||
            gw = py.execnet.SshGateway(self.address, remotepython=python)
 | 
					            gw = py.execnet.SshGateway(self.address, remotepython=self.python)
 | 
				
			||||||
        if self.joinpath:
 | 
					        if self.joinpath:
 | 
				
			||||||
            channel = gw.remote_exec("""
 | 
					            channel = gw.remote_exec("""
 | 
				
			||||||
                import os 
 | 
					                import os 
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -76,7 +76,7 @@ class PopenGateway(PopenCmdGateway):
 | 
				
			||||||
        """ instantiate a gateway to a subprocess 
 | 
					        """ instantiate a gateway to a subprocess 
 | 
				
			||||||
            started with the given 'python' executable. 
 | 
					            started with the given 'python' executable. 
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        if python is None:
 | 
					        if not python:
 | 
				
			||||||
            python = sys.executable
 | 
					            python = sys.executable
 | 
				
			||||||
        cmd = '%s -u -c "exec input()"' % python
 | 
					        cmd = '%s -u -c "exec input()"' % python
 | 
				
			||||||
        super(PopenGateway, self).__init__(cmd)
 | 
					        super(PopenGateway, self).__init__(cmd)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -570,9 +570,8 @@ class TestSocketGateway(SocketGatewaySetup, BasicRemoteExecution):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestSshGateway(BasicRemoteExecution):
 | 
					class TestSshGateway(BasicRemoteExecution):
 | 
				
			||||||
    def setup_class(cls): 
 | 
					    def setup_class(cls): 
 | 
				
			||||||
        if py.test.config.option.sshhost is None: 
 | 
					        sshhost = py.test.config.getvalueorskip("sshhost")
 | 
				
			||||||
            py.test.skip("no known ssh target, use --sshhost to set one")
 | 
					        cls.gw = py.execnet.SshGateway(sshhost)
 | 
				
			||||||
        cls.gw = py.execnet.SshGateway(py.test.config.option.sshhost) 
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_sshconfig_functional(self):
 | 
					    def test_sshconfig_functional(self):
 | 
				
			||||||
        tmpdir = py.test.ensuretemp("test_sshconfig")
 | 
					        tmpdir = py.test.ensuretemp("test_sshconfig")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,24 +18,33 @@ class TestGatewaySpec:
 | 
				
			||||||
    [ssh:]spec:path           SshGateway
 | 
					    [ssh:]spec:path           SshGateway
 | 
				
			||||||
    * [SshGateway]
 | 
					    * [SshGateway]
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    def test_popen_nopath(self):
 | 
					    def test_popen(self):
 | 
				
			||||||
        for joinpath in ('', ':abc', ':ab:cd', ':/x/y'):
 | 
					        for python in ('', 'python2.4'):
 | 
				
			||||||
            spec = GatewaySpec("popen" + joinpath)
 | 
					            for joinpath in ('', 'abc', 'ab:cd', '/x/y'):
 | 
				
			||||||
 | 
					                s = ":".join(["popen", python, joinpath])
 | 
				
			||||||
 | 
					                print s
 | 
				
			||||||
 | 
					                spec = GatewaySpec(s)
 | 
				
			||||||
                assert spec.address == "popen"
 | 
					                assert spec.address == "popen"
 | 
				
			||||||
            assert spec.joinpath == joinpath[1:]
 | 
					                assert spec.python == python 
 | 
				
			||||||
 | 
					                assert spec.joinpath == joinpath
 | 
				
			||||||
                assert spec.type == "popen"
 | 
					                assert spec.type == "popen"
 | 
				
			||||||
                spec2 = GatewaySpec("popen" + joinpath)
 | 
					                spec2 = GatewaySpec("popen" + joinpath)
 | 
				
			||||||
                self._equality(spec, spec2)
 | 
					                self._equality(spec, spec2)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_ssh(self):
 | 
					    def test_ssh(self):
 | 
				
			||||||
        for prefix in ('ssh:', ''): # ssh is default
 | 
					        for prefix in ('ssh', ''): # ssh is default
 | 
				
			||||||
            for hostpart in ('x.y', 'xyz@x.y'):
 | 
					            for hostpart in ('x.y', 'xyz@x.y'):
 | 
				
			||||||
                for joinpath in ('', ':abc', ':ab:cd', ':/tmp'):
 | 
					                for python in ('python', 'python2.5'):
 | 
				
			||||||
                    specstring = prefix + hostpart + joinpath
 | 
					                    for joinpath in ('', 'abc', 'ab:cd', '/tmp'):
 | 
				
			||||||
 | 
					                        specstring = ":".join([prefix, hostpart, python, joinpath])
 | 
				
			||||||
 | 
					                        if specstring[0] == ":":
 | 
				
			||||||
 | 
					                            specstring = specstring[1:]
 | 
				
			||||||
 | 
					                        print specstring
 | 
				
			||||||
                        spec = GatewaySpec(specstring)
 | 
					                        spec = GatewaySpec(specstring)
 | 
				
			||||||
                        assert spec.address == hostpart 
 | 
					                        assert spec.address == hostpart 
 | 
				
			||||||
                    if joinpath[1:]:
 | 
					                        assert spec.python == python
 | 
				
			||||||
                        assert spec.joinpath == joinpath[1:]
 | 
					                        if joinpath:
 | 
				
			||||||
 | 
					                            assert spec.joinpath == joinpath
 | 
				
			||||||
                        else:
 | 
					                        else:
 | 
				
			||||||
                            assert spec.joinpath == "pyexecnetcache"
 | 
					                            assert spec.joinpath == "pyexecnetcache"
 | 
				
			||||||
                        assert spec.type == "ssh"
 | 
					                        assert spec.type == "ssh"
 | 
				
			||||||
| 
						 | 
					@ -72,17 +81,17 @@ class TestGatewaySpecAPI:
 | 
				
			||||||
        gw.exit()
 | 
					        gw.exit()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_popen_makegateway(self, testdir):
 | 
					    def test_popen_makegateway(self, testdir):
 | 
				
			||||||
        spec = GatewaySpec("popen:" + 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_popen_makegateway_python(self, testdir):
 | 
					    def test_popen_makegateway_python(self, testdir):
 | 
				
			||||||
        spec = GatewaySpec("popen")
 | 
					        spec = GatewaySpec("popen:%s" % py.std.sys.executable)
 | 
				
			||||||
        gw = spec.makegateway(python=py.std.sys.executable)
 | 
					        gw = spec.makegateway()
 | 
				
			||||||
        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 == py.std.sys.executable
 | 
				
			||||||
        gw.exit()
 | 
					        gw.exit()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_ssh(self):
 | 
					    def test_ssh(self):
 | 
				
			||||||
| 
						 | 
					@ -118,7 +127,7 @@ class TestGatewayManagerPopen:
 | 
				
			||||||
        assert not len(hm.gateways) 
 | 
					        assert not len(hm.gateways) 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_hostmanager_rsync_popen_with_path(self, source, dest):
 | 
					    def test_hostmanager_rsync_popen_with_path(self, source, dest):
 | 
				
			||||||
        hm = GatewayManager(["popen:%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 = []
 | 
				
			||||||
| 
						 | 
					@ -146,7 +155,7 @@ class TestGatewayManagerPopen:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_multi_chdir_popen_with_path(self, testdir):
 | 
					    def test_multi_chdir_popen_with_path(self, testdir):
 | 
				
			||||||
        import os
 | 
					        import os
 | 
				
			||||||
        hm = GatewayManager(["popen: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()
 | 
				
			||||||
| 
						 | 
					@ -253,7 +262,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("popen:%s" % dest)
 | 
					        spec = GatewaySpec("popen::%s" % dest)
 | 
				
			||||||
        gw = spec.makegateway()
 | 
					        gw = spec.makegateway()
 | 
				
			||||||
        finished = []
 | 
					        finished = []
 | 
				
			||||||
        rsync = HostRSync(source)
 | 
					        rsync = HostRSync(source)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,7 +18,7 @@ def test_terminalwriter_defaultwidth_80():
 | 
				
			||||||
    py.magic.patch(terminalwriter, '_getdimensions', lambda: 0/0)
 | 
					    py.magic.patch(terminalwriter, '_getdimensions', lambda: 0/0)
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
        tw = py.io.TerminalWriter()  
 | 
					        tw = py.io.TerminalWriter()  
 | 
				
			||||||
        assert tw.fullwidth == os.environ.get('COLUMNS', 80)-1
 | 
					        assert tw.fullwidth == int(os.environ.get('COLUMNS', 80)) -1
 | 
				
			||||||
    finally:         
 | 
					    finally:         
 | 
				
			||||||
        py.magic.revert(terminalwriter, '_getdimensions')
 | 
					        py.magic.revert(terminalwriter, '_getdimensions')
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -65,7 +65,7 @@ class TestAsyncFunctional:
 | 
				
			||||||
        p = subdir.join("test_one.py")
 | 
					        p = subdir.join("test_one.py")
 | 
				
			||||||
        p.write("def test_5(): assert not __file__.startswith(%r)" % str(p))
 | 
					        p.write("def test_5(): assert not __file__.startswith(%r)" % str(p))
 | 
				
			||||||
        result = testdir.runpytest("-d", "--rsyncdirs=%(subdir)s" % locals(), 
 | 
					        result = testdir.runpytest("-d", "--rsyncdirs=%(subdir)s" % locals(), 
 | 
				
			||||||
                                   "--gateways=popen:%(dest)s" % locals(), p)
 | 
					                                   "--gateways=popen::%(dest)s" % locals(), p)
 | 
				
			||||||
        assert result.ret == 0
 | 
					        assert result.ret == 0
 | 
				
			||||||
        result.stdout.fnmatch_lines([
 | 
					        result.stdout.fnmatch_lines([
 | 
				
			||||||
            "*1 passed*"
 | 
					            "*1 passed*"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -37,7 +37,7 @@ class TestHostManager:
 | 
				
			||||||
    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")
 | 
				
			||||||
        config = py.test.config._reparse([source])
 | 
					        config = py.test.config._reparse([source])
 | 
				
			||||||
        hm = HostManager(config, hosts=["popen:%s" % dest])
 | 
					        hm = HostManager(config, hosts=["popen::%s" % dest])
 | 
				
			||||||
        assert hm.config.topdir == source == config.topdir
 | 
					        assert hm.config.topdir == source == config.topdir
 | 
				
			||||||
        hm.rsync_roots()
 | 
					        hm.rsync_roots()
 | 
				
			||||||
        p, = hm.gwmanager.multi_exec("import os ; channel.send(os.getcwd())").receive_each()
 | 
					        p, = hm.gwmanager.multi_exec("import os ; channel.send(os.getcwd())").receive_each()
 | 
				
			||||||
| 
						 | 
					@ -51,7 +51,7 @@ class TestHostManager:
 | 
				
			||||||
        dir2 = source.ensure("dir1", "dir2", dir=1)
 | 
					        dir2 = source.ensure("dir1", "dir2", dir=1)
 | 
				
			||||||
        dir2.ensure("hello")
 | 
					        dir2.ensure("hello")
 | 
				
			||||||
        hm = self.gethostmanager(source, 
 | 
					        hm = self.gethostmanager(source, 
 | 
				
			||||||
            hosts = ["popen:%s" % dest],
 | 
					            hosts = ["popen::%s" % dest],
 | 
				
			||||||
            rsyncdirs = ['dir1']
 | 
					            rsyncdirs = ['dir1']
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        assert hm.config.topdir == source
 | 
					        assert hm.config.topdir == source
 | 
				
			||||||
| 
						 | 
					@ -64,7 +64,7 @@ class TestHostManager:
 | 
				
			||||||
        dir2 = source.ensure("dir1", "dir2", dir=1)
 | 
					        dir2 = source.ensure("dir1", "dir2", dir=1)
 | 
				
			||||||
        dir2.ensure("hello")
 | 
					        dir2.ensure("hello")
 | 
				
			||||||
        hm = self.gethostmanager(source, 
 | 
					        hm = self.gethostmanager(source, 
 | 
				
			||||||
            hosts = ["popen:%s" % dest],
 | 
					            hosts = ["popen::%s" % dest],
 | 
				
			||||||
            rsyncdirs = [str(source)]
 | 
					            rsyncdirs = [str(source)]
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        assert hm.config.topdir == source
 | 
					        assert hm.config.topdir == source
 | 
				
			||||||
| 
						 | 
					@ -84,7 +84,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::" + str(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()
 | 
				
			||||||
| 
						 | 
					@ -101,7 +101,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::" + str(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()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue