Commits

hpk  committed f2aa2e9

[svn r63869] * moving execnet events to become api plugin calls.
* defining Execnet hooks in an explicit API

  • Participants
  • Parent commits e6bf525

Comments (0)

Files changed (3)

File execnet/gateway.py

         """ signal initialisation of new gateway. """ 
     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. """
+
+        
         
 # ----------------------------------------------------------
 # Base Gateway (used for both remote and local side) 
         self._io = io
         self._channelfactory = ChannelFactory(self, _startcount)
         self._cleanup.register(self) 
-        try:
+        if _startcount == 1: # only import 'py' on the "client" side 
             from py._com import PluginAPI 
-        except ImportError:
+            self.api = PluginAPI(ExecnetAPI)
+        else:
             self.api = ExecnetAPI()
-        else:
-            self.api = PluginAPI(ExecnetAPI)
 
     def _initreceive(self, requestqueue=False):
         if requestqueue: 

File execnet/gwmanage.py

             if not spec.chdir and not spec.popen:
                 spec.chdir = defaultchdir
             self.specs.append(spec)
+        self.api = py._com.PluginAPI(py.execnet._API)
 
     def trace(self, msg):
         self.notify("trace", "gatewaymanage", msg)
             gw = py.execnet.makegateway(spec)
             self.gateways.append(gw)
             gw.id = "[%s]" % len(self.gateways)
-            self.notify("gwmanage_newgateway", gw, gw._rinfo())
+            self.api.pyexecnet_gwmanage_newgateway(
+                gateway=gw, platinfo=gw._rinfo())
 
     def getgateways(self, remote=True, inplacelocal=True):
         if not self.gateways and self.specs:
                 rsync.add_target_host(gateway, finished=finished)
                 seen[spec] = gateway
         if seen:
-            self.notify("gwmanage_rsyncstart", source=source, gateways=seen.values())
+            self.api.pyexecnet_gwmanage_rsyncstart(
+                source=source, 
+                gateways=seen.values(),
+            )
             rsync.send()
-            self.notify("gwmanage_rsyncfinish", source=source, gateways=seen.values())
+            self.api.pyexecnet_gwmanage_rsyncfinish(
+                source=source, 
+                gateways=seen.values()
+            )
         else:
             self.trace("rsync: nothing to do.")
 

File execnet/testing/test_gwmanage.py

         for spec in GatewayManager(l, defaultchdir="abc").specs:
             assert spec.chdir == "abc"
         
-    def test_popen_makegateway_events(self, eventrecorder):
+    def test_popen_makegateway_events(self, _pytest):
+        rec = _pytest.getcallrecorder(py.execnet._API)
         hm = GatewayManager(["popen"] * 2)
         hm.makegateways()
-        event = eventrecorder.popevent("gwmanage_newgateway")
-        gw, platinfo = event.args[:2]
-        assert gw.id == "[1]" 
-        platinfo.executable = gw._rinfo().executable
-        event = eventrecorder.popevent("gwmanage_newgateway")
-        gw, platinfo = event.args[:2]
-        assert gw.id == "[2]" 
+        call = rec.popcall("pyexecnet_gwmanage_newgateway")
+        assert call.gateway.id == "[1]" 
+        assert call.platinfo.executable == call.gateway._rinfo().executable
+        call = rec.popcall("pyexecnet_gwmanage_newgateway")
+        assert call.gateway.id == "[2]" 
         assert len(hm.gateways) == 2
         hm.exit()
         assert not len(hm.gateways) 
         assert dest.join("dir1", "dir2").check()
         assert dest.join("dir1", "dir2", 'hello').check()
 
-    def test_hostmanage_rsync_same_popen_twice(self, source, dest, eventrecorder):
+    def test_hostmanage_rsync_same_popen_twice(self, source, dest, _pytest):
+        rec = _pytest.getcallrecorder(py.execnet._API)
         hm = GatewayManager(["popen//chdir=%s" %dest] * 2)
         hm.makegateways()
         source.ensure("dir1", "dir2", "hello")
         hm.rsync(source)
-        event = eventrecorder.popevent("gwmanage_rsyncstart") 
-        source2 = event.kwargs['source'] 
-        gws = event.kwargs['gateways'] 
-        assert source2 == source 
-        assert len(gws) == 1
-        assert hm.gateways[0] == gws[0]
-        event = eventrecorder.popevent("gwmanage_rsyncfinish") 
+        call = rec.popcall("pyexecnet_gwmanage_rsyncstart") 
+        assert call.source == source 
+        assert len(call.gateways) == 1
+        assert hm.gateways[0] == call.gateways[0]
+        call = rec.popcall("pyexecnet_gwmanage_rsyncfinish") 
 
     def test_multi_chdir_popen_with_path(self, testdir):
         import os