Debian Codegraph @

ansible_collections/community/windows/tests/integration/targets/win_format/tasks/tests.yml

raw
1 ---
2 - ansible.windows.win_shell: $AnsiPart = Get-Partition -DriveLetter T; $AnsiVol = Get-Volume -DriveLetter T; "$($AnsiPart.Size),$($AnsiVol.Size)"
3 register: shell_result
4
5 - name: Assert volume size is 0 for pristine volume
6 assert:
7 that:
8 - shell_result.stdout | trim == "2096037888,0"
9
10 - name: Get partition access path
11 ansible.windows.win_shell: (Get-Partition -DriveLetter T).AccessPaths[1]
12 register: shell_partition_result
13
14 - name: Try to format using mutually exclusive parameters
15 win_format:
16 drive_letter: T
17 path: "{{ shell_partition_result.stdout | trim }}"
18 register: format_mutex_result
19 ignore_errors: True
20
21 - assert:
22 that:
23 - format_mutex_result is failed
24 - 'format_mutex_result.msg == "parameters are mutually exclusive: drive_letter, path, label"'
25
26 - name: Format volume and assign label (check)
27 win_format:
28 drive_letter: T
29 new_label: Formatted
30 # Fails on Server 2025 with generic error. May be fixed in a future update
31 # but for now we don't test this scenario.
32 # full: True
33 allocation_unit_size: 8192
34 register: format_result_check
35 check_mode: True
36
37 - ansible.windows.win_shell: $AnsiPart = Get-Partition -DriveLetter T; $AnsiVol = Get-Volume -DriveLetter T; "$($AnsiPart.Size),$($AnsiVol.Size),$($AnsiVol.FileSystemLabel),$((Get-CimInstance -ClassName Win32_Volume -Filter "DriveLetter = 'T:'" -Property BlockSize).BlockSize)"
38 register: formatted_value_result_check
39
40 - name: Format volume and assign label
41 win_format:
42 drive_letter: T
43 new_label: Formatted
44 # full: True
45 allocation_unit_size: 8192
46 register: format_result
47
48 - ansible.windows.win_shell: $AnsiPart = Get-Partition -DriveLetter T; $AnsiVol = Get-Volume -DriveLetter T; "$($AnsiPart.Size),$($AnsiVol.Size),$($AnsiVol.FileSystemLabel),$((Get-CimInstance -ClassName Win32_Volume -Filter "DriveLetter = 'T:'" -Property BlockSize).BlockSize)"
49 register: formatted_value_result
50
51 - assert:
52 that:
53 - format_result_check is changed
54 - format_result is changed
55 - formatted_value_result_check.stdout | trim == "2096037888,0,,"
56 - formatted_value_result.stdout | trim == "2096037888,2096029696,Formatted,8192"
57
58 - name: Format NTFS volume with integrity streams enabled
59 win_format:
60 path: "{{ shell_partition_result.stdout | trim }}"
61 file_system: ntfs
62 integrity_streams: True
63 ignore_errors: True
64 register: ntfs_integrity_streams
65
66 - assert:
67 that:
68 - ntfs_integrity_streams is failed
69 - 'ntfs_integrity_streams.msg == "Integrity streams can be enabled only on ReFS volumes. You specified: ntfs"'
70
71 - name: Format volume (require force_format for specifying different file system)
72 win_format:
73 path: "{{ shell_partition_result.stdout | trim }}"
74 file_system: fat32
75 ignore_errors: True
76 register: require_force_format
77
78 - assert:
79 that:
80 - require_force_format is failed
81 - 'require_force_format.msg == "Force format must be specified since target file system: fat32 is different from the current file system of the volume: ntfs"'
82
83 - name: Format volume (forced) (check)
84 win_format:
85 path: "{{ shell_partition_result.stdout | trim }}"
86 file_system: refs
87 force: True
88 check_mode: True
89 ignore_errors: True
90 register: not_pristine_forced_check
91
92 - name: Format volume (forced)
93 win_format:
94 path: "{{ shell_partition_result.stdout | trim }}"
95 file_system: refs
96 force: True
97 register: not_pristine_forced
98
99 - name: Format volume (forced) (idempotence will not work)
100 win_format:
101 path: "{{ shell_partition_result.stdout | trim }}"
102 file_system: refs
103 force: True
104 register: not_pristine_forced_idem_fails
105
106 - name: Format volume (idempotence)
107 win_format:
108 path: "{{ shell_partition_result.stdout | trim }}"
109 file_system: refs
110 register: not_pristine_forced_idem
111
112 - assert:
113 that:
114 - not_pristine_forced_check is changed
115 - not_pristine_forced is changed
116 - not_pristine_forced_idem_fails is changed
117 - not_pristine_forced_idem is not changed
118
119 - name: Add a file
120 ansible.windows.win_file:
121 path: T:\path\to\directory
122 state: directory
123
124 - name: Format volume with file inside without force and same fs
125 win_format:
126 path: "{{ shell_partition_result.stdout | trim }}"
127 register: format_volume_without_force_same_fs
128
129 - name: Format volume (forced) - to test case for files existing and a different fs
130 win_format:
131 path: "{{ shell_partition_result.stdout | trim }}"
132 file_system: ntfs
133 force: True
134
135 - name: Add a file
136 ansible.windows.win_file:
137 path: T:\path\to\directory
138 state: directory
139 register: add_file_to_volume
140
141 - name: Format volume with file inside without force
142 win_format:
143 path: "{{ shell_partition_result.stdout | trim }}"
144 file_system: refs
145 register: format_volume_without_force
146 ignore_errors: True
147
148 - name: Format volume with file inside with force
149 win_format:
150 path: "{{ shell_partition_result.stdout | trim }}"
151 force: True
152 register: format_volume_with_force
153
154 - assert:
155 that:
156 - add_file_to_volume is changed
157 - format_volume_without_force is failed
158 - format_volume_without_force_same_fs is not changed
159 - 'format_volume_without_force.msg == "Force format must be specified to format non-pristine volumes"'
160 - format_volume_with_force is changed
161
162 - name: Reformat using different alu without force format
163 win_format:
164 path: "{{ shell_partition_result.stdout | trim }}"
165 allocation_unit_size: 8192
166 file_system: ntfs
167 register: reformat_using_alu_without_force
168 ignore_errors: True
169
170 - assert:
171 that:
172 - reformat_using_alu_without_force is failed
173
174 - name: Reformat using different alu using force format
175 win_format:
176 path: "{{ shell_partition_result.stdout | trim }}"
177 allocation_unit_size: 8192
178 file_system: ntfs
179 force: True
180 register: reformat_using_alu_with_force
181
182 - assert:
183 that:
184 - reformat_using_alu_with_force is changed