copy action plug-in check mode respects force=no

The copy action accepts force=no, which tells it not to replace an
existing file even if it differs from the source.  The copy action
plug-in wasn't respecting this option when operated in check mode, so it
would report that changes are necessary in check mode even though copy
would make no changes when run normally.

Runner._remote_md5 was changed to make the logic for setting rc perhaps
a little more clear, and to make sure that rc=0 when the file does not
exist.
This commit is contained in:
Dale Sedivec 2013-04-06 21:20:10 -05:00 committed by Michael DeHaan
commit 515fd9e915
3 changed files with 18 additions and 2 deletions

View file

@ -63,12 +63,13 @@ class TestRunner(unittest.TestCase):
filename = os.path.join(self.stage_dir, filename)
return filename
def _run(self, module_name, module_args, background=0):
def _run(self, module_name, module_args, background=0, check_mode=False):
''' run a module and get the localhost results '''
self.runner.module_name = module_name
args = ' '.join(module_args)
self.runner.module_args = args
self.runner.background = background
self.runner.check = check_mode
results = self.runner.run()
# when using nosetests this will only show up on failure
# which is pretty useful
@ -117,6 +118,12 @@ class TestRunner(unittest.TestCase):
"dest=%s" % output,
])
assert result['changed'] is False
with open(output, "a") as output_stream:
output_stream.write("output file now differs from input")
result = self._run('copy',
["src=%s" % input_, "dest=%s" % output, "force=no"],
check_mode=True)
assert result['changed'] is False
def test_command(self):
# test command module, change trigger, etc