From 5df58c619d55fb5984bd498807a6b9022b7d23e2 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Wed, 9 Sep 2009 20:12:03 +0200 Subject: [PATCH] * move gateway management code to py/test/dist because it's not clear how generally useful it is. * provide pytest_dist_makegateway(txspec) hook so that plugins can add their own interpretation/keywords. --HG-- branch : trunk --- py/execnet/gateway_base.py | 9 --- py/execnet/xspec.py | 1 - py/{execnet => test/dist}/gwmanage.py | 16 ++--- py/test/dist/nodemanage.py | 4 +- py/test/plugin/hookspec.py | 9 +++ py/test/plugin/pytest_terminal.py | 6 +- testing/execnet/test_gateway.py | 1 + .../{execnet => pytest/dist}/test_gwmanage.py | 59 +++++++++++-------- testing/pytest/plugin/test_pytest_terminal.py | 6 +- 9 files changed, 58 insertions(+), 53 deletions(-) rename py/{execnet => test/dist}/gwmanage.py (91%) rename testing/{execnet => pytest/dist}/test_gwmanage.py (71%) diff --git a/py/execnet/gateway_base.py b/py/execnet/gateway_base.py index 453439b4f..af182f9af 100644 --- a/py/execnet/gateway_base.py +++ b/py/execnet/gateway_base.py @@ -590,15 +590,6 @@ class ExecnetAPI: def pyexecnet_gateway_exit(self, gateway): """ signal exitting of gateway. """ - def pyexecnet_gwmanage_newgateway(self, gateway, platinfo): - """ called when a manager has made a new gateway. """ - - def pyexecnet_gwmanage_rsyncstart(self, source, gateways): - """ called before rsyncing a directory to remote gateways takes place. """ - - def pyexecnet_gwmanage_rsyncfinish(self, source, gateways): - """ called after rsyncing a directory to remote gateways takes place. """ - class BaseGateway(object): hook = ExecnetAPI() diff --git a/py/execnet/xspec.py b/py/execnet/xspec.py index 732469b9b..3831e1077 100644 --- a/py/execnet/xspec.py +++ b/py/execnet/xspec.py @@ -57,7 +57,6 @@ def makegateway(spec): hostport = spec.socket.split(":") gw = py.execnet.SocketGateway(*hostport) gw.spec = spec - # XXX events if spec.chdir or spec.nice: channel = gw.remote_exec(""" import os diff --git a/py/execnet/gwmanage.py b/py/test/dist/gwmanage.py similarity index 91% rename from py/execnet/gwmanage.py rename to py/test/dist/gwmanage.py index d67431ed4..c78b8db15 100644 --- a/py/execnet/gwmanage.py +++ b/py/test/dist/gwmanage.py @@ -1,27 +1,23 @@ """ - instantiating, managing and rsyncing to hosts - + instantiating, managing and rsyncing to test hosts """ import py import sys, os from py.__.execnet.gateway_base import RemoteError -NO_ENDMARKER_WANTED = object() - class GatewayManager: RemoteError = RemoteError - def __init__(self, specs, defaultchdir="pyexecnetcache"): + def __init__(self, specs, hook, defaultchdir="pyexecnetcache"): self.gateways = [] self.specs = [] + self.hook = hook for spec in specs: if not isinstance(spec, py.execnet.XSpec): spec = py.execnet.XSpec(spec) if not spec.chdir and not spec.popen: spec.chdir = defaultchdir self.specs.append(spec) - self.hook = py._com.HookRelay( - py.execnet._HookSpecs, py._com.comregistry) def makegateways(self): assert not self.gateways @@ -29,7 +25,7 @@ class GatewayManager: gw = py.execnet.makegateway(spec) self.gateways.append(gw) gw.id = "[%s]" % len(self.gateways) - self.hook.pyexecnet_gwmanage_newgateway( + self.hook.pytest_gwmanage_newgateway( gateway=gw, platinfo=gw._rinfo()) def getgateways(self, remote=True, inplacelocal=True): @@ -76,12 +72,12 @@ class GatewayManager: seen.add(spec) gateways.append(gateway) if seen: - self.hook.pyexecnet_gwmanage_rsyncstart( + self.hook.pytest_gwmanage_rsyncstart( source=source, gateways=gateways, ) rsync.send() - self.hook.pyexecnet_gwmanage_rsyncfinish( + self.hook.pytest_gwmanage_rsyncfinish( source=source, gateways=gateways, ) diff --git a/py/test/dist/nodemanage.py b/py/test/dist/nodemanage.py index 0578ffdd5..5ba6525e7 100644 --- a/py/test/dist/nodemanage.py +++ b/py/test/dist/nodemanage.py @@ -1,7 +1,7 @@ import py import sys, os from py.__.test.dist.txnode import TXNode -from py.__.execnet.gwmanage import GatewayManager +from py.__.test.dist.gwmanage import GatewayManager class NodeManager(object): @@ -10,7 +10,7 @@ class NodeManager(object): if specs is None: specs = self.config.getxspecs() self.roots = self.config.getrsyncdirs() - self.gwmanager = GatewayManager(specs) + self.gwmanager = GatewayManager(specs, config.hook) self.nodes = [] self._nodesready = py.std.threading.Event() diff --git a/py/test/plugin/hookspec.py b/py/test/plugin/hookspec.py index a82f718d1..e859125a6 100644 --- a/py/test/plugin/hookspec.py +++ b/py/test/plugin/hookspec.py @@ -133,6 +133,15 @@ pytest_doctest_prepare_content.firstresult = True # distributed testing # ------------------------------------------------------------------------- +def pytest_gwmanage_newgateway(gateway, platinfo): + """ called on new raw gateway creation. """ + +def pytest_gwmanage_rsyncstart(source, gateways): + """ called before rsyncing a directory to remote gateways takes place. """ + +def pytest_gwmanage_rsyncfinish(source, gateways): + """ called after rsyncing a directory to remote gateways takes place. """ + def pytest_testnodeready(node): """ Test Node is ready to operate. """ diff --git a/py/test/plugin/pytest_terminal.py b/py/test/plugin/pytest_terminal.py index 6ed4f09a6..4996d0fbe 100644 --- a/py/test/plugin/pytest_terminal.py +++ b/py/test/plugin/pytest_terminal.py @@ -107,7 +107,7 @@ class TerminalReporter: for line in str(excrepr).split("\n"): self.write_line("INTERNALERROR> " + line) - def pyexecnet_gwmanage_newgateway(self, gateway, platinfo): + def pytest_gwmanage_newgateway(self, gateway, platinfo): #self.write_line("%s instantiated gateway from spec %r" %(gateway.id, gateway.spec._spec)) d = {} d['version'] = repr_pythonversion(platinfo.version_info) @@ -126,14 +126,14 @@ class TerminalReporter: self.write_line(infoline) self.gateway2info[gateway] = infoline - def pyexecnet_gwmanage_rsyncstart(self, source, gateways): + def pytest_gwmanage_rsyncstart(self, source, gateways): targets = ", ".join([gw.id for gw in gateways]) msg = "rsyncstart: %s -> %s" %(source, targets) if not self.config.option.verbose: msg += " # use --verbose to see rsync progress" self.write_line(msg) - def pyexecnet_gwmanage_rsyncfinish(self, source, gateways): + def pytest_gwmanage_rsyncfinish(self, source, gateways): targets = ", ".join([gw.id for gw in gateways]) self.write_line("rsyncfinish: %s -> %s" %(source, targets)) diff --git a/testing/execnet/test_gateway.py b/testing/execnet/test_gateway.py index 42c6f166e..e62cdb5dc 100644 --- a/testing/execnet/test_gateway.py +++ b/testing/execnet/test_gateway.py @@ -391,6 +391,7 @@ class TestChannelFile: def test_join_blocked_execution_gateway(): gateway = py.execnet.PopenGateway() channel = gateway.remote_exec(""" + import time time.sleep(5.0) """) def doit(): diff --git a/testing/execnet/test_gwmanage.py b/testing/pytest/dist/test_gwmanage.py similarity index 71% rename from testing/execnet/test_gwmanage.py rename to testing/pytest/dist/test_gwmanage.py index d8ff55c4f..b64bb09ff 100644 --- a/testing/execnet/test_gwmanage.py +++ b/testing/pytest/dist/test_gwmanage.py @@ -7,36 +7,46 @@ import py import os -from py.__.execnet.gwmanage import GatewayManager, HostRSync +from py.__.test.dist.gwmanage import GatewayManager, HostRSync +from py.__.test.plugin import hookspec + +def pytest_funcarg__hookrecorder(request): + _pytest = request.getfuncargvalue('_pytest') + hook = request.getfuncargvalue('hook') + return _pytest.gethookrecorder(hook._hookspecs, hook._registry) + +def pytest_funcarg__hook(request): + registry = py._com.Registry() + return py._com.HookRelay(hookspec, registry) class TestGatewayManagerPopen: - def test_popen_no_default_chdir(self): - gm = GatewayManager(["popen"]) + def test_popen_no_default_chdir(self, hook): + gm = GatewayManager(["popen"], hook) assert gm.specs[0].chdir is None - def test_default_chdir(self): + def test_default_chdir(self, hook): l = ["ssh=noco", "socket=xyz"] - for spec in GatewayManager(l).specs: + for spec in GatewayManager(l, hook).specs: assert spec.chdir == "pyexecnetcache" - for spec in GatewayManager(l, defaultchdir="abc").specs: + for spec in GatewayManager(l, hook, defaultchdir="abc").specs: assert spec.chdir == "abc" - def test_popen_makegateway_events(self, _pytest): - rec = _pytest.gethookrecorder(py.execnet._HookSpecs) - hm = GatewayManager(["popen"] * 2) + def test_popen_makegateway_events(self, hook, hookrecorder, _pytest): + hm = GatewayManager(["popen"] * 2, hook) hm.makegateways() - call = rec.popcall("pyexecnet_gwmanage_newgateway") - assert call.gateway.id == "[1]" + call = hookrecorder.popcall("pytest_gwmanage_newgateway") + assert call.gateway.spec == py.execnet.XSpec("popen") + assert call.gateway.id == "[1]" assert call.platinfo.executable == call.gateway._rinfo().executable - call = rec.popcall("pyexecnet_gwmanage_newgateway") + call = hookrecorder.popcall("pytest_gwmanage_newgateway") assert call.gateway.id == "[2]" assert len(hm.gateways) == 2 hm.exit() assert not len(hm.gateways) - def test_popens_rsync(self, mysetup): + def test_popens_rsync(self, hook, mysetup): source = mysetup.source - hm = GatewayManager(["popen"] * 2) + hm = GatewayManager(["popen"] * 2, hook) hm.makegateways() assert len(hm.gateways) == 2 for gw in hm.gateways: @@ -47,9 +57,9 @@ class TestGatewayManagerPopen: hm.exit() assert not len(hm.gateways) - def test_rsync_popen_with_path(self, mysetup): + def test_rsync_popen_with_path(self, hook, mysetup): source, dest = mysetup.source, mysetup.dest - hm = GatewayManager(["popen//chdir=%s" %dest] * 1) + hm = GatewayManager(["popen//chdir=%s" %dest] * 1, hook) hm.makegateways() source.ensure("dir1", "dir2", "hello") l = [] @@ -62,21 +72,20 @@ class TestGatewayManagerPopen: assert dest.join("dir1", "dir2").check() assert dest.join("dir1", "dir2", 'hello').check() - def test_hostmanage_rsync_same_popen_twice(self, mysetup, _pytest): + def test_rsync_same_popen_twice(self, hook, mysetup, hookrecorder): source, dest = mysetup.source, mysetup.dest - rec = _pytest.gethookrecorder(py.execnet._HookSpecs) - hm = GatewayManager(["popen//chdir=%s" %dest] * 2) + hm = GatewayManager(["popen//chdir=%s" %dest] * 2, hook) hm.makegateways() source.ensure("dir1", "dir2", "hello") hm.rsync(source) - call = rec.popcall("pyexecnet_gwmanage_rsyncstart") + call = hookrecorder.popcall("pytest_gwmanage_rsyncstart") assert call.source == source assert len(call.gateways) == 1 assert hm.gateways[0] == call.gateways[0] - call = rec.popcall("pyexecnet_gwmanage_rsyncfinish") + call = hookrecorder.popcall("pytest_gwmanage_rsyncfinish") - def test_multi_chdir_popen_with_path(self, testdir): - hm = GatewayManager(["popen//chdir=hello"] * 2) + def test_multi_chdir_popen_with_path(self, hook, testdir): + hm = GatewayManager(["popen//chdir=hello"] * 2, hook) testdir.tmpdir.chdir() hellopath = testdir.tmpdir.mkdir("hello").realpath() hm.makegateways() @@ -96,9 +105,9 @@ class TestGatewayManagerPopen: assert l[0].startswith(curwd) assert l[0].endswith("world") - def test_multi_chdir_popen(self, testdir): + def test_multi_chdir_popen(self, testdir, hook): import os - hm = GatewayManager(["popen"] * 2) + hm = GatewayManager(["popen"] * 2, hook) testdir.tmpdir.chdir() hellopath = testdir.tmpdir.mkdir("hello") hm.makegateways() diff --git a/testing/pytest/plugin/test_pytest_terminal.py b/testing/pytest/plugin/test_pytest_terminal.py index 598e7e546..b9ccae34c 100644 --- a/testing/pytest/plugin/test_pytest_terminal.py +++ b/testing/pytest/plugin/test_pytest_terminal.py @@ -123,16 +123,16 @@ class TestTerminal: platform = "xyz" cwd = "qwe" - rep.pyexecnet_gwmanage_newgateway(gw1, rinfo) + rep.pytest_gwmanage_newgateway(gw1, rinfo) linecomp.assert_contains_lines([ "X1*popen*xyz*2.5*" ]) - rep.pyexecnet_gwmanage_rsyncstart(source="hello", gateways=[gw1, gw2]) + rep.pytest_gwmanage_rsyncstart(source="hello", gateways=[gw1, gw2]) linecomp.assert_contains_lines([ "rsyncstart: hello -> X1, X2" ]) - rep.pyexecnet_gwmanage_rsyncfinish(source="hello", gateways=[gw1, gw2]) + rep.pytest_gwmanage_rsyncfinish(source="hello", gateways=[gw1, gw2]) linecomp.assert_contains_lines([ "rsyncfinish: hello -> X1, X2" ])