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

InstalledCode: Fix bug in validate_filepath_executable for SSH #5787

Merged
merged 1 commit into from
Nov 24, 2022
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
6 changes: 3 additions & 3 deletions aiida/orm/nodes/data/code/installed.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ def validate_filepath_executable(self):
try:
with override_log_level(): # Temporarily suppress noisy logging
with self.computer.get_transport() as transport:
file_exists = transport.isfile(self.filepath_executable)
except Exception: # pylint: disable=broad-except
file_exists = transport.isfile(str(self.filepath_executable))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If local returned a str here and ssh a Path, should we then not also aim to harmonize the behavior of the filepath_executable property?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They both returned a pathlib.Path, the problem is that LocalTransport.isfile accepts a pathlib.Path, whereas SshTransport only accepts strings. We should probably update the transport interfaces to add support for pathlib.Path objects.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - yes, that would make sense. Up to you whether you want to do it here or not

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to do the whole interface in one go. Have opened a feature request for it #5797

except Exception as exception: # pylint: disable=broad-except
raise exceptions.ValidationError(
'Could not connect to the configured computer to determine whether the specified executable exists.'
)
) from exception

if not file_exists:
raise exceptions.ValidationError(
Expand Down
22 changes: 18 additions & 4 deletions tests/orm/data/code/test_installed.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# pylint: disable=redefined-outer-name
"""Tests for the :class:`aiida.orm.nodes.data.code.installed.InstalledCode` class."""
import pathlib
import uuid

import pytest

Expand Down Expand Up @@ -89,16 +88,31 @@ def test_filepath_executable(aiida_localhost):
code.filepath_executable = filepath_executable


def test_validate_filepath_executable():
@pytest.fixture
def computer(request, aiida_computer_local, aiida_computer_ssh):
"""Return a computer configured for ``core.local`` and ``core.ssh`` transport."""
if request.param == 'core.local':
return aiida_computer_local(configure=False)

if request.param == 'core.ssh':
return aiida_computer_ssh(configure=False)

raise ValueError(f'unsupported request parameter: {request.param}')


@pytest.mark.parametrize('computer', ('core.local', 'core.ssh'), indirect=True)
def test_validate_filepath_executable(ssh_key, computer):
"""Test the :meth:`aiida.orm.nodes.data.code.installed.InstalledCode.validate_filepath_executable` method."""
filepath_executable = '/usr/bin/not-existing'
computer = Computer(label=str(uuid.uuid4()), transport_type='core.local')
code = InstalledCode(computer=computer, filepath_executable=filepath_executable)

with pytest.raises(ValidationError, match=r'Could not connect to the configured computer.*'):
code.validate_filepath_executable()

computer.configure()
if computer.transport_type == 'core.ssh':
computer.configure(key_filename=str(ssh_key), key_policy='AutoAddPolicy')
else:
computer.configure()

with pytest.raises(ValidationError, match=r'The provided remote absolute path .* does not exist on the computer\.'):
code.validate_filepath_executable()
Expand Down