Skip to content

Commit

Permalink
update asyncssh dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
khsrali committed Dec 13, 2024
1 parent cf01ac0 commit 6627b21
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies:
- python~=3.9
- alembic~=1.2
- archive-path~=0.4.2
- asyncssh
- asyncssh~=2.19.0
- circus~=0.18.0
- click-spinner~=0.1.8
- click~=8.1
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ classifiers = [
dependencies = [
'alembic~=1.2',
'archive-path~=0.4.2',
"asyncssh",
"asyncssh~=2.19.0",
'circus~=0.18.0',
'click-spinner~=0.1.8',
'click~=8.1',
Expand Down
23 changes: 16 additions & 7 deletions src/aiida/transports/plugins/ssh_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ async def attempt_connection():
class AsyncSshTransport(AsyncTransport):
"""Transport plugin via SSH, asynchronously."""

_DEFAULT_max_io_allowed = 8

# note, I intentionally wanted to keep connection parameters as simple as possible.
_valid_auth_options = [
(
Expand All @@ -84,7 +86,7 @@ class AsyncSshTransport(AsyncTransport):
'max_io_allowed',
{
'type': int,
'default': 8,
'default': _DEFAULT_max_io_allowed,
'prompt': 'Maximum number of concurrent I/O operations.',
'help': 'Depends on various factors, such as your network bandwidth, the server load, etc.'
' (An experimental number)',
Expand Down Expand Up @@ -117,23 +119,30 @@ def _get_machine_suggestion_string(cls, computer):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.machine = kwargs.pop('machine_or_host')
self._max_io_allowed = kwargs.pop('max_io_allowed')
# the machine is passed as `machine=computer.hostname` in the codebase
# 'machine' is immutable.
# 'machine_or_host' is mutable, so it can be changed via command:
# 'verdi computer configure core.ssh_async <LABEL>'.
# by default, 'machine_or_host' is set to 'machine' in the __init__ method, if not provided.
# NOTE: to guarantee a connection,
# a computer with core.ssh_async transport plugin should be configured before any instantiation.
self.machine = kwargs.pop('machine_or_host', kwargs.pop('machine'))
self._max_io_allowed = kwargs.pop('max_io_allowed', self._DEFAULT_max_io_allowed)
self.script_before = kwargs.pop('script_before', 'None')

self._councurrent_io = 0
self._concurrent_io = 0

@property
def max_io_allowed(self):
return self._max_io_allowed

async def _lock(self, sleep_time=0.5):
while self._councurrent_io >= self.max_io_allowed:
while self._concurrent_io >= self.max_io_allowed:
await asyncio.sleep(sleep_time)

Check warning on line 141 in src/aiida/transports/plugins/ssh_async.py

View check run for this annotation

Codecov / codecov/patch

src/aiida/transports/plugins/ssh_async.py#L141

Added line #L141 was not covered by tests
self._councurrent_io += 1
self._concurrent_io += 1

async def _unlock(self):
self._councurrent_io -= 1
self._concurrent_io -= 1

async def open_async(self):
"""Open the transport.
Expand Down
10 changes: 9 additions & 1 deletion tests/cmdline/commands/test_computer.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,14 @@ def test_computer_ssh_async(run_cli_command, aiida_computer):

# It is important that 'ssh localhost' is functional in your test environment.
# It should connect without asking for a password.
options = ['core.ssh_async', computer.uuid, '--non-interactive', '--safe-interval', '0', '--machine', 'localhost']
options = [
'core.ssh_async',
computer.uuid,
'--non-interactive',
'--safe-interval',
'0',
'--machine-or-host',
'localhost',
]
run_cli_command(computer_configure, options, use_subprocess=False)
assert computer.is_configured
4 changes: 3 additions & 1 deletion tests/transports/test_all_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ def custom_transport(request, tmp_path_factory, monkeypatch) -> Union['Transport
if not filepath_config.exists():
filepath_config.write_text('Host localhost')
elif request.param == 'core.ssh_async':
kwargs = {'machine_or_host': 'localhost', 'max_io_allowed': 8}
kwargs = {
'machine': 'localhost',
}
else:
kwargs = {}

Expand Down

0 comments on commit 6627b21

Please sign in to comment.