1. Ronny Pfannschmidt
  2. execnet-patches

Source

execnet-patches / ssh-args

# HG changeset patch
# Parent de2f72d8cf656e56409cad827dee9a5b81e4cb76
extend and test ssh io creation

this adds tests for all kinds of specs and adds the spec format
from http://code.activestate.com/recipes/577545-monkey-patch-execnet-with-more-ssh-settings-port-i/

diff --git a/execnet/gateway_io.py b/execnet/gateway_io.py
--- a/execnet/gateway_io.py
+++ b/execnet/gateway_io.py
@@ -78,6 +78,12 @@ def ssh_args(spec):
     args = ['ssh', '-C' ]
     if spec.ssh_config is not None:
         args.extend(['-F', str(spec.ssh_config)])
+    if spec.ssh_port is not None:
+        args.extend(['-p', str(spec.ssh_port)])
+    if spec.ssh_identity is not None:
+        args.extend(['-i', str(spec.ssh_identity)])
+    if spec.ssh_batchmode:
+        args.extend(["-o", "BatchMode yes"])
     remotecmd = '%s -c "%s"' %(remotepython, popen_bootstrapline)
     args.extend([spec.ssh, remotecmd])
     return args
diff --git a/testing/test_gateway_io.py b/testing/test_gateway_io.py
new file mode 100644
--- /dev/null
+++ b/testing/test_gateway_io.py
@@ -0,0 +1,28 @@
+import shlex
+import pytest
+from execnet.gateway_io import ssh_args
+from execnet import XSpec
+
+
+ssh_cases = [
+    ('id=normal//ssh=host', 'python', 'ssh -C host'),
+    ('id=remotepython//ssh=host//python=foo', 'foo', 'ssh -C host'),
+    ('id=config//ssh=host//ssh_config=foo', 'python', 'ssh -C -F foo host'),
+    ('id=port//ssh=host//ssh_port=35000', 'python', 'ssh -C -p 35000 host'),
+    ('id=identity//ssh=host//ssh_identity=fun', 'python', 'ssh -C -i fun host'),
+    ('id=batchmode//ssh=host//ssh_batchmode', 'python', 'ssh -C -o "BatchMode yes" host'),
+]
+
+ssh_ids = [x[0] for x in ssh_cases]
+
+@pytest.mark.parametrize(('spec', 'remotepython','command'), 
+                         ssh_cases, ids=ssh_ids)
+def test_ssh_args_for_ssh(spec, remotepython, command):
+    spec = XSpec(spec)
+    command = shlex.split(command)
+
+    result = ssh_args(spec)
+    remotecommand = result.pop()
+
+    assert result == command
+    assert remotecommand.split('-c')[0].strip() == remotepython