Fixes #6298 and adds a sudo unit test for synchronize

This commit is contained in:
James Tanner 2014-03-05 14:51:40 -05:00
parent 6a615f18c5
commit 6129ea7566
2 changed files with 36 additions and 3 deletions

View file

@ -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

View file

@ -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):