fix: docker_swarm_service does not publish both tcp and udp ports (#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
pull/60691/head
Mitsuru Nakakawaji 5 years ago committed by Felix Fontein
parent 48541910bf
commit 064cd63f3d

@ -0,0 +1,2 @@
bugfixes:
- "docker_swarm_service - allow the same port to be published both with TCP and UDP."

@ -2028,19 +2028,16 @@ class DockerService(DockerBaseClass):
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

@ -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 }}"
@ -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:

Loading…
Cancel
Save