1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/test/integration/targets/win_stat/tasks/main.yml

639 lines
18 KiB
YAML
Raw Normal View History

2014-06-19 18:20:11 +02:00
# 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
2014-06-19 18:20:11 +02:00
- 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: a9993e364706816aba3e25717850c26c9cd0d89d
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: 900150983cd24fb0d6963f7d28e17f72
owner: BUILTIN\Administrators
path: "{{win_output_dir}}\\win_stat\\nested\\file.ps1"
size: 3
- 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: a9993e364706816aba3e25717850c26c9cd0d89d
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: 3
- 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: ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
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: 900150983cd24fb0d6963f7d28e17f72
owner: BUILTIN\Administrators
path: "{{win_output_dir}}\\win_stat\\nested\\file.ps1"
size: 3
- 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: cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7
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: 900150983cd24fb0d6963f7d28e17f72
owner: BUILTIN\Administrators
path: "{{win_output_dir}}\\win_stat\\nested\\file.ps1"
size: 3
- 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: ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f
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: 900150983cd24fb0d6963f7d28e17f72
owner: BUILTIN\Administrators
path: "{{win_output_dir}}\\win_stat\\nested\\file.ps1"
size: 3
- 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: a9993e364706816aba3e25717850c26c9cd0d89d
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: 900150983cd24fb0d6963f7d28e17f72
owner: BUILTIN\Administrators
path: "{{win_output_dir}}\\win_stat\\nested\\hidden.ps1"
size: 3
- 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: a9993e364706816aba3e25717850c26c9cd0d89d
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: 900150983cd24fb0d6963f7d28e17f72
owner: BUILTIN\Administrators
path: "{{win_output_dir}}\\win_stat\\nested\\read-only.ps1"
size: 3
- 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: a9993e364706816aba3e25717850c26c9cd0d89d
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: 900150983cd24fb0d6963f7d28e17f72
owner: BUILTIN\Administrators
path: "{{win_output_dir}}\\win_stat\\nested\\hard-link.ps1"
size: 3
- 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: 15
- 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: 3
- 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"
2014-06-19 18:20:11 +02:00
- name: test win_stat module non-existent path
win_stat:
path: "{{win_output_dir}}\\win_stat\\this_file_should_not_exist"
2014-06-19 18:20:11 +02:00
register: win_stat_missing
- name: check win_stat missing result
assert:
2014-06-19 18:20:11 +02:00
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
2014-06-19 18:20:11 +02:00
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