Skip to content

Commit

Permalink
fix: docker_swarm_service does not publish both tcp and udp ports (an…
Browse files Browse the repository at this point in the history
…sible#60616)

* fix: docker_swarm_service does not publish both tcp and udp ports for same published port

* fix the linting problems and add the changelog fragment.

* add test

* modify test to ensure result rather than return value
  • Loading branch information
mit0223 authored and felixfontein committed Aug 16, 2019
1 parent 4854191 commit 064cd63
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/60616-support-multiple-port.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- "docker_swarm_service - allow the same port to be published both with TCP and UDP."
19 changes: 8 additions & 11 deletions lib/ansible/modules/cloud/docker/docker_swarm_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2028,19 +2028,16 @@ def build_networks(self, docker_networks):
def build_endpoint_spec(self):
endpoint_spec_args = {}
if self.publish is not None:
ports = {}
ports = []
for port in self.publish:
port_spec = {
'Protocol': port['protocol'],
'PublishedPort': port['published_port'],
'TargetPort': port['target_port']
}
if port.get('mode'):
ports[port['published_port']] = (
port['target_port'],
port['protocol'],
port['mode'],
)
else:
ports[port['published_port']] = (
port['target_port'],
port['protocol'],
)
port_spec['PublishMode'] = port['mode']
ports.append(port_spec)
endpoint_spec_args['ports'] = ports
if self.endpoint_mode is not None:
endpoint_spec_args['mode'] = self.endpoint_mode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1590,6 +1590,28 @@
register: publish_7
ignore_errors: yes

- name: publish (publishes the same port with both protocols)
docker_swarm_service:
name: "{{ service_name }}"
image: alpine:3.8
resolve_image: no
command: '/bin/sh -v -c "sleep 10m"'
publish:
- protocol: udp
published_port: 60001
target_port: 60001
mode: host
- protocol: tcp
published_port: 60001
target_port: 60001
mode: host
register: publish_8
ignore_errors: yes
- name: gather service info
docker_swarm_service_info:
name: "{{ service_name }}"
register: publish_8_info

- name: cleanup
docker_swarm_service:
name: "{{ service_name }}"
Expand All @@ -1605,6 +1627,8 @@
- publish_5 is not changed
- publish_6 is changed
- publish_7 is not changed
- publish_8 is changed
- (publish_8_info.service.Endpoint.Ports | length) == 2
when: docker_api_version is version('1.25', '>=') and docker_py_version is version('3.0.0', '>=')
- assert:
that:
Expand Down

0 comments on commit 064cd63

Please sign in to comment.