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:
parent
c7662d8b2f
commit
74a3eec1d9
3 changed files with 39 additions and 12 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- "win_format - Idem not working if file exist but same fs (https://github.com/ansible/ansible/issues/58302)"
|
|
@ -142,20 +142,27 @@ $ansible_partition = Get-Partition -Volume $ansible_volume
|
||||||
|
|
||||||
foreach ($access_path in $ansible_partition.AccessPaths) {
|
foreach ($access_path in $ansible_partition.AccessPaths) {
|
||||||
if ($access_path -ne $Path) {
|
if ($access_path -ne $Path) {
|
||||||
$files_in_volume = (Get-ChildItem -LiteralPath $access_path -ErrorAction SilentlyContinue | Measure-Object).Count
|
if ($null -ne $file_system -and
|
||||||
|
-not [string]::IsNullOrEmpty($ansible_file_system) -and
|
||||||
if (-not $force_format -and $files_in_volume -gt 0) {
|
$file_system -ne $ansible_file_system)
|
||||||
$module.FailJson("Force format must be specified to format non-pristine volumes")
|
{
|
||||||
} else {
|
if (-not $force_format)
|
||||||
if (-not $force_format -and
|
{
|
||||||
-not $null -eq $file_system -and
|
$no_files_in_volume = (Get-ChildItem -LiteralPath $access_path -ErrorAction SilentlyContinue | Measure-Object).Count -eq 0
|
||||||
-not [string]::IsNullOrEmpty($ansible_file_system) -and
|
if($no_files_in_volume)
|
||||||
$file_system -ne $ansible_file_system) {
|
{
|
||||||
$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())")
|
$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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,6 +112,22 @@
|
||||||
- not_pristine_forced_idem_fails is changed
|
- not_pristine_forced_idem_fails is changed
|
||||||
- not_pristine_forced_idem is not 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
|
- name: Add a file
|
||||||
win_file:
|
win_file:
|
||||||
path: T:\path\to\directory
|
path: T:\path\to\directory
|
||||||
|
@ -121,6 +137,7 @@
|
||||||
- name: Format volume with file inside without force
|
- name: Format volume with file inside without force
|
||||||
win_format:
|
win_format:
|
||||||
path: "{{ shell_partition_result.stdout | trim }}"
|
path: "{{ shell_partition_result.stdout | trim }}"
|
||||||
|
file_system: refs
|
||||||
register: format_volume_without_force
|
register: format_volume_without_force
|
||||||
ignore_errors: True
|
ignore_errors: True
|
||||||
|
|
||||||
|
@ -134,5 +151,6 @@
|
||||||
that:
|
that:
|
||||||
- add_file_to_volume is changed
|
- add_file_to_volume is changed
|
||||||
- format_volume_without_force is failed
|
- 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_without_force.msg == "Force format must be specified to format non-pristine volumes"'
|
||||||
- format_volume_with_force is changed
|
- format_volume_with_force is changed
|
||||||
|
|
Loading…
Reference in a new issue