Browse code

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

* clarify port.mode paramter requiremets, fail if unmet

* changelog fragment

* shorten too long line

* remove unnecessary indentation

* test version on docker_version for better maintainability

* normalize imports

* changelog fragment: minor_changes -> bugfixes

* rollback e96a7e57dfefd566fa47cf465a759637affd4795

* typo

Co-Authored-By: dariko <dariko@users.noreply.github.com>

(cherry picked from commit 89bcd3ff1edc082db659c8d646e4cdf9c71d4219)

Dario Zanzico authored on 2018/11/12 20:36:02
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,2 @@
0
+bugfixes:
1
+- "docker_swarm_service - The ``publish``.``mode`` parameter was being ignored if docker-py version was < 3.0.0. Added a parameter validation test."
... ...
@@ -191,6 +191,7 @@ options:
191 191
     - List of dictionaries describing the service published ports.
192 192
     - Every item must be a dictionary exposing the keys published_port, target_port, protocol (defaults to 'tcp'), mode <ingress|host>, default to ingress.
193 193
     - Only used with api_version >= 1.25
194
+    - If api_version >= 1.32 and docker python library >= 3.0.0 attribute 'mode' can be set to 'ingress' or 'host' (default 'ingress').
194 195
   replicas:
195 196
     required: false
196 197
     default: -1
... ...
@@ -458,6 +459,7 @@ EXAMPLES = '''
458 458
 import time
459 459
 from ansible.module_utils.docker_common import DockerBaseClass
460 460
 from ansible.module_utils.docker_common import AnsibleDockerClient
461
+from ansible.module_utils.docker_common import docker_version
461 462
 from ansible.module_utils.basic import human_to_bytes
462 463
 from ansible.module_utils._text import to_text
463 464
 
... ...
@@ -1031,10 +1033,11 @@ class DockerServiceManager():
1031 1031
                          % (pv['param'], pv['min_version'])))
1032 1032
 
1033 1033
         for publish_def in self.client.module.params.get('publish', []):
1034
-            if ('mode' in publish_def.keys() and
1035
-                    (LooseVersion(self.client.version()['ApiVersion']) <
1036
-                     LooseVersion('1.25'))):
1037
-                self.client.module.fail_json(msg='publish.mode parameter supported only with api_version>=1.25')
1034
+            if 'mode' in publish_def.keys():
1035
+                if LooseVersion(self.client.version()['ApiVersion']) < LooseVersion('1.25'):
1036
+                    self.client.module.fail_json(msg='publish.mode parameter supported only with api_version>=1.25')
1037
+                if LooseVersion(docker_version) < LooseVersion('3.0.0'):
1038
+                    self.client.module.fail_json(msg='publish.mode parameter requires docker python library>=3.0.0')
1038 1039
 
1039 1040
     def run(self):
1040 1041
         self.test_parameter_versions()