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

clarify port.mode paramter requiremets, fail if unmet #47938

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- "docker_swarm_service - The ``publish``.``mode`` parameter was being ignored if docker-py version was < 3.0.0. Added a parameter validation test."
12 changes: 7 additions & 5 deletions lib/ansible/modules/cloud/docker/docker_swarm_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
- List of dictionaries describing the service published ports.
- Every item must be a dictionary exposing the keys published_port, target_port, protocol (defaults to 'tcp')
- Only used with api_version >= 1.25
- If api_version >= 1.32 the dictionaries can contain the attribute 'mode' set to 'ingress' or 'host' (default 'ingress').
- If api_version >= 1.32 and docker python library >= 3.0.0 attribute 'mode' can be set to 'ingress' or 'host' (default 'ingress').
replicas:
required: false
default: -1
Expand Down Expand Up @@ -457,6 +457,7 @@
import time
from ansible.module_utils.docker_common import DockerBaseClass
from ansible.module_utils.docker_common import AnsibleDockerClient
from ansible.module_utils.docker_common import docker_version
from ansible.module_utils.basic import human_to_bytes
from ansible.module_utils._text import to_text

Expand Down Expand Up @@ -1041,10 +1042,11 @@ def test_parameter_versions(self):
% (pv['param'], pv['min_version'])))

for publish_def in self.client.module.params.get('publish', []):
if ('mode' in publish_def.keys() and
(LooseVersion(self.client.version()['ApiVersion']) <
LooseVersion('1.25'))):
self.client.module.fail_json(msg='publish.mode parameter supported only with api_version>=1.25')
if 'mode' in publish_def.keys():
if LooseVersion(self.client.version()['ApiVersion']) < LooseVersion('1.25'):
self.client.module.fail_json(msg='publish.mode parameter supported only with api_version>=1.25')
if LooseVersion(docker_version) < LooseVersion('3.0.0'):
self.client.module.fail_json(msg='publish.mode parameter requires docker python library>=3.0.0')

def run(self):
self.test_parameter_versions()
Expand Down