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

Engine: Fix bug in upload calculation for PortableCode with SSH #6519

Merged
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
8 changes: 4 additions & 4 deletions src/aiida/engine/daemon/execmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ def upload_calculation(
# Note: this will possibly overwrite files
for root, dirnames, filenames in code.base.repository.walk():
# mkdir of root
transport.makedirs(root, ignore_existing=True)
transport.makedirs(str(root), ignore_existing=True)

# remotely mkdir first
for dirname in dirnames:
transport.makedirs((root / dirname), ignore_existing=True)
transport.makedirs(str(root / dirname), ignore_existing=True)

# Note, once #2579 is implemented, use the `node.open` method instead of the named temporary file in
# combination with the new `Transport.put_object_from_filelike`
Expand All @@ -192,8 +192,8 @@ def upload_calculation(
content = code.base.repository.get_object_content((pathlib.Path(root) / filename), mode='rb')
handle.write(content)
handle.flush()
transport.put(handle.name, (root / filename))
transport.chmod(code.filepath_executable, 0o755) # rwxr-xr-x
transport.put(handle.name, str(root / filename))
transport.chmod(str(code.filepath_executable), 0o755) # rwxr-xr-x

# local_copy_list is a list of tuples, each with (uuid, dest_path, rel_path)
# NOTE: validation of these lists are done inside calculation.presubmit()
Expand Down
31 changes: 30 additions & 1 deletion tests/engine/daemon/test_execmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from aiida.common.datastructures import CalcInfo, CodeInfo, FileCopyOperation
from aiida.common.folders import SandboxFolder
from aiida.engine.daemon import execmanager
from aiida.orm import CalcJobNode, FolderData, RemoteData, SinglefileData
from aiida.orm import CalcJobNode, FolderData, PortableCode, RemoteData, SinglefileData
from aiida.plugins import entry_point
from aiida.transports.plugins.local import LocalTransport

Expand Down Expand Up @@ -585,3 +585,32 @@ def test_upload_combinations(
filepath_workdir = pathlib.Path(node.get_remote_workdir())

assert serialize_file_hierarchy(filepath_workdir, read_bytes=False) == expected_hierarchy


def test_upload_calculation_portable_code(fixture_sandbox, node_and_calc_info, tmp_path):
"""Test ``upload_calculation`` with a ``PortableCode`` for different transports.

Regression test for https://github.com/aiidateam/aiida-core/issues/6518
"""
subdir = tmp_path / 'sub'
subdir.mkdir()
(subdir / 'some-file').write_bytes(b'sub dummy')
(tmp_path / 'bash').write_bytes(b'bash implementation')

code = PortableCode(
filepath_executable='bash',
filepath_files=tmp_path,
).store()

node, calc_info = node_and_calc_info
code_info = CodeInfo()
code_info.code_uuid = code.uuid
calc_info.codes_info = [code_info]

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