Skip to content

Commit

Permalink
Use _remote_is_local=True for local connection in synchronize (ansibl…
Browse files Browse the repository at this point in the history
…e#40833)

* All instances of local connection should use _remote_is_local=True. Fixes ansible#40551

* Switch to instance attribute for synchronize

* Add test that shows that synchronize _remote_is_local addresses tmpdir building
  • Loading branch information
sivel authored and Timur Evdokimov committed Jun 26, 2018
1 parent 4f12179 commit c2f11b8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/ansible/plugins/action/synchronize.py
Expand Up @@ -301,6 +301,9 @@ def run(self, tmp=None, task_vars=None):

new_connection = connection_loader.get('local', self._play_context, new_stdin)
self._connection = new_connection
# Override _remote_is_local as an instance attribute specifically for the synchronize use case
# ensuring we set local tmpdir correctly
self._connection._remote_is_local = True
self._override_module_replaced_vars(task_vars)

# SWITCH SRC AND DEST HOST PER MODE
Expand Down
16 changes: 16 additions & 0 deletions test/units/plugins/action/test_synchronize.py
Expand Up @@ -42,6 +42,10 @@
'''


class BreakPoint(Exception):
pass


class TaskMock(object):
args = {'src': u'/tmp/deleteme',
'dest': '/tmp/deleteme',
Expand Down Expand Up @@ -246,3 +250,15 @@ def test_delegate_remote_su(self):
# delegate to other remote host with su enabled
x = SynchronizeTester()
x.runtest(fixturepath=os.path.join(self.fixturedir, 'delegate_remote_su'))

@patch.object(ActionModule, '_low_level_execute_command', side_effect=BreakPoint)
@patch.object(ActionModule, '_remote_expand_user', side_effect=ActionModule._remote_expand_user, autospec=True)
def test_remote_user_not_in_local_tmpdir(self, spy_remote_expand_user, ll_ec):
x = SynchronizeTester()
SAM = ActionModule(x.task, x.connection, x._play_context,
x.loader, x.templar, x.shared_loader_obj)
try:
SAM.run(task_vars={'hostvars': {'foo': {}, 'localhost': {}}, 'inventory_hostname': 'foo'})
except BreakPoint:
pass
self.assertEqual(spy_remote_expand_user.call_count, 0)

0 comments on commit c2f11b8

Please sign in to comment.