Debian Codegraph @

ansible_collections/cloudscale_ch/cloud/tests/integration/targets/custom_image/tasks/tests.yml

raw
1 ---
2 - name: Delete a non existent custom image by uuid
3 cloudscale_ch.cloud.custom_image:
4 uuid: '415caea5-da7c-4aaa-aaaa-ececd38fb8ea'
5 state: absent
6 register: delete
7 - name: Verify Delete a non existent custom image by uuid
8 assert:
9 that:
10 - delete is not changed
11
12 - name: Fail delete a non existent custom image by name
13 cloudscale_ch.cloud.custom_image:
14 name: this-image-is-non-existent
15 state: absent
16 register: delete
17 - name: Verify Fail delete a non existend custom image by name
18 assert:
19 that:
20 - delete is not changed
21
22 - name: Fail import a custom image without url
23 cloudscale_ch.cloud.custom_image:
24 name: "{{ cloudscale_resource_prefix }}-test-image"
25 state: present
26 slug: custom-ansible-image
27 zones: lpg1
28 user_data_handling: 'pass-through'
29 tags:
30 project: mars
31 source_format: raw
32 register: failed_import
33 ignore_errors: true
34 - name: Verify Fail import a custom image without url
35 assert:
36 that:
37 - failed_import is failed
38 - failed_import.msg.startswith('Cannot import a new image without url.')
39
40 - name: Import a custom image and wait for import
41 cloudscale_ch.cloud.custom_image:
42 name: "{{ cloudscale_resource_prefix }}-test-image"
43 state: present
44 slug: custom-ansible-image
45 url: "{{ image_url }}"
46 zones: lpg1
47 user_data_handling: 'pass-through'
48 tags:
49 project: mars
50 source_format: raw
51 register: image1
52 retries: 15
53 delay: 5
54 until: image1.import_status == 'success'
55 failed_when: image1.import_status == 'failed'
56 - name: Verify import a custom image and wait for import
57 assert:
58 that:
59 - image1.import_status == 'success'
60 - image1.name == cloudscale_resource_prefix + '-test-image'
61
62 - name: Import a custom image (idempotency)
63 cloudscale_ch.cloud.custom_image:
64 name: "{{ cloudscale_resource_prefix }}-test-image"
65 state: present
66 slug: custom-ansible-image
67 url: "{{ image_url }}"
68 zones: lpg1
69 user_data_handling: 'pass-through'
70 tags:
71 project: mars
72 source_format: raw
73 register: image
74 - name: Verify import a custom image (idempotency)
75 assert:
76 that:
77 - image is not changed
78 - image.name == cloudscale_resource_prefix + '-test-image'
79 - image.uuid == image1.uuid
80
81 - name: Import a custom image with bad url
82 cloudscale_ch.cloud.custom_image:
83 name: "{{ cloudscale_resource_prefix }}-test-image2"
84 state: present
85 slug: custom-ansible-image
86 url: "{{ image_url }}-non-existent"
87 zones: lpg1
88 user_data_handling: 'pass-through'
89 tags:
90 project: mars
91 source_format: raw
92 register: failed_import
93 ignore_errors: true
94 retries: 15
95 delay: 5
96 until: failed_import.import_status == 'failed'
97 failed_when: failed_import.import_status == 'failed'
98 - name: Verify Fail import a custom image with bad url
99 assert:
100 that:
101 - failed_import is failed
102 - failed_import.error_message.startswith('Expected HTTP 200, got HTTP 40')
103
104 - name: Import a custom image with bad url (idempotency)
105 cloudscale_ch.cloud.custom_image:
106 name: "{{ cloudscale_resource_prefix }}-test-image2"
107 state: present
108 slug: custom-ansible-image
109 url: "{{ image_url }}-non-existent"
110 zones: lpg1
111 user_data_handling: 'pass-through'
112 tags:
113 project: mars
114 source_format: raw
115 register: failed_import_idempotency
116 ignore_errors: true
117 retries: 15
118 delay: 5
119 until: failed_import_idempotency.import_status == 'failed'
120 failed_when: failed_import_idempotency.import_status == 'failed'
121 - name: Verify Fail import a custom image with bad url (idempotency)
122 assert:
123 that:
124 - failed_import_idempotency is failed
125 - failed_import_idempotency.error_message.startswith('Expected HTTP 200, got HTTP 40')
126 - failed_import.uuid == failed_import_idempotency.uuid
127
128 # This task should not loop like the ones above because otherwise each
129 # invocation in the loop will create a new import because of the "force_retry"
130 # parameter. It just check that a new import is created everything else is
131 # already covered above.
132 - name: Import a custom image with bad url (retry)
133 cloudscale_ch.cloud.custom_image:
134 name: "{{ cloudscale_resource_prefix }}-test-image2"
135 state: present
136 slug: custom-ansible-image
137 url: "{{ image_url }}-non-existent"
138 zones: lpg1
139 user_data_handling: 'pass-through'
140 tags:
141 project: mars
142 source_format: raw
143 force_retry: true
144 register: failed_import_retry
145 - name: Verify Fail import a custom image with bad url (retry)
146 assert:
147 that:
148 - failed_import.uuid != failed_import_retry.uuid
149
150 - name: Import a custom image and a failed import with that name exists
151 cloudscale_ch.cloud.custom_image:
152 name: "{{ cloudscale_resource_prefix }}-test-image2"
153 state: present
154 slug: custom-ansible-image
155 url: "{{ image_url }}"
156 zones: lpg1
157 user_data_handling: 'pass-through'
158 tags:
159 project: mars
160 source_format: raw
161 register: image2
162 - name: Verify import a custom image
163 assert:
164 that:
165 - image2 is changed
166 - image2.name == cloudscale_resource_prefix + '-test-image2'
167 - image2.uuid != image1.uuid
168
169 - name: Wait for import
170 cloudscale_ch.cloud.custom_image:
171 uuid: "{{ image2.uuid }}"
172 retries: 15
173 delay: 5
174 register: import_status
175 until: import_status.import_status == 'success'
176 failed_when: import_status.import_status == 'failed'
177 - name: Verify Wait for import
178 assert:
179 that:
180 - import_status is not changed
181 - import_status.name == cloudscale_resource_prefix + '-test-image2'
182
183 - name: Get image by name
184 cloudscale_ch.cloud.custom_image:
185 name: "{{ cloudscale_resource_prefix }}-test-image2"
186 register: image_by_name
187 - name: Verify get image by name
188 assert:
189 that:
190 - image_by_name is not changed
191 - image_by_name.uuid == image2.uuid
192
193 - name: Change the name of an image
194 cloudscale_ch.cloud.custom_image:
195 name: "{{ cloudscale_resource_prefix }}-test-image-with-a-new-name"
196 uuid: "{{ image2.uuid }}"
197 register: change_name
198 - name: Verify Change the name of an image
199 assert:
200 that:
201 - change_name.name == cloudscale_resource_prefix + '-test-image-with-a-new-name'
202 - change_name is changed
203
204 - name: Update slug of a custom image
205 cloudscale_ch.cloud.custom_image:
206 uuid: "{{ image2.uuid }}"
207 slug: ansible-image-slug
208 register: image
209 - name: Verify update slug of a custom image
210 assert:
211 that:
212 - image is changed
213 - image.slug == 'ansible-image-slug'
214
215 - name: Get custom image with updated slug
216 cloudscale_ch.cloud.custom_image:
217 uuid: "{{ image2.uuid }}"
218 register: image
219 - name: Verify update slug of a custom image
220 assert:
221 that:
222 - image.slug == 'ansible-image-slug'
223
224 - name: Update tags of a custom image
225 cloudscale_ch.cloud.custom_image:
226 uuid: "{{ image2.uuid }}"
227 tags:
228 project: luna
229 register: image
230 - name: Verify update tags of a custom image
231 assert:
232 that:
233 - image is changed
234 - image.tags.project == 'luna'
235
236 - name: Update user_data_handling of a custom image
237 cloudscale_ch.cloud.custom_image:
238 uuid: "{{ image2.uuid }}"
239 user_data_handling: 'extend-cloud-config'
240 register: image
241 - name: Verify update user_data_handling of a custom image
242 assert:
243 that:
244 - image is changed
245 - image.user_data_handling == 'extend-cloud-config'
246
247 - name: Get custom image with updated user_data_handling
248 cloudscale_ch.cloud.custom_image:
249 uuid: "{{ image2.uuid }}"
250 register: image
251 - name: Verify update user_data_handling of a custom image
252 assert:
253 that:
254 - image.user_data_handling == 'extend-cloud-config'
255
256 - name: Update slug, tags and user_data_handling of a custom image
257 cloudscale_ch.cloud.custom_image:
258 uuid: "{{ image2.uuid }}"
259 slug: yet-another-slug
260 tags:
261 project: jupiter
262 user_data_handling: 'pass-through'
263 register: image
264 - name: Verify update slug, tags and user_data_handling of a custom image
265 assert:
266 that:
267 - image is changed
268 - image.slug == 'yet-another-slug'
269 - image.tags.project == 'jupiter'
270 - image.user_data_handling == 'pass-through'
271
272 - name: List all custom images, there should be two
273 uri:
274 url: 'https://api.cloudscale.ch/v1/custom-images'
275 headers:
276 Authorization: 'Bearer {{ cloudscale_api_token }}'
277 status_code: 200
278 register: image_list
279 - name: Verify that two custom images are created by this test run
280 assert:
281 that:
282 - image_list.json | selectattr("name","search", cloudscale_resource_prefix) | list | length == 2
283
284 - name: Delete image by uuid
285 cloudscale_ch.cloud.custom_image:
286 uuid: "{{ image1.uuid }}"
287 state: absent
288 register: image1
289 - name: Verify delete image by uuid
290 assert:
291 that:
292 - image1 is changed
293 - image1.state == 'absent'
294
295 - name: Delete image by name
296 cloudscale_ch.cloud.custom_image:
297 name: "{{ change_name.name }}"
298 state: absent
299 register: image2
300 - name: Verify delete image by name
301 assert:
302 that:
303 - image2 is changed
304 - image2.state == 'absent'
305 - name: Check if all images got deleted
306 uri:
307 url: 'https://api.cloudscale.ch/v1/custom-images'
308 headers:
309 Authorization: 'Bearer {{ cloudscale_api_token }}'
310 status_code: 200
311 register: image_list
312 - name: Verify that the two custom images of this test run are deleted
313 assert:
314 that:
315 - image_list.json | selectattr("name","search", cloudscale_resource_prefix) | list | length == 0
316
317 - name: Import a custom image
318 cloudscale_ch.cloud.custom_image:
319 name: "{{ cloudscale_resource_prefix }}-test-image"
320 state: present
321 slug: custom-ansible-image
322 url: "{{ image_url }}"
323 zones: lpg1
324 user_data_handling: 'pass-through'
325 tags:
326 project: mars
327 source_format: raw
328 register: image1
329
330 - name: Import a custom for the second time (uri module)
331 uri:
332 url: 'https://api.cloudscale.ch/v1/custom-images/import'
333 method: POST
334 headers:
335 Authorization: 'Bearer {{ cloudscale_api_token }}'
336 body:
337 url: "{{ image_url }}"
338 name: "{{ cloudscale_resource_prefix }}-test-image"
339 slug: 'custom-ansible-image'
340 zones:
341 - 'rma1'
342 user_data_handling: 'pass-through'
343 tags:
344 project: 'mars'
345 source_format: 'raw'
346 body_format: json
347 status_code: 201
348 register: image2
349
350 - name: Wait for import of first image
351 cloudscale_ch.cloud.custom_image:
352 uuid: "{{ image1.uuid }}"
353 retries: 15
354 delay: 5
355 register: import_status
356 until: import_status.import_status == 'success'
357 failed_when: import_status.import_status == 'failed'
358
359 - name: Wait for import of second image
360 cloudscale_ch.cloud.custom_image:
361 uuid: "{{ image2.json.uuid }}"
362 retries: 15
363 delay: 5
364 register: import_status
365 until: import_status.import_status == 'success'
366 failed_when: import_status.import_status == 'failed'
367
368 - name: Fail get image by name when two exist
369 cloudscale_ch.cloud.custom_image:
370 name: "{{ cloudscale_resource_prefix }}-test-image"
371 register: failed_image_by_name
372 ignore_errors: true
373 - name: Verify Fail get image by name when two exist
374 assert:
375 that:
376 - failed_image_by_name is failed
377 - failed_image_by_name.msg.startswith("More than one custom-images resource with 'name' exists")
378
379 - name: Import a custom image with firmware type uefi and wait for import
380 cloudscale_ch.cloud.custom_image:
381 name: "{{ cloudscale_resource_prefix }}-test-image-uefi"
382 state: present
383 slug: custom-ansible-image-uefi
384 url: "{{ image_url }}"
385 zones: lpg1
386 user_data_handling: 'pass-through'
387 firmware_type: 'uefi'
388 source_format: raw
389 register: image1_uefi
390 retries: 15
391 delay: 5
392 until: image1_uefi.import_status == 'success'
393 failed_when: image1_uefi.import_status == 'failed'
394 - name: Verify import a custom image and wait for import
395 assert:
396 that:
397 - image1_uefi.import_status == 'success'
398 - image1_uefi.name == cloudscale_resource_prefix + '-test-image-uefi'
399
400 - name: Fail changing the firmware type of an already imported image from uefi to bios
401 cloudscale_ch.cloud.custom_image:
402 name: "{{ image1_uefi.name }}"
403 state: present
404 slug: "{{ image1_uefi.slug }}"
405 url: "{{ image_url }}"
406 zones: lpg1
407 user_data_handling: 'pass-through'
408 firmware_type: 'bios'
409 source_format: raw
410 register: fail_firmware_change
411 ignore_errors: true
412 - name: Verify firmware type change failed
413 assert:
414 that:
415 - fail_firmware_change is failed