diff --git a/py/execnet/gwmanage.py b/py/execnet/gwmanage.py index cb446aa8b..6f67b9b34 100644 --- a/py/execnet/gwmanage.py +++ b/py/execnet/gwmanage.py @@ -26,6 +26,7 @@ NO_ENDMARKER_WANTED = object() class GatewaySpec(object): python = None def __init__(self, spec, defaultjoinpath="pyexecnetcache"): + self._spec = spec if spec == "popen" or spec.startswith("popen:"): parts = spec.split(":", 2) self.type = self.address = parts.pop(0) @@ -66,7 +67,7 @@ class GatewaySpec(object): return bool(self.type == "popen" and not self.joinpath) def __str__(self): - return "" % (self.address, self.joinpath) + return "" % self._spec __repr__ = __str__ def makegateway(self, waitclose=True): @@ -102,13 +103,18 @@ class GatewayManager: self.gateways = [] def trace(self, msg): - py._com.pyplugins.notify("trace", "gatewaymanage", msg) + self.notify("trace", "gatewaymanage", msg) + + def notify(self, eventname, *args, **kwargs): + py._com.pyplugins.notify(eventname, *args, **kwargs) def makegateways(self): assert not self.gateways for spec in self.specs: - self.trace("makegateway %s" %(spec)) - self.gateways.append(spec.makegateway()) + gw = spec.makegateway() + self.gateways.append(gw) + gw.id = "[%s]" % len(self.gateways) + self.notify("gwmanage_newgateway", gw) def getgateways(self, remote=True, inplacelocal=True): if not self.gateways and self.specs: diff --git a/py/execnet/testing/test_gateway.py b/py/execnet/testing/test_gateway.py index 1270a0dd4..19efbbb81 100644 --- a/py/execnet/testing/test_gateway.py +++ b/py/execnet/testing/test_gateway.py @@ -565,9 +565,9 @@ class SocketGatewaySetup: ## cls.gw.exit() ## cls.proxygw.exit() -def getsshhost(): +def getsshhost(withpython=False): sshhost = py.test.config.getvalueorskip("sshhost") - if sshhost.find(":") != -1: + if not withpython and sshhost.find(":") != -1: sshhost = sshhost.split(":")[0] ssh = py.path.local.sysfind("ssh") if not ssh: diff --git a/py/execnet/testing/test_gwmanage.py b/py/execnet/testing/test_gwmanage.py index a864c3263..ca357ced7 100644 --- a/py/execnet/testing/test_gwmanage.py +++ b/py/execnet/testing/test_gwmanage.py @@ -1,7 +1,5 @@ """ tests for - - gateway specifications - - multi channels and multi gateways - gateway management - manage rsyncing of hosts @@ -10,10 +8,18 @@ import py from py.__.execnet.gwmanage import GatewayManager, HostRSync +pytest_plugins = "pytest_pytester" + class TestGatewayManagerPopen: - def test_hostmanager_popen_makegateway(self): + def test_hostmanager_popen_makegateway(self, eventrecorder): hm = GatewayManager(["popen"] * 2) hm.makegateways() + event = eventrecorder.popevent("gwmanage_newgateway") + gw = event.args[0] + assert gw.id == "[1]" + event = eventrecorder.popevent("gwmanage_newgateway") + gw = event.args[0] + assert gw.id == "[2]" assert len(hm.gateways) == 2 hm.exit() assert not len(hm.gateways) diff --git a/py/test/dsession/hostmanage.py b/py/test/dsession/hostmanage.py index f8f579c4f..c517c8706 100644 --- a/py/test/dsession/hostmanage.py +++ b/py/test/dsession/hostmanage.py @@ -50,6 +50,11 @@ class HostManager(object): self.gwmanager = GatewayManager(hosts) def makegateways(self): + # we change to the topdir sot that + # PopenGateways will have their cwd + # such that unpickling configs will + # pick it up as the right topdir + # (for other gateways this chdir is irrelevant) old = self.config.topdir.chdir() try: self.gwmanager.makegateways() @@ -74,11 +79,6 @@ class HostManager(object): have the same set of roots in their current directory. """ - # we change to the topdir sot that - # PopenGateways will have their cwd - # such that unpickling configs will - # pick it up as the right topdir - # (for other gateways this chdir is irrelevant) self.makegateways() options = { 'ignores': self.config_getignores(), diff --git a/py/test/dsession/testing/test_functional_dsession.py b/py/test/dsession/testing/test_functional_dsession.py index d469cec0a..07419b8d1 100644 --- a/py/test/dsession/testing/test_functional_dsession.py +++ b/py/test/dsession/testing/test_functional_dsession.py @@ -65,9 +65,12 @@ class TestAsyncFunctional: p = subdir.join("test_one.py") p.write("def test_5(): assert not __file__.startswith(%r)" % str(p)) result = testdir.runpytest("-d", "--rsyncdirs=%(subdir)s" % locals(), - "--gateways=popen::%(dest)s" % locals(), p) + "--gateways=popen::%(dest)s" % locals(), p) assert result.ret == 0 result.stdout.fnmatch_lines([ + "*1* instantiated gateway *popen*", + #"RSyncStart: [G1]", + #"RSyncFinished: [G1]", "*1 passed*" ]) assert dest.join(subdir.basename).check(dir=1) diff --git a/py/test/dsession/testing/test_hostmanage.py b/py/test/dsession/testing/test_hostmanage.py index db1004254..96283bf4f 100644 --- a/py/test/dsession/testing/test_hostmanage.py +++ b/py/test/dsession/testing/test_hostmanage.py @@ -136,7 +136,7 @@ class TestHostManager: hm.teardown_hosts() def test_hostmanage_ssh_setup_hosts(self, testdir): - sshhost = getsshhost() + sshhost = getsshhost(withpython=True) testdir.makepyfile(__init__="", test_x=""" def test_one(): pass @@ -149,7 +149,7 @@ class TestHostManager: @py.test.mark.xfail("implement double-rsync test") def test_ssh_rsync_samehost_twice(self): - sshhost = getsshhost() + sshhost = getsshhost(withpython=True) host1 = Host("%s" % (sshhost, )) host2 = Host("%s" % (sshhost, )) hm = HostManager(config, hosts=[host1, host2]) diff --git a/py/test/plugin/pytest_plugintester.py b/py/test/plugin/pytest_plugintester.py index 1fc6b938a..46b45fade 100644 --- a/py/test/plugin/pytest_plugintester.py +++ b/py/test/plugin/pytest_plugintester.py @@ -186,7 +186,13 @@ class PytestPluginHooks: """ whole test run starts. """ def pyevent_testrunfinish(self, event): - """ whole test run starts. """ + """ whole test run finishes. """ + + def pyevent_gwmanage_newgateway(self, gateway): + """ execnet gateway manager has instantiated a gateway. + The gateway will have an 'id' attribute that is unique + within the gateway manager context. + """ def pyevent_hostup(self, event): """ Host is up. """ diff --git a/py/test/plugin/pytest_terminal.py b/py/test/plugin/pytest_terminal.py index 8dfc73760..97dae73fe 100644 --- a/py/test/plugin/pytest_terminal.py +++ b/py/test/plugin/pytest_terminal.py @@ -84,6 +84,9 @@ class TerminalReporter: for line in str(event.repr).split("\n"): self.write_line("InternalException: " + line) + def pyevent_gwmanage_newgateway(self, gateway): + self.write_line("%s instantiated gateway from spec %r" %(gateway.id, gateway.spec._spec)) + def pyevent_hostgatewayready(self, event): if self.config.option.verbose: self.write_line("HostGatewayReady: %s" %(event.host,))