mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-25 05:23:58 -07:00
Fix synchronize retries (#18535)
* Fix synchronize retries
The synchronize module munges its task args on every invocation of
run(). This was problematic because the munged data was not fit for use
by a second pass of the synchronize module. Correct this by using a copy
of the task args on every invocation of run() so that the original args
are not affected.
Local testing using this playbook seems to confirm that things work as
expected:
- hosts: all
tasks:
- delay: 2
register: task_result
retries: 1
until: task_result.rc == 0
synchronize:
dest: /tmp/out
mode: pull
src: /tmp/nonexistent/
fixes #18281
* Update synchroncization fixture assertions
When we started operating on a copy of the task args the test assertions
were no longer asserting things about the munged state but of the
pristine state. Convert the copy of task args to a class member so that
it can be compared against later in testing and update the assertions to
check this munged copy.
* Shuffle objects around for cleaner testing
Attach the temporary args dict to the task rather than the action as
this makes updating the existing tests cleaner.
This commit is contained in:
parent
9e5d4de49a
commit
a65e34ce77
10 changed files with 57 additions and 51 deletions
|
|
@ -12,6 +12,6 @@ asserts:
|
|||
- "SAM._connection.transport == 'local'"
|
||||
- "self._play_context.shell == 'sh'"
|
||||
- "self.execute_called"
|
||||
- "self.task.args['_local_rsync_path'] == 'rsync'"
|
||||
- "self.task.args['src'] == '/tmp/deleteme'"
|
||||
- "self.task.args['dest'] == 'root@el6host:/tmp/deleteme'"
|
||||
- "self.final_module_args['_local_rsync_path'] == 'rsync'"
|
||||
- "self.final_module_args['src'] == '/tmp/deleteme'"
|
||||
- "self.final_module_args['dest'] == 'root@el6host:/tmp/deleteme'"
|
||||
|
|
|
|||
|
|
@ -23,11 +23,11 @@ asserts:
|
|||
- "hasattr(SAM._connection, 'ismock')"
|
||||
- "SAM._connection.transport == 'local'"
|
||||
- "self.execute_called"
|
||||
- "self.task.args['_local_rsync_path'] == 'rsync'"
|
||||
- "self.final_module_args['_local_rsync_path'] == 'rsync'"
|
||||
# this is a crucial aspect of this scenario ...
|
||||
- "self.task.args['rsync_path'] == '\"sudo rsync\"'"
|
||||
- "self.task.args['src'] == '/tmp/deleteme'"
|
||||
- "self.task.args['dest'] == 'root@el6host:/tmp/deleteme'"
|
||||
- "self.final_module_args['rsync_path'] == '\"sudo rsync\"'"
|
||||
- "self.final_module_args['src'] == '/tmp/deleteme'"
|
||||
- "self.final_module_args['dest'] == 'root@el6host:/tmp/deleteme'"
|
||||
- "self.task.become == True"
|
||||
- "self.task.become_user == None"
|
||||
- "self._play_context.shell == 'sh'"
|
||||
|
|
|
|||
|
|
@ -23,11 +23,11 @@ asserts:
|
|||
- "hasattr(SAM._connection, 'ismock')"
|
||||
- "SAM._connection.transport == 'local'"
|
||||
- "self.execute_called"
|
||||
- "self.task.args['_local_rsync_path'] == 'rsync'"
|
||||
- "self.final_module_args['_local_rsync_path'] == 'rsync'"
|
||||
# this is a crucial aspect of this scenario ...
|
||||
- "self.task.args['rsync_path'] == '\"sudo rsync\"'"
|
||||
- "self.task.args['src'] == '/tmp/deleteme'"
|
||||
- "self.task.args['dest'] == 'root@el6host:/tmp/deleteme'"
|
||||
- "self.final_module_args['rsync_path'] == '\"sudo rsync\"'"
|
||||
- "self.final_module_args['src'] == '/tmp/deleteme'"
|
||||
- "self.final_module_args['dest'] == 'root@el6host:/tmp/deleteme'"
|
||||
- "self.task.become == None"
|
||||
- "self.task.become_user == None"
|
||||
- "self._play_context.shell == 'sh'"
|
||||
|
|
|
|||
|
|
@ -17,10 +17,10 @@ asserts:
|
|||
- "hasattr(SAM._connection, 'ismock')"
|
||||
- "SAM._connection.transport == 'local'"
|
||||
- "self.execute_called"
|
||||
- "self.task.args['_local_rsync_path'] == 'rsync'"
|
||||
- "self.task.args['dest_port'] == 2202"
|
||||
- "self.task.args['src'] == '/tmp/deleteme'"
|
||||
- "self.task.args['dest'] == 'vagrant@127.0.0.1:/tmp/deleteme'"
|
||||
- "self.final_module_args['_local_rsync_path'] == 'rsync'"
|
||||
- "self.final_module_args['dest_port'] == 2202"
|
||||
- "self.final_module_args['src'] == '/tmp/deleteme'"
|
||||
- "self.final_module_args['dest'] == 'vagrant@127.0.0.1:/tmp/deleteme'"
|
||||
- "self._play_context.shell == 'sh'"
|
||||
- "self._play_context.remote_addr == '127.0.0.1'"
|
||||
- "self._play_context.remote_user == 'vagrant'"
|
||||
|
|
|
|||
|
|
@ -20,10 +20,10 @@ asserts:
|
|||
- "hasattr(SAM._connection, 'ismock')"
|
||||
- "SAM._connection.transport == 'local'"
|
||||
- "self.execute_called"
|
||||
- "self.task.args['_local_rsync_path'] == 'rsync'"
|
||||
- "self.task.args['dest_port'] == 2202"
|
||||
- "self.task.args['src'] == '/tmp/deleteme'"
|
||||
- "self.task.args['dest'] == 'vagrant@127.0.0.1:/tmp/deleteme'"
|
||||
- "self.final_module_args['_local_rsync_path'] == 'rsync'"
|
||||
- "self.final_module_args['dest_port'] == 2202"
|
||||
- "self.final_module_args['src'] == '/tmp/deleteme'"
|
||||
- "self.final_module_args['dest'] == 'vagrant@127.0.0.1:/tmp/deleteme'"
|
||||
- "self._play_context.shell == 'sh'"
|
||||
- "self._play_context.remote_addr == '127.0.0.1'"
|
||||
- "self._play_context.remote_user == 'vagrant'"
|
||||
|
|
|
|||
|
|
@ -17,10 +17,10 @@ asserts:
|
|||
- "hasattr(SAM._connection, 'ismock')"
|
||||
- "SAM._connection.transport == 'local'"
|
||||
- "self.execute_called"
|
||||
- "self.task.args['_local_rsync_path'] == 'rsync'"
|
||||
- "self.task.args['dest_port'] == 2202"
|
||||
- "self.task.args['src'] == '/tmp/deleteme'"
|
||||
- "self.task.args['dest'] == 'vagrant@127.0.0.1:/tmp/deleteme'"
|
||||
- "self.final_module_args['_local_rsync_path'] == 'rsync'"
|
||||
- "self.final_module_args['dest_port'] == 2202"
|
||||
- "self.final_module_args['src'] == '/tmp/deleteme'"
|
||||
- "self.final_module_args['dest'] == 'vagrant@127.0.0.1:/tmp/deleteme'"
|
||||
- "self._play_context.shell == 'sh'"
|
||||
- "self._play_context.remote_addr == '127.0.0.1'"
|
||||
- "self._play_context.remote_user == 'vagrant'"
|
||||
|
|
|
|||
|
|
@ -21,6 +21,6 @@ asserts:
|
|||
- "SAM._connection.transport == 'ssh'"
|
||||
- "self._play_context.shell == None"
|
||||
- "self.execute_called"
|
||||
- "self.task.args['_local_rsync_path'] == 'rsync'"
|
||||
- "self.task.args['src'] == '/tmp/deleteme'"
|
||||
- "self.task.args['dest'] == 'el6host:/tmp/deleteme'"
|
||||
- "self.final_module_args['_local_rsync_path'] == 'rsync'"
|
||||
- "self.final_module_args['src'] == '/tmp/deleteme'"
|
||||
- "self.final_module_args['dest'] == 'el6host:/tmp/deleteme'"
|
||||
|
|
|
|||
|
|
@ -28,6 +28,6 @@ asserts:
|
|||
- "not self._play_context.become"
|
||||
- "self._play_context.become_method == 'su'"
|
||||
- "self.execute_called"
|
||||
- "self.task.args['_local_rsync_path'] == 'rsync'"
|
||||
- "self.task.args['src'] == '/tmp/deleteme'"
|
||||
- "self.task.args['dest'] == 'el6host:/tmp/deleteme'"
|
||||
- "self.final_module_args['_local_rsync_path'] == 'rsync'"
|
||||
- "self.final_module_args['src'] == '/tmp/deleteme'"
|
||||
- "self.final_module_args['dest'] == 'el6host:/tmp/deleteme'"
|
||||
|
|
|
|||
|
|
@ -99,11 +99,12 @@ class SynchronizeTester(object):
|
|||
execute_called = False
|
||||
|
||||
|
||||
def _execute_module(self, module_name, task_vars=None):
|
||||
def _execute_module(self, module_name, module_args=None, task_vars=None):
|
||||
self.execute_called = True
|
||||
self.final_module_args = module_args
|
||||
self.final_task_vars = task_vars
|
||||
return {}
|
||||
|
||||
|
||||
def runtest(self, fixturepath='fixtures/synchronize/basic'):
|
||||
|
||||
metapath = os.path.join(fixturepath, 'meta.yaml')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue