Beispiel #1
0
 def test_getrsyncdirs(self, pytester: pytest.Pytester) -> None:
     config = pytester.parseconfigure("--rsyncdir=" + str(pytester.path))
     nm = NodeManager(config, specs=[execnet.XSpec("popen")])
     assert not nm._getrsyncdirs()
     nm = NodeManager(config, specs=[execnet.XSpec("popen//chdir=qwe")])
     assert nm.roots
     assert pytester.path in nm.roots
Beispiel #2
0
 def test_getrsyncdirs(self, testdir):
     config = testdir.parseconfigure('--rsyncdir=' + str(testdir.tmpdir))
     nm = NodeManager(config, specs=[execnet.XSpec("popen")])
     assert not nm._getrsyncdirs()
     nm = NodeManager(config, specs=[execnet.XSpec("popen//chdir=qwe")])
     assert nm.roots
     assert testdir.tmpdir in nm.roots
 def _connect(self):
     if self._cache_key not in ploy_ansible.RPC_CACHE:
         ctrl = self._play_context._ploy_ctrl
         instance = ctrl.instances[self.host]
         if hasattr(instance, '_status'):
             if instance._status() != 'running':
                 raise errors.AnsibleError("Instance '%s' unavailable." %
                                           instance.config_id)
         try:
             ssh_info = instance.init_ssh_key(user=self.user)
         except paramiko.SSHException as e:
             raise errors.AnsibleError(
                 "Couldn't validate fingerprint for '%s': %s" %
                 (instance.config_id, e))
         spec = execnet.XSpec('ssh')
         ssh_args = instance.ssh_args_from_info(ssh_info)
         if display.verbosity > 3:
             ssh_args += ["-vvv"]
         spec.ssh = SSHArgs(ssh_args)
         spec.python = instance.config.get('ansible_python_interpreter',
                                           'python')
         gw = execnet.makegateway(spec)
         try:
             channel = gw.remote_exec(ploy_ansible.remote)
         except IOError as e:
             raise errors.AnsibleError(
                 "Couldn't open execnet channel for '%s': %s" %
                 (instance.config_id, e))
         ploy_ansible.RPC_CACHE[self._cache_key] = RPCWrapper(channel)
     self.rpc = ploy_ansible.RPC_CACHE[self._cache_key]
     return self
Beispiel #4
0
def PopenGateway(python=None):
    """ instantiate a gateway to a subprocess
        started with the given 'python' executable.
    """
    APIWARN("1.0.0b4", "use makegateway('popen')")
    spec = execnet.XSpec("popen")
    spec.python = python
    return execnet.default_group.makegateway(spec)
Beispiel #5
0
def SshGateway(sshaddress, remotepython=None, ssh_config=None):
    """ instantiate a remote ssh process with the
        given 'sshaddress' and remotepython version.
        you may specify an ssh_config file.
    """
    APIWARN("1.0.0b4", "use makegateway('ssh=host')")
    spec = execnet.XSpec("ssh=%s" % sshaddress)
    spec.python = remotepython
    spec.ssh_config = ssh_config
    return execnet.default_group.makegateway(spec)
Beispiel #6
0
 def __init__(self, specs, hook, defaultchdir="pyexecnetcache"):
     self.specs = []
     self.hook = hook
     self.group = execnet.Group()
     for spec in specs:
         if not isinstance(spec, execnet.XSpec):
             spec = execnet.XSpec(spec)
         if not spec.chdir and not spec.popen:
             spec.chdir = defaultchdir
         self.specs.append(spec)
Beispiel #7
0
 def _getxspecs(self):
     appliances = self.config.option.appliances
     numprocesses = len(appliances)
     gateway_spec = 'popen//dont_write_bytecode'
     if numprocesses > 1:
         return [execnet.XSpec(spec) for spec in [gateway_spec] * numprocesses]
     else:
         if appliances:
             self.log.warning('')
         return []
