win_format - Idem not working if file exist but same fs (#59819)

* win_format - Idem not working if file exist but same fs

* Test fix

* Fix test assertion syntax

* Update tests.yml
This commit is contained in:
Shachaf92 2019-09-16 05:45:44 +03:00 committed by ansibot
parent c7662d8b2f
commit 74a3eec1d9
3 changed files with 39 additions and 12 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- "win_format - Idem not working if file exist but same fs (https://github.com/ansible/ansible/issues/58302)"

View file

@ -142,19 +142,26 @@ $ansible_partition = Get-Partition -Volume $ansible_volume
foreach ($access_path in $ansible_partition.AccessPaths) {
if ($access_path -ne $Path) {
$files_in_volume = (Get-ChildItem -LiteralPath $access_path -ErrorAction SilentlyContinue | Measure-Object).Count
if (-not $force_format -and $files_in_volume -gt 0) {
$module.FailJson("Force format must be specified to format non-pristine volumes")
} else {
if (-not $force_format -and
-not $null -eq $file_system -and
if ($null -ne $file_system -and
-not [string]::IsNullOrEmpty($ansible_file_system) -and
$file_system -ne $ansible_file_system) {
$file_system -ne $ansible_file_system)
{
if (-not $force_format)
{
$no_files_in_volume = (Get-ChildItem -LiteralPath $access_path -ErrorAction SilentlyContinue | Measure-Object).Count -eq 0
if($no_files_in_volume)
{
$module.FailJson("Force format must be specified since target file system: $($file_system) is different from the current file system of the volume: $($ansible_file_system.ToLower())")
} else {
$pristine = $true
}
else
{
$module.FailJson("Force format must be specified to format non-pristine volumes")
}
}
}
else
{
$pristine = -not $force_format
}
}
}

View file

@ -112,6 +112,22 @@
- not_pristine_forced_idem_fails is changed
- not_pristine_forced_idem is not changed
- name: Add a file
win_file:
path: T:\path\to\directory
state: directory
- name: Format volume with file inside without force and same fs
win_format:
path: "{{ shell_partition_result.stdout | trim }}"
register: format_volume_without_force_same_fs
- name: Format volume (forced) - to test case for files existing and a different fs
win_format:
path: "{{ shell_partition_result.stdout | trim }}"
file_system: ntfs
force: True
- name: Add a file
win_file:
path: T:\path\to\directory
@ -121,6 +137,7 @@
- name: Format volume with file inside without force
win_format:
path: "{{ shell_partition_result.stdout | trim }}"
file_system: refs
register: format_volume_without_force
ignore_errors: True
@ -134,5 +151,6 @@
that:
- add_file_to_volume is changed
- format_volume_without_force is failed
- format_volume_without_force_same_fs is not changed
- 'format_volume_without_force.msg == "Force format must be specified to format non-pristine volumes"'
- format_volume_with_force is changed