mirror of https://github.com/ansible/ansible.git
[win_get_url] feature: Add support `checksum` to module win_get_url (#51986)
* set valid_until equal to current time + spot_wait_timeout * Add checksum check for downloaded file. * refactoring * fix typo * add fixes * mart try,catch handling * revert lib/ansible/modules/cloud/amazon/ec2.py from upstream * refactoring * remove empty lines * add checksum verification for existing file * fix current file check * refactoring destination file check * add handling exceptions * refactoring * Added download file hash data from url * fix string aligning * fix bug with uri * Added get hash from multy-string file * Added URI support for checksum file location * refactoing * Remove any non-alphanumeric characters for hash from url * fix discussions; add support for PS3 * refactoring * add size return value * checkout from upstream for lib/ansible/modules/cloud/amazon/ec2.py * add Ansible.ModuleUtils.Legacy support; refactoring * Copyright added * Checking files size before and after downloading added. * remove unused code * Corrected regexp for dotted slashed file name prefix in hash-file * hotfix typo error; add int tests * remove legacy module support; split checksum to checksum, checksum_algorithm, checksum_url * changed default hash algorithm * Fixed case for ContentLength = -1 * Old comment removed * fix typo * Remove file size check before downloading * add alias to ; fix tests * adjust tests; fix lint warnings from PSScritpAnalyzer * workaround for bug in win_chocolatey module on win2008 * remove win_get_url.ps1 from /test/sanity/pslint/ignore.txt * add checksum_algorithm as retuen value * first normalise before return Result * resolve discussions Signed-off-by: Viktor Utkin <viktor.utkin7@yandex.ru> * fix discussions fix http tests as discussed * fix last discussions * Reduce code duplication and add idempotency check * fix sanity issue and remove testing code * move back to using tmp file for checksum comparisonpull/52045/head
parent
aafc5538bc
commit
b2a7561a7f
@ -0,0 +1,3 @@
|
||||
minor_changes:
|
||||
- win_get_url - Add the ``checksum`` option to verify the integrity of a downloaded file.
|
||||
- win_get_url - Add idempotency check if the remote file has the same contents as the dest file.
|
@ -0,0 +1,202 @@
|
||||
---
|
||||
- name: create src file
|
||||
win_copy:
|
||||
dest: '{{ remote_http_path }}\27617.txt'
|
||||
content: 'ptux'
|
||||
|
||||
- name: create sha1 checksum file of src
|
||||
win_copy:
|
||||
dest: '{{ remote_http_path }}\sha1sum.txt'
|
||||
content: 'a97e6837f60cec6da4491bab387296bbcd72bdba 27617.txt'
|
||||
|
||||
- name: add sha1 checksum not going to be downloaded
|
||||
win_lineinfile:
|
||||
dest: '{{ remote_http_path }}\sha1sum.txt'
|
||||
line: '{{ item }}'
|
||||
loop:
|
||||
- '3911340502960ca33aece01129234460bfeb2791 not_target1.txt'
|
||||
- '1b4b6adf30992cedb0f6edefd6478ff0a593b2e4 not_target2.txt'
|
||||
|
||||
- name: create sha256 checksum file of src
|
||||
win_copy:
|
||||
dest: '{{ remote_http_path }}\sha256sum.txt'
|
||||
content: 'b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006. 27617.txt'
|
||||
|
||||
- name: add sha256 checksum not going to be downloaded
|
||||
win_lineinfile:
|
||||
dest: '{{ remote_http_path }}\sha256sum.txt'
|
||||
line: '{{ item }}'
|
||||
loop:
|
||||
- '30949cc401e30ac494d695ab8764a9f76aae17c5d73c67f65e9b558f47eff892 not_target1.txt'
|
||||
- 'd0dbfc1945bc83bf6606b770e442035f2c4e15c886ee0c22fb3901ba19900b5b not_target2.txt'
|
||||
|
||||
- name: create sha256 checksum file of src with a dot leading path
|
||||
win_copy:
|
||||
dest: '{{ remote_http_path }}\sha256sum_with_dot.txt'
|
||||
content: 'b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006. ./27617.txt'
|
||||
|
||||
- name: add sha256 checksums with dot leading path not going to be downloaded
|
||||
win_lineinfile:
|
||||
dest: '{{ remote_http_path }}\sha256sum_with_dot.txt'
|
||||
line: '{{ item }}'
|
||||
loop:
|
||||
- '30949cc401e30ac494d695ab8764a9f76aae17c5d73c67f65e9b558f47eff892 ./not_target1.txt'
|
||||
- 'd0dbfc1945bc83bf6606b770e442035f2c4e15c886ee0c22fb3901ba19900b5b ./not_target2.txt'
|
||||
|
||||
- name: copy files to ftp
|
||||
win_copy:
|
||||
src: '{{ remote_http_path }}\'
|
||||
dest: '{{ test_win_get_url_path }}\ftp\{{ item }}\'
|
||||
remote_src: yes
|
||||
loop: '{{ dest_folders }}'
|
||||
vars:
|
||||
dest_folders:
|
||||
- anon
|
||||
- user
|
||||
- user-pass
|
||||
|
||||
- name: download src with sha1 checksum url
|
||||
win_get_url:
|
||||
url: 'ftp://localhost/anon/27617.txt'
|
||||
dest: '{{ remote_tmp_path }}'
|
||||
checksum_url: 'ftp://localhost/anon/sha1sum.txt'
|
||||
force: True
|
||||
register: result_sha1
|
||||
|
||||
- name: download src with sha1 checksum value
|
||||
win_get_url:
|
||||
url: 'ftp://localhost/anon/27617.txt'
|
||||
dest: '{{ remote_tmp_path }}'
|
||||
checksum: 'a97e6837f60cec6da4491bab387296bbcd72bdba'
|
||||
force: True
|
||||
register: result_sha1_alt
|
||||
|
||||
- win_stat:
|
||||
path: '{{ remote_tmp_path }}\27617.txt'
|
||||
register: stat_result_sha1
|
||||
|
||||
- name: download src with sha256 checksum url
|
||||
win_get_url:
|
||||
url: 'ftp://localhost/anon/27617.txt'
|
||||
dest: '{{ remote_tmp_path }}\27617sha256.txt'
|
||||
checksum_url: 'ftp://localhost/anon/sha256sum.txt'
|
||||
checksum_algorithm: sha256
|
||||
force: True
|
||||
register: result_sha256
|
||||
|
||||
- win_stat:
|
||||
path: '{{ remote_tmp_path }}\27617.txt'
|
||||
register: stat_result_sha256
|
||||
|
||||
- name: download src with sha256 checksum url with dot leading paths
|
||||
win_get_url:
|
||||
url: 'ftp://localhost/anon/27617.txt'
|
||||
dest: '{{ remote_tmp_path }}\27617sha256_with_dot.txt'
|
||||
checksum_url: 'ftp://localhost/anon/sha256sum_with_dot.txt'
|
||||
checksum_algorithm: sha256
|
||||
force: True
|
||||
register: result_sha256_with_dot
|
||||
|
||||
- win_stat:
|
||||
path: '{{ remote_tmp_path }}\27617sha256_with_dot.txt'
|
||||
register: stat_result_sha256_with_dot
|
||||
|
||||
- name: Assert that the file was downloaded
|
||||
assert:
|
||||
that:
|
||||
- result_sha1 is changed
|
||||
- result_sha1.checksum_dest == 'a97e6837f60cec6da4491bab387296bbcd72bdba'
|
||||
- result_sha1_alt is succeeded
|
||||
- not result_sha1_alt is changed
|
||||
- result_sha1_alt.checksum_dest == 'a97e6837f60cec6da4491bab387296bbcd72bdba'
|
||||
- result_sha256 is changed
|
||||
- result_sha256_with_dot is changed
|
||||
- stat_result_sha1.stat.exists | bool
|
||||
- stat_result_sha256.stat.exists | bool
|
||||
- stat_result_sha256_with_dot.stat.exists | bool
|
||||
|
||||
# Check download with force: False
|
||||
|
||||
- name: download src with sha1 checksum url
|
||||
win_get_url:
|
||||
url: 'ftp://localhost/anon/27617.txt'
|
||||
dest: '{{ remote_tmp_path }}'
|
||||
checksum_url: 'ftp://localhost/anon/sha1sum.txt'
|
||||
checksum_algorithm: sha1
|
||||
force: False
|
||||
register: result_sha1_no_force
|
||||
|
||||
- name: download src with sha256 checksum url
|
||||
win_get_url:
|
||||
url: 'ftp://localhost/anon/27617.txt'
|
||||
dest: '{{ remote_tmp_path }}/27617sha256.txt'
|
||||
checksum_url: 'ftp://localhost/anon/sha256sum.txt'
|
||||
checksum_algorithm: sha256
|
||||
force: False
|
||||
register: result_sha256_no_force
|
||||
|
||||
- name: assert download single file with force no
|
||||
assert:
|
||||
that:
|
||||
- result_sha1_no_force is not changed
|
||||
- result_sha256_no_force is not changed
|
||||
|
||||
# Check download with check_mode: True
|
||||
|
||||
- name: download src with sha1 checksum url | checkmode
|
||||
win_get_url:
|
||||
url: 'ftp://localhost/anon/27617.txt'
|
||||
dest: '{{ remote_tmp_path }}'
|
||||
checksum_url: 'ftp://localhost/anon/sha1sum.txt'
|
||||
checksum_algorithm: sha1
|
||||
check_mode: True
|
||||
register: result_sha1_check_mode
|
||||
|
||||
- name: download src with sha256 checksum url | checkmode
|
||||
win_get_url:
|
||||
url: 'ftp://localhost/anon/27617.txt'
|
||||
dest: '{{ remote_tmp_path }}\27617sha256.txt'
|
||||
checksum_url: 'ftp://localhost/anon/sha256sum.txt'
|
||||
checksum_algorithm: sha256
|
||||
check_mode: True
|
||||
register: result_sha256_check_mode
|
||||
|
||||
- name: assert download single file with force no
|
||||
assert:
|
||||
that:
|
||||
- result_sha1_check_mode.checksum_dest == 'a97e6837f60cec6da4491bab387296bbcd72bdba'
|
||||
- result_sha256_check_mode.checksum_dest == 'b1b6ce5073c8fac263a8fc5edfffdbd5dec1980c784e09c5bc69f8fb6056f006'
|
||||
- result_sha1_check_mode.checksum_src | length
|
||||
- result_sha256_check_mode.checksum_src | length
|
||||
|
||||
# Check download with wrong checksum
|
||||
|
||||
- name: download src with sha1 checksum value | fail
|
||||
win_get_url:
|
||||
url: 'ftp://localhost/anon/27617.txt'
|
||||
dest: '{{ remote_tmp_path }}'
|
||||
checksum: 'redacted'
|
||||
checksum_algorithm: sha1
|
||||
failed_when:
|
||||
- '"did not match" not in result_sha1_failed.msg'
|
||||
- '"The checksum" not in result_sha1_failed.msg'
|
||||
- '"Unknown error downloading" not in result_sha1_failed.msg'
|
||||
register: result_sha1_failed
|
||||
|
||||
- name: download src with sha256 checksum value | fail
|
||||
win_get_url:
|
||||
url: 'ftp://localhost/anon/27617.txt'
|
||||
dest: '{{ remote_tmp_path }}\27617sha256.txt'
|
||||
checksum: 'redacted'
|
||||
checksum_algorithm: sha256
|
||||
failed_when:
|
||||
- '"did not match" not in result_sha256_failed.msg'
|
||||
- '"The checksum" not in result_sha256_failed.msg'
|
||||
- '"Unknown error downloading" not in result_sha256_failed.msg'
|
||||
register: result_sha256_failed
|
||||
|
||||
- name: assert failed downloads
|
||||
assert:
|
||||
that:
|
||||
- result_sha1_failed is succeeded
|
||||
- result_sha256_failed is succeeded
|
Loading…
Reference in New Issue