Debian Codegraph @

ansible_collections/containers/podman/tests/integration/targets/podman_image/tasks/additional_tests.yml

raw
1 ---
2 - name: Additional podman_image tests
3 block:
4 # Authentication and certificate tests
5 - name: Test image pull with username/password (should fail gracefully)
6 containers.podman.podman_image:
7 executable: "{{ test_executable | default('podman') }}"
8 name: quay.io/testing/private-repo
9 username: invaliduser
10 password: invalidpass
11 validate_certs: false
12 register: auth_pull_result
13 ignore_errors: true
14
15 - name: Verify authentication failure is handled properly
16 assert:
17 that:
18 - auth_pull_result is failed
19 - auth_pull_result is not changed
20
21 # Test with auth_file parameter
22 - name: Create temporary auth file for testing
23 tempfile:
24 state: file
25 suffix: .json
26 register: auth_file
27
28 - name: Write valid JSON to auth file
29 copy:
30 content: "{}"
31 dest: "{{ auth_file.path }}"
32
33 - name: Test image pull with auth_file parameter
34 containers.podman.podman_image:
35 executable: "{{ test_executable | default('podman') }}"
36 name: quay.io/sshnaidm1/alpine:3.16
37 auth_file: "{{ auth_file.path }}"
38 register: auth_file_result
39
40 - name: Verify auth_file parameter works
41 assert:
42 that:
43 - auth_file_result is changed
44
45 # Test with ca_cert_dir parameter
46 - name: Test image pull with ca_cert_dir parameter
47 containers.podman.podman_image:
48 executable: "{{ test_executable | default('podman') }}"
49 name: quay.io/sshnaidm1/alpine:3.17
50 ca_cert_dir: /etc/ssl/certs
51 validate_certs: true
52 register: cert_dir_result
53
54 - name: Verify ca_cert_dir parameter works
55 assert:
56 that:
57 - cert_dir_result is changed
58
59 # Build tests with annotations and volume mounts
60 - name: Create directory for build context with annotations
61 file:
62 path: /tmp/build_annotations
63 state: directory
64
65 - name: Test build with annotations and volume mounts
66 containers.podman.podman_image:
67 executable: "{{ test_executable | default('podman') }}"
68 name: test-annotations
69 path: /tmp/build_annotations
70 build:
71 format: oci
72 annotation:
73 version: "1.0"
74 maintainer: "[email protected]"
75 description: "Test image with annotations"
76 volume:
77 - "/tmp:/host-tmp:ro"
78 - "/var/log:/host-logs"
79 container_file: |
80 FROM quay.io/sshnaidm1/alpine:latest
81 RUN echo "Testing annotations and volumes" > /tmp/test.txt
82 LABEL test=annotation-build
83 register: annotation_build
84
85 - name: Verify annotation build succeeded
86 assert:
87 that:
88 - annotation_build is changed
89 - "'Built image test-annotations:latest from' in annotation_build.actions[0]"
90
91 # Test idempotency with containerfile hash
92 - name: Build same image again (should not rebuild due to containerfile hash)
93 containers.podman.podman_image:
94 executable: "{{ test_executable | default('podman') }}"
95 name: test-annotations
96 path: /tmp/build_annotations
97 build:
98 format: oci
99 annotation:
100 version: "1.0"
101 maintainer: "[email protected]"
102 description: "Test image with annotations"
103 volume:
104 - "/tmp:/host-tmp:ro"
105 - "/var/log:/host-logs"
106 container_file: |
107 FROM quay.io/sshnaidm1/alpine:latest
108 RUN echo "Testing annotations and volumes" > /tmp/test.txt
109 LABEL test=annotation-build
110 register: annotation_build_idempotent
111
112 - name: Verify idempotency based on containerfile hash
113 assert:
114 that:
115 - annotation_build_idempotent is not changed
116
117 # Test force rebuild
118 - name: Force rebuild same image
119 containers.podman.podman_image:
120 executable: "{{ test_executable | default('podman') }}"
121 name: test-annotations
122 path: /tmp/build_annotations
123 force: true
124 build:
125 format: oci
126 annotation:
127 version: "1.0"
128 maintainer: "[email protected]"
129 description: "Test image with annotations"
130 volume:
131 - "/tmp:/host-tmp:ro"
132 - "/var/log:/host-logs"
133 container_file: |
134 FROM quay.io/sshnaidm1/alpine:latest
135 RUN echo "Testing annotations and volumes" > /tmp/test.txt
136 LABEL test=annotation-build
137 register: force_rebuild
138
139 - name: Verify force rebuild works
140 assert:
141 that:
142 - force_rebuild is changed
143 - "'Built image test-annotations:latest from' in force_rebuild.actions[0]"
144
145 # Test build with target stage
146 - name: Test multi-stage build with target
147 containers.podman.podman_image:
148 executable: "{{ test_executable | default('podman') }}"
149 name: test-multistage
150 state: build
151 build:
152 format: oci
153 target: runtime
154 container_file: |
155 FROM quay.io/sshnaidm1/alpine:latest AS builder
156 RUN echo "builder stage" > /tmp/builder.txt
157
158 FROM quay.io/sshnaidm1/alpine:latest AS runtime
159 COPY --from=builder /tmp/builder.txt /tmp/runtime.txt
160 RUN echo "runtime stage" >> /tmp/runtime.txt
161 register: multistage_build
162
163 - name: Verify multi-stage build with target works
164 assert:
165 that:
166 - multistage_build is changed
167 - "'Built image test-multistage:latest from' in multistage_build.actions[0]"
168
169 # Test build with extra_args
170 - name: Test build with extra arguments
171 containers.podman.podman_image:
172 executable: "{{ test_executable | default('podman') }}"
173 name: test-extra-args
174 state: build
175 build:
176 format: oci
177 extra_args: "--pull --no-cache"
178 container_file: |
179 FROM quay.io/sshnaidm1/alpine:latest
180 RUN echo "Testing extra args" > /tmp/extra.txt
181 register: extra_args_build
182
183 - name: Verify build with extra args works
184 assert:
185 that:
186 - extra_args_build is changed
187 - "'Built image test-extra-args:latest from' in extra_args_build.actions[0]"
188
189 # SCP transport tests
190 - name: Include scp transport tests
191 include_tasks: scp.yml
192
193 # Test push functionality with different transports
194 - name: Test push to directory transport
195 containers.podman.podman_image:
196 executable: "{{ test_executable | default('podman') }}"
197 name: test-annotations
198 pull: false
199 push: true
200 push_args:
201 dest: /tmp/push-test-dir
202 transport: dir
203 register: push_dir_result
204
205 - name: Verify push to directory works
206 assert:
207 that:
208 - push_dir_result is changed
209 - "'Pushed image test-annotations:latest' in push_dir_result.actions"
210
211 - name: Test push to oci-archive
212 containers.podman.podman_image:
213 executable: "{{ test_executable | default('podman') }}"
214 name: test-annotations
215 pull: false
216 push: true
217 push_args:
218 dest: /tmp/test-oci-export.tar
219 transport: oci-archive
220 register: push_oci_result
221
222 - name: Verify push to oci-archive works
223 assert:
224 that:
225 - push_oci_result is changed
226 - "'Pushed image test-annotations:latest' in push_oci_result.actions"
227
228 # Test pull with architecture specification
229 - name: Test pull with specific architecture
230 containers.podman.podman_image:
231 executable: "{{ test_executable | default('podman') }}"
232 name: docker.io/library/busybox
233 arch: amd64
234 tag: latest
235 register: arch_pull_result
236
237 - name: Verify architecture-specific pull
238 assert:
239 that:
240 - arch_pull_result is changed
241
242 # Test pull with extra arguments
243 - name: Test pull with extra arguments
244 containers.podman.podman_image:
245 executable: "{{ test_executable | default('podman') }}"
246 name: quay.io/sshnaidm1/alpine:3.18
247 pull_extra_args: "--quiet"
248 register: pull_extra_args_result
249
250 - name: Verify pull with extra args
251 assert:
252 that:
253 - pull_extra_args_result is changed
254
255 # Error handling tests
256 - name: Test pull non-existent image
257 containers.podman.podman_image:
258 executable: "{{ test_executable | default('podman') }}"
259 name: docker.io/nonexistent/imagethatdoesnotexist
260 tag: nonexistent
261 register: nonexistent_pull
262 ignore_errors: true
263
264 - name: Verify non-existent image pull fails properly
265 assert:
266 that:
267 - nonexistent_pull is failed
268 - nonexistent_pull is not changed
269
270 # Test build with missing containerfile
271 - name: Create empty directory for missing containerfile test
272 file:
273 path: /tmp/empty_build_dir
274 state: directory
275
276 - name: Test build with missing containerfile (should fail)
277 containers.podman.podman_image:
278 executable: "{{ test_executable | default('podman') }}"
279 name: test-missing-containerfile
280 path: /tmp/empty_build_dir
281 register: missing_containerfile
282 ignore_errors: true
283
284 - name: Verify missing containerfile fails properly
285 assert:
286 that:
287 - missing_containerfile is failed
288 - missing_containerfile is not changed
289
290 # Test conflicting build parameters
291 - name: Test build with conflicting file and container_file (should fail)
292 containers.podman.podman_image:
293 executable: "{{ test_executable | default('podman') }}"
294 name: test-conflict
295 state: build
296 build:
297 file: /tmp/some/file
298 container_file: |
299 FROM alpine
300 RUN echo "conflict test"
301 register: conflict_build
302 ignore_errors: true
303
304 - name: Verify conflicting build parameters fail
305 assert:
306 that:
307 - conflict_build is failed
308 - conflict_build is not changed
309 - "'Cannot specify both build file and container file content' in conflict_build.msg"
310
311 # Test removal by image ID
312 - name: Get image ID for removal test
313 containers.podman.podman_image_info:
314 executable: "{{ test_executable | default('podman') }}"
315 name: test-multistage
316 register: multistage_info
317
318 - name: Test removal by image ID
319 containers.podman.podman_image:
320 executable: "{{ test_executable | default('podman') }}"
321 name: "{{ multistage_info.images[0].Id }}"
322 state: absent
323 register: remove_by_id
324 when: multistage_info.images | length > 0
325
326 - name: Verify removal by ID works
327 assert:
328 that:
329 - remove_by_id is changed
330 - "'Removed image with ID' in remove_by_id.actions[0]"
331 when: multistage_info.images | length > 0
332
333 # Test image repository parsing edge cases
334 - name: Test image with digest
335 containers.podman.podman_image:
336 executable: "{{ test_executable | default('podman') }}"
337 name: "quay.io/sshnaidm1/alpine@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3"
338 register: digest_pull
339 ignore_errors: true
340
341 - name: Test image with port in registry name
342 containers.podman.podman_image:
343 executable: "{{ test_executable | default('podman') }}"
344 name: localhost:5000/test-image
345 tag: latest
346 register: port_registry
347 ignore_errors: true
348
349 # Test push failure scenarios
350 - name: Test push without pull and image doesn't exist
351 containers.podman.podman_image:
352 executable: "{{ test_executable | default('podman') }}"
353 name: nonexistent-local-image
354 pull: false
355 push: true
356 register: push_nonexistent
357 ignore_errors: true
358
359 - name: Verify push nonexistent image fails
360 assert:
361 that:
362 - push_nonexistent is failed
363 - push_nonexistent is not changed
364 - "'Image nonexistent-local-image:latest not found' in push_nonexistent.msg"
365 - "'pull is disabled' in push_nonexistent.msg"
366
367 # Test validate_certs parameter variations
368 - name: Test with validate_certs explicitly true
369 containers.podman.podman_image:
370 executable: "{{ test_executable | default('podman') }}"
371 name: quay.io/sshnaidm1/alpine:3.19
372 validate_certs: true
373 register: validate_true_result
374
375 - name: Test with validate_certs explicitly false
376 containers.podman.podman_image:
377 executable: "{{ test_executable | default('podman') }}"
378 name: quay.io/sshnaidm1/alpine:3.20
379 validate_certs: false
380 register: validate_false_result
381
382 - name: Verify validate_certs parameter works
383 assert:
384 that:
385 - validate_true_result is changed
386 - validate_false_result is changed
387
388 # Test containerfile hash changes trigger rebuild
389 - name: Create directory for hash change test
390 file:
391 path: /tmp/hash_change_test
392 state: directory
393
394 - name: Build image with first containerfile
395 containers.podman.podman_image:
396 executable: "{{ test_executable | default('podman') }}"
397 name: test-hash-change
398 path: /tmp/hash_change_test
399 build:
400 container_file: |
401 FROM quay.io/sshnaidm1/alpine:latest
402 RUN echo "version 1" > /tmp/version.txt
403 register: hash_build_1
404
405 - name: Build image with modified containerfile (should rebuild)
406 containers.podman.podman_image:
407 executable: "{{ test_executable | default('podman') }}"
408 name: test-hash-change
409 path: /tmp/hash_change_test
410 build:
411 container_file: |
412 FROM quay.io/sshnaidm1/alpine:latest
413 RUN echo "version 2" > /tmp/version.txt
414 register: hash_build_2
415
416 - name: Verify containerfile change triggers rebuild
417 assert:
418 that:
419 - hash_build_1 is changed
420 - hash_build_2 is changed
421 - "'Built image test-hash-change:latest from' in hash_build_1.actions[0]"
422 - "'Built image test-hash-change:latest from' in hash_build_2.actions[0]"
423
424 # Test build without cache
425 - name: Test build with cache disabled
426 containers.podman.podman_image:
427 executable: "{{ test_executable | default('podman') }}"
428 name: test-no-cache
429 state: build
430 build:
431 cache: false
432 container_file: |
433 FROM quay.io/sshnaidm1/alpine:latest
434 RUN echo "no cache build" > /tmp/nocache.txt
435 register: no_cache_build
436
437 - name: Verify no-cache build works
438 assert:
439 that:
440 - no_cache_build is changed
441 - "'Built image test-no-cache:latest from' in no_cache_build.actions[0]"
442
443 # Test build with force_rm
444 - name: Test build with force_rm option
445 containers.podman.podman_image:
446 executable: "{{ test_executable | default('podman') }}"
447 name: test-force-rm
448 state: build
449 build:
450 force_rm: true
451 container_file: |
452 FROM quay.io/sshnaidm1/alpine:latest
453 RUN echo "force rm test" > /tmp/forcerm.txt
454 register: force_rm_build
455
456 - name: Verify force_rm build works
457 assert:
458 that:
459 - force_rm_build is changed
460 - "'Built image test-force-rm:latest from' in force_rm_build.actions[0]"
461
462 # Test push with compress option
463 - name: Test push with compression
464 containers.podman.podman_image:
465 executable: "{{ test_executable | default('podman') }}"
466 name: test-force-rm
467 pull: false
468 push: true
469 push_args:
470 dest: /tmp/compressed-export.tar
471 transport: docker-archive
472 compress: true
473 register: compress_push
474
475 - name: Verify compressed push works
476 assert:
477 that:
478 - compress_push is changed
479 - "'Pushed image test-force-rm:latest' in compress_push.actions"
480
481 # Test edge case: empty volumes list
482 - name: Test build with empty volumes list
483 containers.podman.podman_image:
484 executable: "{{ test_executable | default('podman') }}"
485 name: test-empty-volumes
486 state: build
487 build:
488 volume: []
489 container_file: |
490 FROM quay.io/sshnaidm1/alpine:latest
491 RUN echo "empty volumes test" > /tmp/empty.txt
492 register: empty_volumes_build
493
494 - name: Verify empty volumes build works
495 assert:
496 that:
497 - empty_volumes_build is changed
498
499 # Test edge case: empty annotations dict
500 - name: Test build with empty annotations
501 containers.podman.podman_image:
502 executable: "{{ test_executable | default('podman') }}"
503 name: test-empty-annotations
504 state: build
505 build:
506 annotation: {}
507 container_file: |
508 FROM quay.io/sshnaidm1/alpine:latest
509 RUN echo "empty annotations test" > /tmp/empty-ann.txt
510 register: empty_annotations_build
511
512 - name: Verify empty annotations build works
513 assert:
514 that:
515 - empty_annotations_build is changed
516
517 always:
518 # Cleanup all test images and directories
519 - name: Remove test images
520 containers.podman.podman_image:
521 executable: "{{ test_executable | default('podman') }}"
522 name: "{{ item }}"
523 state: absent
524 force: true
525 loop:
526 - quay.io/testing/private-repo
527 - quay.io/sshnaidm1/alpine:3.16
528 - quay.io/sshnaidm1/alpine:3.17
529 - quay.io/sshnaidm1/alpine:3.18
530 - quay.io/sshnaidm1/alpine:3.19
531 - quay.io/sshnaidm1/alpine:3.20
532 - test-annotations
533 - test-multistage
534 - test-extra-args
535 - docker.io/library/busybox
536 - test-missing-containerfile
537 - test-conflict
538 - nonexistent-local-image
539 - test-hash-change
540 - test-no-cache
541 - test-force-rm
542 - test-empty-volumes
543 - test-empty-annotations
544 - docker.io/nonexistent/imagethatdoesnotexist
545 ignore_errors: true
546
547 - name: Remove test directories
548 file:
549 path: "{{ item }}"
550 state: absent
551 loop:
552 - /tmp/build_annotations
553 - /tmp/push-test-dir
554 - /tmp/empty_build_dir
555 - /tmp/hash_change_test
556 - "{{ auth_file.path | default('/tmp/nonexistent') }}"
557 ignore_errors: true
558
559 - name: Remove test archive files
560 file:
561 path: "{{ item }}"
562 state: absent
563 loop:
564 - /tmp/test-oci-export.tar
565 - /tmp/compressed-export.tar
566 - /tmp/testimage-dir
567 - /tmp/testimage-dir1
568 - /tmp/testimage-dir15
569 - /tmp/testimage-dir25
570 - /tmp/test-docker-arch
571 - /tmp/test-docker-arch1
572 - /tmp/test-docker-arch5
573 - /tmp/test-docker-arch15
574 - /tmp/test-oci-arch
575 - /tmp/test-oci-arch1
576 - /tmp/test-oci-arch5
577 - /tmp/test-oci-arch15
578 ignore_errors: true