Remove retries decorator from ssh plugin

The decorator is used when calling exec_command, which in turn calls
exec_command from the original SSH plugin, which calls _run
that has it's own retry logic.

This patch removes the retry logic from the openstack-ansible
connection plugin and relies on what is present in the original
SSH connection plugin.

Change-Id: I28cd7a8321665d52d123ae14336346d14df82a36
This commit is contained in:
Jonathan Rosser 2023-10-26 13:28:20 +01:00
parent faf4b76ea5
commit 93fd7c2c22
1 changed files with 0 additions and 37 deletions

View File

@ -278,46 +278,13 @@ DOCUMENTATION = '''
- name: ansible_ssh_pkcs11_provider
'''
import functools
import importlib
import os
import time
from ansible.module_utils.six.moves import shlex_quote
SSH = importlib.import_module('ansible.plugins.connection.ssh')
def retry(ExceptionToCheck, tries=3, delay=1, backoff=2):
"""Retry calling the decorated function using an exponential backoff.
:param ExceptionToCheck: the exception to check. may be a tuple of
exceptions to check
:type ExceptionToCheck: Exception or tuple
:param tries: number of times to try (not retry) before giving up
:type tries: int
:param delay: initial delay between retries in seconds
:type delay: int
:param backoff: backoff multiplier e.g. value of 2 will double the delay
each retry
:type backoff: int
"""
def deco_retry(f):
@functools.wraps(f)
def f_retry(*args, **kwargs):
mtries, mdelay = tries, delay
while mtries > 1:
try:
return f(*args, **kwargs)
except ExceptionToCheck:
time.sleep(mdelay)
mtries -= 1
mdelay *= backoff
return f(*args, **kwargs)
return f_retry
return deco_retry
class Connection(SSH.Connection):
"""Transport options for containers.
@ -342,9 +309,6 @@ class Connection(SSH.Connection):
self.container_name = None
self.physical_host = None
if not hasattr(self._play_context, 'retries'):
self._play_context.retries = 3
# Store the container pid for multi-use
self.container_pid = None
self.is_container = None
@ -380,7 +344,6 @@ class Connection(SSH.Connection):
self.physical_host)
self.host = self._options['host'] = self._play_context.remote_addr = physical_host_addr
@retry(ExceptionToCheck=Exception)
def exec_command(self, cmd, in_data=None, sudoable=True):
"""run a command on the remote host."""