mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
docker_container: show warnings, fix/improve tests (#53440)
* Output warnings from docker daemon on container create and update. * Accept warning for blkio_weight instead of idempotency. * Value quoting. * Avoid loop variable conflict. * Add changelog. * Make one test case faster. * Add 'Docker warning: ' prefix. * Add a generalized warning reporting function.
This commit is contained in:
parent
7bb174214c
commit
3117900b1e
7 changed files with 89 additions and 67 deletions
2
changelogs/fragments/53440-docker_container-warnings.yml
Normal file
2
changelogs/fragments/53440-docker_container-warnings.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- "docker_container - now returns warnings from docker daemon on container creation and updating."
|
|
@ -23,6 +23,7 @@ from distutils.version import LooseVersion
|
||||||
|
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule, env_fallback
|
from ansible.module_utils.basic import AnsibleModule, env_fallback
|
||||||
|
from ansible.module_utils.common._collections_compat import Mapping, Sequence
|
||||||
from ansible.module_utils.six.moves.urllib.parse import urlparse
|
from ansible.module_utils.six.moves.urllib.parse import urlparse
|
||||||
from ansible.module_utils.parsing.convert_bool import BOOLEANS_TRUE, BOOLEANS_FALSE
|
from ansible.module_utils.parsing.convert_bool import BOOLEANS_TRUE, BOOLEANS_FALSE
|
||||||
|
|
||||||
|
@ -660,6 +661,20 @@ class AnsibleDockerClient(Client):
|
||||||
|
|
||||||
return new_tag, old_tag == new_tag
|
return new_tag, old_tag == new_tag
|
||||||
|
|
||||||
|
def report_warnings(self, result, warnings_key=None):
|
||||||
|
'''
|
||||||
|
Checks result of client operation for warnings, and if present, outputs them.
|
||||||
|
'''
|
||||||
|
if warnings_key is None:
|
||||||
|
warnings_key = ['Warnings']
|
||||||
|
for key in warnings_key:
|
||||||
|
if not isinstance(result, Mapping):
|
||||||
|
return
|
||||||
|
result = result.get(key)
|
||||||
|
if isinstance(result, Sequence):
|
||||||
|
for warning in result:
|
||||||
|
self.module.warn('Docker warning: {0}'.format(warning))
|
||||||
|
|
||||||
|
|
||||||
def compare_dict_allow_more_present(av, bv):
|
def compare_dict_allow_more_present(av, bv):
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -2480,6 +2480,7 @@ class ContainerManager(DockerBaseClass):
|
||||||
if not self.check_mode:
|
if not self.check_mode:
|
||||||
try:
|
try:
|
||||||
new_container = self.client.create_container(image, **create_parameters)
|
new_container = self.client.create_container(image, **create_parameters)
|
||||||
|
self.client.report_warnings(new_container)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
self.fail("Error creating container: %s" % str(exc))
|
self.fail("Error creating container: %s" % str(exc))
|
||||||
return self._get_container(new_container['Id'])
|
return self._get_container(new_container['Id'])
|
||||||
|
@ -2572,7 +2573,8 @@ class ContainerManager(DockerBaseClass):
|
||||||
self.results['changed'] = True
|
self.results['changed'] = True
|
||||||
if not self.check_mode and callable(getattr(self.client, 'update_container')):
|
if not self.check_mode and callable(getattr(self.client, 'update_container')):
|
||||||
try:
|
try:
|
||||||
self.client.update_container(container_id, **update_parameters)
|
result = self.client.update_container(container_id, **update_parameters)
|
||||||
|
self.client.report_warnings(result)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
self.fail("Error updating container %s: %s" % (container_id, str(exc)))
|
self.fail("Error updating container %s: %s" % (container_id, str(exc)))
|
||||||
return self._get_container(container_id)
|
return self._get_container(container_id)
|
||||||
|
|
|
@ -121,8 +121,8 @@
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
state: started
|
state: started
|
||||||
groups:
|
groups:
|
||||||
- 1010
|
- "1010"
|
||||||
- 1011
|
- "1011"
|
||||||
register: set_1
|
register: set_1
|
||||||
|
|
||||||
- name: set (change, ignore)
|
- name: set (change, ignore)
|
||||||
|
@ -132,9 +132,9 @@
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
state: started
|
state: started
|
||||||
groups:
|
groups:
|
||||||
- 1010
|
- "1010"
|
||||||
- 1011
|
- "1011"
|
||||||
- 1012
|
- "1012"
|
||||||
force_kill: yes
|
force_kill: yes
|
||||||
comparisons:
|
comparisons:
|
||||||
groups: ignore
|
groups: ignore
|
||||||
|
@ -147,9 +147,9 @@
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
state: started
|
state: started
|
||||||
groups:
|
groups:
|
||||||
- 1010
|
- "1010"
|
||||||
- 1011
|
- "1011"
|
||||||
- 1012
|
- "1012"
|
||||||
force_kill: yes
|
force_kill: yes
|
||||||
comparisons:
|
comparisons:
|
||||||
groups: allow_more_present
|
groups: allow_more_present
|
||||||
|
@ -162,8 +162,8 @@
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
state: started
|
state: started
|
||||||
groups:
|
groups:
|
||||||
- 1010
|
- "1010"
|
||||||
- 1012
|
- "1012"
|
||||||
force_kill: yes
|
force_kill: yes
|
||||||
comparisons:
|
comparisons:
|
||||||
groups: allow_more_present
|
groups: allow_more_present
|
||||||
|
@ -176,8 +176,8 @@
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
state: started
|
state: started
|
||||||
groups:
|
groups:
|
||||||
- 1010
|
- "1010"
|
||||||
- 1012
|
- "1012"
|
||||||
force_kill: yes
|
force_kill: yes
|
||||||
comparisons:
|
comparisons:
|
||||||
groups: strict
|
groups: strict
|
||||||
|
|
|
@ -8,11 +8,13 @@
|
||||||
|
|
||||||
- name: Pull images
|
- name: Pull images
|
||||||
docker_image:
|
docker_image:
|
||||||
name: "{{ item }}"
|
name: "{{ image }}"
|
||||||
pull: true
|
pull: true
|
||||||
loop:
|
loop:
|
||||||
- "hello-world:latest"
|
- "hello-world:latest"
|
||||||
- "alpine:3.8"
|
- "alpine:3.8"
|
||||||
|
loop_control:
|
||||||
|
loop_var: image
|
||||||
|
|
||||||
- name: Get image ID of hello-world and alpine images
|
- name: Get image ID of hello-world and alpine images
|
||||||
docker_image_facts:
|
docker_image_facts:
|
||||||
|
|
|
@ -101,7 +101,7 @@
|
||||||
- assert:
|
- assert:
|
||||||
that:
|
that:
|
||||||
- blkio_weight_1 is changed
|
- blkio_weight_1 is changed
|
||||||
- blkio_weight_2 is not changed
|
- "blkio_weight_2 is not changed or 'Docker warning: Your kernel does not support Block I/O weight or the cgroup is not mounted. Weight discarded.' in blkio_weight_2.warnings"
|
||||||
- blkio_weight_3 is changed
|
- blkio_weight_3 is changed
|
||||||
|
|
||||||
####################################################################
|
####################################################################
|
||||||
|
@ -356,7 +356,7 @@
|
||||||
image: alpine:3.8
|
image: alpine:3.8
|
||||||
command: '/bin/sh -c "sleep 10m"'
|
command: '/bin/sh -c "sleep 10m"'
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
cpuset_cpus: 0
|
cpuset_cpus: "0"
|
||||||
state: started
|
state: started
|
||||||
register: cpuset_cpus_1
|
register: cpuset_cpus_1
|
||||||
|
|
||||||
|
@ -365,7 +365,7 @@
|
||||||
image: alpine:3.8
|
image: alpine:3.8
|
||||||
command: '/bin/sh -c "sleep 10m"'
|
command: '/bin/sh -c "sleep 10m"'
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
cpuset_cpus: 0
|
cpuset_cpus: "0"
|
||||||
state: started
|
state: started
|
||||||
register: cpuset_cpus_2
|
register: cpuset_cpus_2
|
||||||
|
|
||||||
|
@ -374,7 +374,7 @@
|
||||||
image: alpine:3.8
|
image: alpine:3.8
|
||||||
command: '/bin/sh -c "sleep 10m"'
|
command: '/bin/sh -c "sleep 10m"'
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
cpuset_cpus: 1
|
cpuset_cpus: "1"
|
||||||
state: started
|
state: started
|
||||||
force_kill: yes
|
force_kill: yes
|
||||||
# This will fail if the system the test is run on doesn't have
|
# This will fail if the system the test is run on doesn't have
|
||||||
|
@ -404,7 +404,7 @@
|
||||||
image: alpine:3.8
|
image: alpine:3.8
|
||||||
command: '/bin/sh -c "sleep 10m"'
|
command: '/bin/sh -c "sleep 10m"'
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
cpuset_mems: 0
|
cpuset_mems: "0"
|
||||||
state: started
|
state: started
|
||||||
register: cpuset_mems_1
|
register: cpuset_mems_1
|
||||||
|
|
||||||
|
@ -413,7 +413,7 @@
|
||||||
image: alpine:3.8
|
image: alpine:3.8
|
||||||
command: '/bin/sh -c "sleep 10m"'
|
command: '/bin/sh -c "sleep 10m"'
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
cpuset_mems: 0
|
cpuset_mems: "0"
|
||||||
state: started
|
state: started
|
||||||
register: cpuset_mems_2
|
register: cpuset_mems_2
|
||||||
|
|
||||||
|
@ -422,7 +422,7 @@
|
||||||
image: alpine:3.8
|
image: alpine:3.8
|
||||||
command: '/bin/sh -c "sleep 10m"'
|
command: '/bin/sh -c "sleep 10m"'
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
cpuset_mems: 1
|
cpuset_mems: "1"
|
||||||
state: started
|
state: started
|
||||||
force_kill: yes
|
force_kill: yes
|
||||||
# This will fail if the system the test is run on doesn't have
|
# This will fail if the system the test is run on doesn't have
|
||||||
|
@ -1115,7 +1115,7 @@
|
||||||
state: started
|
state: started
|
||||||
register: entrypoint_2
|
register: entrypoint_2
|
||||||
|
|
||||||
- name: entrypoint (change order idempotency)
|
- name: entrypoint (change order, should not be idempotent)
|
||||||
docker_container:
|
docker_container:
|
||||||
image: alpine:3.8
|
image: alpine:3.8
|
||||||
entrypoint:
|
entrypoint:
|
||||||
|
@ -1125,6 +1125,7 @@
|
||||||
- "-v"
|
- "-v"
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
state: started
|
state: started
|
||||||
|
force_kill: yes
|
||||||
register: entrypoint_3
|
register: entrypoint_3
|
||||||
|
|
||||||
- name: entrypoint (less parameters)
|
- name: entrypoint (less parameters)
|
||||||
|
@ -1355,8 +1356,8 @@
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
state: started
|
state: started
|
||||||
exposed_ports:
|
exposed_ports:
|
||||||
- 1234
|
- "1234"
|
||||||
- 5678
|
- "5678"
|
||||||
register: exposed_ports_1
|
register: exposed_ports_1
|
||||||
|
|
||||||
- name: exposed_ports (idempotency)
|
- name: exposed_ports (idempotency)
|
||||||
|
@ -1366,8 +1367,8 @@
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
state: started
|
state: started
|
||||||
exposed_ports:
|
exposed_ports:
|
||||||
- 5678
|
- "5678"
|
||||||
- 1234
|
- "1234"
|
||||||
register: exposed_ports_2
|
register: exposed_ports_2
|
||||||
|
|
||||||
- name: exposed_ports (less ports)
|
- name: exposed_ports (less ports)
|
||||||
|
@ -1377,7 +1378,7 @@
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
state: started
|
state: started
|
||||||
exposed_ports:
|
exposed_ports:
|
||||||
- 1234
|
- "1234"
|
||||||
register: exposed_ports_3
|
register: exposed_ports_3
|
||||||
|
|
||||||
- name: exposed_ports (more ports)
|
- name: exposed_ports (more ports)
|
||||||
|
@ -1387,8 +1388,8 @@
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
state: started
|
state: started
|
||||||
exposed_ports:
|
exposed_ports:
|
||||||
- 1234
|
- "1234"
|
||||||
- 1235
|
- "1235"
|
||||||
force_kill: yes
|
force_kill: yes
|
||||||
register: exposed_ports_4
|
register: exposed_ports_4
|
||||||
|
|
||||||
|
@ -1423,8 +1424,8 @@
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
state: started
|
state: started
|
||||||
groups:
|
groups:
|
||||||
- 1234
|
- "1234"
|
||||||
- 5678
|
- "5678"
|
||||||
register: groups_1
|
register: groups_1
|
||||||
|
|
||||||
- name: groups (idempotency)
|
- name: groups (idempotency)
|
||||||
|
@ -1434,8 +1435,8 @@
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
state: started
|
state: started
|
||||||
groups:
|
groups:
|
||||||
- 5678
|
- "5678"
|
||||||
- 1234
|
- "1234"
|
||||||
register: groups_2
|
register: groups_2
|
||||||
|
|
||||||
- name: groups (less groups)
|
- name: groups (less groups)
|
||||||
|
@ -1445,7 +1446,7 @@
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
state: started
|
state: started
|
||||||
groups:
|
groups:
|
||||||
- 1234
|
- "1234"
|
||||||
register: groups_3
|
register: groups_3
|
||||||
|
|
||||||
- name: groups (more groups)
|
- name: groups (more groups)
|
||||||
|
@ -1455,8 +1456,8 @@
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
state: started
|
state: started
|
||||||
groups:
|
groups:
|
||||||
- 1234
|
- "1234"
|
||||||
- 2345
|
- "2345"
|
||||||
force_kill: yes
|
force_kill: yes
|
||||||
register: groups_4
|
register: groups_4
|
||||||
|
|
||||||
|
@ -3413,7 +3414,7 @@
|
||||||
image: alpine:3.8
|
image: alpine:3.8
|
||||||
command: '/bin/sh -c "sleep 10m"'
|
command: '/bin/sh -c "sleep 10m"'
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
stop_signal: 30
|
stop_signal: "30"
|
||||||
state: started
|
state: started
|
||||||
register: stop_signal_1
|
register: stop_signal_1
|
||||||
|
|
||||||
|
@ -3422,7 +3423,7 @@
|
||||||
image: alpine:3.8
|
image: alpine:3.8
|
||||||
command: '/bin/sh -c "sleep 10m"'
|
command: '/bin/sh -c "sleep 10m"'
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
stop_signal: 30
|
stop_signal: "30"
|
||||||
state: started
|
state: started
|
||||||
register: stop_signal_2
|
register: stop_signal_2
|
||||||
|
|
||||||
|
@ -3431,7 +3432,7 @@
|
||||||
image: alpine:3.8
|
image: alpine:3.8
|
||||||
command: '/bin/sh -c "sleep 10m"'
|
command: '/bin/sh -c "sleep 10m"'
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
stop_signal: 9
|
stop_signal: "9"
|
||||||
state: started
|
state: started
|
||||||
force_kill: yes
|
force_kill: yes
|
||||||
register: stop_signal_3
|
register: stop_signal_3
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
state: started
|
state: started
|
||||||
exposed_ports:
|
exposed_ports:
|
||||||
- 8080
|
- "8080"
|
||||||
- 8081
|
- "8081"
|
||||||
published_ports:
|
published_ports:
|
||||||
- all
|
- all
|
||||||
force_kill: yes
|
force_kill: yes
|
||||||
|
@ -28,8 +28,8 @@
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
state: started
|
state: started
|
||||||
exposed_ports:
|
exposed_ports:
|
||||||
- 8080
|
- "8080"
|
||||||
- 8081
|
- "8081"
|
||||||
published_ports:
|
published_ports:
|
||||||
- all
|
- all
|
||||||
force_kill: yes
|
force_kill: yes
|
||||||
|
@ -42,11 +42,11 @@
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
state: started
|
state: started
|
||||||
exposed_ports:
|
exposed_ports:
|
||||||
- 8080
|
- "8080"
|
||||||
- 8081
|
- "8081"
|
||||||
published_ports:
|
published_ports:
|
||||||
- 8080
|
- "8080"
|
||||||
- 8081
|
- "8081"
|
||||||
force_kill: yes
|
force_kill: yes
|
||||||
register: published_ports_3
|
register: published_ports_3
|
||||||
|
|
||||||
|
@ -57,11 +57,11 @@
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
state: started
|
state: started
|
||||||
exposed_ports:
|
exposed_ports:
|
||||||
- 8080
|
- "8080"
|
||||||
- 8081
|
- "8081"
|
||||||
published_ports:
|
published_ports:
|
||||||
- 8080
|
- "8080"
|
||||||
- 8081
|
- "8081"
|
||||||
force_kill: yes
|
force_kill: yes
|
||||||
register: published_ports_4
|
register: published_ports_4
|
||||||
|
|
||||||
|
@ -72,8 +72,8 @@
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
state: started
|
state: started
|
||||||
exposed_ports:
|
exposed_ports:
|
||||||
- 8080
|
- "8080"
|
||||||
- 8081
|
- "8081"
|
||||||
published_ports:
|
published_ports:
|
||||||
- all
|
- all
|
||||||
force_kill: yes
|
force_kill: yes
|
||||||
|
@ -105,11 +105,11 @@
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
state: started
|
state: started
|
||||||
exposed_ports:
|
exposed_ports:
|
||||||
- 8080
|
- "8080"
|
||||||
- 5000-5040
|
- "5000-5040"
|
||||||
published_ports:
|
published_ports:
|
||||||
- 8080:8080
|
- "8080:8080"
|
||||||
- 5000-5040:5000-5040
|
- "5000-5040:5000-5040"
|
||||||
force_kill: yes
|
force_kill: yes
|
||||||
register: published_ports_1
|
register: published_ports_1
|
||||||
|
|
||||||
|
@ -120,11 +120,11 @@
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
state: started
|
state: started
|
||||||
exposed_ports:
|
exposed_ports:
|
||||||
- 8080
|
- "8080"
|
||||||
- 5000-5040
|
- "5000-5040"
|
||||||
published_ports:
|
published_ports:
|
||||||
- 8080:8080
|
- "8080:8080"
|
||||||
- 5000-5040:5000-5040
|
- "5000-5040:5000-5040"
|
||||||
force_kill: yes
|
force_kill: yes
|
||||||
register: published_ports_2
|
register: published_ports_2
|
||||||
|
|
||||||
|
@ -135,11 +135,11 @@
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
state: started
|
state: started
|
||||||
exposed_ports:
|
exposed_ports:
|
||||||
- 8080
|
- "8080"
|
||||||
- 5000-5040
|
- "5000-5040"
|
||||||
published_ports:
|
published_ports:
|
||||||
- 8080:8080
|
- "8080:8080"
|
||||||
- 5010-5050:5010-5050
|
- "5010-5050:5010-5050"
|
||||||
force_kill: yes
|
force_kill: yes
|
||||||
register: published_ports_3
|
register: published_ports_3
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
state: started
|
state: started
|
||||||
published_ports:
|
published_ports:
|
||||||
- 127.0.0.1:8080:8080
|
- "127.0.0.1:8080:8080"
|
||||||
force_kill: yes
|
force_kill: yes
|
||||||
register: published_ports_3
|
register: published_ports_3
|
||||||
|
|
||||||
|
@ -200,7 +200,7 @@
|
||||||
name: "{{ cname }}"
|
name: "{{ cname }}"
|
||||||
state: started
|
state: started
|
||||||
published_ports:
|
published_ports:
|
||||||
- localhost:8080:8080
|
- "localhost:8080:8080"
|
||||||
force_kill: yes
|
force_kill: yes
|
||||||
register: published_ports_4
|
register: published_ports_4
|
||||||
ignore_errors: yes
|
ignore_errors: yes
|
||||||
|
|
Loading…
Reference in a new issue