mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
971783a7fd
* Added more return results to win_stat * Changed Win2012 methods to support older versions in setup * staging of the tests to work with older servers
638 lines
18 KiB
YAML
638 lines
18 KiB
YAML
# test code for the win_stat module
|
|
# (c) 2014, Chris Church <chris@ninemoreminutes.com>
|
|
|
|
# This file is part of Ansible
|
|
#
|
|
# Ansible is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# Ansible is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
- name: remove links if they exist as win_file struggles
|
|
win_command: cmd.exe /c rmdir "{{item}}"
|
|
ignore_errors: True
|
|
with_items:
|
|
- "{{win_stat_dir}}\\link"
|
|
- "{{win_stat_dir}}\\nested\\hard-link.ps1"
|
|
- "{{win_stat_dir}}\\junction-link"
|
|
|
|
- name: ensure the testing directory is cleared before the run
|
|
win_file:
|
|
path: "{{win_stat_dir}}"
|
|
state: absent
|
|
|
|
- name: ensure win testing directories exist
|
|
win_file:
|
|
path: "{{item}}"
|
|
state: directory
|
|
with_items:
|
|
- "{{win_stat_dir}}\\folder"
|
|
- "{{win_stat_dir}}\\folder space"
|
|
- "{{win_stat_dir}}\\nested"
|
|
- "{{win_stat_dir}}\\nested\\nested"
|
|
- "{{win_stat_dir}}\\shared"
|
|
- "{{win_stat_dir}}\\hidden"
|
|
- "{{win_stat_dir}}\\link-dest"
|
|
- "{{win_stat_dir}}\\junction-dest"
|
|
|
|
- name: create empty test files
|
|
win_file:
|
|
path: "{{item}}"
|
|
state: touch
|
|
with_items:
|
|
- "{{win_stat_dir}}\\nested\\file.ps1"
|
|
- "{{win_stat_dir}}\\nested\\read-only.ps1"
|
|
- "{{win_stat_dir}}\\nested\\archive.ps1"
|
|
- "{{win_stat_dir}}\\nested\\hidden.ps1"
|
|
- "{{win_stat_dir}}\\nested\\nested\\file.ps1"
|
|
- "{{win_stat_dir}}\\folder space\\file.ps1"
|
|
|
|
- name: populate files with a test string
|
|
win_lineinfile:
|
|
dest: "{{item}}"
|
|
line: abc
|
|
with_items:
|
|
- "{{win_stat_dir}}\\nested\\file.ps1"
|
|
- "{{win_stat_dir}}\\nested\\read-only.ps1"
|
|
- "{{win_stat_dir}}\\nested\\archive.ps1"
|
|
- "{{win_stat_dir}}\\nested\\hidden.ps1"
|
|
- "{{win_stat_dir}}\\nested\\nested\\file.ps1"
|
|
- "{{win_stat_dir}}\\folder space\\file.ps1"
|
|
|
|
- name: create share
|
|
script: setup_share.ps1 {{win_stat_dir}}\shared
|
|
|
|
- name: create links
|
|
win_command: cmd.exe /c mklink /{{item.type}} {{item.source}} {{item.target}}
|
|
with_items:
|
|
- { type: 'D', source: "{{win_stat_dir}}\\link", target: "{{win_stat_dir}}\\link-dest" }
|
|
- { type: 'H', source: "{{win_stat_dir}}\\nested\\hard-link.ps1", target: "{{win_stat_dir}}\\nested\\file.ps1" }
|
|
- { type: 'J', source: "{{win_stat_dir}}\\junction-link", target: "{{win_stat_dir}}\\junction-dest" }
|
|
|
|
- name: set modification date on files/folders
|
|
script: set_filedate.ps1 "{{item}}"
|
|
with_items:
|
|
- "{{win_stat_dir}}\\nested\\file.ps1"
|
|
- "{{win_stat_dir}}\\nested\\read-only.ps1"
|
|
- "{{win_stat_dir}}\\nested\\archive.ps1"
|
|
- "{{win_stat_dir}}\\nested\\hidden.ps1"
|
|
- "{{win_stat_dir}}\\nested\\nested\\file.ps1"
|
|
- "{{win_stat_dir}}\\folder space\\file.ps1"
|
|
- "{{win_stat_dir}}\\folder"
|
|
- "{{win_stat_dir}}\\folder space"
|
|
- "{{win_stat_dir}}\\nested"
|
|
- "{{win_stat_dir}}\\nested\\nested"
|
|
- "{{win_stat_dir}}\\shared"
|
|
- "{{win_stat_dir}}\\hidden"
|
|
- "{{win_stat_dir}}\\link-dest"
|
|
- "{{win_stat_dir}}\\junction-dest"
|
|
|
|
- name: set file attributes for test
|
|
script: set_attributes.ps1 {{item.path}} {{item.attr}}
|
|
with_items:
|
|
- { path: "{{win_stat_dir}}\\hidden", attr: "Hidden" }
|
|
- { path: "{{win_stat_dir}}\\nested\\read-only.ps1", attr: "ReadOnly" }
|
|
- { path: "{{win_stat_dir}}\\nested\\archive.ps1", attr: "Archive" }
|
|
- { path: "{{win_stat_dir}}\\nested\\hidden.ps1", attr: "Hidden" }
|
|
# End setup of test files
|
|
|
|
- name: test win_stat module on file
|
|
win_stat:
|
|
path: "{{win_output_dir}}\\win_stat\\nested\\file.ps1"
|
|
register: actual
|
|
|
|
- name: set expected fact for file
|
|
set_fact:
|
|
expected:
|
|
changed: False
|
|
stat:
|
|
attributes: Archive
|
|
checksum: 5943831380243c1269c8b68bb92de6e2f1844590
|
|
creationtime: 1477984205
|
|
exists: True
|
|
extension: .ps1
|
|
filename: file.ps1
|
|
isarchive: True
|
|
isdir: False
|
|
ishidden: False
|
|
islink: False
|
|
isreadonly: False
|
|
isshared: False
|
|
lastaccesstime: 1477984205
|
|
lastwritetime: 1477984205
|
|
md5: c627105fad747457b7e88ed1016e065f
|
|
owner: BUILTIN\Administrators
|
|
path: "{{win_output_dir}}\\win_stat\\nested\\file.ps1"
|
|
size: 8
|
|
|
|
- name: check actual for file
|
|
assert:
|
|
that:
|
|
- "actual == expected"
|
|
|
|
- name: test win_stat module on file without md5
|
|
win_stat:
|
|
path: "{{win_output_dir}}\\win_stat\\nested\\file.ps1"
|
|
get_md5: False
|
|
register: actual
|
|
|
|
- name: set expected fact for file without md5
|
|
set_fact:
|
|
expected:
|
|
changed: False
|
|
stat:
|
|
attributes: Archive
|
|
checksum: 5943831380243c1269c8b68bb92de6e2f1844590
|
|
creationtime: 1477984205
|
|
exists: True
|
|
extension: .ps1
|
|
filename: file.ps1
|
|
isarchive: True
|
|
isdir: False
|
|
ishidden: False
|
|
islink: False
|
|
isreadonly: False
|
|
isshared: False
|
|
lastaccesstime: 1477984205
|
|
lastwritetime: 1477984205
|
|
owner: BUILTIN\Administrators
|
|
path: "{{win_output_dir}}\\win_stat\\nested\\file.ps1"
|
|
size: 8
|
|
|
|
- name: check actual for file without md5
|
|
assert:
|
|
that:
|
|
- "actual == expected"
|
|
|
|
- name: test win_stat module on file with sha256
|
|
win_stat:
|
|
path: "{{win_output_dir}}\\win_stat\\nested\\file.ps1"
|
|
checksum_algorithm: sha256
|
|
register: actual
|
|
|
|
- name: set expected fact for file with sha256
|
|
set_fact:
|
|
expected:
|
|
changed: False
|
|
stat:
|
|
attributes: Archive
|
|
checksum: aec4cd5ed4c05ed5cf9dea5a8b30f5e655ad87b937b36e3c059840ce3cf3642f
|
|
creationtime: 1477984205
|
|
exists: True
|
|
extension: .ps1
|
|
filename: file.ps1
|
|
isarchive: True
|
|
isdir: False
|
|
ishidden: False
|
|
islink: False
|
|
isreadonly: False
|
|
isshared: False
|
|
lastaccesstime: 1477984205
|
|
lastwritetime: 1477984205
|
|
md5: c627105fad747457b7e88ed1016e065f
|
|
owner: BUILTIN\Administrators
|
|
path: "{{win_output_dir}}\\win_stat\\nested\\file.ps1"
|
|
size: 8
|
|
|
|
- name: check actual for file with sha256
|
|
assert:
|
|
that:
|
|
- "actual == expected"
|
|
|
|
- name: test win_stat module on file with sha384
|
|
win_stat:
|
|
path: "{{win_output_dir}}\\win_stat\\nested\\file.ps1"
|
|
checksum_algorithm: sha384
|
|
register: actual
|
|
|
|
- name: set expected fact for file with sha384
|
|
set_fact:
|
|
expected:
|
|
changed: False
|
|
stat:
|
|
attributes: Archive
|
|
checksum: 862076ed4ef117cb61395daa839ccfe20a880e8cd048e76b3b1503d39d72f4c09d58ab3c44cdd5a3272ca8da9d8d8666
|
|
creationtime: 1477984205
|
|
exists: True
|
|
extension: .ps1
|
|
filename: file.ps1
|
|
isarchive: True
|
|
isdir: False
|
|
ishidden: False
|
|
islink: False
|
|
isreadonly: False
|
|
isshared: False
|
|
lastaccesstime: 1477984205
|
|
lastwritetime: 1477984205
|
|
md5: c627105fad747457b7e88ed1016e065f
|
|
owner: BUILTIN\Administrators
|
|
path: "{{win_output_dir}}\\win_stat\\nested\\file.ps1"
|
|
size: 8
|
|
|
|
- name: check actual for file with sha384
|
|
assert:
|
|
that:
|
|
- "actual == expected"
|
|
|
|
- name: test win_stat module on file with sha512
|
|
win_stat:
|
|
path: "{{win_output_dir}}\\win_stat\\nested\\file.ps1"
|
|
checksum_algorithm: sha512
|
|
register: actual
|
|
|
|
- name: set expected fact for file with sha512
|
|
set_fact:
|
|
expected:
|
|
changed: False
|
|
stat:
|
|
attributes: Archive
|
|
checksum: 6d821d068cd8f09582de9ef14550666547eb6d4ae1d34cfc5aea921e595dbb9c462bf7f4c88a90190a69e52d69ac157e8146b555ed679a3e997061ca69632d0f
|
|
creationtime: 1477984205
|
|
exists: True
|
|
extension: .ps1
|
|
filename: file.ps1
|
|
isarchive: True
|
|
isdir: False
|
|
ishidden: False
|
|
islink: False
|
|
isreadonly: False
|
|
isshared: False
|
|
lastaccesstime: 1477984205
|
|
lastwritetime: 1477984205
|
|
md5: c627105fad747457b7e88ed1016e065f
|
|
owner: BUILTIN\Administrators
|
|
path: "{{win_output_dir}}\\win_stat\\nested\\file.ps1"
|
|
size: 8
|
|
|
|
- name: check actual for file with sha512
|
|
assert:
|
|
that:
|
|
- "actual == expected"
|
|
|
|
- name: test win_stat on hidden file
|
|
win_stat:
|
|
path: "{{win_output_dir}}\\win_stat\\nested\\hidden.ps1"
|
|
register: actual
|
|
|
|
- name: set expected fact for hidden file
|
|
set_fact:
|
|
expected:
|
|
changed: False
|
|
stat:
|
|
attributes: "Hidden, Archive"
|
|
checksum: 5943831380243c1269c8b68bb92de6e2f1844590
|
|
creationtime: 1477984205
|
|
exists: True
|
|
extension: .ps1
|
|
filename: hidden.ps1
|
|
isarchive: True
|
|
isdir: False
|
|
ishidden: True
|
|
islink: False
|
|
isreadonly: False
|
|
isshared: False
|
|
lastaccesstime: 1477984205
|
|
lastwritetime: 1477984205
|
|
md5: c627105fad747457b7e88ed1016e065f
|
|
owner: BUILTIN\Administrators
|
|
path: "{{win_output_dir}}\\win_stat\\nested\\hidden.ps1"
|
|
size: 8
|
|
|
|
- name: check actual for hidden file
|
|
assert:
|
|
that:
|
|
- "actual == expected"
|
|
|
|
- name: test win_stat on readonly file
|
|
win_stat:
|
|
path: "{{win_output_dir}}\\win_stat\\nested\\read-only.ps1"
|
|
register: actual
|
|
|
|
- name: set expected fact for readonly file
|
|
set_fact:
|
|
expected:
|
|
changed: False
|
|
stat:
|
|
attributes: "ReadOnly, Archive"
|
|
checksum: 5943831380243c1269c8b68bb92de6e2f1844590
|
|
creationtime: 1477984205
|
|
exists: True
|
|
extension: .ps1
|
|
filename: read-only.ps1
|
|
isarchive: True
|
|
isdir: False
|
|
ishidden: False
|
|
islink: False
|
|
isreadonly: True
|
|
isshared: False
|
|
lastaccesstime: 1477984205
|
|
lastwritetime: 1477984205
|
|
md5: c627105fad747457b7e88ed1016e065f
|
|
owner: BUILTIN\Administrators
|
|
path: "{{win_output_dir}}\\win_stat\\nested\\read-only.ps1"
|
|
size: 8
|
|
|
|
- name: check actual for readonly file
|
|
assert:
|
|
that:
|
|
- "actual == expected"
|
|
|
|
- name: test win_stat on hard link file
|
|
win_stat:
|
|
path: "{{win_output_dir}}\\win_stat\\nested\\hard-link.ps1"
|
|
register: actual
|
|
|
|
- name: set expected fact for hard link file
|
|
set_fact:
|
|
expected:
|
|
changed: False
|
|
stat:
|
|
attributes: Archive
|
|
checksum: 5943831380243c1269c8b68bb92de6e2f1844590
|
|
creationtime: 1477984205
|
|
exists: True
|
|
extension: .ps1
|
|
filename: hard-link.ps1
|
|
isarchive: True
|
|
isdir: False
|
|
ishidden: False
|
|
islink: False
|
|
isreadonly: False
|
|
isshared: False
|
|
lastaccesstime: 1477984205
|
|
lastwritetime: 1477984205
|
|
md5: c627105fad747457b7e88ed1016e065f
|
|
owner: BUILTIN\Administrators
|
|
path: "{{win_output_dir}}\\win_stat\\nested\\hard-link.ps1"
|
|
size: 8
|
|
|
|
- name: check actual for hard link file
|
|
assert:
|
|
that:
|
|
- "actual == expected"
|
|
|
|
- name: test win_stat on directory
|
|
win_stat:
|
|
path: "{{win_output_dir}}\\win_stat\\nested"
|
|
register: actual
|
|
|
|
- name: set expected fact for directory
|
|
set_fact:
|
|
expected:
|
|
changed: False
|
|
stat:
|
|
attributes: Directory
|
|
creationtime: 1477984205
|
|
exists: True
|
|
filename: nested
|
|
isarchive: False
|
|
isdir: True
|
|
ishidden: False
|
|
islink: False
|
|
isreadonly: False
|
|
isshared: False
|
|
lastaccesstime: 1477984205
|
|
lastwritetime: 1477984205
|
|
owner: BUILTIN\Administrators
|
|
path: "{{win_output_dir}}\\win_stat\\nested"
|
|
size: 40
|
|
|
|
- name: check actual for directory
|
|
assert:
|
|
that:
|
|
- "actual == expected"
|
|
|
|
- name: test win_stat on empty directory
|
|
win_stat:
|
|
path: "{{win_output_dir}}\\win_stat\\folder"
|
|
register: actual
|
|
|
|
- name: set expected fact for empty directory
|
|
set_fact:
|
|
expected:
|
|
changed: False
|
|
stat:
|
|
attributes: Directory
|
|
creationtime: 1477984205
|
|
exists: True
|
|
filename: folder
|
|
isarchive: False
|
|
isdir: True
|
|
ishidden: False
|
|
islink: False
|
|
isreadonly: False
|
|
isshared: False
|
|
lastaccesstime: 1477984205
|
|
lastwritetime: 1477984205
|
|
owner: BUILTIN\Administrators
|
|
path: "{{win_output_dir}}\\win_stat\\folder"
|
|
size: 0
|
|
|
|
- name: check actual for empty directory
|
|
assert:
|
|
that:
|
|
- "actual == expected"
|
|
|
|
- name: test win_stat on directory with space in name
|
|
win_stat:
|
|
path: "{{win_output_dir}}\\win_stat\\folder space"
|
|
register: actual
|
|
|
|
- name: set expected fact for directory with space in name
|
|
set_fact:
|
|
expected:
|
|
changed: False
|
|
stat:
|
|
attributes: Directory
|
|
creationtime: 1477984205
|
|
exists: True
|
|
filename: folder space
|
|
isarchive: False
|
|
isdir: True
|
|
ishidden: False
|
|
islink: False
|
|
isreadonly: False
|
|
isshared: False
|
|
lastaccesstime: 1477984205
|
|
lastwritetime: 1477984205
|
|
owner: BUILTIN\Administrators
|
|
path: "{{win_output_dir}}\\win_stat\\folder space"
|
|
size: 8
|
|
|
|
- name: check actual for directory with space in name
|
|
assert:
|
|
that:
|
|
- "actual == expected"
|
|
|
|
- name: test win_stat on hidden directory
|
|
win_stat:
|
|
path: "{{win_output_dir}}\\win_stat\\hidden"
|
|
register: actual
|
|
|
|
- name: set expected fact for hidden directory
|
|
set_fact:
|
|
expected:
|
|
changed: False
|
|
stat:
|
|
attributes: "Hidden, Directory"
|
|
creationtime: 1477984205
|
|
exists: True
|
|
filename: hidden
|
|
isarchive: False
|
|
isdir: True
|
|
ishidden: True
|
|
islink: False
|
|
isreadonly: False
|
|
isshared: False
|
|
lastaccesstime: 1477984205
|
|
lastwritetime: 1477984205
|
|
owner: BUILTIN\Administrators
|
|
path: "{{win_output_dir}}\\win_stat\\hidden"
|
|
size: 0
|
|
|
|
- name: check actual for hidden directory
|
|
assert:
|
|
that:
|
|
- "actual == expected"
|
|
|
|
- name: test win_stat on shared directory
|
|
win_stat:
|
|
path: "{{win_output_dir}}\\win_stat\\shared"
|
|
register: actual
|
|
|
|
- name: set expected fact for shared directory
|
|
set_fact:
|
|
expected:
|
|
changed: False
|
|
stat:
|
|
attributes: Directory
|
|
creationtime: 1477984205
|
|
exists: True
|
|
filename: shared
|
|
isarchive: False
|
|
isdir: True
|
|
ishidden: False
|
|
islink: False
|
|
isreadonly: False
|
|
isshared: True
|
|
lastaccesstime: 1477984205
|
|
lastwritetime: 1477984205
|
|
owner: BUILTIN\Administrators
|
|
path: "{{win_output_dir}}\\win_stat\\shared"
|
|
sharename: folder-share
|
|
size: 0
|
|
|
|
- name: check actual for shared directory
|
|
assert:
|
|
that:
|
|
- "actual == expected"
|
|
|
|
- name: test win_stat on symlink
|
|
win_stat:
|
|
path: "{{win_output_dir}}\\win_stat\\link"
|
|
register: actual
|
|
|
|
# I cannot change modification time on links so we are resorting to checking the dict against known valuea
|
|
- name: assert symlink actual
|
|
assert:
|
|
that:
|
|
- "actual.stat.attributes == 'Directory, ReparsePoint'"
|
|
- "actual.stat.creationtime is defined"
|
|
- "actual.stat.exists == True"
|
|
- "actual.stat.filename == 'link'"
|
|
- "actual.stat.isarchive == False"
|
|
- "actual.stat.isdir == True"
|
|
- "actual.stat.ishidden == False"
|
|
- "actual.stat.islink == True"
|
|
- "actual.stat.isreadonly == False"
|
|
- "actual.stat.isshared == False"
|
|
- "actual.stat.lastaccesstime is defined"
|
|
- "actual.stat.lastwritetime is defined"
|
|
- "actual.stat.lnk_source == '{{win_output_dir|regex_replace('\\\\', '\\\\\\\\')}}\\\\win_stat\\\\link-dest'"
|
|
- "actual.stat.owner == 'BUILTIN\\Administrators'"
|
|
- "actual.stat.path == '{{win_output_dir|regex_replace('\\\\', '\\\\\\\\')}}\\\\win_stat\\\\link'"
|
|
- "actual.stat.size is not defined"
|
|
- "actual.stat.checksum is not defined"
|
|
- "actual.stat.md5 is not defined"
|
|
|
|
- name: test win_stat on junction
|
|
win_stat:
|
|
path: "{{win_output_dir}}\\win_stat\\junction-link"
|
|
register: actual
|
|
|
|
- name: assert symlink actual
|
|
assert:
|
|
that:
|
|
- "actual.stat.attributes == 'Directory, ReparsePoint'"
|
|
- "actual.stat.creationtime is defined"
|
|
- "actual.stat.exists == True"
|
|
- "actual.stat.filename == 'junction-link'"
|
|
- "actual.stat.isarchive == False"
|
|
- "actual.stat.isdir == True"
|
|
- "actual.stat.ishidden == False"
|
|
- "actual.stat.islink == True"
|
|
- "actual.stat.isreadonly == False"
|
|
- "actual.stat.isshared == False"
|
|
- "actual.stat.lastaccesstime is defined"
|
|
- "actual.stat.lastwritetime is defined"
|
|
- "actual.stat.lnk_source == '{{win_output_dir|regex_replace('\\\\', '\\\\\\\\')}}\\\\win_stat\\\\junction-dest'"
|
|
- "actual.stat.owner == 'BUILTIN\\Administrators'"
|
|
- "actual.stat.path == '{{win_output_dir|regex_replace('\\\\', '\\\\\\\\')}}\\\\win_stat\\\\junction-link'"
|
|
- "actual.stat.size is not defined"
|
|
- "actual.stat.checksum is not defined"
|
|
- "actual.stat.md5 is not defined"
|
|
|
|
- name: test win_stat module non-existent path
|
|
win_stat:
|
|
path: "{{win_output_dir}}\\win_stat\\this_file_should_not_exist"
|
|
register: win_stat_missing
|
|
|
|
- name: check win_stat missing result
|
|
assert:
|
|
that:
|
|
- "not win_stat_missing.stat.exists"
|
|
- "not win_stat_missing|failed"
|
|
- "not win_stat_missing|changed"
|
|
|
|
- name: test win_stat module without path argument
|
|
action: win_stat
|
|
register: win_stat_no_args
|
|
ignore_errors: true
|
|
|
|
- name: check win_stat result with no path argument
|
|
assert:
|
|
that:
|
|
- "win_stat_no_args|failed"
|
|
- "win_stat_no_args.msg"
|
|
- "not win_stat_no_args|changed"
|
|
|
|
- name: check if junction symbolic link exists
|
|
win_stat:
|
|
path: "{{win_output_dir}}\\win_stat\\junction-link"
|
|
register: junction_link_exists
|
|
|
|
- name: delete junction symbolic link if it exists
|
|
win_command: cmd.exe /c rmdir {{win_output_dir}}\win_stat\junction-link
|
|
when: junction_link_exists.stat.exists
|
|
|
|
- name: check if symbolic link exists
|
|
win_stat:
|
|
path: "{{win_output_dir}}\\win_stat\\link"
|
|
register: nested_link_exists
|
|
|
|
- name: delete nested symbolic link if it exists
|
|
win_shell: cmd.exe /c rmdir {{win_output_dir}}\win_stat\link
|
|
when: nested_link_exists.stat.exists
|
|
|
|
- name: remove testing folder
|
|
win_file:
|
|
path: "{{win_output_dir}}\\win_stat"
|
|
state: absent
|