ansible/test/integration/targets/win_copy/tasks/remote_tests.yml
Jordan Borean 8e40ac54dd win_copy: rewrite with new tests and functionality (#27678)
* win_copy rewrite with new tests and functionality

* minor pep fixes

* Handle UTF-8 filenames in zip

* fix for template

* when zip assemblies are not available in .net revert to old behaviour of copying one by one

* typo fix

* some more typos

* updated logic to correctly handle when new directories can be created

* removed testing file as it is not needed

* updated documentation based on PR
2017-08-18 20:33:37 -07:00

414 lines
15 KiB
YAML

---
- name: fail when source does not exist remote
win_copy:
src: fakesource
dest: fakedest
remote_src: yes
register: fail_remote_invalid_source
failed_when: "fail_remote_invalid_source.msg != 'Cannot copy src file: fakesource as it does not exist'"
- name: setup source folder for remote tests
win_copy:
src: files/
dest: '{{test_win_copy_path}}\source\'
- name: setup remote failure tests
win_file:
path: '{{item.path}}'
state: '{{item.state}}'
with_items:
- { 'path': '{{test_win_copy_path}}\target\folder', 'state': 'directory' }
- { 'path': '{{test_win_copy_path}}\target\file', 'state': 'touch' }
- { 'path': '{{test_win_copy_path}}\target\subdir', 'state': 'touch' }
- name: fail source is a file but dest is a folder
win_copy:
src: '{{test_win_copy_path}}\source\foo.txt'
dest: '{{test_win_copy_path}}\target\folder'
remote_src: yes
register: fail_remote_file_to_folder
failed_when: "'dest is already a folder' not in fail_remote_file_to_folder.msg"
- name: fail source is a file but dest is a folder
win_copy:
src: '{{test_win_copy_path}}\source\'
dest: '{{test_win_copy_path}}\target\'
remote_src: yes
register: fail_remote_folder_to_file
failed_when: "'dest is already a file' not in fail_remote_folder_to_file.msg"
- name: fail source is a file dest parent dir is also a file
win_copy:
src: '{{test_win_copy_path}}\source\foo.txt'
dest: '{{test_win_copy_path}}\target\file\foo.txt'
remote_src: yes
register: fail_remote_file_parent_dir_file
failed_when: fail_remote_file_parent_dir_file.msg != 'object at destination parent dir ' + test_win_copy_path + '\\target\\file is currently a file'
- name: fail source is a folder dest parent dir is also a file
win_copy:
src: '{{test_win_copy_path}}\source\subdir'
dest: '{{test_win_copy_path}}\target\file'
remote_src: yes
register: fail_remote_folder_parent_dir_file
failed_when: "'object at dest parent dir is not a folder' not in fail_remote_folder_parent_dir_file.msg"
- name: fail to copy a remote file with parent dir that doesn't exist and filename is set
win_copy:
src: '{{test_win_copy_path}}\source\foo.txt'
dest: '{{test_win_copy_path}}\missing-dir\foo.txt'
remote_src: yes
register: fail_remote_missing_parent_dir
failed_when: "'Destination directory ' + test_win_copy_path + '\\missing-dir does not exist' not in fail_remote_missing_parent_dir.msg"
- name: remove target after remote failure tests
win_file:
path: '{{test_win_copy_path}}\target'
state: absent
- name: create remote target after cleaning
win_file:
path: '{{test_win_copy_path}}\target'
state: directory
- name: copy single file remote (check mode)
win_copy:
src: '{{test_win_copy_path}}\source\foo.txt'
dest: '{{test_win_copy_path}}\target\foo-target.txt'
remote_src: yes
register: remote_copy_file_check
check_mode: yes
- name: get result of copy single file remote (check mode)
win_stat:
path: '{{test_win_copy_path}}\target\foo-target.txt'
register: remote_copy_file_actual_check
- name: assert copy single file remote (check mode)
assert:
that:
- remote_copy_file_check|changed
- remote_copy_file_actual_check.stat.exists == False
- name: copy single file remote
win_copy:
src: '{{test_win_copy_path}}\source\foo.txt'
dest: '{{test_win_copy_path}}\target\foo-target.txt'
remote_src: yes
register: remote_copy_file
- name: get result of copy single file remote
win_stat:
path: '{{test_win_copy_path}}\target\foo-target.txt'
register: remote_copy_file_actual
- name: assert copy single file remote
assert:
that:
- remote_copy_file|changed
- remote_copy_file.operation == 'file_copy'
- remote_copy_file.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
- remote_copy_file.size == 8
- remote_copy_file.original_basename == 'foo.txt'
- remote_copy_file_actual.stat.exists == True
- remote_copy_file_actual.stat.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
- name: copy single file remote (idempotent)
win_copy:
src: '{{test_win_copy_path}}\source\foo.txt'
dest: '{{test_win_copy_path}}\target\foo-target.txt'
remote_src: yes
register: remote_copy_file_again
- name: assert copy single file remote (idempotent)
assert:
that:
- not remote_copy_file_again|changed
- name: copy single file into folder remote (check mode)
win_copy:
src: '{{test_win_copy_path}}\source\foo.txt'
dest: '{{test_win_copy_path}}\target\'
remote_src: yes
register: remote_copy_file_to_folder_check
check_mode: yes
- name: get result of copy single file into folder remote (check mode)
win_stat:
path: '{{test_win_copy_path}}\target\foo.txt'
register: remote_copy_file_to_folder_actual_check
- name: assert copy single file into folder remote (check mode)
assert:
that:
- remote_copy_file_to_folder_check|changed
- remote_copy_file_to_folder_actual_check.stat.exists == False
- name: copy single file into folder remote
win_copy:
src: '{{test_win_copy_path}}\source\foo.txt'
dest: '{{test_win_copy_path}}\target\'
remote_src: yes
register: remote_copy_file_to_folder
- name: get result of copy single file into folder remote
win_stat:
path: '{{test_win_copy_path}}\target\foo.txt'
register: remote_copy_file_to_folder_actual
- name: assert copy single file into folder remote
assert:
that:
- remote_copy_file_to_folder|changed
- remote_copy_file_to_folder.operation == 'file_copy'
- remote_copy_file_to_folder.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
- remote_copy_file_to_folder.size == 8
- remote_copy_file_to_folder.original_basename == 'foo.txt'
- remote_copy_file_to_folder_actual.stat.exists == True
- remote_copy_file_to_folder_actual.stat.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
- name: copy single file into folder remote (idempotent)
win_copy:
src: '{{test_win_copy_path}}\source\foo.txt'
dest: '{{test_win_copy_path}}\target\'
remote_src: yes
register: remote_copy_file_to_folder_again
- name: assert copy single file into folder remote
assert:
that:
- not remote_copy_file_to_folder_again|changed
- name: copy single file to missing folder (check mode)
win_copy:
src: '{{test_win_copy_path}}\source\foo.txt'
dest: '{{test_win_copy_path}}\target\missing\'
remote_src: yes
register: remote_copy_file_to_missing_folder_check
check_mode: yes
- name: get result of copy single file to missing folder remote (check mode)
win_stat:
path: '{{test_win_copy_path}}\target\missing\foo.txt'
register: remote_copy_file_to_missing_folder_actual_check
- name: assert copy single file to missing folder remote (check mode)
assert:
that:
- remote_copy_file_to_missing_folder_check|changed
- remote_copy_file_to_missing_folder_check.operation == 'file_copy'
- remote_copy_file_to_missing_folder_actual_check.stat.exists == False
- name: copy single file to missing folder remote
win_copy:
src: '{{test_win_copy_path}}\source\foo.txt'
dest: '{{test_win_copy_path}}\target\missing\'
remote_src: yes
register: remote_copy_file_to_missing_folder
- name: get result of copy single file to missing folder remote
win_stat:
path: '{{test_win_copy_path}}\target\missing\foo.txt'
register: remote_copy_file_to_missing_folder_actual
- name: assert copy single file to missing folder remote
assert:
that:
- remote_copy_file_to_missing_folder|changed
- remote_copy_file_to_missing_folder.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
- remote_copy_file_to_missing_folder.operation == 'file_copy'
- remote_copy_file_to_missing_folder.size == 8
- remote_copy_file_to_missing_folder_actual.stat.exists == True
- remote_copy_file_to_missing_folder_actual.stat.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
- name: clear target for folder to folder test
win_file:
path: '{{test_win_copy_path}}\target'
state: absent
- name: copy folder to folder remote (check mode)
win_copy:
src: '{{test_win_copy_path}}\source'
dest: '{{test_win_copy_path}}\target'
remote_src: yes
register: remote_copy_folder_to_folder_check
check_mode: yes
- name: get result of copy folder to folder remote (check mode)
win_stat:
path: '{{test_win_copy_path}}\target'
register: remote_copy_folder_to_folder_actual_check
- name: assert copy folder to folder remote (check mode)
assert:
that:
- remote_copy_folder_to_folder_check|changed
- remote_copy_folder_to_folder_check.operation == 'folder_copy'
- remote_copy_folder_to_folder_actual_check.stat.exists == False
- name: copy folder to folder remote
win_copy:
src: '{{test_win_copy_path}}\source'
dest: '{{test_win_copy_path}}\target'
remote_src: yes
register: remote_copy_folder_to_folder
- name: get result of copy folder to folder remote
win_find:
paths: '{{test_win_copy_path}}\target'
recurse: yes
file_type: directory
register: remote_copy_folder_to_folder_actual
- name: assert copy folder to folder remote
assert:
that:
- remote_copy_folder_to_folder|changed
- remote_copy_folder_to_folder.operation == 'folder_copy'
- remote_copy_folder_to_folder_actual.examined == 11
- remote_copy_folder_to_folder_actual.matched == 6
- remote_copy_folder_to_folder_actual.files[0].filename == 'source'
- remote_copy_folder_to_folder_actual.files[1].filename == 'subdir'
- remote_copy_folder_to_folder_actual.files[2].filename == 'empty'
- remote_copy_folder_to_folder_actual.files[3].filename == 'subdir2'
- remote_copy_folder_to_folder_actual.files[4].filename == 'subdir3'
- remote_copy_folder_to_folder_actual.files[5].filename == 'subdir4'
- name: copy folder to folder remote (idempotent)
win_copy:
src: '{{test_win_copy_path}}\source'
dest: '{{test_win_copy_path}}\target'
remote_src: yes
register: remote_copy_folder_to_folder_again
- name: assert copy folder to folder remote (idempotent)
assert:
that:
- not remote_copy_folder_to_folder_again|changed
- name: change remote file after folder to folder test
win_copy:
content: bar.txt
dest: '{{test_win_copy_path}}\target\source\foo.txt'
- name: remote remote folder after folder to folder test
win_file:
path: '{{test_win_copy_path}}\target\source\subdir\subdir2\subdir3\subdir4'
state: absent
- name: copy folder to folder remote after change
win_copy:
src: '{{test_win_copy_path}}\source'
dest: '{{test_win_copy_path}}\target'
remote_src: yes
register: remote_copy_folder_to_folder_after_change
- name: get result of copy folder to folder remote after change
win_find:
paths: '{{test_win_copy_path}}\target\source'
recurse: yes
patterns: ['foo.txt', 'qux.txt']
register: remote_copy_folder_to_folder_after_change_actual
- name: assert copy folder after changes
assert:
that:
- remote_copy_folder_to_folder_after_change|changed
- remote_copy_folder_to_folder_after_change_actual.matched == 2
- remote_copy_folder_to_folder_after_change_actual.files[0].checksum == 'b54ba7f5621240d403f06815f7246006ef8c7d43'
- remote_copy_folder_to_folder_after_change_actual.files[1].checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
- name: clear target folder before folder contents to remote test
win_file:
path: '{{test_win_copy_path}}\target'
state: absent
- name: copy folder contents to folder remote with backslash (check mode)
win_copy:
src: '{{test_win_copy_path}}\source\'
dest: '{{test_win_copy_path}}\target'
remote_src: yes
register: remote_copy_folder_content_backslash_check
check_mode: yes
- name: get result of copy folder contents to folder remote with backslash (check mode)
win_stat:
path: '{{test_win_copy_path}}\target'
register: remote_copy_folder_content_backslash_actual_check
- name: assert copy folder content to folder remote with backslash (check mode)
assert:
that:
- remote_copy_folder_content_backslash_check|changed
- remote_copy_folder_content_backslash_actual_check.stat.exists == False
- name: copy folder contents to folder remote with backslash
win_copy:
src: '{{test_win_copy_path}}\source\'
dest: '{{test_win_copy_path}}\target'
remote_src: yes
register: remote_copy_folder_content_backslash
- name: get result of copy folder contents to folder remote with backslash
win_find:
paths: '{{test_win_copy_path}}\target'
recurse: yes
file_type: directory
register: remote_copy_folder_content_backslash_actual
- name: assert copy folder content to folder remote with backslash
assert:
that:
- remote_copy_folder_content_backslash|changed
- remote_copy_folder_content_backslash.operation == 'folder_copy'
- remote_copy_folder_content_backslash_actual.examined == 10
- remote_copy_folder_content_backslash_actual.matched == 5
- remote_copy_folder_content_backslash_actual.files[0].filename == 'subdir'
- remote_copy_folder_content_backslash_actual.files[1].filename == 'empty'
- remote_copy_folder_content_backslash_actual.files[2].filename == 'subdir2'
- remote_copy_folder_content_backslash_actual.files[3].filename == 'subdir3'
- remote_copy_folder_content_backslash_actual.files[4].filename == 'subdir4'
- name: copy folder contents to folder remote with backslash (idempotent)
win_copy:
src: '{{test_win_copy_path}}\source\'
dest: '{{test_win_copy_path}}\target'
remote_src: yes
register: remote_copy_folder_content_backslash_again
- name: assert copy folder content to folder remote with backslash (idempotent)
assert:
that:
- not remote_copy_folder_content_backslash_again|changed
- name: change remote file after folder content to folder test
win_copy:
content: bar.txt
dest: '{{test_win_copy_path}}\target\foo.txt'
- name: remote remote folder after folder content to folder test
win_file:
path: '{{test_win_copy_path}}\target\subdir\subdir2\subdir3\subdir4'
state: absent
- name: copy folder content to folder remote after change
win_copy:
src: '{{test_win_copy_path}}/source/'
dest: '{{test_win_copy_path}}/target/'
remote_src: yes
register: remote_copy_folder_content_to_folder_after_change
- name: get result of copy folder content to folder remote after change
win_find:
paths: '{{test_win_copy_path}}\target'
recurse: yes
patterns: ['foo.txt', 'qux.txt']
register: remote_copy_folder_content_to_folder_after_change_actual
- name: assert copy folder content to folder after changes
assert:
that:
- remote_copy_folder_content_to_folder_after_change|changed
- remote_copy_folder_content_to_folder_after_change_actual.matched == 2
- remote_copy_folder_content_to_folder_after_change_actual.files[0].checksum == 'b54ba7f5621240d403f06815f7246006ef8c7d43'
- remote_copy_folder_content_to_folder_after_change_actual.files[1].checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'