From 76037168b10f7e9ac09a084cbc16a19fd1a1c8c1 Mon Sep 17 00:00:00 2001 From: James Tanner Date: Wed, 5 Mar 2014 14:51:40 -0500 Subject: [PATCH] Fixes #6298 and adds a sudo unit test for synchronize --- .../runner/action_plugins/synchronize.py | 9 ++++-- test/units/TestSynchronize.py | 30 ++++++++++++++++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/lib/ansible/runner/action_plugins/synchronize.py b/lib/ansible/runner/action_plugins/synchronize.py index d7c9113f28e..c66fcdff3ce 100644 --- a/lib/ansible/runner/action_plugins/synchronize.py +++ b/lib/ansible/runner/action_plugins/synchronize.py @@ -173,6 +173,11 @@ class ActionModule(object): if self.runner.noop_on_check(inject): module_items += " CHECKMODE=True" - return self.runner._execute_module(conn, tmp, 'synchronize', - module_items, inject=inject) + # run the module and store the result + result = self.runner._execute_module(conn, tmp, 'synchronize', module_items, inject=inject) + + # reset the sudo property + self.runner.sudo = self.original_sudo + + return result diff --git a/test/units/TestSynchronize.py b/test/units/TestSynchronize.py index 7965f2295e7..dfb1a129e5a 100644 --- a/test/units/TestSynchronize.py +++ b/test/units/TestSynchronize.py @@ -61,7 +61,35 @@ class TestSynchronize(unittest.TestCase): assert runner.executed_inject['delegate_to'] == "127.0.0.1", "was not delegated to 127.0.0.1" assert runner.executed_args == "dest=root@el6.lab.net:/tmp/bar src=/tmp/foo", "wrong args used" - assert runner.sudo == False, "sudo not set to false" + assert runner.sudo == None, "sudo was not reset to None" + + def test_synchronize_action_sudo(self): + + """ verify the synchronize action plugin unsets and then sets sudo """ + + runner = FakeRunner() + runner.sudo = True + runner.remote_user = "root" + runner.transport = "ssh" + conn = FakeConn() + inject = { + 'inventory_hostname': "el6.lab.net", + 'inventory_hostname_short': "el6", + 'ansible_connection': None, + 'ansible_ssh_user': 'root', + 'delegate_to': None, + 'playbook_dir': '.', + } + + x = Synchronize(runner) + x.setup("synchronize", inject) + x.run(conn, "/tmp", "synchronize", "src=/tmp/foo dest=/tmp/bar", inject) + + assert runner.executed_inject['delegate_to'] == "127.0.0.1", "was not delegated to 127.0.0.1" + assert runner.executed_args == 'dest=root@el6.lab.net:/tmp/bar src=/tmp/foo rsync_path="sudo rsync"', \ + "wrong args used: %s" % runner.executed_args + assert runner.sudo == True, "sudo was not reset to True" + def test_synchronize_action_local(self):