Beispiel #8
0
def SocketGateway(host, port):
    """ This Gateway provides interaction with a remote process
        by connecting to a specified socket.  On the remote
        side you need to manually start a small script
        (py/execnet/script/socketserver.py) that accepts
        SocketGateway connections or use the experimental
        new_remote() method on existing gateways.
    """
    APIWARN("1.0.0b4", "use makegateway('socket=host:port')")
    spec = execnet.XSpec("socket={}:{}".format(host, port))
    return execnet.default_group.makegateway(spec)
Beispiel #9
0
def makeportgateway(self, spec):
    spec = execnet.XSpec(spec)
    self.allocate_id(spec)
    gw = SshPortGateway(spec.ssh,
                        remotepython=spec.python,
                        ssh_config=spec.ssh_config,
                        id=spec.id,
                        ssh_port=spec.ssh_port,
                        ssh_identity=spec.ssh_identity,
                        ssh_batchmode=spec.ssh_batchmode)
    gw.spec = spec
    self._register(gw)
    # TODO add spec.{chdir,nice,env}
    return gw
    def test_popen_makegateway_events(self, config, hookrecorder, workercontroller):
        hm = NodeManager(config, ["popen"] * 2)
        hm.setup_nodes(None)
        call = hookrecorder.popcall("pytest_xdist_setupnodes")
        assert len(call.specs) == 2

        call = hookrecorder.popcall("pytest_xdist_newgateway")
        assert call.gateway.spec == execnet.XSpec("popen")
        assert call.gateway.id == "gw0"
        call = hookrecorder.popcall("pytest_xdist_newgateway")
        assert call.gateway.id == "gw1"
        assert len(hm.group) == 2
        hm.teardown_nodes()
        assert not len(hm.group)
 def _getxspecs(self):
     xspeclist = []
     for xspec in self.config.getvalue("tx"):
         i = xspec.find("*")
         try:
             num = int(xspec[:i])
         except ValueError:
             xspeclist.append(xspec)
         else:
             xspeclist.extend([xspec[i + 1:]] * num)
     if not xspeclist:
         raise pytest.UsageError(
             "MISSING test execution (tx) nodes: please specify --tx")
     return [execnet.XSpec(x) for x in xspeclist]
Beispiel #12
0
 def __init__(self, config, specs=None, defaultchdir="pyexecnetcache"):
     self.config = config
     self._nodesready = py.std.threading.Event()
     self.trace = self.config.trace.get("nodemanager")
     self.group = execnet.Group()
     if specs is None:
         specs = self._getxspecs()
     self.specs = []
     for spec in specs:
         if not isinstance(spec, execnet.XSpec):
             spec = execnet.XSpec(spec)
         if not spec.chdir and not spec.popen:
             spec.chdir = defaultchdir
         self.group.allocate_id(spec)
         self.specs.append(spec)
     self.roots = self._getrsyncdirs()
Beispiel #13
0
 def test_getrsyncdirs_with_conftest(self, testdir):
     p = py.path.local()
     for bn in 'x y z'.split():
         p.mkdir(bn)
     testdir.makeini("""
         [pytest]
         rsyncdirs= x
     """)
     config = testdir.parseconfigure(testdir.tmpdir, '--rsyncdir=y',
                                     '--rsyncdir=z')
     nm = NodeManager(config, specs=[execnet.XSpec("popen//chdir=xyz")])
     roots = nm._getrsyncdirs()
     # assert len(roots) == 3 + 1 # pylib
     assert py.path.local('y') in roots
     assert py.path.local('z') in roots
     assert testdir.tmpdir.join('x') in roots
