Skip to content

Commit

Permalink
CalcJob: Add support for nested targets in remote_symlink_list (#…
Browse files Browse the repository at this point in the history
…5974)

It is now possible to specify a target in the `remote_symlink_list` that
contains nested directories that do not necessarily exist. The
`upload_calculation` will automatically create them before creating the
symlink.
  • Loading branch information
sphuber committed Sep 7, 2023
1 parent d6093d1 commit 0ec650c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions aiida/engine/daemon/execmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ def upload_calculation(
f'[submission of calculation {node.pk}] copying {dest_rel_path} remotely, '
f'directly on the machine {computer.label}'
)
remote_dirname = pathlib.Path(dest_rel_path).parent
try:
transport.makedirs(remote_dirname, ignore_existing=True)
transport.symlink(remote_abs_path, dest_rel_path)
except (IOError, OSError):
logger.warning(
Expand Down
23 changes: 23 additions & 0 deletions tests/engine/daemon/test_execmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,26 @@ def test_upload_local_copy_list_files_folders(fixture_sandbox, node_and_calc_inf
expected_hierarchy['files']['file_x'] = 'content_x'
expected_hierarchy['files']['file_y'] = 'content_y'
assert expected_hierarchy == written_hierarchy


def test_upload_remote_symlink_list(fixture_sandbox, node_and_calc_info, file_hierarchy, tmp_path):
"""Test the ``remote_symlink_list`` functionality in ``upload_calculation``.
Nested subdirectories in the target should be automatically created.
"""
create_file_hierarchy(file_hierarchy, tmp_path)
node, calc_info = node_and_calc_info

calc_info.remote_symlink_list = [
(node.computer.uuid, str(tmp_path / 'path' / 'sub'), 'path/sub'),
(node.computer.uuid, str(tmp_path / 'file_a.txt'), 'file_a.txt'),
]

with LocalTransport() as transport:
execmanager.upload_calculation(node, transport, calc_info, fixture_sandbox)

filepath_workdir = pathlib.Path(node.get_remote_workdir())
assert (filepath_workdir / 'file_a.txt').is_symlink()
assert (filepath_workdir / 'path' / 'sub').is_symlink()
assert (filepath_workdir / 'file_a.txt').read_text() == 'file_a'
assert (filepath_workdir / 'path' / 'sub' / 'file_c.txt').read_text() == 'file_c'

0 comments on commit 0ec650c

Please sign in to comment.