From 47ce1fabe86b234246c741d6e4ff562d2a231771 Mon Sep 17 00:00:00 2001 From: Marnik Bercx Date: Wed, 17 Feb 2021 22:50:02 +0100 Subject: [PATCH 1/3] `verdi calcjob gotocomputer`: Add proxy command Currently the `verdi calcjob gocomputer` command does not work in case the connection to the remote computer is via a proxy. Here we add the `ProxyCommand` option to the parameters for the `ssh` command. --- aiida/transports/plugins/ssh.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/aiida/transports/plugins/ssh.py b/aiida/transports/plugins/ssh.py index 5f1a765608..8c91f70827 100644 --- a/aiida/transports/plugins/ssh.py +++ b/aiida/transports/plugins/ssh.py @@ -1340,6 +1340,9 @@ def gotocomputer_command(self, remotedir): if 'key_filename' in self._connect_args and self._connect_args['key_filename']: further_params.append(f"-i {escape_for_bash(self._connect_args['key_filename'])}") + if 'proxy_command' in self._connect_args and self._connect_args['proxy_command']: + further_params.append(f"-o ProxyCommand={escape_for_bash(self._connect_args['proxy_command'])}") + further_params_str = ' '.join(further_params) connect_string = self._gotocomputer_string(remotedir) From 2e485290d34742cf4c2365b0384ef4faf88cf10f Mon Sep 17 00:00:00 2001 From: Marnik Bercx Date: Wed, 17 Feb 2021 23:22:06 +0100 Subject: [PATCH 2/3] Fix test to appease the CodeCov gods --- tests/transports/test_ssh.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/transports/test_ssh.py b/tests/transports/test_ssh.py index 6c8c713622..f4c95cc8fa 100644 --- a/tests/transports/test_ssh.py +++ b/tests/transports/test_ssh.py @@ -59,11 +59,17 @@ def test_no_host_key(self): def test_gotocomputer(): """Test gotocomputer""" - with SshTransport(machine='localhost', timeout=30, use_login_shell=False, key_policy='AutoAddPolicy') as transport: + with SshTransport( + machine='localhost', + timeout=30, + use_login_shell=False, + key_policy='AutoAddPolicy', + proxy_command='ssh -W localhost:22 localhost' + ) as transport: cmd_str = transport.gotocomputer_command('/remote_dir/') expected_str = ( - """ssh -t localhost "if [ -d '/remote_dir/' ] ;""" + """ssh -t localhost -o ProxyCommand="ssh -W localhost:22 localhost" "if [ -d '/remote_dir/' ] ;""" """ then cd '/remote_dir/' ; bash ; else echo ' ** The directory' ; """ """echo ' ** /remote_dir/' ; echo ' ** seems to have been deleted, I logout...' ; fi" """ ) From fd7e641c113a1e6df9065fd55f4b6b092b3be7ac Mon Sep 17 00:00:00 2001 From: Marnik Bercx Date: Fri, 16 Apr 2021 17:42:58 +0200 Subject: [PATCH 3/3] Fix test and issue with `open` method popping connect arg keys --- aiida/transports/plugins/ssh.py | 2 +- tests/transports/test_ssh.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/aiida/transports/plugins/ssh.py b/aiida/transports/plugins/ssh.py index 8c91f70827..ada3650186 100644 --- a/aiida/transports/plugins/ssh.py +++ b/aiida/transports/plugins/ssh.py @@ -426,7 +426,7 @@ def open(self): if self._is_open: raise InvalidOperation('Cannot open the transport twice') # Open a SSHClient - connection_arguments = self._connect_args + connection_arguments = self._connect_args.copy() if 'key_filename' in connection_arguments and not connection_arguments['key_filename']: connection_arguments.pop('key_filename') proxystring = connection_arguments.pop('proxy_command', None) diff --git a/tests/transports/test_ssh.py b/tests/transports/test_ssh.py index f4c95cc8fa..98dcf8a113 100644 --- a/tests/transports/test_ssh.py +++ b/tests/transports/test_ssh.py @@ -64,12 +64,12 @@ def test_gotocomputer(): timeout=30, use_login_shell=False, key_policy='AutoAddPolicy', - proxy_command='ssh -W localhost:22 localhost' + proxy_command='ssh -W localhost:22 localhost', ) as transport: cmd_str = transport.gotocomputer_command('/remote_dir/') expected_str = ( - """ssh -t localhost -o ProxyCommand="ssh -W localhost:22 localhost" "if [ -d '/remote_dir/' ] ;""" + """ssh -t localhost -o ProxyCommand='ssh -W localhost:22 localhost' "if [ -d '/remote_dir/' ] ;""" """ then cd '/remote_dir/' ; bash ; else echo ' ** The directory' ; """ """echo ' ** /remote_dir/' ; echo ' ** seems to have been deleted, I logout...' ; fi" """ )