Пример #1
0
 def __init__(self, config, specs=None):
     self.config = config
     if specs is None:
         specs = self.config.getxspecs()
     self.roots = self.config.getrsyncdirs()
     self.gwmanager = GatewayManager(specs)
     self.nodes = []
     self._nodesready = py.std.threading.Event()
 def test_hostmanage_rsync_same_popen_twice(self, source, dest, eventrecorder):
     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")
Пример #3
0
 def test_popen_makegateway_events(self, _pytest):
     rec = _pytest.gethookrecorder(py.execnet._HookSpecs)
     hm = GatewayManager(["popen"] * 2)
     hm.makegateways()
     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) 
Пример #4
0
 def test_hostmanage_rsync_same_popen_twice(self, mysetup, _pytest):
     source, dest = mysetup.source, mysetup.dest 
     rec = _pytest.gethookrecorder(py.execnet._HookSpecs)
     hm = GatewayManager(["popen//chdir=%s" %dest] * 2)
     hm.makegateways()
     source.ensure("dir1", "dir2", "hello")
     hm.rsync(source)
     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_popen_makegateway_events(self, eventrecorder):
     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]"
     assert len(hm.gateways) == 2
     hm.exit()
     assert not len(hm.gateways)
Пример #6
0
 def __init__(self, config, specs=None):
     self.config = config
     if specs is None:
         specs = self.config.getxspecs()
     self.roots = self.config.getrsyncdirs()
     self.gwmanager = GatewayManager(specs)
     self.nodes = []
     self._nodesready = py.std.threading.Event()
Пример #7
0
 def test_popens_rsync(self, mysetup):
     source = mysetup.source
     hm = GatewayManager(["popen"] * 2)
     hm.makegateways()
     assert len(hm.gateways) == 2
     for gw in hm.gateways:
         gw.remote_exec = None
     l = []
     hm.rsync(source, notify=lambda *args: l.append(args))
     assert not l
     hm.exit()
     assert not len(hm.gateways)
Пример #8
0
    def test_multi_chdir_popen(self, testdir):
        import os
        hm = GatewayManager(["popen"] * 2)
        testdir.tmpdir.chdir()
        hellopath = testdir.tmpdir.mkdir("hello")
        hm.makegateways()
        hm.multi_chdir("hello", inplacelocal=False)
        l = hm.multi_exec(
            "import os ; channel.send(os.getcwd())").receive_each()
        assert len(l) == 2
        curwd = os.path.realpath(os.getcwd())
        assert l == [curwd] * 2

        hm.multi_chdir("hello")
        l = hm.multi_exec(
            "import os ; channel.send(os.getcwd())").receive_each()
        assert len(l) == 2
        assert l[0] == l[1]
        assert l[0].startswith(curwd)
        assert l[0].endswith("hello")
Пример #9
0
 def test_rsync_popen_with_path(self, mysetup):
     source, dest = mysetup.source, mysetup.dest
     hm = GatewayManager(["popen//chdir=%s" % dest] * 1)
     hm.makegateways()
     source.ensure("dir1", "dir2", "hello")
     l = []
     hm.rsync(source, notify=lambda *args: l.append(args))
     assert len(l) == 1
     assert l[0] == ("rsyncrootready", hm.gateways[0].spec, source)
     hm.exit()
     dest = dest.join(source.basename)
     assert dest.join("dir1").check()
     assert dest.join("dir1", "dir2").check()
     assert dest.join("dir1", "dir2", 'hello').check()
Пример #10
0
    def test_multi_chdir_popen(self, testdir):
        import os
        hm = GatewayManager(["popen"] * 2)
        testdir.tmpdir.chdir()
        hellopath = testdir.tmpdir.mkdir("hello")
        hm.makegateways()
        hm.multi_chdir("hello", inplacelocal=False)
        l = hm.multi_exec("import os ; channel.send(os.getcwd())").receive_each()
        assert len(l) == 2
        curwd = os.path.realpath(os.getcwd())
        assert l == [curwd] * 2

        hm.multi_chdir("hello")
        l = hm.multi_exec("import os ; channel.send(os.getcwd())").receive_each()
        assert len(l) == 2
        assert l[0] == l[1]
        assert l[0].startswith(curwd)
        assert l[0].endswith("hello")
Пример #11
0
 def test_popens_rsync(self, source):
     hm = GatewayManager(["popen"] * 2)
     hm.makegateways()
     assert len(hm.gateways) == 2
     for gw in hm.gateways:
         gw.remote_exec = None
     l = []
     hm.rsync(source, notify=lambda *args: l.append(args))
     assert not l
     hm.exit()
     assert not len(hm.gateways)
Пример #12
0
 def test_rsync_popen_with_path(self, source, dest):
     hm = GatewayManager(["popen//chdir=%s" % dest] * 1)
     hm.makegateways()
     source.ensure("dir1", "dir2", "hello")
     l = []
     hm.rsync(source, notify=lambda *args: l.append(args))
     assert len(l) == 1
     assert l[0] == ("rsyncrootready", hm.gateways[0].spec, source)
     hm.exit()
     dest = dest.join(source.basename)
     assert dest.join("dir1").check()
     assert dest.join("dir1", "dir2").check()
     assert dest.join("dir1", "dir2", "hello").check()
Пример #13
0
 def test_popen_makegateway_events(self, _pytest):
     rec = _pytest.gethookrecorder(py.execnet._HookSpecs)
     hm = GatewayManager(["popen"] * 2)
     hm.makegateways()
     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)
Пример #14
0
 def test_hostmanage_rsync_same_popen_twice(self, mysetup, _pytest):
     source, dest = mysetup.source, mysetup.dest
     rec = _pytest.gethookrecorder(py.execnet._HookSpecs)
     hm = GatewayManager(["popen//chdir=%s" % dest] * 2)
     hm.makegateways()
     source.ensure("dir1", "dir2", "hello")
     hm.rsync(source)
     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")
Пример #15
0
 def test_multi_chdir_popen_with_path(self, testdir):
     import os
     hm = GatewayManager(["popen//chdir=hello"] * 2)
     testdir.tmpdir.chdir()
     hellopath = testdir.tmpdir.mkdir("hello").realpath()
     hm.makegateways()
     l = hm.multi_exec(
         "import os ; channel.send(os.getcwd())").receive_each()
     paths = [x[1] for x in l]
     assert l == [str(hellopath)] * 2
     py.test.raises(hm.RemoteError,
                    'hm.multi_chdir("world", inplacelocal=False)')
     worldpath = hellopath.mkdir("world")
     hm.multi_chdir("world", inplacelocal=False)
     l = hm.multi_exec(
         "import os ; channel.send(os.getcwd())").receive_each()
     assert len(l) == 2
     assert l[0] == l[1]
     curwd = os.getcwd()
     assert l[0].startswith(curwd)
     assert l[0].endswith("world")
Пример #16
0
 def test_multi_chdir_popen_with_path(self, testdir):
     import os
     hm = GatewayManager(["popen//chdir=hello"] * 2)
     testdir.tmpdir.chdir()
     hellopath = testdir.tmpdir.mkdir("hello").realpath()
     hm.makegateways()
     l = hm.multi_exec("import os ; channel.send(os.getcwd())").receive_each()
     paths = [x[1] for x in l]
     assert l == [str(hellopath)] * 2
     py.test.raises(hm.RemoteError, 'hm.multi_chdir("world", inplacelocal=False)')
     worldpath = hellopath.mkdir("world")
     hm.multi_chdir("world", inplacelocal=False)
     l = hm.multi_exec("import os ; channel.send(os.getcwd())").receive_each()
     assert len(l) == 2
     assert l[0] == l[1]
     curwd = os.getcwd()
     assert l[0].startswith(curwd)
     assert l[0].endswith("world")
Пример #17
0
 def test_default_chdir(self):
     l = ["ssh=noco", "socket=xyz"]
     for spec in GatewayManager(l).specs:
         assert spec.chdir == "pyexecnetcache"
     for spec in GatewayManager(l, defaultchdir="abc").specs:
         assert spec.chdir == "abc"
Пример #18
0
class NodeManager(object):
    def __init__(self, config, specs=None):
        self.config = config
        if specs is None:
            specs = self.config.getxspecs()
        self.roots = self.config.getrsyncdirs()
        self.gwmanager = GatewayManager(specs)
        self.nodes = []
        self._nodesready = py.std.threading.Event()

    def trace(self, msg):
        self.config.hook.pytest_trace(category="nodemanage", msg=msg)

    def config_getignores(self):
        return self.config.getconftest_pathlist("rsyncignore")

    def rsync_roots(self):
        """ make sure that all remote gateways
            have the same set of roots in their
            current directory. 
        """
        self.makegateways()
        options = {"ignores": self.config_getignores(), "verbose": self.config.option.verbose}
        if self.roots:
            # send each rsync root
            for root in self.roots:
                self.gwmanager.rsync(root, **options)
        else:
            XXX  # do we want to care for situations without explicit rsyncdirs?
            # we transfer our topdir as the root
            self.gwmanager.rsync(self.config.topdir, **options)
            # and cd into it
            self.gwmanager.multi_chdir(self.config.topdir.basename, inplacelocal=False)

    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)
        self.trace("making gateways")
        old = self.config.topdir.chdir()
        try:
            self.gwmanager.makegateways()
        finally:
            old.chdir()

    def setup_nodes(self, putevent):
        self.rsync_roots()
        self.trace("setting up nodes")
        for gateway in self.gwmanager.gateways:
            node = TXNode(gateway, self.config, putevent, slaveready=self._slaveready)
            gateway.node = node  # to keep node alive
            self.trace("started node %r" % node)

    def _slaveready(self, node):
        # assert node.gateway == node.gateway
        # assert node.gateway.node == node
        self.nodes.append(node)
        self.trace("%s slave node ready %r" % (node.gateway.id, node))
        if len(self.nodes) == len(self.gwmanager.gateways):
            self._nodesready.set()

    def wait_nodesready(self, timeout=None):
        self._nodesready.wait(timeout)
        if not self._nodesready.isSet():
            raise IOError("nodes did not get ready for %r secs" % timeout)

    def teardown_nodes(self):
        # XXX do teardown nodes?
        self.gwmanager.exit()
Пример #19
0
class NodeManager(object):
    def __init__(self, config, specs=None):
        self.config = config
        if specs is None:
            specs = self.config.getxspecs()
        self.roots = self.config.getrsyncdirs()
        self.gwmanager = GatewayManager(specs)
        self.nodes = []
        self._nodesready = py.std.threading.Event()

    def trace(self, msg):
        self.config.hook.pytest_trace(category="nodemanage", msg=msg)

    def config_getignores(self):
        return self.config.getconftest_pathlist("rsyncignore")

    def rsync_roots(self):
        """ make sure that all remote gateways
            have the same set of roots in their
            current directory. 
        """
        self.makegateways()
        options = {
            'ignores': self.config_getignores(),
            'verbose': self.config.option.verbose,
        }
        if self.roots:
            # send each rsync root
            for root in self.roots:
                self.gwmanager.rsync(root, **options)
        else:
            XXX  # do we want to care for situations without explicit rsyncdirs?
            # we transfer our topdir as the root
            self.gwmanager.rsync(self.config.topdir, **options)
            # and cd into it
            self.gwmanager.multi_chdir(self.config.topdir.basename,
                                       inplacelocal=False)

    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)
        self.trace("making gateways")
        old = self.config.topdir.chdir()
        try:
            self.gwmanager.makegateways()
        finally:
            old.chdir()

    def setup_nodes(self, putevent):
        self.rsync_roots()
        self.trace("setting up nodes")
        for gateway in self.gwmanager.gateways:
            node = TXNode(gateway,
                          self.config,
                          putevent,
                          slaveready=self._slaveready)
            gateway.node = node  # to keep node alive
            self.trace("started node %r" % node)

    def _slaveready(self, node):
        #assert node.gateway == node.gateway
        #assert node.gateway.node == node
        self.nodes.append(node)
        self.trace("%s slave node ready %r" % (node.gateway.id, node))
        if len(self.nodes) == len(self.gwmanager.gateways):
            self._nodesready.set()

    def wait_nodesready(self, timeout=None):
        self._nodesready.wait(timeout)
        if not self._nodesready.isSet():
            raise IOError("nodes did not get ready for %r secs" % timeout)

    def teardown_nodes(self):
        # XXX do teardown nodes?
        self.gwmanager.exit()
Пример #20
0
 def test_popen_no_default_chdir(self):
     gm = GatewayManager(["popen"])
     assert gm.specs[0].chdir is None