Beispiel #14
0
 def test_getrsyncdirs_with_conftest(self,
                                     pytester: pytest.Pytester) -> None:
     p = Path.cwd()
     for bn in ("x", "y", "z"):
         p.joinpath(bn).mkdir()
     pytester.makeini("""
         [pytest]
         rsyncdirs= x
     """)
     config = pytester.parseconfigure(pytester.path, "--rsyncdir=y",
                                      "--rsyncdir=z")
     nm = NodeManager(config, specs=[execnet.XSpec("popen//chdir=xyz")])
     roots = nm._getrsyncdirs()
     # assert len(roots) == 3 + 1 # pylib
     assert Path("y").resolve() in roots
     assert Path("z").resolve() in roots
     assert pytester.path.joinpath("x") in roots
Beispiel #15
0
 def __init__(self, config, specs=None, defaultchdir="pyexecnetcache"):
     self.config = config
     self.trace = self.config.trace.get("nodemanager")
     self.testrunuid = self.config.getoption("testrunuid")
     if self.testrunuid is None:
         self.testrunuid = uuid.uuid4().hex
     self.group = execnet.Group()
     if specs is None:
         specs = self._getxspecs()
     self.specs = []
     for spec in specs:
         if not isinstance(spec, execnet.XSpec):
             spec = execnet.XSpec(spec)
         if not spec.chdir and not spec.popen:
             spec.chdir = defaultchdir
         self.group.allocate_id(spec)
         self.specs.append(spec)
     self.roots = self._getrsyncdirs()
     self.rsyncoptions = self._getrsyncoptions()
     self._rsynced_specs = set()
Beispiel #16
0
    def execnet_gateways(self):
        # TODO: Eventlet hangs on Mac OS X with popen.
        # execnet.set_execmodel("eventlet", "thread")
        gw = self.gateway

        if not gw:
            for _ in range(self.job_num):
                yield execnet.makegateway('' if 'FOWLER_PYTHON' not in
                                          os.environ else 'popen//python={}'.
                                          format(os.environ['FOWLER_PYTHON']))

        for gateway_spec in gw:
            if '*' in gateway_spec:
                num, spec = gateway_spec.split('*')
                num = int(num)

                group = execnet.Group()
                group.defaultspec = spec

                xspec = execnet.XSpec(spec)
                master_spec = ('ssh={xspec.via}//'
                               'id={xspec.via}//'
                               'python={xspec.python}'
                               ''.format(xspec=xspec))

                logger.debug(
                    'Connecting to master %s to create %s gateways.',
                    master_spec,
                    num,
                )
                group.makegateway(master_spec)

                for _ in range(num):
                    yield group.makegateway()
            else:
                yield execnet.makegateway()
Beispiel #17
0
 class gw2:
     id = "X2"
     spec = execnet.XSpec("popen")
Beispiel #18
0
 def test_getrsyncignore(self, testdir):
     config = testdir.parseconfigure('--rsyncignore=fo*')
     nm = NodeManager(config, specs=[execnet.XSpec("popen//chdir=qwe")])
     assert 'fo*' in nm.rsyncoptions['ignores']
Beispiel #19
0
def getgspecs(config) -> List[execnet.XSpec]:
    return [execnet.XSpec(spec) for spec in config.getvalueorskip("gspecs")]
Beispiel #20
0
 def test_getrsyncignore(self, pytester: pytest.Pytester) -> None:
     config = pytester.parseconfigure("--rsyncignore=fo*")
     nm = NodeManager(config, specs=[execnet.XSpec("popen//chdir=qwe")])
     assert "fo*" in nm.rsyncoptions["ignores"]
Beispiel #21
0
def getgspecs(config=None):
    if config is None:
        config = py.test.config
    return [execnet.XSpec(spec) for spec in config.getvalueorskip("gspecs")]
Beispiel #22
0
def test_popen_args(spec, expected_args):
    expected_args = expected_args + [
        '-u', '-c', gateway_io.popen_bootstrapline]
    args = gateway_io.popen_args(execnet.XSpec(spec))
    assert args == expected_args
Beispiel #23
0
 def _getxspecs(self):
     return [execnet.XSpec(x) for x in parse_spec_config(self.config)]
Beispiel #24
0
 class gw1:
     id = "X1"
     spec = execnet.XSpec("popen")