Skip to content

Commit

Permalink
Revert "Remove deprecations from docker_container, bump collection ve…
Browse files Browse the repository at this point in the history
…rsion to 3.0.0 (#399)"

This reverts commit 49ce0a3.
  • Loading branch information
felixfontein committed Jul 2, 2022
1 parent 7b46e4d commit 57e19ca
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 18 deletions.
3 changes: 0 additions & 3 deletions changelogs/fragments/399-deprecations.yml

This file was deleted.

2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace: community
name: docker
version: 3.0.0
version: 2.7.0
readme: README.md
authors:
- Ansible Docker Working Group
Expand Down
58 changes: 45 additions & 13 deletions plugins/modules/docker_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,16 @@
- Also, setting I(command) to an empty list of string, and setting I(entrypoint) to an empty
list will be handled as if these options are not specified. This is different from idempotency
handling for other container-config related options.
- When this is set to C(compatibility), which was the default until community.docker 3.0.0, the
- When this is set to C(compatibility), which is the default until community.docker 3.0.0, the
current behavior will be kept.
- When this is set to C(correct), these options are kept as lists, and an empty value or empty
list will be handled correctly for idempotency checks. This has been the default since
community.docker 3.0.0.
list will be handled correctly for idempotency checks.
- In community.docker 3.0.0, the default will change to C(correct).
type: str
choices:
- compatibility
- correct
version_added: 1.9.0
default: correct
cpu_period:
description:
- Limit CPU CFS (Completely Fair Scheduler) period.
Expand Down Expand Up @@ -703,14 +702,15 @@
- "Bind addresses must be either IPv4 or IPv6 addresses. Hostnames are B(not) allowed. This
is different from the C(docker) command line utility. Use the R(dig lookup,ansible_collections.community.general.dig_lookup)
to resolve hostnames."
- A value of C(all) will publish all exposed container ports to random host ports, ignoring
any other mappings. This is deprecated since version 2.0.0 and will be disallowed in
community.docker 3.0.0. Use the I(publish_all_ports) option instead.
- If I(networks) parameter is provided, will inspect each network to see if there exists
a bridge network with optional parameter C(com.docker.network.bridge.host_binding_ipv4).
If such a network is found, then published ports where no host IP address is specified
will be bound to the host IP pointed to by C(com.docker.network.bridge.host_binding_ipv4).
Note that the first bridge network with a C(com.docker.network.bridge.host_binding_ipv4)
value encountered in the list of I(networks) is the one that will be used.
- The value C(all) was allowed in earlier versions of this module. Support for it was removed in
community.docker 3.0.0. Use the I(publish_all_ports) option instead.
type: list
elements: str
aliases:
Expand Down Expand Up @@ -1452,6 +1452,13 @@ def __init__(self, client):

self.published_ports = self._parse_publish_ports()

if self.published_ports == 'all':
if self.publish_all_ports is None:
self.publish_all_ports = True
self.published_ports = None
else:
self.fail('"all" is not a valid value for "published_ports" when "publish_all_ports" is specified')

self.ports = self._parse_exposed_ports(self.published_ports)
self.log("expose ports:")
self.log(self.ports, pretty_print=True)
Expand Down Expand Up @@ -1504,18 +1511,37 @@ def __init__(self, client):
self.command = shlex.split(to_text(self.command, errors='surrogate_or_strict'))
self.command = [to_text(x, errors='surrogate_or_strict') for x in self.command]
else:
will_change = False
if self.entrypoint:
# convert from list to str.
correct_entrypoint = [to_text(x, errors='surrogate_or_strict') for x in self.entrypoint]
self.entrypoint = shlex.split(' '.join([to_text(x, errors='surrogate_or_strict') for x in self.entrypoint]))
self.entrypoint = [to_text(x, errors='surrogate_or_strict') for x in self.entrypoint]
if correct_entrypoint != self.entrypoint:
will_change = True
elif self.entrypoint is not None:
will_change = True

if self.command:
# convert from list to str
if isinstance(self.command, list):
self.command = ' '.join([to_text(x, errors='surrogate_or_strict') for x in self.command])
correct_command = [to_text(x, errors='surrogate_or_strict') for x in self.command]
self.command = shlex.split(' '.join([to_text(x, errors='surrogate_or_strict') for x in self.command]))
self.command = [to_text(x, errors='surrogate_or_strict') for x in self.command]
if correct_command != self.command:
will_change = True
else:
self.command = to_text(self.command, errors='surrogate_or_strict')
self.command = [to_text(x, errors='surrogate_or_strict') for x in shlex.split(self.command)]
self.command = shlex.split(to_text(self.command, errors='surrogate_or_strict'))
self.command = [to_text(x, errors='surrogate_or_strict') for x in self.command]
elif self.command is not None:
will_change = True

if will_change and client.module.params['command_handling'] is None:
client.module.deprecate(
'The command_handling option will change its default value from "compatibility" to '
'"correct" in community.docker 3.0.0. To remove this warning, please specify an explicit value for it now',
version='3.0.0', collection_name='community.docker'
)

self.mounts_opt, self.expected_mounts = self._process_mounts()

Expand Down Expand Up @@ -1783,9 +1809,15 @@ def _parse_publish_ports(self):
return None

if 'all' in self.published_ports:
self.client.module.fail_json(
msg='Specifying "all" in published_ports is no longer allowed. Set publish_all_ports to "true" instead '
'to randomly assign port mappings for those not specified by published_ports.')
if len(self.published_ports) > 1:
self.client.module.fail_json(msg='"all" can no longer be specified in published_ports next to '
'other values. Set publish_all_ports to "true" to randomly '
'assign port mappings for those not specified by published_ports.')
self.client.module.deprecate(
'Specifying "all" in published_ports is deprecated. Set publish_all_ports to "true" instead '
'to randomly assign port mappings for those not specified by published_ports',
collection_name='community.docker', version='3.0.0')
return 'all'

default_ip = self.get_default_host_ip()

Expand Down Expand Up @@ -3521,7 +3553,7 @@ def main():
command=dict(type='raw'),
comparisons=dict(type='dict'),
container_default_behavior=dict(type='str', default='no_defaults', choices=['compatibility', 'no_defaults']),
command_handling=dict(type='str', choices=['compatibility', 'correct'], default='correct'),
command_handling=dict(type='str', choices=['compatibility', 'correct']),
cpu_period=dict(type='int'),
cpu_quota=dict(type='int'),
cpus=dict(type='float'),
Expand Down
107 changes: 106 additions & 1 deletion tests/integration/targets/docker_container/tasks/tests/ports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,111 @@
- published_ports_3 is failed
- "published_ports_3.msg == 'Bind addresses for published ports must be IPv4 or IPv6 addresses, not hostnames. Use the dig lookup to resolve hostnames. (Found hostname: foo)'"

####################################################################
## published_ports: all ############################################
####################################################################

- name: published_ports -- all
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
exposed_ports:
- "9001"
- "9002"
published_ports:
- all
force_kill: yes
register: published_ports_1

- name: published_ports -- all (idempotency)
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
exposed_ports:
- "9001"
- "9002"
published_ports:
- all
force_kill: yes
register: published_ports_2

- name: published_ports -- all (writing out 'all')
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
exposed_ports:
- "9001"
- "9002"
published_ports:
- "9001"
- "9002"
force_kill: yes
register: published_ports_3

- name: published_ports -- all (idempotency 2)
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
exposed_ports:
- "9001"
- "9002"
published_ports:
- "9002"
- "9001"
force_kill: yes
register: published_ports_4

- name: published_ports -- all (switching back to 'all')
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
exposed_ports:
- "9001"
- "9002"
published_ports:
- all
force_kill: yes
register: published_ports_5

- name: published_ports -- all equivalence with publish_all_ports
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
exposed_ports:
- "9001"
- "9002"
publish_all_ports: true
force_kill: yes
register: published_ports_6

- name: cleanup
docker_container:
name: "{{ cname }}"
state: absent
force_kill: yes
diff: no

- assert:
that:
- published_ports_1 is changed
- published_ports_2 is not changed
- published_ports_3 is changed
- published_ports_4 is not changed
- published_ports_5 is changed
- published_ports_6 is not changed

####################################################################
## published_ports: port range #####################################
####################################################################
Expand Down Expand Up @@ -319,4 +424,4 @@
loop: "{{ publish_all_ports_test_cases }}"
loop_control:
index_var: index
loop_var: test_case
loop_var: test_case

0 comments on commit 57e19ca

Please sign in to comment.