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

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Nov 21, 2022

Fixes #5795

If the code was attached to a Computer with core.ssh transport, the
validate_filepath_executable would always return that the computer
could not be connected to. This is because the actual exception that was
caught does not come from Computer.get_transport but is a TypeError
raised by transport.isfile since it receives a pathlib.Path were it
expects a str.

The problem went undetected since it only tested against a computer with
core.local transport. A new test is added to also test against a
computer with core.ssh transport`.

@sphuber
Copy link
Contributor Author

sphuber commented Nov 21, 2022

This bug was discovered in today's hackathon. It only occurs for a computer with core.ssh transport. To make the test possible, a new fixture was necessary, which is proposed in #5786 so that needs to be reviewed and merged first.

@sphuber sphuber added the pr/blocked PR is blocked by another PR that should be merged first label Nov 21, 2022
@sphuber sphuber force-pushed the fix/validate-filepath-executable branch from 8ed6f71 to 0186c3f Compare November 24, 2022 08:50
@sphuber sphuber removed the pr/blocked PR is blocked by another PR that should be merged first label Nov 24, 2022
@sphuber sphuber requested a review from ltalirz November 24, 2022 08:53
@sphuber sphuber force-pushed the fix/validate-filepath-executable branch 2 times, most recently from 511ecf7 to 4275455 Compare November 24, 2022 09:29
Copy link
Member

@ltalirz ltalirz left a comment

Choose a reason for hiding this comment

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

thanks @sphuber ! just one question

@@ -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

If the code was attached to a `Computer` with `core.ssh` transport, the
`validate_filepath_executable` would always return that the computer
could not be connected to. This is because the actual exception that was
caught does not come from `Computer.get_transport` but is a `TypeError`
raised by `transport.isfile` since it receives a `pathlib.Path` were it
expects a `str`.

The problem went undetected since it only tested against a computer with
`core.local` transport. A new test is added to also test against a
computer with `core.ssh` transport`.
@sphuber sphuber force-pushed the fix/validate-filepath-executable branch from 4275455 to 6af9422 Compare November 24, 2022 11:17
@sphuber sphuber requested a review from ltalirz November 24, 2022 11:17
@sphuber sphuber merged commit 3cc681c into aiidateam:main Nov 24, 2022
@sphuber sphuber deleted the fix/validate-filepath-executable branch November 24, 2022 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

verdi code test failing
2 participants