mirror of
https://github.com/ansible-collections/community.docker.git
synced 2026-07-29 11:55:04 +00:00
Add image_label_mismatch parameter to docker_container (#370)
* Add image_label_mismatch to docker_container * Apply suggestions from code review Co-authored-by: Felix Fontein <felix@fontein.de> * Test image_label_mismatch error message * Add change fragment for image_label_mismatch * Break long line in docker_container.py for pep-8 compliance * pep8 compliance * Update changelogs/fragments/370-add-image-label-mismatch.yml Co-authored-by: Felix Fontein <felix@fontein.de> * fix: add expected_labels to parameters_map in docker_container * Apply suggestions from code review * Apply suggestions from code review * Update tests/integration/targets/docker_container/tasks/tests/options.yml Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
committed by
GitHub
parent
9580c25579
commit
497c2fda91
@@ -22,6 +22,7 @@
|
||||
set_fact:
|
||||
cname_prefix: "{{ 'ansible-docker-test-%0x' % ((2**32) | random) }}"
|
||||
cnames: []
|
||||
inames: []
|
||||
dnetworks: []
|
||||
|
||||
- debug:
|
||||
@@ -41,6 +42,11 @@
|
||||
force_kill: yes
|
||||
with_items: "{{ cnames }}"
|
||||
diff: no
|
||||
- name: "Make sure all images are removed"
|
||||
docker_image:
|
||||
name: "{{ item }}"
|
||||
state: absent
|
||||
with_items: "{{ inames }}"
|
||||
- name: "Make sure all networks are removed"
|
||||
docker_network:
|
||||
name: "{{ item }}"
|
||||
|
||||
@@ -2194,6 +2194,169 @@
|
||||
- ignore_image is not changed
|
||||
- image_change is changed
|
||||
|
||||
####################################################################
|
||||
## image_label_mismatch ############################################
|
||||
####################################################################
|
||||
|
||||
- name: Registering image name
|
||||
set_fact:
|
||||
iname_labels: "{{ cname_prefix ~ '-labels' }}"
|
||||
- name: Registering image name
|
||||
set_fact:
|
||||
inames: "{{ inames + [iname_labels] }}"
|
||||
- name: build image with labels
|
||||
command:
|
||||
cmd: "docker build --label img_label=base --tag {{ iname_labels }} -"
|
||||
stdin: "FROM {{ docker_test_image_alpine }}"
|
||||
|
||||
- name: image_label_mismatch
|
||||
docker_container:
|
||||
image: "{{ iname_labels }}"
|
||||
command: '/bin/sh -c "sleep 10m"'
|
||||
name: "{{ cname }}"
|
||||
state: started
|
||||
register: image_label_mismatch_1
|
||||
|
||||
- name: image_label_mismatch (ignore,unmanaged labels)
|
||||
docker_container:
|
||||
image: "{{ iname_labels }}"
|
||||
command: '/bin/sh -c "sleep 10m"'
|
||||
name: "{{ cname }}"
|
||||
image_label_mismatch: ignore
|
||||
state: started
|
||||
register: image_label_mismatch_2
|
||||
|
||||
- name: image_label_mismatch (ignore,missing img label)
|
||||
docker_container:
|
||||
image: "{{ iname_labels }}"
|
||||
command: '/bin/sh -c "sleep 10m"'
|
||||
name: "{{ cname }}"
|
||||
image_label_mismatch: ignore
|
||||
labels: {}
|
||||
state: started
|
||||
register: image_label_mismatch_3
|
||||
|
||||
- name: image_label_mismatch (ignore,match img label)
|
||||
docker_container:
|
||||
image: "{{ iname_labels }}"
|
||||
command: '/bin/sh -c "sleep 10m"'
|
||||
name: "{{ cname }}"
|
||||
image_label_mismatch: ignore
|
||||
labels:
|
||||
img_label: base
|
||||
state: started
|
||||
register: image_label_mismatch_4
|
||||
|
||||
- name: image_label_mismatch (ignore,mismatched img label)
|
||||
docker_container:
|
||||
image: "{{ iname_labels }}"
|
||||
command: '/bin/sh -c "sleep 10m"'
|
||||
name: "{{ cname }}"
|
||||
image_label_mismatch: ignore
|
||||
labels:
|
||||
img_label: override
|
||||
state: started
|
||||
force_kill: yes
|
||||
register: image_label_mismatch_5
|
||||
|
||||
- name: image_label_mismatch (ignore,remove img label)
|
||||
docker_container:
|
||||
image: "{{ iname_labels }}"
|
||||
command: '/bin/sh -c "sleep 10m"'
|
||||
name: "{{ cname }}"
|
||||
image_label_mismatch: ignore
|
||||
labels: {}
|
||||
state: started
|
||||
force_kill: yes
|
||||
register: image_label_mismatch_6
|
||||
|
||||
- name: image_label_mismatch (fail,unmanaged labels)
|
||||
docker_container:
|
||||
image: "{{ iname_labels }}"
|
||||
command: '/bin/sh -c "sleep 10m"'
|
||||
name: "{{ cname }}"
|
||||
image_label_mismatch: fail
|
||||
state: started
|
||||
register: image_label_mismatch_7
|
||||
|
||||
- name: image_label_mismatch (fail,non-strict,missing img label)
|
||||
docker_container:
|
||||
image: "{{ iname_labels }}"
|
||||
command: '/bin/sh -c "sleep 10m"'
|
||||
name: "{{ cname }}"
|
||||
image_label_mismatch: fail
|
||||
labels: {}
|
||||
state: started
|
||||
register: image_label_mismatch_8
|
||||
|
||||
- name: image_label_mismatch (fail,strict,missing img label)
|
||||
docker_container:
|
||||
image: "{{ iname_labels }}"
|
||||
command: '/bin/sh -c "sleep 10m"'
|
||||
name: "{{ cname }}"
|
||||
image_label_mismatch: fail
|
||||
comparisons:
|
||||
labels: strict
|
||||
labels: {}
|
||||
state: started
|
||||
ignore_errors: yes
|
||||
register: image_label_mismatch_9
|
||||
|
||||
- name: image_label_mismatch (fail,match img label)
|
||||
docker_container:
|
||||
image: "{{ iname_labels }}"
|
||||
command: '/bin/sh -c "sleep 10m"'
|
||||
name: "{{ cname }}"
|
||||
image_label_mismatch: fail
|
||||
labels:
|
||||
img_label: base
|
||||
state: started
|
||||
register: image_label_mismatch_10
|
||||
|
||||
- name: image_label_mismatch (fail,mismatched img label)
|
||||
docker_container:
|
||||
image: "{{ iname_labels }}"
|
||||
command: '/bin/sh -c "sleep 10m"'
|
||||
name: "{{ cname }}"
|
||||
image_label_mismatch: fail
|
||||
labels:
|
||||
img_label: override
|
||||
state: started
|
||||
force_kill: yes
|
||||
register: image_label_mismatch_11
|
||||
|
||||
- name: cleanup container
|
||||
docker_container:
|
||||
name: "{{ cname }}"
|
||||
state: absent
|
||||
force_kill: yes
|
||||
diff: no
|
||||
|
||||
- name: cleanup image
|
||||
docker_image:
|
||||
name: "{{ iname_labels }}"
|
||||
state: absent
|
||||
diff: no
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- image_label_mismatch_1 is changed
|
||||
- image_label_mismatch_1.container.Config.Labels.img_label == "base"
|
||||
- image_label_mismatch_2 is not changed
|
||||
- image_label_mismatch_3 is not changed
|
||||
- image_label_mismatch_4 is not changed
|
||||
- image_label_mismatch_5 is changed
|
||||
- image_label_mismatch_5.container.Config.Labels.img_label == "override"
|
||||
- image_label_mismatch_6 is changed
|
||||
- image_label_mismatch_6.container.Config.Labels.img_label == "base"
|
||||
- image_label_mismatch_7 is not changed
|
||||
- image_label_mismatch_8 is not changed
|
||||
- image_label_mismatch_9 is failed
|
||||
- >-
|
||||
image_label_mismatch_9.msg == ("Some labels should be removed but are present in the base image. You can set image_label_mismatch to 'ignore' to ignore this error. " ~ 'Labels: "img_label"')
|
||||
- image_label_mismatch_10 is not changed
|
||||
- image_label_mismatch_11 is changed
|
||||
|
||||
####################################################################
|
||||
## ipc_mode ########################################################
|
||||
####################################################################
|
||||
|
||||
Reference in New Issue
Block a user