Debian Codegraph @

ansible_collections/community/libvirt/tests/integration/targets/virt_volume/tasks/main.yml

raw
1 ---
2 - include_vars: '{{ item }}'
3 with_first_found:
4 - "{{ ansible_distribution }}-{{ ansible_distribution_version}}.yml"
5 - "{{ ansible_distribution }}-{{ ansible_distribution_major_version}}.yml"
6 - "{{ ansible_distribution }}.yml"
7 - "default.yml"
8
9 - block:
10 #
11 # Initialisation tasks
12 #
13 - name: Install libvirt packages
14 package:
15 name: "{{ virt_volume_packages }}"
16
17 - name: Install pip packages
18 ansible.builtin.pip:
19 name: "{{ virt_volume_pip_packages }}"
20 state: present
21
22 - name: Start libvirt
23 service:
24 name: libvirtd
25 state: started
26
27 - name: Create Storage Pool Dir
28 file:
29 path: /var/lib/virt/images
30 state: directory
31 recurse: yes
32
33 - name: Define the foobar storage pool
34 community.libvirt.virt_pool:
35 command: define
36 name: "{{ pool_name }}"
37 xml: '{{ lookup("template", "pool_definition.xml.j2") }}'
38
39 - name: Start the default pool
40 community.libvirt.virt_pool:
41 state: active
42 name: "{{ pool_name }}"
43
44 #
45 # Tests for volume create and delete (and list_volumes)
46 #
47 - name: Create volume (using state=present)
48 community.libvirt.virt_volume:
49 pool: "{{ pool_name }}"
50 state: present
51 xml: '{{ lookup("template", "volume_definition.xml.j2") }}'
52 vars:
53 v__volume: "{{volume_name}}"
54
55 - name: List volumes
56 community.libvirt.virt_volume:
57 pool: "{{ pool_name }}"
58 command: list_volumes
59 register: r__list_volumes1
60
61 - name: Assert that volume is created
62 assert: { that: [ volume_name in r__list_volumes1.list_volumes | map(attribute='name') | list ] }
63
64 - name: Create volume again (using state)
65 community.libvirt.virt_volume:
66 pool: "{{ pool_name }}"
67 state: present
68 xml: '{{ lookup("template", "volume_definition.xml.j2") }}'
69 vars:
70 v__volume: "{{volume_name}}"
71 register: create_test1_2
72
73 - name: Ensure the second calls return "unchanged"
74 assert: { that: [ create_test1_2 is not changed ] }
75
76 - name: Delete volume (using state=absent)
77 community.libvirt.virt_volume:
78 pool: "{{ pool_name }}"
79 state: absent
80 name: "{{ volume_name }}"
81
82 - name: List volumes
83 community.libvirt.virt_volume:
84 pool: "{{ pool_name }}"
85 command: list_volumes
86 register: r__list_volumes2
87
88 - name: Assert that volume is removed
89 assert: { that: [ volume_name not in r__list_volumes2.list_volumes | map(attribute='name') | list ] }
90
91 - name: Create volume (using command=create)
92 community.libvirt.virt_volume:
93 pool: "{{ pool_name }}"
94 command: create
95 xml: '{{ lookup("template", "volume_definition.xml.j2") }}'
96 vars:
97 v__volume: "{{volume_name}}"
98
99 - name: List volumes
100 community.libvirt.virt_volume:
101 pool: "{{ pool_name }}"
102 command: list_volumes
103 register: r__list_volumes3
104
105 - name: Assert that volume is created
106 assert: { that: [ volume_name in r__list_volumes3.list_volumes | map(attribute='name') | list ] }
107
108 - name: Delete volume with a wipe first (using command=delete)
109 community.libvirt.virt_volume:
110 pool: "{{ pool_name }}"
111 command: delete
112 name: "{{ volume_name }}"
113 wipe: true
114
115 - name: List volumes
116 community.libvirt.virt_volume:
117 pool: "{{ pool_name }}"
118 command: list_volumes
119 register: r__list_volumes4
120
121 - name: Assert that volume is removed
122 assert: { that: [ volume_name not in r__list_volumes4.list_volumes | map(attribute='name') | list ] }
123
124 #
125 # Tests for volume create with clone_source
126 #
127 - name: Create a base volume for cloning
128 community.libvirt.virt_volume:
129 pool: "{{ pool_name }}"
130 state: present
131 xml: '{{ lookup("template", "volume_definition.xml.j2") }}'
132 register: r__virt_volume__create_base
133 vars:
134 v__volume: "{{volume_name}}"
135
136 - name: Clone the first volume to the second one
137 community.libvirt.virt_volume:
138 pool: "{{ pool_name }}"
139 state: present
140 xml: '{{ lookup("template", "volume_definition.xml.j2") }}'
141 clone_source: "{{ r__virt_volume__create_base.create.name }}"
142 vars:
143 v__volume: "{{volume_name_clone}}"
144
145 - name: List volumes after clone
146 community.libvirt.virt_volume:
147 pool: "{{ pool_name }}"
148 command: list_volumes
149 register: r__list_volumes5
150
151 - name: Assert that both volumes exist after cloning
152 assert:
153 that:
154 - volume_name in r__list_volumes5.list_volumes | map(attribute='name') | list
155 - volume_name_clone in r__list_volumes5.list_volumes | map(attribute='name') | list
156
157 - name: Wipe volumes
158 community.libvirt.virt_volume:
159 pool: "{{ pool_name }}"
160 command: wipe
161 name: "{{ item }}"
162 with_items:
163 - "{{ volume_name }}"
164 - "{{ volume_name_clone }}"
165
166 - name: Delete volumes
167 community.libvirt.virt_volume:
168 pool: "{{ pool_name }}"
169 command: delete
170 name: "{{ item }}"
171 with_items:
172 - "{{ volume_name }}"
173 - "{{ volume_name_clone }}"
174
175 #
176 # Tests for volume create_cidata_cdrom
177 #
178 - name: Create CIDATA (cloud-init) cdrom
179 community.libvirt.virt_volume:
180 pool: "default"
181 command: "create_cidata_cdrom"
182 name: "{{ volume_name_cidata }}"
183 cloudinit_config: '{{ lookup("template", "cidata.yml.j2") }}'
184 register: r__virt_volume__cidata_cdrom
185
186 - name: List volumes
187 community.libvirt.virt_volume:
188 pool: "{{ pool_name }}"
189 command: list_volumes
190 register: r__list_volumes6
191
192 - name: Assert that volume is created
193 assert: { that: [ volume_name_cidata in r__list_volumes6.list_volumes | map(attribute='name') | list ] }
194
195 - name: get_xml for volume
196 community.libvirt.virt_volume:
197 pool: "{{ pool_name }}"
198 command: get_xml
199 name: "{{ volume_name_cidata }}"
200 register: r__virt_volume__get_xml
201
202 - name: Assert that volume XML is valid
203 assert:
204 that:
205 - r__virt_volume__get_xml.get_xml is defined
206 - r__virt_volume__cidata_cdrom.create_cidata_cdrom.name in r__virt_volume__get_xml.get_xml
207
208 - name: Delete volume
209 community.libvirt.virt_volume:
210 pool: "{{ pool_name }}"
211 state: absent
212 name: "{{ r__virt_volume__cidata_cdrom.create_cidata_cdrom.name }}"
213
214 #
215 # Tests for volume resize
216 #
217 - name: Create volume (volume_initial_size)
218 community.libvirt.virt_volume:
219 pool: "{{ pool_name }}"
220 state: present
221 xml: '{{ lookup("template", "volume_definition.xml.j2") }}'
222 vars:
223 v__volume: "{{ volume_name }}"
224 size: "{{ volume_initial_size }}"
225
226 - name: Create on existing volume with the same size (volume_initial_size)
227 community.libvirt.virt_volume:
228 pool: "{{ pool_name }}"
229 state: present
230 xml: '{{ lookup("template", "volume_definition.xml.j2") }}'
231 vars:
232 v__volume: "{{ volume_name }}"
233 size: "{{ volume_initial_size }}"
234 register: r__virt_volume__create
235
236 - name: Resize existing volume (volume_new_size)
237 community.libvirt.virt_volume:
238 pool: "{{ pool_name }}"
239 state: present
240 xml: '{{ lookup("template", "volume_definition.xml.j2") }}'
241 vars:
242 v__volume: "{{ volume_name }}"
243 size: "{{ volume_new_size }}"
244 register: r__virt_volume__resize
245
246 - name: get_xml for volume
247 community.libvirt.virt_volume:
248 pool: "{{ pool_name }}"
249 command: get_xml
250 name: "{{ volume_name }}"
251 register: r__virt_volume__get_xml
252
253 - name: Assert
254 vars:
255 unit_multiplier:
256 bytes: 1
257 b: 1
258 k: 1024
259 m: 1048576
260 g: 1073741824
261 t: 1099511627776
262 new_size_bytes: "{{ volume_new_size * unit_multiplier[unit | lower] }}"
263 capacity: "<capacity unit='bytes'>{{ new_size_bytes }}</capacity>"
264 ansible.builtin.assert:
265 that:
266 - not r__virt_volume__create.changed
267 - r__virt_volume__resize.changed
268 - capacity in r__virt_volume__get_xml.get_xml
269
270 - name: Delete volume (using state=absent)
271 community.libvirt.virt_volume:
272 pool: "{{ pool_name }}"
273 state: absent
274 name: "{{ volume_name }}"
275
276 #
277 # Cleanup tasks for libvirt volume management
278 #
279 - name: Destroy the pool
280 community.libvirt.virt_pool:
281 command: destroy
282 name: "{{ pool_name }}"
283
284 - name: Delete the pool
285 community.libvirt.virt_pool:
286 command: delete
287 name: "{{ pool_name }}"
288
289 - name: Undefine the pool
290 community.libvirt.virt_pool:
291 command: undefine
292 name: "{{ pool_name }}"
293
294
295 always:
296 - name: Stop libvirt
297 service:
298 name: libvirtd
299 state: stopped
300
301 - name: Remove only the libvirt packages
302 package:
303 name: "{{ virt_volume_packages|select('match', '.*libvirt.*')|list }}"
304 state: absent