From e37b63386c0c77e8ab8216e5520be80400ea6170 Mon Sep 17 00:00:00 2001 From: Jon Hawkesworth Date: Tue, 9 Dec 2014 23:38:35 +0000 Subject: [PATCH] Revised following comments from Chris Church. Now uses sha1 checksums following merge of 9688. Also I undid the changes I made to fetch.py win_template.py now uses conn.shell.has_trailing_slash and conn.shell.join_path updated integration tests. --- lib/ansible/module_utils/powershell.ps1 | 6 +++--- lib/ansible/runner/action_plugins/fetch.py | 7 +++---- lib/ansible/runner/action_plugins/win_template.py | 5 ++--- test/integration/roles/test_win_copy/tasks/main.yml | 6 ++++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/ansible/module_utils/powershell.ps1 b/lib/ansible/module_utils/powershell.ps1 index 57d2c1b101c..ee7d3ddeca4 100644 --- a/lib/ansible/module_utils/powershell.ps1 +++ b/lib/ansible/module_utils/powershell.ps1 @@ -142,14 +142,14 @@ Function ConvertTo-Bool return } -# Helper function to calculate md5 of a file in a way which powershell 3 +# Helper function to calculate a hash of a file in a way which powershell 3 # and above can handle: -Function Get-FileMd5($path) +Function Get-FileChecksum($path) { $hash = "" If (Test-Path -PathType Leaf $path) { - $sp = new-object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider; + $sp = new-object -TypeName System.Security.Cryptography.SHA1CryptoServiceProvider; $fp = [System.IO.File]::Open($path, [System.IO.Filemode]::Open, [System.IO.FileAccess]::Read); [System.BitConverter]::ToString($sp.ComputeHash($fp)).Replace("-", "").ToLower(); $fp.Dispose(); diff --git a/lib/ansible/runner/action_plugins/fetch.py b/lib/ansible/runner/action_plugins/fetch.py index 61f9f032a34..3fa748ccbd1 100644 --- a/lib/ansible/runner/action_plugins/fetch.py +++ b/lib/ansible/runner/action_plugins/fetch.py @@ -127,13 +127,13 @@ class ActionModule(object): elif remote_checksum == '2': result = dict(msg="no read permission on remote file, not transferring, ignored", file=source, changed=False) elif remote_checksum == '3': - result = dict(failed=True, msg="remote file is a directory, fetch cannot work on directories", file=source, changed=False) + result = dict(msg="remote file is a directory, fetch cannot work on directories", file=source, changed=False) elif remote_checksum == '4': result = dict(msg="python isn't present on the system. Unable to compute checksum", file=source, changed=False) return ReturnData(conn=conn, result=result) # calculate checksum for the local file - local_checksum = utils.md5(dest) + local_checksum = utils.checksum(dest) if remote_checksum != local_checksum: # create the containing directories, if needed @@ -147,8 +147,7 @@ class ActionModule(object): f = open(dest, 'w') f.write(remote_data) f.close() - new_checksum = utils.md5(dest) - # new_checksum = utils.secure_hash(dest) + new_checksum = utils.secure_hash(dest) # For backwards compatibility. We'll return None on FIPS enabled # systems try: diff --git a/lib/ansible/runner/action_plugins/win_template.py b/lib/ansible/runner/action_plugins/win_template.py index e2843161915..e32a5806c4b 100644 --- a/lib/ansible/runner/action_plugins/win_template.py +++ b/lib/ansible/runner/action_plugins/win_template.py @@ -75,10 +75,9 @@ class ActionModule(object): else: source = utils.path_dwim(self.runner.basedir, source) - - if dest.endswith("\\"): # TODO: Check that this fixes the path for Windows hosts. + if conn.shell.path_has_trailing_slash(dest): base = os.path.basename(source) - dest = os.path.join(dest, base) + dest = conn.shell.join_path(dest, base) # template the source data locally & get ready to transfer try: diff --git a/test/integration/roles/test_win_copy/tasks/main.yml b/test/integration/roles/test_win_copy/tasks/main.yml index f0fe2d04c48..d898219a85c 100644 --- a/test/integration/roles/test_win_copy/tasks/main.yml +++ b/test/integration/roles/test_win_copy/tasks/main.yml @@ -62,12 +62,14 @@ - name: verify that the file checksum is correct assert: that: - - "copy_result.checksum[0] == 'c47397529fe81ab62ba3f85e9f4c71f2'" + - "copy_result.checksum[0] == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'" - name: check the stat results of the file win_stat: path={{output_file}} register: stat_results +- debug: var=stat_results + - name: assert the stat results are correct assert: that: @@ -76,7 +78,7 @@ # - "stat_results.stat.isfifo == false" # - "stat_results.stat.isreg == true" # - "stat_results.stat.issock == false" - - "stat_results.stat.md5[0] == 'c47397529fe81ab62ba3f85e9f4c71f2'" + - "stat_results.stat.checksum[0] == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'" - name: overwrite the file via same means win_copy: src=foo.txt dest={{output_file}}