Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

verdi calcjob gotocomputer: Add proxy command #4761

Merged
merged 3 commits into from
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion aiida/transports/plugins/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions tests/transports/test_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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" """
)
Expand Down