mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 03:11:24 -07:00
the smart transport is broken by ssh retry code
1fe67f9
introduced retries to the ssh connection put file and fetch
file. Unfortunately, that change broke the smart transport because it
started raising exceptions instead of returning from _run(). This
breakage is documented in #23711.
An attempt to fix it was made at #23717 but the first attempt was
objected to as needing to touch too much code. The second attmept was
objected to as smart was forced to encapsulate retries (thus retrying
a sftp "rety" times before trying scp "retry" times and then finally
moving onto piped). This third attempt has retries encapsulate smart.
So each sub-transport is tried once and if all three fail, another retry
attempt is made which tries each of the three again.
Fixes #23711
Fixes #23717
This commit is contained in:
parent
ab81c6c0f3
commit
3edac559d3
2 changed files with 33 additions and 27 deletions
|
@ -491,8 +491,7 @@ class Connection(ConnectionBase):
|
|||
|
||||
return b''.join(output), remainder
|
||||
|
||||
@_ssh_retry
|
||||
def _run(self, cmd, in_data, sudoable=True, checkrc=True):
|
||||
def _bare_run(self, cmd, in_data, sudoable=True, checkrc=True):
|
||||
'''
|
||||
Starts the command and communicates with it until it ends.
|
||||
'''
|
||||
|
@ -767,6 +766,13 @@ class Connection(ConnectionBase):
|
|||
|
||||
return (p.returncode, b_stdout, b_stderr)
|
||||
|
||||
@_ssh_retry
|
||||
def _run(self, cmd, in_data, sudoable=True, checkrc=True):
|
||||
"""Wrapper around _bare_run that retries the connection
|
||||
"""
|
||||
return self._bare_run(cmd, in_data, sudoable, checkrc)
|
||||
|
||||
@_ssh_retry
|
||||
def _file_transport_command(self, in_path, out_path, sftp_action):
|
||||
# scp and sftp require square brackets for IPv6 addresses, but
|
||||
# accept them for hostnames and IPv4 addresses too.
|
||||
|
@ -807,14 +813,14 @@ class Connection(ConnectionBase):
|
|||
cmd = self._build_command('sftp', to_bytes(host))
|
||||
in_data = u"{0} {1} {2}\n".format(sftp_action, shlex_quote(in_path), shlex_quote(out_path))
|
||||
in_data = to_bytes(in_data, nonstring='passthru')
|
||||
(returncode, stdout, stderr) = self._run(cmd, in_data, checkrc=False)
|
||||
(returncode, stdout, stderr) = self._bare_run(cmd, in_data, checkrc=False)
|
||||
elif method == 'scp':
|
||||
if sftp_action == 'get':
|
||||
cmd = self._build_command('scp', u'{0}:{1}'.format(host, shlex_quote(in_path)), out_path)
|
||||
else:
|
||||
cmd = self._build_command('scp', in_path, u'{0}:{1}'.format(host, shlex_quote(out_path)))
|
||||
in_data = None
|
||||
(returncode, stdout, stderr) = self._run(cmd, in_data, checkrc=False)
|
||||
(returncode, stdout, stderr) = self._bare_run(cmd, in_data, checkrc=False)
|
||||
elif method == 'piped':
|
||||
if sftp_action == 'get':
|
||||
# we pass sudoable=False to disable pty allocation, which
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue