Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker_container - adding publish_all_ports option #162

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/modules/docker_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -1761,7 +1761,7 @@ def _parse_publish_ports(self):
'Specifying "all" in published_ports together with port mappings is not properly '
'supported by the module. The port mappings are currently ignored. Set publish_all_ports '
'to "true" to randomly assign port mappings for those not specified by published_ports. '
'The use of "all" in published_ports will be removed in version 2.0.0.',
'The use of "all" in published_ports next to other values will be removed in version 2.0.0.',
collection_name='community.docker', version='2.0.0')
return 'all'

Expand Down
203 changes: 66 additions & 137 deletions tests/integration/targets/docker_container/tasks/tests/ports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -303,149 +303,78 @@
## publish_all_ports ###############################################
####################################################################

- name: publish_all_ports (true)
- set_fact:
publish_all_ports_test_cases:
- test_name: no_options
changed: true
- test_name: null_to_true
publish_all_ports_value: true
changed: true
- test_name: true_idempotency
publish_all_ports_value: true
changed: false
- test_name: true_to_null
changed: false
- test_name: null_to_true_2
publish_all_ports_value: true
changed: false
- test_name: true_to_false
publish_all_ports_value: false
changed: true
- test_name: false_idempotency
publish_all_ports_value: false
changed: false
- test_name: false_to_null
changed: false
- test_name: null_with_published_ports
published_ports_value: &ports
- "9001:9001"
- "9010-9050:9010-9050"
changed: true
- test_name: null_to_true_with_published_ports
publish_all_ports_value: true
published_ports_value: *ports
changed: true
- test_name: true_idempotency_with_published_ports
publish_all_ports_value: true
published_ports_value: *ports
changed: false
- test_name: true_to_null_with_published_ports
published_ports_value: *ports
changed: false
- test_name: null_to_true_2_with_published_ports
publish_all_ports_value: true
published_ports_value: *ports
changed: false
- test_name: true_to_false_with_published_ports
publish_all_ports_value: false
published_ports_value: *ports
changed: true
- test_name: false_idempotency_with_published_ports
publish_all_ports_value: false
published_ports_value: *ports
changed: false
- test_name: false_to_null_with_published_ports
published_ports_value: *ports
changed: false

- name: publish_all_ports ({{ test_case.test_name }})
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
publish_all_ports: true
force_kill: yes
register: publish_all_ports_1

- name: publish_all_ports (Idempotency)
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
publish_all_ports: true
force_kill: yes
register: publish_all_ports_2

- name: publish_all_ports (false)
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
publish_all_ports: false
force_kill: yes
register: publish_all_ports_3

- name: publish_all_ports (Idempotency 2)
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
publish_all_ports: false
force_kill: yes
register: publish_all_ports_4

- name: publish_all_ports (null)
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
force_kill: yes
register: publish_all_ports_5

- name: publish_all_ports (null with published_ports)
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
published_ports:
- "9001:9001"
- "9010-9050:9010-9050"
publish_all_ports: "{{ test_case.publish_all_ports_value | default(omit) }}"
published_ports: "{{ test_case.published_ports_value | default(omit) }}"
force_kill: yes
register: publish_all_ports_6

- name: publish_all_ports (null -> true with published_ports)
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
publish_all_ports: true
published_ports:
- "9001:9001"
- "9010-9050:9010-9050"
force_kill: yes
register: publish_all_ports_7

- name: publish_all_ports (Idempotency with published_ports)
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
publish_all_ports: true
published_ports:
- "9001:9001"
- "9010-9050:9010-9050"
force_kill: yes
register: publish_all_ports_8

- name: publish_all_ports (true -> false with published_ports)
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
publish_all_ports: false
published_ports:
- "9001:9001"
- "9010-9050:9010-9050"
force_kill: yes
register: publish_all_ports_9

- name: publish_all_ports (Idempotency2 with published_ports)
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
publish_all_ports: false
published_ports:
- "9001:9001"
- "9010-9050:9010-9050"
force_kill: yes
register: publish_all_ports_10

- name: publish_all_ports (false -> null with published_ports)
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
publish_all_ports: false
published_ports:
- "9001:9001"
- "9010-9050:9010-9050"
force_kill: yes
register: publish_all_ports_11

- name: cleanup
docker_container:
name: "{{ cname }}"
state: absent
force_kill: yes
diff: no
register: publish_all_ports
loop_control:
loop_var: test_case
loop: "{{ publish_all_ports_test_cases }}"

- assert:
that:
- publish_all_ports_1 is changed
- publish_all_ports_2 is not changed
- publish_all_ports_3 is changed
- publish_all_ports_4 is not changed
- publish_all_ports_5 is not changed
- publish_all_ports_6 is changed
- publish_all_ports_7 is changed
- publish_all_ports_8 is not changed
- publish_all_ports_9 is changed
- publish_all_ports_10 is not changed
- publish_all_ports_11 is not changed
- publish_all_ports.results[index].changed == publish_all_ports_test_cases[index].changed
loop: "{{ range(0, publish_all_ports_test_cases | length) | list }}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

@Ajpantuso Ajpantuso Jun 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I updated it to the loop analogue.

loop_control:
loop_var: index